Alisa Allaire
/
4180L1_P1WD
j
main.cpp@1:f37bf2328d79, 2018-01-18 (annotated)
- Committer:
- aallaire3
- Date:
- Thu Jan 18 20:10:21 2018 +0000
- Revision:
- 1:f37bf2328d79
- Parent:
- 0:947209d21c35
j
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aallaire3 | 0:947209d21c35 | 1 | #include "mbed.h" |
aallaire3 | 0:947209d21c35 | 2 | |
aallaire3 | 0:947209d21c35 | 3 | DigitalOut redLed(p21); |
aallaire3 | 0:947209d21c35 | 4 | DigitalIn pb(p8); // Pushbutton for redLed |
aallaire3 | 0:947209d21c35 | 5 | DigitalOut led1(LED1); |
aallaire3 | 0:947209d21c35 | 6 | DigitalOut led3(LED3); |
aallaire3 | 0:947209d21c35 | 7 | |
aallaire3 | 0:947209d21c35 | 8 | void kick() { |
aallaire3 | 0:947209d21c35 | 9 | LPC_WDT->WDFEED = 0xAA; |
aallaire3 | 0:947209d21c35 | 10 | LPC_WDT->WDFEED = 0x55; |
aallaire3 | 0:947209d21c35 | 11 | } |
aallaire3 | 0:947209d21c35 | 12 | |
aallaire3 | 0:947209d21c35 | 13 | void kick(float s) { |
aallaire3 | 0:947209d21c35 | 14 | LPC_WDT -> WDCLKSEL = 0x1; |
aallaire3 | 0:947209d21c35 | 15 | uint32_t clk = SystemCoreClock/16; |
aallaire3 | 0:947209d21c35 | 16 | LPC_WDT->WDTC = s * (float)clk; |
aallaire3 | 0:947209d21c35 | 17 | LPC_WDT->WDMOD = 0x3; |
aallaire3 | 0:947209d21c35 | 18 | kick(); |
aallaire3 | 0:947209d21c35 | 19 | } |
aallaire3 | 0:947209d21c35 | 20 | |
aallaire3 | 0:947209d21c35 | 21 | |
aallaire3 | 0:947209d21c35 | 22 | |
aallaire3 | 0:947209d21c35 | 23 | int main() { |
aallaire3 | 0:947209d21c35 | 24 | int count = 0; |
aallaire3 | 0:947209d21c35 | 25 | // Use internal pullup for pushbutton |
aallaire3 | 0:947209d21c35 | 26 | pb.mode(PullUp); |
aallaire3 | 0:947209d21c35 | 27 | |
aallaire3 | 0:947209d21c35 | 28 | // Delay for initial pullup to take effect |
aallaire3 | 0:947209d21c35 | 29 | wait(.001); |
aallaire3 | 0:947209d21c35 | 30 | |
aallaire3 | 1:f37bf2328d79 | 31 | // Indicate watchdog timer reset |
aallaire3 | 0:947209d21c35 | 32 | if((LPC_WDT->WDMOD >> 2) & 1) { |
aallaire3 | 0:947209d21c35 | 33 | led1 = 1; |
aallaire3 | 1:f37bf2328d79 | 34 | } |
aallaire3 | 0:947209d21c35 | 35 | |
aallaire3 | 0:947209d21c35 | 36 | kick(5); // 5 second timeout |
aallaire3 | 0:947209d21c35 | 37 | while(1) { |
aallaire3 | 0:947209d21c35 | 38 | redLed = !pb; |
aallaire3 | 0:947209d21c35 | 39 | led3 = 1; |
aallaire3 | 1:f37bf2328d79 | 40 | // Simulate a fault lockup with infinite loop after a bunch of iterations |
aallaire3 | 0:947209d21c35 | 41 | if (count == 1000000) { |
aallaire3 | 0:947209d21c35 | 42 | while(1){ |
aallaire3 | 0:947209d21c35 | 43 | |
aallaire3 | 0:947209d21c35 | 44 | } |
aallaire3 | 0:947209d21c35 | 45 | } |
aallaire3 | 0:947209d21c35 | 46 | led3 = 0; // led will stay on during fault |
aallaire3 | 0:947209d21c35 | 47 | count++; |
aallaire3 | 0:947209d21c35 | 48 | kick(); |
aallaire3 | 0:947209d21c35 | 49 | } |
aallaire3 | 0:947209d21c35 | 50 | } |