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: TPixy-Interface
Fork of ManualControlFinal by
ExternalInterruptThread.cpp@7:73fd05fe556a, 2018-02-15 (annotated)
- Committer:
 - asobhy
 - Date:
 - Thu Feb 15 01:15:26 2018 +0000
 - Revision:
 - 7:73fd05fe556a
 - Parent:
 - 0:a355e511bc5d
 - Child:
 - 8:a0890fa79084
 
Added comments to several files and organized the code a bit
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| asobhy | 0:a355e511bc5d | 1 | #include "mbed.h" | 
| asobhy | 0:a355e511bc5d | 2 | |
| asobhy | 0:a355e511bc5d | 3 | void ExtInterruptISR(void); | 
| asobhy | 0:a355e511bc5d | 4 | void ExtInterruptThread(void const *argument); | 
| asobhy | 0:a355e511bc5d | 5 | |
| asobhy | 0:a355e511bc5d | 6 | osThreadId ExtInterruptId; | 
| asobhy | 0:a355e511bc5d | 7 | |
| asobhy | 0:a355e511bc5d | 8 | osThreadDef(ExtInterruptThread, osPriorityHigh, 1024); // Declare ExtInterruptThread as a thread/process | 
| asobhy | 0:a355e511bc5d | 9 | |
| asobhy | 0:a355e511bc5d | 10 | InterruptIn Bumper(p8); // External interrupt pin declared as Bumper | 
| asobhy | 0:a355e511bc5d | 11 | |
| asobhy | 0:a355e511bc5d | 12 | DigitalOut led2(LED2); | 
| asobhy | 0:a355e511bc5d | 13 | |
| asobhy | 0:a355e511bc5d | 14 | |
| asobhy | 7:73fd05fe556a | 15 | /******************************************************************************* | 
| asobhy | 7:73fd05fe556a | 16 | * @brief This is the initialization function for ExternalInterruptthread | 
| asobhy | 7:73fd05fe556a | 17 | * @param none | 
| asobhy | 7:73fd05fe556a | 18 | * @return none | 
| asobhy | 7:73fd05fe556a | 19 | *******************************************************************************/ | 
| asobhy | 0:a355e511bc5d | 20 | void ExternalInterruptThreadInit() | 
| asobhy | 0:a355e511bc5d | 21 | { | 
| asobhy | 0:a355e511bc5d | 22 | Bumper.rise(&ExtInterruptISR); // Attach the address of the interrupt handler to the rising edge of Bumper | 
| asobhy | 0:a355e511bc5d | 23 | ExtInterruptId = osThreadCreate(osThread(ExtInterruptThread), NULL); | 
| asobhy | 0:a355e511bc5d | 24 | } | 
| asobhy | 0:a355e511bc5d | 25 | |
| asobhy | 7:73fd05fe556a | 26 | |
| asobhy | 7:73fd05fe556a | 27 | /******************************************************************************* | 
| asobhy | 7:73fd05fe556a | 28 | * @brief ******** External Interrupt Thread ******** | 
| asobhy | 7:73fd05fe556a | 29 | * @param none | 
| asobhy | 7:73fd05fe556a | 30 | * @return none | 
| asobhy | 7:73fd05fe556a | 31 | *******************************************************************************/ | 
| asobhy | 0:a355e511bc5d | 32 | void ExtInterruptThread(void const *argument) | 
| asobhy | 0:a355e511bc5d | 33 | { | 
| asobhy | 0:a355e511bc5d | 34 | while (true) { | 
| asobhy | 0:a355e511bc5d | 35 | osSignalWait(0x01, osWaitForever); // Go to sleep until signal, SignalExtCollision, is received | 
| asobhy | 0:a355e511bc5d | 36 | led2 = !led2; | 
| asobhy | 0:a355e511bc5d | 37 | } | 
| asobhy | 0:a355e511bc5d | 38 | } | 
| asobhy | 0:a355e511bc5d | 39 | |
| asobhy | 0:a355e511bc5d | 40 | |
| asobhy | 7:73fd05fe556a | 41 | /******************************************************************************* | 
| asobhy | 7:73fd05fe556a | 42 | * @brief ******** External Interrupt ISR ******** | 
| asobhy | 7:73fd05fe556a | 43 | * @param none | 
| asobhy | 7:73fd05fe556a | 44 | * @return none | 
| asobhy | 7:73fd05fe556a | 45 | *******************************************************************************/ | 
| asobhy | 0:a355e511bc5d | 46 | void ExtInterruptISR(void) | 
| asobhy | 0:a355e511bc5d | 47 | { | 
| asobhy | 0:a355e511bc5d | 48 | osSignalSet(ExtInterruptId,0x01); // Send signal to the thread with ID, ExtInterruptId, i.e., ExtInterruptThread. | 
| asobhy | 0:a355e511bc5d | 49 | } | 
