Skip to content

Commit

Permalink
Better IWD handeling
Browse files Browse the repository at this point in the history
  • Loading branch information
david_s5 committed Mar 6, 2014
1 parent 5bdb6f2 commit 1a222a6
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
1 change: 1 addition & 0 deletions CC3000_Host_Driver/evnt_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ hci_event_handler(void *pRetParams, unsigned char *from, long *fromlen)
{
if (tSLInformation.usEventOrDataReceived == 0)
{
KICK_WDT();
volatile system_tick_t now = GetSystem1MsTick();
volatile long elapsed = now - start;
if (elapsed < 0) { // Did we wrap
Expand Down
19 changes: 19 additions & 0 deletions SPARK_Firmware_Driver/inc/hw_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/* Includes ------------------------------------------------------------------*/

#include "platform_config.h"
#include "config.h"
#include "sst25vf_spi.h"
#include "cc3000_common.h"
#include "usb_type.h"
Expand Down Expand Up @@ -273,4 +274,22 @@ extern uint16_t FLASH_OTA_Update_SysFlag;
extern unsigned char wlan_rx_buffer[];
extern unsigned char wlan_tx_buffer[];

enum eSystemHealth {
FIRST_RETRY = 1,
SECOND_RETRY = 2,
THIRD_RETRY = 3,
ENTERED_SparkCoreConfig,
ENTERED_Main,
ENTERED_WLAN_Loop,
ENTERED_Setup,
ENTERED_Loop,
RAN_Loop,
PRESERVE_APP,
};

#define SET_SYS_HEALTH(health) BKP_WriteBackupRegister(BKP_DR1, (health))
#define GET_SYS_HEALTH() BKP_ReadBackupRegister(BKP_DR1)
extern uint16_t sys_health_cache;
#define DECLARE_SYS_HEALTH(health) do { if ((health) > sys_health_cache) {SET_SYS_HEALTH(sys_health_cache=(health));}} while(0)
#define KICK_WDT() IWDG_ReloadCounter()
#endif /*__HW_CONFIG_H*/
5 changes: 3 additions & 2 deletions SPARK_Firmware_Driver/inc/panic_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def_panic_codes(System,RGB_COLOR_RED,OutOfHeap)

def_panic_codes(System,RGB_COLOR_RED,SPIOverRun)

def_panic_codes(Softare,RGB_COLOR_RED,AssertionFailure)
def_panic_codes(Softare,RGB_COLOR_RED,InvalidCase)
def_panic_codes(Sofwtare,RGB_COLOR_RED,AssertionFailure)
def_panic_codes(Sofwtare,RGB_COLOR_RED,InvalidCase)
def_panic_codes(Sofwtare,RGB_COLOR_RED,PureVirtualCall)

20 changes: 10 additions & 10 deletions SPARK_Firmware_Driver/src/hw_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

/* Private variables ---------------------------------------------------------*/
uint8_t USE_SYSTEM_FLAGS = 0; //0, 1
uint16_t sys_health_cache = 0; // Used by the SYS_HEALTH macros store new heath if higher

volatile uint32_t TimingDelay;
volatile uint32_t TimingLED;
Expand Down Expand Up @@ -107,9 +108,13 @@ __IO uint16_t sFLASH_SPI_CR;
* @brief Initialise Data Watchpoint and Trace Register (DWT).
* @param None
* @retval None
*
*
*/

static void DWT_Init(void)
{
DBGMCU->CR |= DBGMCU_SETTINGS;
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
DWT->CYCCNT = 0;
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
Expand Down Expand Up @@ -231,6 +236,7 @@ void Delay_Microsecond(uint32_t uSec)

while (1)
{
KICK_WDT();
volatile uint32_t current_DWT_CYCCNT = DWT->CYCCNT;
volatile long elapsed_DWT_CYCCNT = current_DWT_CYCCNT - last_DWT_CYCCNT;

Expand All @@ -239,7 +245,6 @@ void Delay_Microsecond(uint32_t uSec)
{
elapsed_DWT_CYCCNT = last_DWT_CYCCNT + current_DWT_CYCCNT;
}

if((elapsed_DWT_CYCCNT / SYSTEM_US_TICKS) >= uSec)
{
break;
Expand Down Expand Up @@ -344,21 +349,17 @@ void Enter_STANDBY_Mode(void)

void IWDG_Reset_Enable(uint32_t msTimeout)
{
uint16_t Reload_Value;

if(msTimeout > 10000)
msTimeout = 10000; //Max IWDG timeout that can be set is 10 sec

/* Enable write access to IWDG_PR and IWDG_RLR registers */
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);

/* IWDG counter clock: LSI/256 */
IWDG_SetPrescaler(IWDG_Prescaler_256);

/* IWDG timeout may vary due to LSI frequency dispersion */
Reload_Value = (uint16_t)((msTimeout * 40) / 256); //Assuming LSI Frequency = 40000
/* IWDG timeout may vary due to LSI frequency dispersion */
msTimeout = ((msTimeout * 40) / 256); //Assuming LSI Frequency = 40000
if (msTimeout > 0xfff) msTimeout = 0xfff; // 26214.4

IWDG_SetReload(Reload_Value);
IWDG_SetReload((uint16_t)msTimeout);

/* Reload IWDG counter */
IWDG_ReloadCounter();
Expand Down Expand Up @@ -1761,4 +1762,3 @@ system_tick_t GetSystem1MsTick()
{
return system_1ms_tick;
}

16 changes: 13 additions & 3 deletions SPARK_Firmware_Driver/src/panic.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "hw_config.h"
#include "spark_macros.h"
#include "panic.h"
#include "debug.h"


#define LOOPSPERMSEC 5483
Expand All @@ -33,12 +34,17 @@ static const flash_codes_t flash_codes[] = {
void panic_(ePanicCode code)
{
__disable_irq();
// Flush any serial message to help the poor bugger debug this;
flash_codes_t pcd = flash_codes[code];
LED_SetRGBColor(RGB_COLOR_WHITE);
LED_Off(LED_RGB);
LED_SetRGBColor(RGB_COLOR_RED);
LED_On(LED_RGB);
uint16_t c;
while(1) {
int loops = 2;
if (debug_output_)(debug_output_("!"));
LED_Off(LED_RGB);
while(loops) {
// preamble
KICK_WDT();
for (c = 3; c; c--) {
LED_SetRGBColor(pcd.led);
LED_On(LED_RGB);
Expand Down Expand Up @@ -77,5 +83,9 @@ void panic_(ePanicCode code)
}
// pause
Delay_Microsecond(MS2u(800));
#ifdef RELEASE_BUILD
if (--loops == 0) NVIC_SystemReset();
#endif
}

}

0 comments on commit 1a222a6

Please sign in to comment.