![](/media/cache/group/logo_lbuWYaA.png.50x50_q85.png)
Basic implementation of watchdog
Dependencies: STM_ResetSupervisor USBDevice
main.cpp@2:50b1371247da, 2019-10-06 (annotated)
- Committer:
- rlanders73
- Date:
- Sun Oct 06 02:59:58 2019 +0000
- Revision:
- 2:50b1371247da
- Parent:
- 1:38b385f34687
using new STM_ResetSupervisor library that has watchdog functionality
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JesiMiranda | 0:975e02a70882 | 1 | #include "mbed.h" |
rlanders73 | 2:50b1371247da | 2 | #include "ResetSupervisor.h" |
JesiMiranda | 0:975e02a70882 | 3 | |
t1jain | 1:38b385f34687 | 4 | int i = 1; |
JesiMiranda | 0:975e02a70882 | 5 | |
rlanders73 | 2:50b1371247da | 6 | #include "USBSerial.h" |
JesiMiranda | 0:975e02a70882 | 7 | |
rlanders73 | 2:50b1371247da | 8 | /******************** Comms *********************/ |
rlanders73 | 2:50b1371247da | 9 | USBSerial pc; |
rlanders73 | 2:50b1371247da | 10 | FileHandle* mbed::mbed_override_console(int) |
rlanders73 | 2:50b1371247da | 11 | { |
rlanders73 | 2:50b1371247da | 12 | return &pc; |
rlanders73 | 2:50b1371247da | 13 | } |
rlanders73 | 2:50b1371247da | 14 | |
rlanders73 | 2:50b1371247da | 15 | Supervisor foreman; |
JesiMiranda | 0:975e02a70882 | 16 | int main(void) |
JesiMiranda | 0:975e02a70882 | 17 | { |
rlanders73 | 2:50b1371247da | 18 | wait(1); |
rlanders73 | 2:50b1371247da | 19 | |
rlanders73 | 2:50b1371247da | 20 | foreman.initWD(5); // turn on the Watchdog Timer and set it for 5 seconds |
rlanders73 | 2:50b1371247da | 21 | if(foreman.resetReason() == RCC_FLAG_IWDGRST) |
rlanders73 | 2:50b1371247da | 22 | pc.printf("Watchdog Reset!\n"); |
JesiMiranda | 0:975e02a70882 | 23 | |
rlanders73 | 2:50b1371247da | 24 | while(1) |
JesiMiranda | 0:975e02a70882 | 25 | { |
rlanders73 | 2:50b1371247da | 26 | pc.printf("Hello! I'm working! Iteration: %d \n", i); |
rlanders73 | 2:50b1371247da | 27 | wait(1); |
rlanders73 | 2:50b1371247da | 28 | |
rlanders73 | 2:50b1371247da | 29 | if (i == 10) { |
rlanders73 | 2:50b1371247da | 30 | wait(10); |
rlanders73 | 2:50b1371247da | 31 | } |
rlanders73 | 2:50b1371247da | 32 | |
rlanders73 | 2:50b1371247da | 33 | |
rlanders73 | 2:50b1371247da | 34 | foreman.pingWD(); |
rlanders73 | 2:50b1371247da | 35 | i++; |
JesiMiranda | 0:975e02a70882 | 36 | } |
JesiMiranda | 0:975e02a70882 | 37 | } |