UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
watchdog_int.c
1 // this is development code to aid in implementing watchdog kicking on interrupt
2 
3 // not necessarily in Uos3 Cubesat flight software - risk that automatically kicking on interrupt
4 
5 // might prevent watchdog timer resetting when operation has actually failed
6 
7 // could set a flag regularly, but actual kicking should be done as far as possible explicitly
8 
9 //
10 
11 // Two ways to initialise the interrupt. Dynamically with TimerIntRegister, or statically by setting
12 // the define variable TIMER0A to the routine name (with my modified tm4c_startup_gcc.c this works)
13 
14 // (C) Suzanna Lucarotti 20/9/17
15 
16 // Developed for Uos3 Cubesat
17 
18 
19 //#define TIMER0A Timer0IntHandler // this is for static interrupt compilation
20 
21 //#include "../firmware.h"
22 #include "board.h"
23 #include "../watchdog_int.h"
24 
25 // this code is evolved from an online purdue uni tutorial and the ti peripheral driver manual
26 
27 #include "inc/hw_ints.h"
28 #include "inc/hw_memmap.h"
29 #include "inc/hw_types.h"
30 #include "driverlib/sysctl.h"
31 #include "driverlib/interrupt.h"
32 #include "driverlib/gpio.h"
33 #include "driverlib/timer.h"
34 #include "../led.h"
35 
36 void Timer0IntHandler(void)
37 {
38 // Clear the timer interrupt
39  TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
40  WDT_kick(); // kick the watchdog
41  LED_toggle(LED_B);
42 }
43 void setupwatchdoginterrupt(void)
44  {
45  unsigned long ulPeriod;
46  SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // turn on timer
47  while (!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0)) {} // wait for timer to be ready
48  TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); // set it to periodically trigger interrupt
49  ulPeriod = (SysCtlClockGet() / 4) ; // how often it triggers (counts down) (half will miss watchdog)
50  // third will miss sometimes if processor busy
51  TimerLoadSet(TIMER0_BASE, TIMER_A, ulPeriod-1); // prime it
52  TimerIntRegister(TIMER0_BASE,TIMER_A,Timer0IntHandler); // this is for dynamic interrupt compilation
53  TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // enable interrupt
54  TimerEnable(TIMER0_BASE, TIMER_A); // start timer
55  }
void WDT_kick(void)
Definition: wdt.c:19