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