PlayBack
Dependencies: TPixy-Interface
Fork of ObjectFollower by
ExternalInterruptThread.cpp@8:a0890fa79084, 2018-02-19 (annotated)
- Committer:
- asobhy
- Date:
- Mon Feb 19 17:42:33 2018 +0000
- Revision:
- 8:a0890fa79084
- Parent:
- 7:73fd05fe556a
- Child:
- 9:fe56b888985c
added more comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
asobhy | 8:a0890fa79084 | 1 | /******************************************************************************/ |
asobhy | 8:a0890fa79084 | 2 | // ECE4333 |
asobhy | 8:a0890fa79084 | 3 | // LAB Partner 1: Ahmed Sobhy - ID: 3594449 |
asobhy | 8:a0890fa79084 | 4 | // LAB Partner 2: Brandon Kingman - ID: 3470444 |
asobhy | 8:a0890fa79084 | 5 | // Project: Autonomous Robot Design |
asobhy | 8:a0890fa79084 | 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 | 0:a355e511bc5d | 14 | #include "mbed.h" |
asobhy | 0:a355e511bc5d | 15 | |
asobhy | 0:a355e511bc5d | 16 | void ExtInterruptISR(void); |
asobhy | 0:a355e511bc5d | 17 | void ExtInterruptThread(void const *argument); |
asobhy | 0:a355e511bc5d | 18 | |
asobhy | 0:a355e511bc5d | 19 | osThreadId ExtInterruptId; |
asobhy | 0:a355e511bc5d | 20 | |
asobhy | 0:a355e511bc5d | 21 | osThreadDef(ExtInterruptThread, osPriorityHigh, 1024); // Declare ExtInterruptThread as a thread/process |
asobhy | 0:a355e511bc5d | 22 | |
asobhy | 0:a355e511bc5d | 23 | InterruptIn Bumper(p8); // External interrupt pin declared as Bumper |
asobhy | 0:a355e511bc5d | 24 | |
asobhy | 0:a355e511bc5d | 25 | DigitalOut led2(LED2); |
asobhy | 0:a355e511bc5d | 26 | |
asobhy | 0:a355e511bc5d | 27 | |
asobhy | 7:73fd05fe556a | 28 | /******************************************************************************* |
asobhy | 7:73fd05fe556a | 29 | * @brief This is the initialization function for ExternalInterruptthread |
asobhy | 7:73fd05fe556a | 30 | * @param none |
asobhy | 7:73fd05fe556a | 31 | * @return none |
asobhy | 7:73fd05fe556a | 32 | *******************************************************************************/ |
asobhy | 0:a355e511bc5d | 33 | void ExternalInterruptThreadInit() |
asobhy | 0:a355e511bc5d | 34 | { |
asobhy | 0:a355e511bc5d | 35 | Bumper.rise(&ExtInterruptISR); // Attach the address of the interrupt handler to the rising edge of Bumper |
asobhy | 0:a355e511bc5d | 36 | ExtInterruptId = osThreadCreate(osThread(ExtInterruptThread), NULL); |
asobhy | 0:a355e511bc5d | 37 | } |
asobhy | 0:a355e511bc5d | 38 | |
asobhy | 7:73fd05fe556a | 39 | |
asobhy | 7:73fd05fe556a | 40 | /******************************************************************************* |
asobhy | 7:73fd05fe556a | 41 | * @brief ******** External Interrupt Thread ******** |
asobhy | 7:73fd05fe556a | 42 | * @param none |
asobhy | 7:73fd05fe556a | 43 | * @return none |
asobhy | 7:73fd05fe556a | 44 | *******************************************************************************/ |
asobhy | 0:a355e511bc5d | 45 | void ExtInterruptThread(void const *argument) |
asobhy | 0:a355e511bc5d | 46 | { |
asobhy | 0:a355e511bc5d | 47 | while (true) { |
asobhy | 0:a355e511bc5d | 48 | osSignalWait(0x01, osWaitForever); // Go to sleep until signal, SignalExtCollision, is received |
asobhy | 0:a355e511bc5d | 49 | led2 = !led2; |
asobhy | 0:a355e511bc5d | 50 | } |
asobhy | 0:a355e511bc5d | 51 | } |
asobhy | 0:a355e511bc5d | 52 | |
asobhy | 0:a355e511bc5d | 53 | |
asobhy | 7:73fd05fe556a | 54 | /******************************************************************************* |
asobhy | 7:73fd05fe556a | 55 | * @brief ******** External Interrupt ISR ******** |
asobhy | 7:73fd05fe556a | 56 | * @param none |
asobhy | 7:73fd05fe556a | 57 | * @return none |
asobhy | 7:73fd05fe556a | 58 | *******************************************************************************/ |
asobhy | 0:a355e511bc5d | 59 | void ExtInterruptISR(void) |
asobhy | 0:a355e511bc5d | 60 | { |
asobhy | 0:a355e511bc5d | 61 | osSignalSet(ExtInterruptId,0x01); // Send signal to the thread with ID, ExtInterruptId, i.e., ExtInterruptThread. |
asobhy | 0:a355e511bc5d | 62 | } |