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: ExternalInterruptThread.cpp
asobhy 8:a0890fa79084 9 // file content description:
asobhy 8:a0890fa79084 10 // * Function to create the External Interrupt Thread
asobhy 8:a0890fa79084 11 // * ExternalInterruptThread
asobhy 8:a0890fa79084 12 // * ExternalInterrupt ISR
asobhy 8:a0890fa79084 13 /******************************************************************************/
asobhy 9:fe56b888985c 14
asobhy 0:a355e511bc5d 15 #include "mbed.h"
asobhy 0:a355e511bc5d 16
asobhy 0:a355e511bc5d 17 void ExtInterruptISR(void);
asobhy 0:a355e511bc5d 18 void ExtInterruptThread(void const *argument);
asobhy 0:a355e511bc5d 19
asobhy 0:a355e511bc5d 20 osThreadId ExtInterruptId;
asobhy 0:a355e511bc5d 21
asobhy 0:a355e511bc5d 22 osThreadDef(ExtInterruptThread, osPriorityHigh, 1024); // Declare ExtInterruptThread as a thread/process
asobhy 0:a355e511bc5d 23
asobhy 0:a355e511bc5d 24 InterruptIn Bumper(p8); // External interrupt pin declared as Bumper
asobhy 0:a355e511bc5d 25
asobhy 0:a355e511bc5d 26 DigitalOut led2(LED2);
asobhy 0:a355e511bc5d 27
asobhy 0:a355e511bc5d 28
asobhy 7:73fd05fe556a 29 /*******************************************************************************
asobhy 7:73fd05fe556a 30 * @brief This is the initialization function for ExternalInterruptthread
asobhy 7:73fd05fe556a 31 * @param none
asobhy 7:73fd05fe556a 32 * @return none
asobhy 7:73fd05fe556a 33 *******************************************************************************/
asobhy 0:a355e511bc5d 34 void ExternalInterruptThreadInit()
asobhy 0:a355e511bc5d 35 {
asobhy 0:a355e511bc5d 36 Bumper.rise(&ExtInterruptISR); // Attach the address of the interrupt handler to the rising edge of Bumper
asobhy 0:a355e511bc5d 37 ExtInterruptId = osThreadCreate(osThread(ExtInterruptThread), NULL);
asobhy 0:a355e511bc5d 38 }
asobhy 0:a355e511bc5d 39
asobhy 7:73fd05fe556a 40
asobhy 7:73fd05fe556a 41 /*******************************************************************************
asobhy 7:73fd05fe556a 42 * @brief ******** External Interrupt Thread ********
asobhy 7:73fd05fe556a 43 * @param none
asobhy 7:73fd05fe556a 44 * @return none
asobhy 7:73fd05fe556a 45 *******************************************************************************/
asobhy 0:a355e511bc5d 46 void ExtInterruptThread(void const *argument)
asobhy 0:a355e511bc5d 47 {
asobhy 0:a355e511bc5d 48 while (true) {
asobhy 0:a355e511bc5d 49 osSignalWait(0x01, osWaitForever); // Go to sleep until signal, SignalExtCollision, is received
asobhy 0:a355e511bc5d 50 led2 = !led2;
asobhy 0:a355e511bc5d 51 }
asobhy 0:a355e511bc5d 52 }
asobhy 0:a355e511bc5d 53
asobhy 0:a355e511bc5d 54
asobhy 7:73fd05fe556a 55 /*******************************************************************************
asobhy 7:73fd05fe556a 56 * @brief ******** External Interrupt ISR ********
asobhy 7:73fd05fe556a 57 * @param none
asobhy 7:73fd05fe556a 58 * @return none
asobhy 7:73fd05fe556a 59 *******************************************************************************/
asobhy 0:a355e511bc5d 60 void ExtInterruptISR(void)
asobhy 0:a355e511bc5d 61 {
asobhy 0:a355e511bc5d 62 osSignalSet(ExtInterruptId,0x01); // Send signal to the thread with ID, ExtInterruptId, i.e., ExtInterruptThread.
asobhy 0:a355e511bc5d 63 }