ManualControl

Dependencies:   TPixy-Interface

Fork of MbedOS_Robot_Team by ECE4333 - 2018 - Ahmed & Brandon

Committer:
asobhy
Date:
Tue Apr 10 20:54:37 2018 +0000
Branch:
ManualControl
Revision:
29:83c103d12078
Parent:
9:fe56b888985c
ManualControl

Who changed what in which revision?

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