#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
static int dogDelay;

void watchdogInit(void) 
{
  dogDelay = 0;
  
  WDTCTL = WDT_ADLY_1000;                 // Set Watchdog Timer interval to 1 sec
  IE1 |= WDTIE;                         // Enable WDT interrupt
  _EINT();                              // Enable interrupts
}

void watchdogDelay(int delaySec)
{
  dogDelay = delaySec;
  while (dogDelay > 0) ;
}

// 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
{

  if (dogDelay > 0)
    dogDelay--;
     
  // bump the rtc
 
  _EINT();

}

