Skip to content

Commit eafdb73

Browse files
committed
add software watchdog
1 parent 50a8413 commit eafdb73

File tree

10 files changed

+55
-6
lines changed

10 files changed

+55
-6
lines changed

examples/ex14/config.h

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#define FF_I2C_MASTER_SPEED 100
1919

20+
//#define FF_SYS_SW_WATCHDOG 10
21+
2022
// complete configuration by including the defaults
2123
#include "defconfig.h"
2224

examples/ex14/ex14.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void appCreateTask(void)
4646
{
4747
static uint8_t stack[250];
4848
static OS_TASK_t task;
49-
osTaskCreate("app", 5, &task, stack, sizeof(stack), sAppTask, NULL);
49+
osTaskCreate("app", 7, &task, stack, sizeof(stack), sAppTask, NULL);
5050
}
5151

5252
/* ***** application functions *********************************************** */

projects/temperaturdings/config.h

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#define FF_SYS_TASK_STACK 260
2323
#define FF_OS_IDLE_STACK 80
2424

25+
// software watchdog
26+
#define FF_SYS_SW_WATCHDOG 16
27+
2528
// gain some memory by disabling serial port receive1
2629
#define FF_HW_RX_BUFSIZE 0
2730

projects/temperaturdings/temperaturdings.c

+3
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,9 @@ static void sAppTask(void *pArg)
523523
// keep running...
524524
while (ENDLESS)
525525
{
526+
// FIXME: need to use sw watchdog as sometimes the i2c stuff hangs :-(
527+
sysAssertSwWatchdog();
528+
526529
if (!osTaskDelayUntil(&sTime, MEAS_PERIOD))
527530
{
528531
WARNING("meas miss");

src/defconfig.h

+5
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@
129129
# define FF_SYS_MON_STRLEN 64
130130
#endif
131131

132+
//! software watchdog period [#SYS_TASK_PERIOD]
133+
#if !defined(FF_SYS_SW_WATCHDOG) || defined(__DOXYGEN__)
134+
# define FF_SYS_SW_WATCHDOG 0
135+
#endif
136+
132137

133138
/* *************************************************************************** */
134139

src/hw.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ __FORCEINLINE void hwLedLoadOff(void) { }
403403
#ifndef __DOXYGEN__ // STFU
404404
const const char skHwPanicStr[][6] PROGMEM =
405405
{
406-
{ "NONE\0" }, { "HW\0" }, { "OS\0" }, { "OTHER\0" }
406+
{ "NONE\0" }, { "HW\0" }, { "OS\0" }, { "SYS\0" }, { "OTHER\0" }
407407
};
408408
#endif
409409

@@ -427,10 +427,14 @@ void hwPanic(const HW_PANIC_t reason, const uint32_t u0, const uint32_t u1)
427427
n = 3;
428428
time = 10000;
429429
break;
430-
case HW_PANIC_OTHER:
430+
case HW_PANIC_SYS:
431431
n = 4;
432432
time = 10000;
433433
break;
434+
case HW_PANIC_OTHER:
435+
n = 5;
436+
time = 10000;
437+
break;
434438
default:
435439
break;
436440
}

src/hw.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ typedef enum HW_PANIC_e
117117
HW_PANIC_NONE = 0, //!< null problemo
118118
HW_PANIC_HW = 1, //!< \ref HW problem (blinks two times)
119119
HW_PANIC_OS = 2, //!< \ref OS problem (blinks three times)
120-
HW_PANIC_OTHER = 3, //!< other problem (blinks four times)
120+
HW_PANIC_SYS = 3, //!< \ref SYS problem (blinks four times)
121+
HW_PANIC_OTHER = 4, //!< other problem (blinks four times)
121122
} HW_PANIC_t;
122123

123124
//! panic! (and display load LED blink code)

src/i2c.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
\addtogroup I2C
88
@{
99
10-
\todo use interrupts?
10+
\todo use interrupts? http://www.chrisherring.net/all/tutorial-interrupt-driven-twi-interface-for-avr-part1/
1111
*/
1212

1313
#include <string.h> // libc: string operations

src/sys.c

+25-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include "hw.h" // ff: hardware
1515
#include "sys.h" // ff: system task
1616

17+
#if ( (FF_SYS_SW_WATCHDOG < 0) || (FF_SYS_SW_WATCHDOG > 255) )
18+
# error Illegal value for FF_SYS_SW_WATCHDOG!
19+
#endif
20+
1721
/* ************************************************************************** */
1822

1923
static uint8_t sSysTaskStack[FF_SYS_TASK_STACK];
@@ -22,7 +26,9 @@ static void sSysTask(void *pArg);
2226

2327
void sysInit(void)
2428
{
25-
DEBUG("sys: init (stack %"PRIu16", mon %"PRIu16")", (uint16_t)sizeof(sSysTaskStack), (uint16_t)FF_SYS_MON_PERIOD);
29+
DEBUG("sys: init (stack %"PRIu16", mon %"PRIu16", prio "PRIu8")",
30+
(uint16_t)sizeof(sSysTaskStack), (uint16_t)FF_SYS_MON_PERIOD,
31+
(uint8_t)FF_SYS_TASK_PRIO);
2632
}
2733

2834
void sysCreateSystemTask(void)
@@ -56,6 +62,14 @@ void sysRegisterMonFunc(SYS_MON_FUNC_t func) { UNUSED(func); }
5662

5763
#define SYS_TASK_PERIOD 1000
5864

65+
#if (FF_SYS_SW_WATCHDOG > 0)
66+
static uint8_t sSysSwWatchdogCount;
67+
void sysAssertSwWatchdog(void)
68+
{
69+
sSysSwWatchdogCount = 0;
70+
}
71+
#endif
72+
5973
static void sSysTask(void *pArg)
6074
{
6175
UNUSED(pArg);
@@ -72,6 +86,16 @@ static void sSysTask(void *pArg)
7286
hwAssertWatchdog();
7387
period++;
7488

89+
#if (FF_SYS_SW_WATCHDOG > 0)
90+
sSysSwWatchdogCount++;
91+
if (sSysSwWatchdogCount >= FF_SYS_SW_WATCHDOG)
92+
{
93+
ERROR("sys: sw watchdog");
94+
osTaskDelay(100);
95+
hwPanic(HW_PANIC_SYS, 0x01, 0x00);
96+
}
97+
#endif
98+
7599
/* ***** stuff to be done every FF_SYS_MON_PERIOD seconds ***** */
76100

77101
#if (FF_SYS_MON_VERBOSE > 0)

src/sys.h

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- #FF_SYS_MON_VERBOSE
1515
- #FF_SYS_TASK_PRIO
1616
- #FF_SYS_TASK_STACK
17+
- #FF_SYS_SW_WATCHDOG
1718
1819
@{
1920
*/
@@ -46,6 +47,12 @@ typedef void (* SYS_MON_FUNC_t)(char *, size_t);
4647
*/
4748
void sysRegisterMonFunc(SYS_MON_FUNC_t func);
4849

50+
//! assert software watchdog
51+
/*!
52+
Asserts the software watchdog. Active only if compiled in by setting #FF_SYS_SW_WATCHDOG > 0.
53+
*/
54+
void sysAssertSwWatchdog(void);
55+
4956

5057
/* *************************************************************************** */
5158

0 commit comments

Comments
 (0)