Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
wdt.cpp@137:32dd35a6dbc9, 2015-11-24 (annotated)
- Committer:
- klauss
- Date:
- Tue Nov 24 14:06:22 2015 +0000
- Revision:
- 137:32dd35a6dbc9
- Parent:
- 121:ee02790d00b7
core source of the .bin (09/21/2015) in the field
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
klauss | 17:67a6b557eda5 | 1 | #include "wdt.h" |
klauss | 17:67a6b557eda5 | 2 | |
klauss | 17:67a6b557eda5 | 3 | /// Watchdog gets instantiated at the module level |
klauss | 17:67a6b557eda5 | 4 | Watchdog::Watchdog() { |
klauss | 17:67a6b557eda5 | 5 | wdreset = (LPC_WDT->MOD >> 2) & 1; // capture the cause of the previous reset |
klauss | 17:67a6b557eda5 | 6 | } |
klauss | 17:67a6b557eda5 | 7 | |
klauss | 17:67a6b557eda5 | 8 | /// Load timeout value in watchdog timer and enable |
klauss | 17:67a6b557eda5 | 9 | void Watchdog::Configure(float s) { |
klauss | 17:67a6b557eda5 | 10 | //LPC_WDT->CLKSEL = 0x1; // Set CLK src to PCLK |
klauss | 17:67a6b557eda5 | 11 | uint32_t clk = 500000 / 4; // WD has a fixed /4 prescaler, and a 500khz oscillator |
klauss | 81:3656f00ab3db | 12 | LPC_WDT->TC = ( uint32_t )( s * ( float )clk ); |
klauss | 17:67a6b557eda5 | 13 | LPC_WDT->MOD = 0x3; // Enabled and Reset |
klauss | 81:3656f00ab3db | 14 | kick(); |
klauss | 17:67a6b557eda5 | 15 | } |
klauss | 17:67a6b557eda5 | 16 | |
klauss | 17:67a6b557eda5 | 17 | /// "Service", "kick" or "feed" the dog - reset the watchdog timer |
klauss | 17:67a6b557eda5 | 18 | /// by writing this required bit pattern |
klauss | 17:67a6b557eda5 | 19 | void Watchdog::kick() { |
Cola | 21:0bd688722e81 | 20 | //x = NVIC_disable_IRQ(); |
klauss | 33:735fd60e96d8 | 21 | /* |
klauss | 33:735fd60e96d8 | 22 | antes de desabilitar as irqs, eu preciso salvar o status delas |
klauss | 33:735fd60e96d8 | 23 | */ |
klauss | 33:735fd60e96d8 | 24 | //IRQn irqn; |
klauss | 33:735fd60e96d8 | 25 | //uint16_t ret = NVIC_GetActive( irqn ); |
klauss | 33:735fd60e96d8 | 26 | //debug_msg( "NVIC_GetActive --%i--", ret ); |
klauss | 33:735fd60e96d8 | 27 | //debug_msg("+"); |
klauss | 33:735fd60e96d8 | 28 | //__disable_irq(); |
klauss | 33:735fd60e96d8 | 29 | //Interrupt ID == 0 -- Exception Number 16 |
klauss | 17:67a6b557eda5 | 30 | LPC_WDT->FEED = 0xAA; |
klauss | 17:67a6b557eda5 | 31 | LPC_WDT->FEED = 0x55; |
klauss | 33:735fd60e96d8 | 32 | |
klauss | 33:735fd60e96d8 | 33 | //__enable_irq(); |
klauss | 33:735fd60e96d8 | 34 | //debug_msg("."); |
klauss | 81:3656f00ab3db | 35 | } |
klauss | 81:3656f00ab3db | 36 | |
klauss | 81:3656f00ab3db | 37 | bool Watchdog::WatchdogCausedReset(){ |
klauss | 81:3656f00ab3db | 38 | return( this->wdreset ); |
klauss | 33:735fd60e96d8 | 39 | } |