ManualControl

Dependencies:   TPixy-Interface

Fork of MbedOS_Robot_Team by ECE4333 - 2018 - Ahmed & Brandon

Committer:
asobhy
Date:
Thu Feb 01 03:58:00 2018 +0000
Revision:
0:a355e511bc5d
Child:
8:a0890fa79084
before testing the QEI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
asobhy 0:a355e511bc5d 1 #include "mbed.h"
asobhy 0:a355e511bc5d 2
asobhy 0:a355e511bc5d 3 osThreadId WatchdogId;
asobhy 0:a355e511bc5d 4 osTimerId oneShot;
asobhy 0:a355e511bc5d 5
asobhy 0:a355e511bc5d 6
asobhy 0:a355e511bc5d 7 // Function prototypes
asobhy 0:a355e511bc5d 8 void WatchdogISR(void const *n);
asobhy 0:a355e511bc5d 9 void WatchdogThread(void const *argument);
asobhy 0:a355e511bc5d 10
asobhy 0:a355e511bc5d 11 // Declare WatchdogThread as a thread/process
asobhy 0:a355e511bc5d 12 osTimerDef(Wdtimer, WatchdogISR);
asobhy 0:a355e511bc5d 13
asobhy 0:a355e511bc5d 14 /******************************************************************************/
asobhy 0:a355e511bc5d 15 // osPriorityIdle = -3, ///< priority: idle (lowest)
asobhy 0:a355e511bc5d 16 // osPriorityLow = -2, ///< priority: low
asobhy 0:a355e511bc5d 17 // osPriorityBelowNormal = -1, ///< priority: below normal
asobhy 0:a355e511bc5d 18 // osPriorityNormal = 0, ///< priority: normal (default)
asobhy 0:a355e511bc5d 19 // osPriorityAboveNormal = +1, ///< priority: above normal
asobhy 0:a355e511bc5d 20 // osPriorityHigh = +2, ///< priority: high
asobhy 0:a355e511bc5d 21 // osPriorityRealtime = +3, ///< priority: realtime (highest)
asobhy 0:a355e511bc5d 22 /******************************************************************************/
asobhy 0:a355e511bc5d 23
asobhy 0:a355e511bc5d 24 // Declare WatchdogThread as a thread/process
asobhy 0:a355e511bc5d 25 osThreadDef(WatchdogThread, osPriorityRealtime, 1024);
asobhy 0:a355e511bc5d 26
asobhy 0:a355e511bc5d 27 DigitalOut led1(LED1);
asobhy 0:a355e511bc5d 28
asobhy 0:a355e511bc5d 29
asobhy 0:a355e511bc5d 30 bool WatchdogThreadInit()
asobhy 0:a355e511bc5d 31 {
asobhy 0:a355e511bc5d 32 bool retval;
asobhy 0:a355e511bc5d 33
asobhy 0:a355e511bc5d 34 WatchdogId = osThreadCreate(osThread(WatchdogThread), NULL);
asobhy 0:a355e511bc5d 35
asobhy 0:a355e511bc5d 36 if(WatchdogId)
asobhy 0:a355e511bc5d 37 {
asobhy 0:a355e511bc5d 38 // Start the watch dog timer and enable the watch dog interrupt
asobhy 0:a355e511bc5d 39 oneShot = osTimerCreate(osTimer(Wdtimer), osTimerOnce, (void *)0);
asobhy 0:a355e511bc5d 40 retval = true;
asobhy 0:a355e511bc5d 41 }
asobhy 0:a355e511bc5d 42 else
asobhy 0:a355e511bc5d 43 {
asobhy 0:a355e511bc5d 44 retval = false;
asobhy 0:a355e511bc5d 45 }
asobhy 0:a355e511bc5d 46
asobhy 0:a355e511bc5d 47 return retval;
asobhy 0:a355e511bc5d 48
asobhy 0:a355e511bc5d 49 }
asobhy 0:a355e511bc5d 50
asobhy 0:a355e511bc5d 51
asobhy 0:a355e511bc5d 52 /*******************************************************************************
asobhy 0:a355e511bc5d 53 * ******** Watchdog Reset ********
asobhy 0:a355e511bc5d 54 *******************************************************************************/
asobhy 0:a355e511bc5d 55 void WatchdogReset(void)
asobhy 0:a355e511bc5d 56 {
asobhy 0:a355e511bc5d 57 led1=0; // Turn LED off.
asobhy 0:a355e511bc5d 58 // Start or restart the watchdog timer interrupt and set to 2000ms.
asobhy 0:a355e511bc5d 59 osTimerStart(oneShot, 2000);
asobhy 0:a355e511bc5d 60 }
asobhy 0:a355e511bc5d 61
asobhy 0:a355e511bc5d 62
asobhy 0:a355e511bc5d 63 /*******************************************************************************
asobhy 0:a355e511bc5d 64 * ******** Watchdog Thread ********
asobhy 0:a355e511bc5d 65 *******************************************************************************/
asobhy 0:a355e511bc5d 66 static void WatchdogThread(void const *argument)
asobhy 0:a355e511bc5d 67 {
asobhy 0:a355e511bc5d 68 while (true)
asobhy 0:a355e511bc5d 69 {
asobhy 0:a355e511bc5d 70 // Go to sleep until a signal, SignalWatchdog, is received
asobhy 0:a355e511bc5d 71 osSignalWait(0x01, osWaitForever);
asobhy 0:a355e511bc5d 72 led1 = 1;
asobhy 0:a355e511bc5d 73 }
asobhy 0:a355e511bc5d 74
asobhy 0:a355e511bc5d 75 }
asobhy 0:a355e511bc5d 76
asobhy 0:a355e511bc5d 77
asobhy 0:a355e511bc5d 78 /*******************************************************************************
asobhy 0:a355e511bc5d 79 * ******** Watchdog Interrupt Handler ********
asobhy 0:a355e511bc5d 80 *******************************************************************************/
asobhy 0:a355e511bc5d 81 void WatchdogISR(void const *n)
asobhy 0:a355e511bc5d 82 {
asobhy 0:a355e511bc5d 83 // Send signal to thread with ID, WatchdogId, i.e., WatchdogThread
asobhy 0:a355e511bc5d 84 osSignalSet(WatchdogId,0x01);
asobhy 0:a355e511bc5d 85 }