Yes can communication is implemented with interrupts.
void __ISR(_CAN_1_VECTOR, ipl4) vCANInterruptWrapper(void); //For CAN use only ipl4!!!
//void __attribute__((vector(46), interrupt(ipl4), nomips16)) vCANInterruptWrapper(void);
void vCANInterruptHandler ( void )
{
//interrup handler for CAN1
if((CANGetModuleEvent(CAN1) & CAN_RX_EVENT) != 0)
{
if(CANGetPendingEventCode(CAN1) == CAN_CHANNEL1_EVENT)
{
CANEnableChannelEvent(CAN1, CAN_CHANNEL1, CAN_RX_CHANNEL_NOT_EMPTY, FALSE);
// isCAN1MsgReceived = TRUE;
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(xBinarySemaphore,xHigherPriorityTaskWoken);
portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );
}
}
INTClearFlag(INT_CAN1);
}
void CAN1RxMsgProcess(void)
{
xSemaphoreTake( xBinarySemaphore, 0 );
canID_master=0x02;
//canID_master= ReadShortEEPROM(EE_CAN_ID_MASTER);
CANRxMessageBuffer * message;
while(1){
CanRXProcess_timeout = 1;
//vParTestToggleLEDA( 0 );
if(xSemaphoreTake(xBinarySemaphore,portMAX_DELAY2))
{
message = (CANRxMessageBuffer *)CANGetRxMessage(CAN1,CAN_CHANNEL1);
//vParTestToggleLED3( 0 );
CANUpdateChannel(CAN1, CAN_CHANNEL1);
CANEnableChannelEvent(CAN1, CAN_CHANNEL1, CAN_RX_CHANNEL_NOT_EMPTY, TRUE);
//send confirm response for set data commands
CANMessageProcessing(canID_master, message);
}else{
CANResetChannel(CAN1,CAN_CHANNEL1);
}
}
}
extract from main()
/* --- APPLICATION TASKS CAN BE CREATED HERE --- */
xBinarySemaphore = xSemaphoreCreateBinary();
xBinarySemaphoreIO = xSemaphoreCreateBinary(); // Not used
xBinarySemaphoreADC = xSemaphoreCreateBinary();
if( xBinarySemaphore != NULL )
{
xTaskCreate( CAN1RxMsgProcess, "CANHandler", 1024, NULL, 4, &xTaskRX_CANHandler ); //id:1
xTaskCreate( EEPROMGetValuesTask, "EEPROMRead", 240, NULL, 5, &xTask_EEPROM ); //id:2
xTaskCreate( DigitalOutputsTask, "DigitalOutputs", 240, NULL, 2, &xTaskDigOutHandler); //id:3
xTaskCreate( DigitalInputsTask, "DigitalInputs", 240, NULL, 2, &xTaskDigInHandler ); //id:4
xTaskCreate( StatusValuesTask, "StatusHandler", 240, NULL, 2, &xTaskStatValHandler ); //id:5
xTaskCreate( WatchdogProcess, "Watchdog", 240, NULL, 3, NULL );
/* Start the scheduler so the created tasks start executing. */
vTaskStartScheduler();
}
while(1);
This code was developed by another programmer, I am not sure about the xSemaphore use for CAN communication, please advise. Thanks