Skip to content

Commit

Permalink
Merge branch 'wdt_rework' of https://github.com/davids5/core-common-lib
Browse files Browse the repository at this point in the history
… into davids5-wdt_rework

Conflicts:
	SPARK_Firmware_Driver/src/hw_config.c
  • Loading branch information
towynlin committed Mar 17, 2014
2 parents cb78bf7 + 1a222a6 commit 712fb20
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 20 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
8 changes: 7 additions & 1 deletion SPARK_Firmware_Driver/inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
#define RELEASE_BUILD
#undef DEBUG_BUILD
#endif
//#define USE_ONLY_PANIC // Define to remove all Logging and only have Panic


#if defined(DEBUG_BUILD)
#define DBGMCU_SETTINGS (DBGMCU_CR_DBG_SLEEP|DBGMCU_CR_DBG_STOP|DBGMCU_CR_DBG_STANDBY|DBGMCU_CR_DBG_IWDG_STOP|DBGMCU_CR_DBG_WWDG_STOP)
#else
#define USE_ONLY_PANIC // Define to remove all Logging and only have Panic
#define DBGMCU_SETTINGS (DBGMCU_CR_DBG_IWDG_STOP|DBGMCU_CR_DBG_WWDG_STOP)
#endif
// define to include __FILE__ information within the debug output
#define INCLUDE_FILE_INFO_IN_DEBUG
#define MAX_DEBUG_MESSAGE_LENGTH 120
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 @@ -30,6 +30,7 @@

#include <limits.h>
#include "platform_config.h"
#include "config.h"
#include "sst25vf_spi.h"
#include "cc3000_common.h"
#include "usb_type.h"
Expand Down Expand Up @@ -274,4 +275,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)

35 changes: 21 additions & 14 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 @@ -227,13 +232,20 @@ void Delay(uint32_t nTime)
*******************************************************************************/
void Delay_Microsecond(uint32_t uSec)
{
volatile uint32_t DWT_START = DWT->CYCCNT;
volatile uint32_t DWT_START = DWT->CYCCNT;

// keep DWT_TOTAL from overflowing (max 59.652323s w/72MHz SystemCoreClock)
if(uSec > (UINT_MAX/SYSTEM_US_TICKS)) uSec = (UINT_MAX/SYSTEM_US_TICKS);
// keep DWT_TOTAL from overflowing (max 59.652323s w/72MHz SystemCoreClock)
if (uSec > (UINT_MAX / SYSTEM_US_TICKS))
{
uSec = (UINT_MAX / SYSTEM_US_TICKS);
}

volatile uint32_t DWT_TOTAL = (SYSTEM_US_TICKS * uSec);
while((DWT->CYCCNT - DWT_START) < DWT_TOTAL);
volatile uint32_t DWT_TOTAL = (SYSTEM_US_TICKS * uSec);

while((DWT->CYCCNT - DWT_START) < DWT_TOTAL)
{
KICK_WDT();
}
}

void RTC_Configuration(void)
Expand Down Expand Up @@ -333,21 +345,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 @@ -1750,4 +1758,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 712fb20

Please sign in to comment.