I need to verify myself about what I am doing.
In my app., there is data stream between my device and vehicle CAN bus which contains like speed, gearbox etc. My device gets these data and by interpreting them, it gives an output to the vehicle. Now. I am handling all these receive transactions in RxCallback and in order to not cause circular dependency, I create a User_RxIndication function.
In this function, I am checking id, dlc, frame, format etc. If all validation passed, then data is passing from specific parser and it is saved. All these transactions are handling in User_RxInditication and this fuction is passed from application layer to the lower layers.
Here is the code sample.
static CanMsg_t RxMsg;
static vehicle_t MyBus;
void VDCU_CanReceiveIndication(CanHandle_t Dummy)
{
if(ComM_CanRead(&RxMsg)== E_OK)
{
switch(RxMsg.id)
{
case SPEED_CAN_ID:
if( VALIDATE_DATA_FORMAT(RxMsg.id, SPEED_ID_FORMAT) &&
VALIDATE_DATA_FRAME(RxMsg.frame, SPEED_FRAME) &&
VALIDATE_DATA_LENGTH(RxMsg.len, SPEED_LENGTH ))
{
/*TODO: Apply Parser, if required ?*/
VehicleIf_SetVehicleSpeed(MyBus, RxMsg.data[0]);
}
else
/*TODO: Send Dia*/
break;
case STEERINGWHEEL_CAN_ID:
if( VALIDATE_DATA_FORMAT(RxMsg.id, STEERINGWHEEL_ID_FORMAT) &&
VALIDATE_DATA_FRAME(RxMsg.frame, STEERINGWHEEL_FRAME) &&
VALIDATE_DATA_LENGTH(RxMsg.len, STEERINGWHEEL_LENGTH ))
{
/*TODO: Apply Parser, if required ?*/
VehicleIf_SetVehicleWheelAngle(MyBus, RxMsg.data[1]);
}
else
/*TODO: Send Dia*/
break;
default:
break;
}
}
}
These cases may extend up to 9-10 btw. I did not design parser but, I will do.
Now, This approach is valid ? Whenever read something about Interrupt mechanism. It is said "keep interrupts as short as possible. Set a flag and do whatever you want in main."
Should I apply this switch case and guard conditions in main or here is okey ?
In case of handling in main , do I miss data while interpreting them in main depending on other task time allocation in app ?
What is the right approach. Thanks.