![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
ManualControl
Dependencies: TPixy-Interface
Fork of MbedOS_Robot by
ExternalInterruptThread.cpp@0:a355e511bc5d, 2018-02-01 (annotated)
- Committer:
- asobhy
- Date:
- Thu Feb 01 03:58:00 2018 +0000
- Revision:
- 0:a355e511bc5d
- Child:
- 7:73fd05fe556a
before testing the QEI
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 | 0:a355e511bc5d | 15 | void ExternalInterruptThreadInit() |
asobhy | 0:a355e511bc5d | 16 | { |
asobhy | 0:a355e511bc5d | 17 | Bumper.rise(&ExtInterruptISR); // Attach the address of the interrupt handler to the rising edge of Bumper |
asobhy | 0:a355e511bc5d | 18 | ExtInterruptId = osThreadCreate(osThread(ExtInterruptThread), NULL); |
asobhy | 0:a355e511bc5d | 19 | } |
asobhy | 0:a355e511bc5d | 20 | |
asobhy | 0:a355e511bc5d | 21 | |
asobhy | 0:a355e511bc5d | 22 | // ******** External Interrupt Thread ******** |
asobhy | 0:a355e511bc5d | 23 | void ExtInterruptThread(void const *argument) |
asobhy | 0:a355e511bc5d | 24 | { |
asobhy | 0:a355e511bc5d | 25 | while (true) { |
asobhy | 0:a355e511bc5d | 26 | osSignalWait(0x01, osWaitForever); // Go to sleep until signal, SignalExtCollision, is received |
asobhy | 0:a355e511bc5d | 27 | led2 = !led2; |
asobhy | 0:a355e511bc5d | 28 | } |
asobhy | 0:a355e511bc5d | 29 | } |
asobhy | 0:a355e511bc5d | 30 | |
asobhy | 0:a355e511bc5d | 31 | |
asobhy | 0:a355e511bc5d | 32 | // ******** External Interrupt Handler ******** |
asobhy | 0:a355e511bc5d | 33 | void ExtInterruptISR(void) |
asobhy | 0:a355e511bc5d | 34 | { |
asobhy | 0:a355e511bc5d | 35 | osSignalSet(ExtInterruptId,0x01); // Send signal to the thread with ID, ExtInterruptId, i.e., ExtInterruptThread. |
asobhy | 0:a355e511bc5d | 36 | } |