Simulink模型
创建简单加法和计数器
TestFunction_Input1和TestFunction_Input2接是接受0x300的信号
TestFunction_Output1和TestFunction_Output2由0x123发送到CAN上
定义simulink.signal数据
把simulink生成的.c和.h复制到SDS32工程路径下面
simulink导入S32DS环境
创建UserCode和UserInclude存放simulink的.c和.h文件
在接收到0x300报文的时候赋值给TestFunction_Input1和TestFunction_Input2
extern uint16 TestFunction_Output1; /* '<Root>/Add' */
extern uint8 TestFunction_Output2;
void Get_BUF00_msg()
{
err_status = Check_CAN_MB_Status(0, 0, buffer00_status);
if( buffer00_status[0] == NEWDATA)
{
uint8_t cnt;
err_status = Read_CAN_MB_Data(0, 0, Buffer00);
for(cnt=1;cnt<9;cnt++)
{
Buffer00_Data[cnt-1] = Buffer00[cnt];
}
TestFunction_Input1 = Buffer00_Data[0];
TestFunction_Input2 = Buffer00_Data[1];
Buffer05[0] = 8;
Buffer05[1] = TestFunction_Output1;
Buffer05[2] = TestFunction_Output2;
err_status = Load_CAN_MB(0, 5,Buffer05);
}
}
在10ms中断中添加TestFunction_step()函数,将TestFunction_Output1和TestFunction_Output2 通过0x123发送到CAN上
uint8 Buffer05[9];
void Task10ms()
{
//10ms processor
if (TimeCounter_10ms==10)
{
NVIC_DisableIRQ(PIT_CH0_IRQn);
TimeCounter_10ms=0;
TestFunction_step();
uint8_t err_status;
uint8_t data_rec[9];
data_rec[0] = 8;
data_rec[1] = 1;
data_rec[2] = 2;
data_rec[3] = 3;
data_rec[4] = 4;
data_rec[5] = 5;
data_rec[6] = 6;
data_rec[7] = 7;
data_rec[8] = 8;
Buffer05[0] = 8;
Buffer05[1] = (uint8)(TestFunction_Output1>>8);
Buffer05[2] = (uint8)(TestFunction_Output1);
Buffer05[3] = TestFunction_Output2;
err_status = Load_CAN_MB(0, 5,Buffer05);
err_status = Load_CAN_MB(0, 9, data_rec);
err_status = Load_CAN_MB(0, 10, data_rec);
err_status = Load_CAN_MB(0, 11, data_rec);
err_status = Load_CAN_MB(0, 12, data_rec);
err_status = Load_CAN_MB(0, 13, data_rec);
err_status = Transmit_CAN_MB(0, 5);
err_status = Transmit_CAN_MB(0, 9);
err_status = Transmit_CAN_MB(0, 10);
err_status = Transmit_CAN_MB(0, 11);
err_status = Transmit_CAN_MB(0, 12);
err_status = Transmit_CAN_MB(0, 13);
/*******************************************************/
}
NVIC_EnableIRQ(PIT_CH0_IRQn);
}