Toyomasa Watarai
/
Watchdog-test-lpc824
Windowed Watchdog Timer (WWDT) example code for the LPC824
main.cpp@0:3d3dd1e8cfd0, 2015-08-05 (annotated)
- Committer:
- MACRUM
- Date:
- Wed Aug 05 14:33:36 2015 +0000
- Revision:
- 0:3d3dd1e8cfd0
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MACRUM | 0:3d3dd1e8cfd0 | 1 | /* |
MACRUM | 0:3d3dd1e8cfd0 | 2 | Windowed Watchdog Timer (WWDT) example code for the LPC824 |
MACRUM | 0:3d3dd1e8cfd0 | 3 | */ |
MACRUM | 0:3d3dd1e8cfd0 | 4 | |
MACRUM | 0:3d3dd1e8cfd0 | 5 | #include "mbed.h" |
MACRUM | 0:3d3dd1e8cfd0 | 6 | |
MACRUM | 0:3d3dd1e8cfd0 | 7 | Serial pc(USBTX, USBRX); |
MACRUM | 0:3d3dd1e8cfd0 | 8 | |
MACRUM | 0:3d3dd1e8cfd0 | 9 | void kick(float s); |
MACRUM | 0:3d3dd1e8cfd0 | 10 | void feed(); |
MACRUM | 0:3d3dd1e8cfd0 | 11 | |
MACRUM | 0:3d3dd1e8cfd0 | 12 | void kick(float s) |
MACRUM | 0:3d3dd1e8cfd0 | 13 | { |
MACRUM | 0:3d3dd1e8cfd0 | 14 | LPC_SYSCON->WDTOSCCTRL = (0xA << 5); // wdt_osc_clk = Fclkana/2, Fclkana = 3.5MHz |
MACRUM | 0:3d3dd1e8cfd0 | 15 | LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 17); // Enable Clock WWDT |
MACRUM | 0:3d3dd1e8cfd0 | 16 | LPC_SYSCON->PDRUNCFG &= ~(1 << 6); // Enable Power WDTOSC_PD |
MACRUM | 0:3d3dd1e8cfd0 | 17 | uint32_t clk = ((3500000/2)/4); // COUNT = wdt_osc_clk/4 |
MACRUM | 0:3d3dd1e8cfd0 | 18 | LPC_WWDT->TC = s * (float)clk; |
MACRUM | 0:3d3dd1e8cfd0 | 19 | LPC_WWDT->MOD = 0x3; // Enabled and Reset |
MACRUM | 0:3d3dd1e8cfd0 | 20 | feed(); |
MACRUM | 0:3d3dd1e8cfd0 | 21 | } |
MACRUM | 0:3d3dd1e8cfd0 | 22 | |
MACRUM | 0:3d3dd1e8cfd0 | 23 | void feed() |
MACRUM | 0:3d3dd1e8cfd0 | 24 | { |
MACRUM | 0:3d3dd1e8cfd0 | 25 | LPC_WWDT->FEED = 0xAA; |
MACRUM | 0:3d3dd1e8cfd0 | 26 | LPC_WWDT->FEED = 0x55; |
MACRUM | 0:3d3dd1e8cfd0 | 27 | } |
MACRUM | 0:3d3dd1e8cfd0 | 28 | |
MACRUM | 0:3d3dd1e8cfd0 | 29 | int main() |
MACRUM | 0:3d3dd1e8cfd0 | 30 | { |
MACRUM | 0:3d3dd1e8cfd0 | 31 | pc.printf("\nProgram start.\n"); |
MACRUM | 0:3d3dd1e8cfd0 | 32 | kick(2.5); |
MACRUM | 0:3d3dd1e8cfd0 | 33 | |
MACRUM | 0:3d3dd1e8cfd0 | 34 | int count = 0; |
MACRUM | 0:3d3dd1e8cfd0 | 35 | while(1) { |
MACRUM | 0:3d3dd1e8cfd0 | 36 | wait(0.2); |
MACRUM | 0:3d3dd1e8cfd0 | 37 | if (count < 10) { |
MACRUM | 0:3d3dd1e8cfd0 | 38 | feed(); |
MACRUM | 0:3d3dd1e8cfd0 | 39 | pc.printf("*"); |
MACRUM | 0:3d3dd1e8cfd0 | 40 | } |
MACRUM | 0:3d3dd1e8cfd0 | 41 | count++; |
MACRUM | 0:3d3dd1e8cfd0 | 42 | } |
MACRUM | 0:3d3dd1e8cfd0 | 43 | } |