赞
踩
目录
使用的模型
信号对象和信号指定
由于输入没指定维度时,生成代码报错,无法自动确定数据维度,后指定了维度。
模型参数配置:
尝试仅仅生成代码,不指定硬件为树莓派,此时勾选并发执行,将会报错:This model is configured for concurrent execution and has modeling constraints. To generate code, the 'Generate an example main program' option must be selected and the 'Target operating system' must be set to 'NativeThreadsExample' from the 'Templates' section of the 'Code Generation' pane of the Configuration Parameters dialog.该模型被配置为用于并发执行,并且具有建模约束。若要生成代码,必须选择“生成示例主程序”选项,并且必须从“配置参数”对话框的“代码生成”窗格的“模板”部分将“目标操作系统”设置为“NativeThreadsExample”。
此先设置为不并发。
现在先只试试中间算法部分,不涉及树莓派硬件IO,可以不勾选Package code and artifacts,勾选可以生成一个压缩包,包含所有内容,就有树莓派上的一些头文件、dll。
指定了一下step函数名字。
生成的代码文件位于模型同级目录下“模型名_ert_rtw”文件夹内,这六个文件的作用分别是:
- ert_main.c:该文件是一个样例文件,向用户展示主程序如何调用模型代码,在代码集成时可以参考该文件;
- 模型名.c:该文件包含模型的全部实现方法,包含变量的声明和定义,Step函数、初始化函数、终止函数等的定义和实现,即“模型的本身”;
- 模型名.h:该文件包含模型所依赖的数据结构、数据类型的定义和声明,以及模型变量、模型算法函数的外部声明;
- 模型名_private.h:包含模型本地的宏和数据类型定义,有定义才会生成相关内容;
- 模型名_types.h:该文件包含模块参数(Parameters)和模型数据(Model Data)的数据结构的向前声明,在一些可重用函数中可能会被使用;
- rtwtypes.h:定义了基本的数据类型和宏,大部分的生成代码可能会依赖该文件;
- 模型名_data.c:上图中没有生成,但在某些情况下会生成该文件,其中包含模型中的模块参数(Parameters)、常数模块和I/O的数据结构的定义和声明。
- /*
- * File: CAN2PSC_types.h
- *
- * Code generated for Simulink model 'CAN2PSC'.
- *
- * Model version : 1.3
- * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Mon Jun 12 16:10:53 2023
- *
- * Target selection: ert.tlc
- * Embedded hardware selection: ARM Compatible->ARM Cortex
- * Code generation objectives: Unspecified
- * Validation result: Not run
- */
-
- #ifndef RTW_HEADER_CAN2PSC_types_h_
- #define RTW_HEADER_CAN2PSC_types_h_
-
- /* Model Code Variants */
-
- /* Forward declaration for rtModel */
- typedef struct tag_RTM_CAN2PSC_T RT_MODEL_CAN2PSC_T;
-
- #endif /* RTW_HEADER_CAN2PSC_types_h_ */
-
- /*
- * File trailer for generated code.
- *
- * [EOF]
- */
- /*
- * File: CAN2PSC_private.h
- *
- * Code generated for Simulink model 'CAN2PSC'.
- *
- * Model version : 1.3
- * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Mon Jun 12 16:10:53 2023
- *
- * Target selection: ert.tlc
- * Embedded hardware selection: ARM Compatible->ARM Cortex
- * Code generation objectives: Unspecified
- * Validation result: Not run
- */
-
- #ifndef RTW_HEADER_CAN2PSC_private_h_
- #define RTW_HEADER_CAN2PSC_private_h_
- #include "rtwtypes.h"
- #include "CAN2PSC.h"
-
- extern void CAN2PSC_MATLABFunction1(const uint8_T rtu_UDP[26], real_T rtu_Num,
- real_T rtu_TCANid, uint8_T rty_TCAN_Data[8], DW_MATLABFunction1_CAN2PSC_T
- *localDW);
-
- #endif /* RTW_HEADER_CAN2PSC_private_h_ */
-
- /*
- * File trailer for generated code.
- *
- * [EOF]
- */
- /*
- * File: CAN2PSC.h
- *
- * Code generated for Simulink model 'CAN2PSC'.
- *
- * Model version : 1.3
- * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Mon Jun 12 16:10:53 2023
- *
- * Target selection: ert.tlc
- * Embedded hardware selection: ARM Compatible->ARM Cortex
- * Code generation objectives: Unspecified
- * Validation result: Not run
- */
-
- #ifndef RTW_HEADER_CAN2PSC_h_
- #define RTW_HEADER_CAN2PSC_h_
- #include <string.h>
- #ifndef CAN2PSC_COMMON_INCLUDES_
- #define CAN2PSC_COMMON_INCLUDES_
- #include <math.h>
- #include <string.h>
- #include "rtwtypes.h"
- #include "can_message.h"
- #endif /* CAN2PSC_COMMON_INCLUDES_ */
-
- #include "CAN2PSC_types.h"
-
- /* Macros for accessing real-time model data structure */
- /*用于访问实时模型数据结构的宏*/
- #ifndef rtmGetErrorStatus
- #define rtmGetErrorStatus(rtm) ((rtm)->errorStatus)
- #endif
-
- #ifndef rtmSetErrorStatus
- #define rtmSetErrorStatus(rtm, val) ((rtm)->errorStatus = (val))
- #endif
-
- /* user code (top of export header file) */
- /*用户代码(导出头文件顶部)*/
- #include "can_message.h"
-
- /* Block states (default storage) for system '<S1>/MATLAB Function1' */
- /*系统'<S1>/MATLAB Function1'的块状态(默认存储)*/
- typedef struct {
- uint8_T TCAN_Last[8]; /* '<S1>/MATLAB Function1' */
- } DW_MATLABFunction1_CAN2PSC_T;
-
- /* Block signals (default storage) */
- /*块信号(默认存储)*/
- typedef struct {
- CAN_DATATYPE CANPack3; /* '<S1>/CAN Pack3' */
- CAN_DATATYPE CANPack1; /* '<S1>/CAN Pack1' */
- real_T CANUnpack4_o1; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o2; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o3; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o4; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o5; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o6; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o7; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o8; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o9; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o10; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o11; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o12; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o13; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o14; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o15; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o24; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o25; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o26; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack4_o27; /* '<S1>/CAN Unpack4' */
- real_T CANUnpack1_o3; /* '<S1>/CAN Unpack1' */
- real_T CANUnpack1_o4; /* '<S1>/CAN Unpack1' */
- real_T CANUnpack1_o6; /* '<S1>/CAN Unpack1' */
- real_T CANUnpack1_o7; /* '<S1>/CAN Unpack1' */
- uint8_T TCAN_Data[8]; /* '<S1>/MATLAB Function8' */
- uint8_T TCAN_Data_n[8]; /* '<S1>/MATLAB Function1' */
- } B_CAN2PSC_T;
-
- /* Block states (default storage) for system '<Root>' */
- /*系统'<Root>'的块状态(默认存储)*/
- typedef struct {
- int_T CANUnpack4_ModeSignalID; /* '<S1>/CAN Unpack4' */
- int_T CANUnpack4_StatusPortID; /* '<S1>/CAN Unpack4' */
- int_T CANUnpack1_ModeSignalID; /* '<S1>/CAN Unpack1' */
- int_T CANUnpack1_StatusPortID; /* '<S1>/CAN Unpack1' */
- DW_MATLABFunction1_CAN2PSC_T sf_MATLABFunction8;/* '<S1>/MATLAB Function8' */
- DW_MATLABFunction1_CAN2PSC_T sf_MATLABFunction1;/* '<S1>/MATLAB Function1' */
- } DW_CAN2PSC_T;
-
- /* Real-time Model Data Structure */
- /*实时模型数据结构*/
- struct tag_RTM_CAN2PSC_T {
- const char_T *errorStatus;
- };
-
- /* Block signals (default storage) */
- extern B_CAN2PSC_T CAN2PSC_B;
-
- /* Block states (default storage) */
- extern DW_CAN2PSC_T CAN2PSC_DW;
-
- /* Model entry point functions */
- /*模型入口点函数*/
- extern void CAN2PSC_initialize(void);
- extern void CAN2PSCFunc(void);
- extern void CAN2PSC_terminate(void);
-
- /* Real-time Model object */
- /*实时模型对象*/
- extern RT_MODEL_CAN2PSC_T *const CAN2PSC_M;
-
- /* Exported data declaration */
- /*导出的数据声明*/
-
- /* Declaration for custom storage class: Global */
- /*自定义存储类的声明:全局*/
- extern real_T PDC1_Status_DistanceFL_Lvl;/* '<S1>/CAN Unpack4' */
- extern real_T PDC1_Status_DistanceFML_Lvl;/* '<S1>/CAN Unpack4' */
- extern real_T PDC1_Status_DistanceFMR_Lvl;/* '<S1>/CAN Unpack4' */
- extern real_T PDC1_Status_DistanceFR_Lvl;/* '<S1>/CAN Unpack4' */
- extern real_T PDC1_Status_DistanceRL_Lvl;/* '<S1>/CAN Unpack4' */
- extern real_T PDC1_Status_DistanceRML_Lvl;/* '<S1>/CAN Unpack4' */
- extern real_T PDC1_Status_DistanceRMR_Lvl;/* '<S1>/CAN Unpack4' */
- extern real_T PDC1_Status_DistanceRR_Lvl;/* '<S1>/CAN Unpack4' */
- extern real_T PSC2_Status_FlankDistanceFL_Lvl;/* '<S1>/CAN Unpack1' */
- extern real_T PSC2_Status_FlankDistanceFR_Lvl;/* '<S1>/CAN Unpack1' */
- extern real_T PSC2_Status_FlankDistanceRL_Lvl;/* '<S1>/CAN Unpack1' */
- extern real_T PSC2_Status_FlankDistanceRR_Lvl;/* '<S1>/CAN Unpack1' */
- extern uint8_T PSC_UDP_Data[26]; /* '<Root>/In1' */
-
- /*-
- * The generated code includes comments that allow you to trace directly
- * back to the appropriate location in the model. The basic format
- * is <system>/block_name, where system is the system number (uniquely
- * assigned by Simulink) and block_name is the name of the block.
- *
- * Use the MATLAB hilite_system command to trace the generated code back
- * to the model. For example,
- *
- * hilite_system('<S3>') - opens system 3
- * hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
- *
- * Here is the system hierarchy for this model
- *
- * '<Root>' : 'CAN2PSC'
- * '<S1>' : 'CAN2PSC/CAN2_PSC'
- * '<S2>' : 'CAN2PSC/CAN2_PSC/MATLAB Function1'
- * '<S3>' : 'CAN2PSC/CAN2_PSC/MATLAB Function8'
- */
-
- /*-
- *生成的代码包括注释,这些注释允许您直接追溯到模型中的适当位置。基本格式为<system>/block_name,其中system是系统编号(由Simulink唯一分配),block_name是块的名称。
- *
- *使用MATLAB hilite_system命令将生成的代码追溯到模型。例如
- *
- *hilite_system('<S3>')-打开系统3
- *hilite_system('<S3>/Kp')-打开并选择驻留在S3中的块Kp
- *
- *以下是此模型的系统层次结构
- *
- *'<Root>':'CAN2PSC'
- *“<S1>”:“CAN2PSC/CAN2_PSC”
- *“<S2>”:“CAN2PSC/CAN2_PSC/MATLAB函数1”
- *“<S3>”:“CAN2PSC/CAN2_PSC/MATLAB函数8”
- */
-
- #endif /* RTW_HEADER_CAN2PSC_h_ */
-
- /*
- * File trailer for generated code.
- *
- * [EOF]
- */
- /*
- * File: CAN2PSC.c
- *
- * Code generated for Simulink model 'CAN2PSC'.
- *
- * Model version : 1.3
- * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Mon Jun 12 16:10:53 2023
- *
- * Target selection: ert.tlc
- * Embedded hardware selection: ARM Compatible->ARM Cortex
- * Code generation objectives: Unspecified
- * Validation result: Not run
- */
-
- #include "CAN2PSC.h"
- #include "CAN2PSC_private.h"
-
- /* Block signals (default storage) */
- B_CAN2PSC_T CAN2PSC_B;
-
- /* Block states (default storage) */
- DW_CAN2PSC_T CAN2PSC_DW;
-
- /* Real-time model */
- static RT_MODEL_CAN2PSC_T CAN2PSC_M_;
- RT_MODEL_CAN2PSC_T *const CAN2PSC_M = &CAN2PSC_M_;
-
- /* Exported data definition */
-
- /* Definition for custom storage class: Global */
- real_T PDC1_Status_DistanceFL_Lvl; /* '<S1>/CAN Unpack4' */
- real_T PDC1_Status_DistanceFML_Lvl; /* '<S1>/CAN Unpack4' */
- real_T PDC1_Status_DistanceFMR_Lvl; /* '<S1>/CAN Unpack4' */
- real_T PDC1_Status_DistanceFR_Lvl; /* '<S1>/CAN Unpack4' */
- real_T PDC1_Status_DistanceRL_Lvl; /* '<S1>/CAN Unpack4' */
- real_T PDC1_Status_DistanceRML_Lvl; /* '<S1>/CAN Unpack4' */
- real_T PDC1_Status_DistanceRMR_Lvl; /* '<S1>/CAN Unpack4' */
- real_T PDC1_Status_DistanceRR_Lvl; /* '<S1>/CAN Unpack4' */
- real_T PSC2_Status_FlankDistanceFL_Lvl;/* '<S1>/CAN Unpack1' */
- real_T PSC2_Status_FlankDistanceFR_Lvl;/* '<S1>/CAN Unpack1' */
- real_T PSC2_Status_FlankDistanceRL_Lvl;/* '<S1>/CAN Unpack1' */
- real_T PSC2_Status_FlankDistanceRR_Lvl;/* '<S1>/CAN Unpack1' */
- uint8_T PSC_UDP_Data[26]; /* '<Root>/In1' */
-
- /*
- * Output and update for atomic system:
- * '<S1>/MATLAB Function1'
- * '<S1>/MATLAB Function8'
- */
-
- void CAN2PSC_MATLABFunction1(const uint8_T rtu_UDP[26], real_T rtu_Num, real_T
- rtu_TCANid, uint8_T rty_TCAN_Data[8], DW_MATLABFunction1_CAN2PSC_T *localDW)
- {
- real_T j;
- int32_T i;
- int32_T i_0;
- for (i = 0; i < 8; i++) {
- rty_TCAN_Data[i] = 0U;
- }
-
- for (i = 0; i < (int32_T)(rtu_Num - 1.0); i++) {
- j = ((real_T)i + 1.0) * 13.0 + 2.0;
- if ((((rtu_UDP[(int32_T)(j + 1.0) - 1] << 16) + ((uint32_T)rtu_UDP[(int32_T)
- j - 1] << 24)) + (rtu_UDP[(int32_T)(j + 2.0) - 1] << 8)) + rtu_UDP
- [(int32_T)(j + 3.0) - 1] == rtu_TCANid) {
- for (i_0 = 0; i_0 < 8; i_0++) {
- rty_TCAN_Data[i_0] = rtu_UDP[(int32_T)(((real_T)i_0 + 4.0) + j) - 1];
- localDW->TCAN_Last[i_0] = rty_TCAN_Data[i_0];
- }
- } else {
- for (i_0 = 0; i_0 < 8; i_0++) {
- rty_TCAN_Data[i_0] = localDW->TCAN_Last[i_0];
- }
- }
- }
- }
-
- /* Model step function */
- void CAN2PSCFunc(void)
- {
- /* MATLAB Function: '<S1>/MATLAB Function8' incorporates:
- * Constant: '<S1>/Tid2'
- * Constant: '<S1>/Tid8'
- * Inport: '<Root>/In1'
- */
- CAN2PSC_MATLABFunction1((&(PSC_UDP_Data[0])), 2.0, 608.0, CAN2PSC_B.TCAN_Data,
- &CAN2PSC_DW.sf_MATLABFunction8);
-
- /* MATLAB Function: '<S1>/MATLAB Function1' incorporates:
- * Constant: '<S1>/Tid1'
- * Constant: '<S1>/Tid2'
- * Inport: '<Root>/In1'
- */
- CAN2PSC_MATLABFunction1((&(PSC_UDP_Data[0])), 2.0, 1073.0,
- CAN2PSC_B.TCAN_Data_n, &CAN2PSC_DW.sf_MATLABFunction1);
-
- /* S-Function (scanpack): '<S1>/CAN Pack3' */
- /* S-Function (scanpack): '<S1>/CAN Pack3' */
- CAN2PSC_B.CANPack3.ID = 608U;
- CAN2PSC_B.CANPack3.Length = 8U;
- CAN2PSC_B.CANPack3.Extended = 0U;
- CAN2PSC_B.CANPack3.Remote = 0;
- CAN2PSC_B.CANPack3.Data[0] = 0;
- CAN2PSC_B.CANPack3.Data[1] = 0;
- CAN2PSC_B.CANPack3.Data[2] = 0;
- CAN2PSC_B.CANPack3.Data[3] = 0;
- CAN2PSC_B.CANPack3.Data[4] = 0;
- CAN2PSC_B.CANPack3.Data[5] = 0;
- CAN2PSC_B.CANPack3.Data[6] = 0;
- CAN2PSC_B.CANPack3.Data[7] = 0;
-
- {
- (void) memcpy((CAN2PSC_B.CANPack3.Data), &CAN2PSC_B.TCAN_Data[0],
- 8 * sizeof(uint8_T));
- }
-
- /* S-Function (scanunpack): '<S1>/CAN Unpack4' */
- {
- /* S-Function (scanunpack): '<S1>/CAN Unpack4' */
- if ((8 == CAN2PSC_B.CANPack3.Length) && (CAN2PSC_B.CANPack3.ID !=
- INVALID_CAN_ID) ) {
- if ((608 == CAN2PSC_B.CANPack3.ID) && (0U == CAN2PSC_B.CANPack3.Extended) )
- {
- {
- /* --------------- START Unpacking signal 0 ------------------
- * startBit = 0
- * length = 1
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 1 ------------------
- * startBit = 52
- * length = 1
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 2 ------------------
- * startBit = 2
- * length = 1
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 3 ------------------
- * startBit = 3
- * length = 1
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 4 ------------------
- * startBit = 1
- * length = 1
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 5 ------------------
- * startBit = 53
- * length = 1
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 6 ------------------
- * startBit = 4
- * length = 1
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 7 ------------------
- * startBit = 54
- * length = 1
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 8 ------------------
- * startBit = 5
- * length = 1
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 9 ------------------
- * startBit = 6
- * length = 1
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 10 ------------------
- * startBit = 7
- * length = 1
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 11 ------------------
- * startBit = 55
- * length = 1
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 12 ------------------
- * startBit = 10
- * length = 2
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 13 ------------------
- * startBit = 49
- * length = 3
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 14 ------------------
- * startBit = 56
- * length = 3
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 15 ------------------
- * startBit = 16
- * length = 4
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- {
- real64_T outValue = 0;
-
- {
- uint8_T unpackedValue = 0;
-
- {
- uint8_T tempValue = (uint8_T) (0);
-
- {
- tempValue = tempValue | (uint8_T)((uint8_T)
- (CAN2PSC_B.CANPack3.Data[2]) & (uint8_T)(0xFU));
- }
-
- unpackedValue = tempValue;
- }
-
- outValue = (real64_T) (unpackedValue);
- }
-
- {
- real64_T result = (real64_T) outValue;
- PDC1_Status_DistanceFL_Lvl = result;
- }
- }
-
- /* --------------- START Unpacking signal 16 ------------------
- * startBit = 24
- * length = 4
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- {
- real64_T outValue = 0;
-
- {
- uint8_T unpackedValue = 0;
-
- {
- uint8_T tempValue = (uint8_T) (0);
-
- {
- tempValue = tempValue | (uint8_T)((uint8_T)
- (CAN2PSC_B.CANPack3.Data[3]) & (uint8_T)(0xFU));
- }
-
- unpackedValue = tempValue;
- }
-
- outValue = (real64_T) (unpackedValue);
- }
-
- {
- real64_T result = (real64_T) outValue;
- PDC1_Status_DistanceFML_Lvl = result;
- }
- }
-
- /* --------------- START Unpacking signal 17 ------------------
- * startBit = 28
- * length = 4
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- {
- real64_T outValue = 0;
-
- {
- uint8_T unpackedValue = 0;
-
- {
- uint8_T tempValue = (uint8_T) (0);
-
- {
- tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
- (CAN2PSC_B.CANPack3.Data[3]) & (uint8_T)(0xF0U)) >> 4);
- }
-
- unpackedValue = tempValue;
- }
-
- outValue = (real64_T) (unpackedValue);
- }
-
- {
- real64_T result = (real64_T) outValue;
- PDC1_Status_DistanceFMR_Lvl = result;
- }
- }
-
- /* --------------- START Unpacking signal 18 ------------------
- * startBit = 20
- * length = 4
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- {
- real64_T outValue = 0;
-
- {
- uint8_T unpackedValue = 0;
-
- {
- uint8_T tempValue = (uint8_T) (0);
-
- {
- tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
- (CAN2PSC_B.CANPack3.Data[2]) & (uint8_T)(0xF0U)) >> 4);
- }
-
- unpackedValue = tempValue;
- }
-
- outValue = (real64_T) (unpackedValue);
- }
-
- {
- real64_T result = (real64_T) outValue;
- PDC1_Status_DistanceFR_Lvl = result;
- }
- }
-
- /* --------------- START Unpacking signal 19 ------------------
- * startBit = 32
- * length = 4
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- {
- real64_T outValue = 0;
-
- {
- uint8_T unpackedValue = 0;
-
- {
- uint8_T tempValue = (uint8_T) (0);
-
- {
- tempValue = tempValue | (uint8_T)((uint8_T)
- (CAN2PSC_B.CANPack3.Data[4]) & (uint8_T)(0xFU));
- }
-
- unpackedValue = tempValue;
- }
-
- outValue = (real64_T) (unpackedValue);
- }
-
- {
- real64_T result = (real64_T) outValue;
- PDC1_Status_DistanceRL_Lvl = result;
- }
- }
-
- /* --------------- START Unpacking signal 20 ------------------
- * startBit = 36
- * length = 4
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- {
- real64_T outValue = 0;
-
- {
- uint8_T unpackedValue = 0;
-
- {
- uint8_T tempValue = (uint8_T) (0);
-
- {
- tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
- (CAN2PSC_B.CANPack3.Data[4]) & (uint8_T)(0xF0U)) >> 4);
- }
-
- unpackedValue = tempValue;
- }
-
- outValue = (real64_T) (unpackedValue);
- }
-
- {
- real64_T result = (real64_T) outValue;
- PDC1_Status_DistanceRML_Lvl = result;
- }
- }
-
- /* --------------- START Unpacking signal 21 ------------------
- * startBit = 40
- * length = 4
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- {
- real64_T outValue = 0;
-
- {
- uint8_T unpackedValue = 0;
-
- {
- uint8_T tempValue = (uint8_T) (0);
-
- {
- tempValue = tempValue | (uint8_T)((uint8_T)
- (CAN2PSC_B.CANPack3.Data[5]) & (uint8_T)(0xFU));
- }
-
- unpackedValue = tempValue;
- }
-
- outValue = (real64_T) (unpackedValue);
- }
-
- {
- real64_T result = (real64_T) outValue;
- PDC1_Status_DistanceRMR_Lvl = result;
- }
- }
-
- /* --------------- START Unpacking signal 22 ------------------
- * startBit = 44
- * length = 4
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- {
- real64_T outValue = 0;
-
- {
- uint8_T unpackedValue = 0;
-
- {
- uint8_T tempValue = (uint8_T) (0);
-
- {
- tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
- (CAN2PSC_B.CANPack3.Data[5]) & (uint8_T)(0xF0U)) >> 4);
- }
-
- unpackedValue = tempValue;
- }
-
- outValue = (real64_T) (unpackedValue);
- }
-
- {
- real64_T result = (real64_T) outValue;
- PDC1_Status_DistanceRR_Lvl = result;
- }
- }
-
- /* --------------- START Unpacking signal 23 ------------------
- * startBit = 9
- * length = 1
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 24 ------------------
- * startBit = 8
- * length = 1
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 25 ------------------
- * startBit = 59
- * length = 3
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 26 ------------------
- * startBit = 12
- * length = 4
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
- }
- }
- }
- }
-
- /* S-Function (scanpack): '<S1>/CAN Pack1' */
- /* S-Function (scanpack): '<S1>/CAN Pack1' */
- CAN2PSC_B.CANPack1.ID = 1073U;
- CAN2PSC_B.CANPack1.Length = 8U;
- CAN2PSC_B.CANPack1.Extended = 0U;
- CAN2PSC_B.CANPack1.Remote = 0;
- CAN2PSC_B.CANPack1.Data[0] = 0;
- CAN2PSC_B.CANPack1.Data[1] = 0;
- CAN2PSC_B.CANPack1.Data[2] = 0;
- CAN2PSC_B.CANPack1.Data[3] = 0;
- CAN2PSC_B.CANPack1.Data[4] = 0;
- CAN2PSC_B.CANPack1.Data[5] = 0;
- CAN2PSC_B.CANPack1.Data[6] = 0;
- CAN2PSC_B.CANPack1.Data[7] = 0;
-
- {
- (void) memcpy((CAN2PSC_B.CANPack1.Data), &CAN2PSC_B.TCAN_Data_n[0],
- 8 * sizeof(uint8_T));
- }
-
- /* S-Function (scanunpack): '<S1>/CAN Unpack1' */
- {
- /* S-Function (scanunpack): '<S1>/CAN Unpack1' */
- if ((8 == CAN2PSC_B.CANPack1.Length) && (CAN2PSC_B.CANPack1.ID !=
- INVALID_CAN_ID) ) {
- if ((1073 == CAN2PSC_B.CANPack1.ID) && (0U == CAN2PSC_B.CANPack1.Extended)
- ) {
- {
- /* --------------- START Unpacking signal 0 ------------------
- * startBit = 2
- * length = 3
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- {
- real64_T outValue = 0;
-
- {
- uint8_T unpackedValue = 0;
-
- {
- uint8_T tempValue = (uint8_T) (0);
-
- {
- tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
- (CAN2PSC_B.CANPack1.Data[0]) & (uint8_T)(0x1CU)) >> 2);
- }
-
- unpackedValue = tempValue;
- }
-
- outValue = (real64_T) (unpackedValue);
- }
-
- {
- real64_T result = (real64_T) outValue;
- PSC2_Status_FlankDistanceFL_Lvl = result;
- }
- }
-
- /* --------------- START Unpacking signal 1 ------------------
- * startBit = 5
- * length = 3
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- {
- real64_T outValue = 0;
-
- {
- uint8_T unpackedValue = 0;
-
- {
- uint8_T tempValue = (uint8_T) (0);
-
- {
- tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
- (CAN2PSC_B.CANPack1.Data[0]) & (uint8_T)(0xE0U)) >> 5);
- }
-
- unpackedValue = tempValue;
- }
-
- outValue = (real64_T) (unpackedValue);
- }
-
- {
- real64_T result = (real64_T) outValue;
- PSC2_Status_FlankDistanceFR_Lvl = result;
- }
- }
-
- /* --------------- START Unpacking signal 2 ------------------
- * startBit = 15
- * length = 3
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 3 ------------------
- * startBit = 16
- * length = 3
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 4 ------------------
- * startBit = 9
- * length = 3
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- {
- real64_T outValue = 0;
-
- {
- uint8_T unpackedValue = 0;
-
- {
- uint8_T tempValue = (uint8_T) (0);
-
- {
- tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
- (CAN2PSC_B.CANPack1.Data[1]) & (uint8_T)(0xEU)) >> 1);
- }
-
- unpackedValue = tempValue;
- }
-
- outValue = (real64_T) (unpackedValue);
- }
-
- {
- real64_T result = (real64_T) outValue;
- PSC2_Status_FlankDistanceRL_Lvl = result;
- }
- }
-
- /* --------------- START Unpacking signal 5 ------------------
- * startBit = 19
- * length = 3
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 6 ------------------
- * startBit = 22
- * length = 3
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- /*
- * Signal is not connected or connected to terminator.
- * No unpacking code generated.
- */
-
- /* --------------- START Unpacking signal 7 ------------------
- * startBit = 12
- * length = 3
- * desiredSignalByteLayout = BIGENDIAN
- * dataType = UNSIGNED
- * factor = 1.0
- * offset = 0.0
- * -----------------------------------------------------------------------*/
- {
- real64_T outValue = 0;
-
- {
- uint8_T unpackedValue = 0;
-
- {
- uint8_T tempValue = (uint8_T) (0);
-
- {
- tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
- (CAN2PSC_B.CANPack1.Data[1]) & (uint8_T)(0x70U)) >> 4);
- }
-
- unpackedValue = tempValue;
- }
-
- outValue = (real64_T) (unpackedValue);
- }
-
- {
- real64_T result = (real64_T) outValue;
- PSC2_Status_FlankDistanceRR_Lvl = result;
- }
- }
- }
- }
- }
- }
- }
-
- /* Model initialize function */
- void CAN2PSC_initialize(void)
- {
- /* Start for S-Function (scanunpack): '<S1>/CAN Unpack4' */
-
- /*-----------S-Function Block: <S1>/CAN Unpack4 -----------------*/
-
- /* Start for S-Function (scanunpack): '<S1>/CAN Unpack1' */
-
- /*-----------S-Function Block: <S1>/CAN Unpack1 -----------------*/
- }
-
- /* Model terminate function */
- void CAN2PSC_terminate(void)
- {
- /* (no terminate code required) */
- }
-
- /*
- * File trailer for generated code.
- *
- * [EOF]
- */
-
- /*
- * File: rtmodel.h
- *
- * Code generated for Simulink model 'CAN2PSC'.
- *
- * Model version : 1.3
- * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Mon Jun 12 16:10:53 2023
- *
- * Target selection: ert.tlc
- * Embedded hardware selection: ARM Compatible->ARM Cortex
- * Code generation objectives: Unspecified
- * Validation result: Not run
- */
-
- #ifndef RTW_HEADER_rtmodel_h_
- #define RTW_HEADER_rtmodel_h_
- #include "CAN2PSC.h"
-
- /* Macros generated for backwards compatibility */
- #ifndef rtmGetStopRequested
- #define rtmGetStopRequested
- (rtm) ((void*) 0)
- #endif
- #endif /* RTW_HEADER_rtmodel_h_ */
-
- /*
- * File trailer for generated code.
- *
- * [EOF]
- */
- /*
- * File: rtwtypes.h
- *
- * Code generated for Simulink model 'CAN2PSC'.
- *
- * Model version : 1.3
- * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Mon Jun 12 16:10:53 2023
- *
- * Target selection: ert.tlc
- * Embedded hardware selection: ARM Compatible->ARM Cortex
- * Code generation objectives: Unspecified
- * Validation result: Not run
- */
-
- #ifndef RTWTYPES_H
- #define RTWTYPES_H
-
- /* Logical type definitions */
- #if (!defined(__cplusplus))
- #ifndef false
- #define false (0U)
- #endif
-
- #ifndef true
- #define true (1U)
- #endif
- #endif
-
- /*=======================================================================*
- * Target hardware information
- * Device type: ARM Compatible->ARM Cortex
- * Number of bits: char: 8 short: 16 int: 32
- * long: 32 long long: 64
- * native word size: 32
- * Byte ordering: LittleEndian
- * Signed integer division rounds to: Zero
- * Shift right on a signed integer as arithmetic shift: on
- *=======================================================================*/
-
- /*=======================================================================*
- * Fixed width word size data types: *
- * int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers *
- * uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers *
- * real32_T, real64_T - 32 and 64 bit floating point numbers *
- *=======================================================================*/
- typedef signed char int8_T;
- typedef unsigned char uint8_T;
- typedef short int16_T;
- typedef unsigned short uint16_T;
- typedef int int32_T;
- typedef unsigned int uint32_T;
- typedef long long int64_T;
- typedef unsigned long long uint64_T;
- typedef float real32_T;
- typedef double real64_T;
-
- /*===========================================================================*
- * Generic type definitions: boolean_T, char_T, byte_T, int_T, uint_T, *
- * real_T, time_T, ulong_T, ulonglong_T. *
- *===========================================================================*/
- typedef double real_T;
- typedef double time_T;
- typedef unsigned char boolean_T;
- typedef int int_T;
- typedef unsigned int uint_T;
- typedef unsigned long ulong_T;
- typedef unsigned long long ulonglong_T;
- typedef char char_T;
- typedef unsigned char uchar_T;
- typedef char_T byte_T;
-
- /*===========================================================================*
- * Complex number type definitions *
- *===========================================================================*/
- #define CREAL_T
-
- typedef struct {
- real32_T re;
- real32_T im;
- } creal32_T;
-
- typedef struct {
- real64_T re;
- real64_T im;
- } creal64_T;
-
- typedef struct {
- real_T re;
- real_T im;
- } creal_T;
-
- #define CINT8_T
-
- typedef struct {
- int8_T re;
- int8_T im;
- } cint8_T;
-
- #define CUINT8_T
-
- typedef struct {
- uint8_T re;
- uint8_T im;
- } cuint8_T;
-
- #define CINT16_T
-
- typedef struct {
- int16_T re;
- int16_T im;
- } cint16_T;
-
- #define CUINT16_T
-
- typedef struct {
- uint16_T re;
- uint16_T im;
- } cuint16_T;
-
- #define CINT32_T
-
- typedef struct {
- int32_T re;
- int32_T im;
- } cint32_T;
-
- #define CUINT32_T
-
- typedef struct {
- uint32_T re;
- uint32_T im;
- } cuint32_T;
-
- #define CINT64_T
-
- typedef struct {
- int64_T re;
- int64_T im;
- } cint64_T;
-
- #define CUINT64_T
-
- typedef struct {
- uint64_T re;
- uint64_T im;
- } cuint64_T;
-
- /*=======================================================================*
- * Min and Max: *
- * int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers *
- * uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers *
- *=======================================================================*/
- #define MAX_int8_T ((int8_T)(127))
- #define MIN_int8_T ((int8_T)(-128))
- #define MAX_uint8_T ((uint8_T)(255U))
- #define MAX_int16_T ((int16_T)(32767))
- #define MIN_int16_T ((int16_T)(-32768))
- #define MAX_uint16_T ((uint16_T)(65535U))
- #define MAX_int32_T ((int32_T)(2147483647))
- #define MIN_int32_T ((int32_T)(-2147483647-1))
- #define MAX_uint32_T ((uint32_T)(0xFFFFFFFFU))
- #define MAX_int64_T ((int64_T)(9223372036854775807LL))
- #define MIN_int64_T ((int64_T)(-9223372036854775807LL-1LL))
- #define MAX_uint64_T ((uint64_T)(0xFFFFFFFFFFFFFFFFULL))
-
- /* Block D-Work pointer type */
- typedef void * pointer_T;
-
- #endif /* RTWTYPES_H */
-
- /*
- * File trailer for generated code.
- *
- * [EOF]
- */
在声明一些变量后,先定义了函数CAN2PSC_MATLABFunction1,即为模型中的Matlab Function。上面的注释为:原子系统的输出和更新:代码为Simulink显示对应使用的,点击即可高亮出对应模型部分内容。
可以对比看看,他这将输出、状态值也当成输入,给了函数,然后对输出进行赋0操作。本来M代码是使用永久变量来存上次数据,这里对应的是状态变量。
状态(States)是离散系统运算过程中必不可少的元素。
我们知道,离散系统是在每一个离散的时间点上, 运行一次Step函数。某一时刻运行一次Step函数,除了需要输入数据(通过外部输入信号输入)以外,往往还需要上一个时刻的运算结果,甚至之前连续几个时刻的运算结果。
在嵌入式系统中,这些结果需要一个变量来存储,这个变量即为状态变量。
在Simulink模型库中,凡是包含离散因子“z”的模块,全部具有状态变量。这些模块在生成代码时,都会生成一个名为“模型名_DW”的变量来保存状态变量。
然后就是step函数的定义,先引用了CAN2PSC_MATLABFunction1,完成红框部分的处理,再引用一次完成蓝框处理。
然后就CANPack部分,将结构变量CAN2PSC_B的CANPack3的ID长度和Data内容赋值,然后将TCAN_Data的内容拷贝给CANPack3的Data部分。
其中结构体的定义如下,出现的o1等是模型中输出没在用的内容。
CANUpack部分,if语句下长度对,ID不为Invalid ID,的情况下,ID对,长度Extended对,进行解析,注释是对应CANdbc文件内容,各个信号的解析,但是其出口接的是terminator或没接,就美生成代码。
在用的出口就生成了下面的代码
然后类似的,再执行下面的1073的解析内容。
结束后为一个初始化函数和一个终止函数的定义
当设置选择了硬件树莓派、并发执行。生成代码内容如下
除了CAN2PSC_types.h其他应该没啥差别,多了#include "rtwtypes.h"和
typedef struct P_CAN2PSC_T_ P_CAN2PSC_T;
-
- /*
- * File: CAN2PSC_types.h
- *
- * Code generated for Simulink model 'CAN2PSC'.
- *
- * Model version : 1.4
- * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Tue Jun 13 09:58:54 2023
- *
- * Target selection: ert.tlc
- * Embedded hardware selection: ARM Compatible->ARM Cortex
- * Code generation objectives: Unspecified
- * Validation result: Not run
- */
-
- #ifndef RTW_HEADER_CAN2PSC_types_h_
- #define RTW_HEADER_CAN2PSC_types_h_
- #include "rtwtypes.h"
-
- /* Model Code Variants */
-
- /* Parameters (default storage) */
- typedef struct P_CAN2PSC_T_ P_CAN2PSC_T;
-
- /* Forward declaration for rtModel */
- typedef struct tag_RTM_CAN2PSC_T RT_MODEL_CAN2PSC_T;
-
- #endif /* RTW_HEADER_CAN2PSC_types_h_ */
-
- /*
- * File trailer for generated code.
- *
- * [EOF]
- */
- /*
- * File: ert_main.c
- *
- * Code generated for Simulink model 'CAN2PSC'.
- *
- * Model version : 1.4
- * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Tue Jun 13 09:58:54 2023
- *
- * Target selection: ert.tlc
- * Embedded hardware selection: ARM Compatible->ARM Cortex
- * Code generation objectives: Unspecified
- * Validation result: Not run
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include "CAN2PSC.h"
- #include "CAN2PSC_private.h"
- #include "rtwtypes.h"
- #include "limits.h"
- #include "MW_raspi_init.h"
- #include "MW_Pyserver_control.h"
- #include "linuxinitialize.h"
- #define UNUSED(x) x = x
- #define NAMELEN 16
-
- /* Function prototype declaration*/
- /*函数原型声明*/
-
- void exitFcn(int sig);
- void *terminateTask(void *arg);
- void *baseRateTask(void *arg);
- void *subrateTask(void *arg);
- volatile boolean_T stopRequested = false;
- volatile boolean_T runModel = true;
- sem_t stopSem;
- sem_t baserateTaskSem;
- pthread_t schedulerThread;
- pthread_t baseRateThread;
- void *threadJoinStatus;
- int terminatingmodel = 0;
- void *baseRateTask(void *arg)
- {
- runModel = (rtmGetErrorStatus(CAN2PSC_M) == (NULL));
- while (runModel) {
- sem_wait(&baserateTaskSem);
- CAN2PSCFunc();
-
- /* Get model outputs here */
- stopRequested = !((rtmGetErrorStatus(CAN2PSC_M) == (NULL)));
- }
-
- runModel = 0;
- terminateTask(arg);
- pthread_exit((void *)0);
- return NULL;
- }
-
- void exitFcn(int sig)
- {
- UNUSED(sig);
- rtmSetErrorStatus(CAN2PSC_M, "stopping the model");
- runModel = 0;
- }
-
- void *terminateTask(void *arg)
- {
- UNUSED(arg);
- terminatingmodel = 1;
-
- {
- runModel = 0;
- }
-
- MW_killPyserver();
- mwRaspiTerminate();
-
- /* Disable rt_OneStep() here */
-
- /* Terminate model */
- CAN2PSC_terminate();
- sem_post(&stopSem);
- return NULL;
- }
-
- int main(int argc, char **argv)
- {
- UNUSED(argc);
- UNUSED(argv);
- mwRaspiInit();
- MW_launchPyserver();
- rtmSetErrorStatus(CAN2PSC_M, 0);
-
- /* Initialize model */
- CAN2PSC_initialize();
-
- /* Call RTOS Initialization function */
- myRTOSInit(0.01, 0);
-
- /* Wait for stop semaphore */
- sem_wait(&stopSem);
-
- #if (MW_NUMBER_TIMER_DRIVEN_TASKS > 0)
-
- {
- int i;
- for (i=0; i < MW_NUMBER_TIMER_DRIVEN_TASKS; i++) {
- CHECK_STATUS(sem_destroy(&timerTaskSem[i]), 0, "sem_destroy");
- }
- }
-
- #endif
-
- return 0;
- }
-
- /*
- * File trailer for generated code.
- *
- * [EOF]
- */
-
- /*
- * File: CAN2PSC_data.c
- *
- * Code generated for Simulink model 'CAN2PSC'.
- *
- * Model version : 1.4
- * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Tue Jun 13 09:58:54 2023
- *
- * Target selection: ert.tlc
- * Embedded hardware selection: ARM Compatible->ARM Cortex
- * Code generation objectives: Unspecified
- * Validation result: Not run
- */
-
- #include "CAN2PSC.h"
- #include "CAN2PSC_private.h"
-
- /* Block parameters (default storage) */
- P_CAN2PSC_T CAN2PSC_P = {
- /* Expression: 2
- * Referenced by: '<S1>/Tid2'
- */
- 2.0,
-
- /* Expression: 608
- * Referenced by: '<S1>/Tid8'
- */
- 608.0,
-
- /* Expression: 1073
- * Referenced by: '<S1>/Tid1'
- */
- 1073.0
- };
-
- /*
- * File trailer for generated code.
- *
- * [EOF]
- */
-
- /*
- * File: rtmodel.h
- *
- * Code generated for Simulink model 'CAN2PSC'.
- *
- * Model version : 1.4
- * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Tue Jun 13 09:58:54 2023
- *
- * Target selection: ert.tlc
- * Embedded hardware selection: ARM Compatible->ARM Cortex
- * Code generation objectives: Unspecified
- * Validation result: Not run
- */
-
- #ifndef RTW_HEADER_rtmodel_h_
- #define RTW_HEADER_rtmodel_h_
- #include "CAN2PSC.h"
-
- /* Macros generated for backwards compatibility */
- #ifndef rtmGetStopRequested
- #define rtmGetStopRequested(rtm) ((void*) 0)
- #endif
- #endif /* RTW_HEADER_rtmodel_h_ */
-
- /*
- * File trailer for generated code.
- *
- * [EOF]
- */
剩下的应该是在树莓派上运行需要的内容。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。