Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-rtos ECE4333Lab3
Fork of ECE4333Lab3 by
Revision 1:79e780124b58, committed 2016-02-03
- Comitter:
- JordanWisdom
- Date:
- Wed Feb 03 17:41:51 2016 +0000
- Parent:
- 0:a046f7397436
- Child:
- 2:f1ce213d3367
- Commit message:
- Made it pretty for Adam.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Feb 03 17:30:19 2016 +0000
+++ b/main.cpp Wed Feb 03 17:41:51 2016 +0000
@@ -10,10 +10,13 @@
void PiControlThread(void const *argument);
void ExtCollisionThread(void const *argument);
void Watchdog(void const *n);
+
// Global variables for interrupt handler
int Position;
+
// Processes and threads
int32_t SignalPi, SignalWdt, SignalExtCollision;
+
osThreadId PiControl,WdtFault,ExtCollision;
osThreadDef(PiControlThread, osPriorityRealtime, DEFAULT_STACK_SIZE); // Declare Control as a thread/process
osThreadDef(ExtCollisionThread, osPriorityHigh, DEFAULT_STACK_SIZE); // Declare External Collision as a thread/process
@@ -25,6 +28,7 @@
// osPriorityAboveNormal = +1, ///< priority: above normal
// osPriorityHigh = +2, ///< priority: high
// osPriorityRealtime = +3, ///< priority: realtime (highest)
+
// IO Port Configuration
DigitalOut led1(LED1);
DigitalOut led2(LED2);
@@ -33,64 +37,74 @@
Serial pc(USBTX, USBRX); // Pins (tx, rx) for PC serial channel
Ticker PeriodicInt; // Declare a timer interrupt: PeriodicInt
InterruptIn Bumper(p8); // External interrupt pin declared as Bumper
+
+
// ******** Main Thread ********
int main() { // This thread executes first upon reset or power-on.
-char x;
-// Attach the address of the ExtCollisionISR to the rising edge of Bumper:
-Bumper.rise(&ExtCollisionISR);
-// Start execution of the threads: PiControlThread and ExtCollisionThread:
-PiControl = osThreadCreate(osThread(PiControlThread), NULL);
-ExtCollision = osThreadCreate(osThread(ExtCollisionThread), NULL);
-// Start the watch dog timer and enable the watch dog interrupt
-osTimerId OneShot = osTimerCreate(osTimer(Wdtimer), osTimerOnce, (void *)0);
-pc.printf("\r\n RTOS Template Program");
-// May prompt user for input data here:
-// Specify address of the PeriodicInt ISR as PiControllerISR, specify the interval
-// in seconds between interrupts, and start interrupt generation:
-PeriodicInt.attach(&PiControllerISR, .05);
-do {
- if (pc.readable()){
- x=pc.getc();
- pc.putc(x); // Echo keyboard entry
-// Start or restart the watchdog timer interrupt and set to 2000ms.
- osTimerStart(OneShot, 2000);
- led3=0; // Clear watch dog led3 status
- led4=0;
- }
- // Display variables at the terminal emulator for logging:
- pc.printf("\r\n%6d", Position); // The terminal emulator may be configured to
- // store received data to a file
- Thread::wait(500); // Go to sleep for 500 ms
+ char x;
+ // Attach the address of the ExtCollisionISR to the rising edge of Bumper:
+ Bumper.rise(&ExtCollisionISR);
+
+ // Start execution of the threads: PiControlThread and ExtCollisionThread:
+ PiControl = osThreadCreate(osThread(PiControlThread), NULL);
+ ExtCollision = osThreadCreate(osThread(ExtCollisionThread), NULL);
+
+ // Start the watch dog timer and enable the watch dog interrupt
+ osTimerId OneShot = osTimerCreate(osTimer(Wdtimer), osTimerOnce, (void *)0);
+ pc.printf("\r\n RTOS Template Program");
+
+ // May prompt user for input data here:
+ // Specify address of the PeriodicInt ISR as PiControllerISR, specify the interval
+ // in seconds between interrupts, and start interrupt generation:
+ PeriodicInt.attach(&PiControllerISR, .05);
+ do {
+ if (pc.readable()){
+ x=pc.getc();
+ pc.putc(x); // Echo keyboard entry
+ // Start or restart the watchdog timer interrupt and set to 2000ms.
+ osTimerStart(OneShot, 2000);
+ led3=0; // Clear watch dog led3 status
+ led4=0;
+ }
+ // Display variables at the terminal emulator for logging:
+ pc.printf("\r\n%6d", Position); // The terminal emulator may be configured to
+ // store received data to a file
+ Thread::wait(500); // Go to sleep for 500 ms
+ }
+ while(1);
}
-while(1);
-}
+
// ******** Control Thread ********
void PiControlThread(void const *argument) {
-while (true) {
- osSignalWait(SignalPi, osWaitForever); // Go to sleep until, SignalPi, is received.
- led2= !led2; // Alive status - led2 toggles each time PiControlThread is signaled.
- Position = Position + 1;
- }
+ while (true) {
+ osSignalWait(SignalPi, osWaitForever); // Go to sleep until, SignalPi, is received.
+ led2= !led2; // Alive status - led2 toggles each time PiControlThread is signaled.
+ Position = Position + 1;
+ }
}
+
// ******** Collision Thread ********
void ExtCollisionThread(void const *argument) {
-while (true) {
- // Go to sleep until signal, SignalExtCollision, is received:
- osSignalWait(SignalExtCollision, osWaitForever);
- led4 = 1;
- }
+ while (true) {
+ // Go to sleep until signal, SignalExtCollision, is received:
+ osSignalWait(SignalExtCollision, osWaitForever);
+ led4 = 1;
+ }
}
+
// ******** Watchdog Interrupt Handler ********
void Watchdog(void const *n) {
- led3=1; // led3 is activated when the watchdog timer times out
+ led3=1; // led3 is activated when the watchdog timer times out
}
+
// ******** Period Timer Interrupt Handler ********
void PiControllerISR(void) {
- // Activate the signal, PiControl, with each periodic timer interrupt.
- osSignalSet(PiControl,0x1); }
+ // Activate the signal, PiControl, with each periodic timer interrupt.
+ osSignalSet(PiControl,0x1);
+}
// ******** Collision Interrupt Handler ********
void ExtCollisionISR(void) {
- // Activate the signal, ExtCollision, with each pexternal interrupt.
- osSignalSet(ExtCollision,0x1);
- }
+ // Activate the signal, ExtCollision, with each pexternal interrupt.
+ osSignalSet(ExtCollision,0x1);
+}
