diff options
author | Guillaume Knispel <gknispel@avencall.com> | 2012-10-05 18:32:44 +0200 |
---|---|---|
committer | Guillaume Knispel <gknispel@avencall.com> | 2012-10-05 18:32:44 +0200 |
commit | 42db6f9f644570e0725976ffd79a9073fff9c6f6 (patch) | |
tree | 495baa2290336ca7bc8129ce44b460ebb1e774f2 | |
parent | 6bbe88125feb5bf32b680fd336af9e5232ca40cc (diff) |
implement watchdog
-rw-r--r-- | main.c | 49 |
1 files changed, 43 insertions, 6 deletions
@@ -30,11 +30,16 @@ * with the EP80579 standard ACPI subsystem. Likewise for the reset button. */ +/* define WATCHDOG to get one :) */ +#define WATCHDOG +//#undef WATCHDOG + /* define TRACE_SERIAL to get debugging traces capabilities on the * MSP430 serial port * WARNING: This might disable some functions too, check the code * to see exactly what that does in this particular version */ -#define TRACE_SERIAL +//#define TRACE_SERIAL +#undef TRACE_SERIAL /* define LOOP_REBOOT if you want that the board reboot forever * define it to the number of ms to spend in the WAIT_STOP state. @@ -239,7 +244,9 @@ int main(void) { u16 state, resetState; - WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer to prevent time out reset +#ifndef WATCHDOG + WDTCTL = WDTPW | WDTHOLD; +#endif /* WATCHDOG */ __disable_interrupt(); @@ -433,6 +440,11 @@ int main(void) #pragma vector = TIMERA1_VECTOR __interrupt void Timer_A(void) { +#ifdef WATCHDOG + /* ACLK (VLO) /64 => T belongs to [0.016; 0.0032] s */ + WDTCTL = WDTPW | WDCNTCL | WDTSSEL | WTDIS1 | WTDIS0; +#endif /* WATCHDOG */ + if (!(P1IN & START_SW1_N)) SW1State++; else @@ -491,15 +503,40 @@ static void InitPorts(void) static void GlobalInit(void) { + /******** MCLK SMCLK ACLK Configuration ********/ + /* freq selection procedure compliant with errata BCL12 * (potentially switching from RSEL < 12 to > 13) */ DCOCTL = 0; - BCSCTL1 = CALBC1_12MHZ; + /* LFXT1 low freq (to allow for VLO), ACLK will be /1 */ + BCSCTL1 = CALBC1_12MHZ & ~(XTS | DIVA0 | DIVA1); DCOCTL = CALDCO_12MHZ; - TACTL = TASSEL_2 + ID_3 + TACLR + TAIE + MC_1; // SMCLK + div by 8 + reset + - // enable interrupt + UP + BCSCTL3 = LFXT1S_2 /* VLO */; + + /* Status here: + * MCLK and SMCLK from DCO, 12MHz nominal. + * ACLK from VLOCLK, 4 -> 20kHz. + */ + + +#ifdef WATCHDOG + /******** Watchdog early configuration ********/ + + /* ACLK /8192 */ + WDTCTL = WDTPW + WDCNTCL + WDTSSEL + WTDIS0; + /* This initial WDT will expire in 0.4 to 2.1 s + * Note that it will be reconfigured to expire with shorter intervals + * starting from the next clearing. + */ +#endif /* WATCHDOG */ + + + /******** Timer A configuration ********/ + + TACTL = TASSEL_2 | ID_3 | TACLR | TAIE | MC_1; // SMCLK | div by 8 | reset | + // enable interrupt | UP // Calibrated DCO Frequencies - Tolerance Over Temperature 0C to 85C // @@ -517,5 +554,5 @@ static void GlobalInit(void) // >>> 1539 / 1500000. * 1.025 // 0.00105165 1.052 ms max - TACCR0 = 1539 + 1; /* TA16 errata */ + TACCR0 = 1539 + 1; /* TA16 errata => + 1 => so T belongs to [1.000 ; 1.053] */ } |