VZTECH / Mbed 2 deprecated main_src

Dependencies:   EALib EthernetInterface_vz mbed-rtos mbed

Fork of header_main_colinas_V0-20-09-14 by VZTECH

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers wdt.cpp Source File

wdt.cpp

00001 #include "wdt.h"
00002  
00003  /// Watchdog gets instantiated at the module level
00004 Watchdog::Watchdog() {
00005     wdreset = (LPC_WDT->MOD >> 2) & 1;    // capture the cause of the previous reset
00006 }
00007  
00008 /// Load timeout value in watchdog timer and enable
00009 void Watchdog::Configure(float s) {
00010     //LPC_WDT->CLKSEL = 0x1;                // Set CLK src to PCLK
00011     uint32_t clk = 500000 / 4;    // WD has a fixed /4 prescaler, and a 500khz oscillator
00012     LPC_WDT->TC = ( uint32_t )( s * ( float )clk );
00013     LPC_WDT->MOD = 0x3;                   // Enabled and Reset
00014     kick();
00015 }
00016  
00017 /// "Service", "kick" or "feed" the dog - reset the watchdog timer
00018 /// by writing this required bit pattern
00019 void Watchdog::kick() {
00020     //x = NVIC_disable_IRQ();
00021     /*
00022         antes de desabilitar as irqs, eu preciso salvar o status delas
00023     */
00024     //IRQn irqn;
00025     //uint16_t ret = NVIC_GetActive( irqn );
00026     //debug_msg( "NVIC_GetActive --%i--", ret );
00027     //debug_msg("+");
00028     //__disable_irq();
00029     //Interrupt ID == 0 -- Exception Number 16
00030     LPC_WDT->FEED = 0xAA;
00031     LPC_WDT->FEED = 0x55;
00032     
00033     //__enable_irq();
00034     //debug_msg(".");
00035 }
00036 
00037 bool Watchdog::WatchdogCausedReset(){
00038     return( this->wdreset );
00039 }