Files
slhal/B3_AP/hal_can_receive_wrapper.c
T

91 lines
1.7 KiB
C
Raw Normal View History

2020-09-18 11:42:54 +08:00
/*
* Include Files
*
*/
#if defined(MATLAB_MEX_FILE)
#include "tmwtypes.h"
#include "simstruc_types.h"
#else
#include "rtwtypes.h"
#endif
#include "hal_can_receive_bus.h"
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
#ifdef HAL_IMPL
#include "can_devs.h"
#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
#define y_width 1
/*
* Create external references here.
*
*/
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
#ifdef HAL_IMPL
static int32_T popMsg(CAN_BUS_t *can_bus, CAN_MESSAGE_BUS *msg)
{
CAN_PKG_t pkg;
msg->ID = 0U;
msg->Length = 0U;
msg->Extended = 0U;
msg->Remote = 0;
msg->Data[0] = 0;
msg->Data[1] = 0;
msg->Data[2] = 0;
msg->Data[3] = 0;
msg->Data[4] = 0;
msg->Data[5] = 0;
msg->Data[6] = 0;
msg->Data[7] = 0;
if (CAN_BUS_receive(can_bus, &pkg))
{
msg->ID = pkg.canid;
msg->Length = pkg.len;
if (pkg.ide == CAN_ID_EXT)
{
msg->Extended = CAN_ID_EXT;
}
else
{
msg->Extended = 0;
}
memcpy(msg->Data, pkg.data, pkg.len);
return 0;
}
return -1;
}
#endif
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */
/*
* Output function
*
*/
void hal_can_receive_Outputs_wrapper(CAN_MESSAGE_BUS *msg,
int32_T *ErrorCode,
const uint8_T *canbus_id, const int_T p_width0)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
ErrorCode[0] = -1;
#ifdef HAL_IMPL
switch (canbus_id[0])
{
case 0:
ErrorCode[0] = popMsg(&can_bus1, msg);
break;
case 1:
ErrorCode[0] = popMsg(&can_bus3, msg);
break;
default:
break;
}
#endif
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}