ManualControl

Dependencies:   TPixy-Interface

Fork of MbedOS_Robot_Team by ECE4333 - 2018 - Ahmed & Brandon

ExternalInterruptThread.cpp

Committer:
asobhy
Date:
2018-02-15
Revision:
7:73fd05fe556a
Parent:
0:a355e511bc5d
Child:
8:a0890fa79084

File content as of revision 7:73fd05fe556a:

#include "mbed.h"

void ExtInterruptISR(void);
void ExtInterruptThread(void const *argument);

osThreadId ExtInterruptId;

osThreadDef(ExtInterruptThread, osPriorityHigh, 1024); // Declare ExtInterruptThread as a thread/process

InterruptIn Bumper(p8); // External interrupt pin declared as Bumper

DigitalOut led2(LED2);


/*******************************************************************************
* @brief    This is the initialization function for ExternalInterruptthread
* @param    none
* @return   none
*******************************************************************************/
void ExternalInterruptThreadInit()
{
    Bumper.rise(&ExtInterruptISR); // Attach the address of the interrupt handler to the rising edge of Bumper
    ExtInterruptId = osThreadCreate(osThread(ExtInterruptThread), NULL);            
}

 
/*******************************************************************************
* @brief    ******** External Interrupt Thread ********
* @param    none
* @return   none
*******************************************************************************/
void ExtInterruptThread(void const *argument)
{
    while (true) {
        osSignalWait(0x01, osWaitForever); // Go to sleep until signal, SignalExtCollision, is received
        led2 = !led2;
    }
}


/*******************************************************************************
* @brief    ******** External Interrupt ISR ********
* @param    none
* @return   none
*******************************************************************************/
void ExtInterruptISR(void)
{
    osSignalSet(ExtInterruptId,0x01); // Send signal to the thread with ID, ExtInterruptId, i.e., ExtInterruptThread.
}