System Management code
Dependencies: CANBuffer mbed SystemManagement mbed-rtos
System Management code for Penn Electric Racing
Functions:
Controls Fans and Pumps via instruction from CAN Messages, ramps them up over time to prevent damage
Turns on/off DC-DC converter via instruction from CAN Messages
Watchdog/Watchdog.cpp@7:5f6e31faa08e, 2014-10-10 (annotated)
- Committer:
- martydd3
- Date:
- Fri Oct 10 20:59:36 2014 +0000
- Revision:
- 7:5f6e31faa08e
- Parent:
- 6:6a04210a3f4f
PollSwitch code;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
martydd3 | 6:6a04210a3f4f | 1 | // Simon's Watchdog code from |
martydd3 | 6:6a04210a3f4f | 2 | // http://mbed.org/forum/mbed/topic/508/ |
martydd3 | 6:6a04210a3f4f | 3 | |
martydd3 | 6:6a04210a3f4f | 4 | #include "mbed.h" |
martydd3 | 6:6a04210a3f4f | 5 | |
martydd3 | 6:6a04210a3f4f | 6 | class Watchdog { |
martydd3 | 6:6a04210a3f4f | 7 | public: |
martydd3 | 6:6a04210a3f4f | 8 | // Load timeout value in watchdog timer and enable |
martydd3 | 6:6a04210a3f4f | 9 | void kick(float s) { |
martydd3 | 6:6a04210a3f4f | 10 | LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK |
martydd3 | 6:6a04210a3f4f | 11 | uint32_t clk = SystemCoreClock / 16; // WD has a fixed /4 prescaler, PCLK default is /4 |
martydd3 | 6:6a04210a3f4f | 12 | LPC_WDT->WDTC = s * (float)clk; |
martydd3 | 6:6a04210a3f4f | 13 | LPC_WDT->WDMOD = 0x3; // Enabled and Reset |
martydd3 | 6:6a04210a3f4f | 14 | kick(); |
martydd3 | 6:6a04210a3f4f | 15 | } |
martydd3 | 6:6a04210a3f4f | 16 | // "kick" or "feed" the dog - reset the watchdog timer |
martydd3 | 6:6a04210a3f4f | 17 | // by writing this required bit pattern |
martydd3 | 6:6a04210a3f4f | 18 | void kick() { |
martydd3 | 6:6a04210a3f4f | 19 | LPC_WDT->WDFEED = 0xAA; |
martydd3 | 6:6a04210a3f4f | 20 | LPC_WDT->WDFEED = 0x55; |
martydd3 | 6:6a04210a3f4f | 21 | } |
martydd3 | 6:6a04210a3f4f | 22 | }; |