#include <msp430x14x.h>
#include <stdio.h>

#include "basic.h"
#include "config.h"
#include "errnum.h"
#include "eventq.h"

// NOTE: watchdog timer should be clocked by ACLK (32 KHz) for 1 sec intervals

void watchdogInit(void) 
{
  WDTCTL = WDT_ADLY_1000;                 // Set Watchdog Timer interval to 1 sec
  IE1 |= WDTIE;                         // Enable WDT interrupt
  _EINT();                              // Enable interrupts
}

// Watchdog Timer interrupt service routine
#if __VER__ < 200
interrupt [ WDT_VECTOR ] void watchdog_timer( void )
#else
#pragma vector=WDT_VECTOR
__interrupt void watchdog_timer( void )
#endif
{
  // bring the processor out of sleep mode
  // _BIC_SR_IRQ(LPM3_bits);             // Clear LPM3 bits from 0(SR)
 
  // bump the rtc
  eventqPut(EVENTQ_EVENT_RTCTICK);
  eventqPut(EVENTQ_EVENT_TIMERTICK);
  _EINT();

}

