当前位置:   article > 正文

【Simulink代码生成】初尝试_rtmgeterrorstatus

rtmgeterrorstatus

目录

不指定硬件树莓派

 生成文件

CAN2PSC_types.h文件:

CAN2PSC_private.h文件:

CAN2PSC.h文件:

CAN2PSC.c文件:

rtmodel.c文件:

 rtwtypes.h文件:

核心代码部分CAN2PSC.c文件解析:

指定硬件树莓派,勾选并行

生成的文件

CAN2PSC_types.h内容

ert_main.c的内容

 CAN2PSC_data.c内容

rtmodel.h内容


不指定硬件树莓派

使用的模型

信号对象和信号指定

由于输入没指定维度时,生成代码报错,无法自动确定数据维度,后指定了维度。

模型参数配置:

尝试仅仅生成代码,不指定硬件为树莓派,此时勾选并发执行,将会报错: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的数据结构的定义和声明。

引用来源: MBD的Simulink使用技巧②:Simulink代码生成的基本概念 - 知乎

CAN2PSC_types.h文件:

  1. /*
  2. * File: CAN2PSC_types.h
  3. *
  4. * Code generated for Simulink model 'CAN2PSC'.
  5. *
  6. * Model version : 1.3
  7. * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. * C/C++ source code generated on : Mon Jun 12 16:10:53 2023
  9. *
  10. * Target selection: ert.tlc
  11. * Embedded hardware selection: ARM Compatible->ARM Cortex
  12. * Code generation objectives: Unspecified
  13. * Validation result: Not run
  14. */
  15. #ifndef RTW_HEADER_CAN2PSC_types_h_
  16. #define RTW_HEADER_CAN2PSC_types_h_
  17. /* Model Code Variants */
  18. /* Forward declaration for rtModel */
  19. typedef struct tag_RTM_CAN2PSC_T RT_MODEL_CAN2PSC_T;
  20. #endif /* RTW_HEADER_CAN2PSC_types_h_ */
  21. /*
  22. * File trailer for generated code.
  23. *
  24. * [EOF]
  25. */

CAN2PSC_private.h文件:

  1. /*
  2. * File: CAN2PSC_private.h
  3. *
  4. * Code generated for Simulink model 'CAN2PSC'.
  5. *
  6. * Model version : 1.3
  7. * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. * C/C++ source code generated on : Mon Jun 12 16:10:53 2023
  9. *
  10. * Target selection: ert.tlc
  11. * Embedded hardware selection: ARM Compatible->ARM Cortex
  12. * Code generation objectives: Unspecified
  13. * Validation result: Not run
  14. */
  15. #ifndef RTW_HEADER_CAN2PSC_private_h_
  16. #define RTW_HEADER_CAN2PSC_private_h_
  17. #include "rtwtypes.h"
  18. #include "CAN2PSC.h"
  19. extern void CAN2PSC_MATLABFunction1(const uint8_T rtu_UDP[26], real_T rtu_Num,
  20. real_T rtu_TCANid, uint8_T rty_TCAN_Data[8], DW_MATLABFunction1_CAN2PSC_T
  21. *localDW);
  22. #endif /* RTW_HEADER_CAN2PSC_private_h_ */
  23. /*
  24. * File trailer for generated code.
  25. *
  26. * [EOF]
  27. */

CAN2PSC.h文件:

  1. /*
  2. * File: CAN2PSC.h
  3. *
  4. * Code generated for Simulink model 'CAN2PSC'.
  5. *
  6. * Model version : 1.3
  7. * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. * C/C++ source code generated on : Mon Jun 12 16:10:53 2023
  9. *
  10. * Target selection: ert.tlc
  11. * Embedded hardware selection: ARM Compatible->ARM Cortex
  12. * Code generation objectives: Unspecified
  13. * Validation result: Not run
  14. */
  15. #ifndef RTW_HEADER_CAN2PSC_h_
  16. #define RTW_HEADER_CAN2PSC_h_
  17. #include <string.h>
  18. #ifndef CAN2PSC_COMMON_INCLUDES_
  19. #define CAN2PSC_COMMON_INCLUDES_
  20. #include <math.h>
  21. #include <string.h>
  22. #include "rtwtypes.h"
  23. #include "can_message.h"
  24. #endif /* CAN2PSC_COMMON_INCLUDES_ */
  25. #include "CAN2PSC_types.h"
  26. /* Macros for accessing real-time model data structure */
  27. /*用于访问实时模型数据结构的宏*/
  28. #ifndef rtmGetErrorStatus
  29. #define rtmGetErrorStatus(rtm) ((rtm)->errorStatus)
  30. #endif
  31. #ifndef rtmSetErrorStatus
  32. #define rtmSetErrorStatus(rtm, val) ((rtm)->errorStatus = (val))
  33. #endif
  34. /* user code (top of export header file) */
  35. /*用户代码(导出头文件顶部)*/
  36. #include "can_message.h"
  37. /* Block states (default storage) for system '<S1>/MATLAB Function1' */
  38. /*系统'<S1>/MATLAB Function1'的块状态(默认存储)*/
  39. typedef struct {
  40. uint8_T TCAN_Last[8]; /* '<S1>/MATLAB Function1' */
  41. } DW_MATLABFunction1_CAN2PSC_T;
  42. /* Block signals (default storage) */
  43. /*块信号(默认存储)*/
  44. typedef struct {
  45. CAN_DATATYPE CANPack3; /* '<S1>/CAN Pack3' */
  46. CAN_DATATYPE CANPack1; /* '<S1>/CAN Pack1' */
  47. real_T CANUnpack4_o1; /* '<S1>/CAN Unpack4' */
  48. real_T CANUnpack4_o2; /* '<S1>/CAN Unpack4' */
  49. real_T CANUnpack4_o3; /* '<S1>/CAN Unpack4' */
  50. real_T CANUnpack4_o4; /* '<S1>/CAN Unpack4' */
  51. real_T CANUnpack4_o5; /* '<S1>/CAN Unpack4' */
  52. real_T CANUnpack4_o6; /* '<S1>/CAN Unpack4' */
  53. real_T CANUnpack4_o7; /* '<S1>/CAN Unpack4' */
  54. real_T CANUnpack4_o8; /* '<S1>/CAN Unpack4' */
  55. real_T CANUnpack4_o9; /* '<S1>/CAN Unpack4' */
  56. real_T CANUnpack4_o10; /* '<S1>/CAN Unpack4' */
  57. real_T CANUnpack4_o11; /* '<S1>/CAN Unpack4' */
  58. real_T CANUnpack4_o12; /* '<S1>/CAN Unpack4' */
  59. real_T CANUnpack4_o13; /* '<S1>/CAN Unpack4' */
  60. real_T CANUnpack4_o14; /* '<S1>/CAN Unpack4' */
  61. real_T CANUnpack4_o15; /* '<S1>/CAN Unpack4' */
  62. real_T CANUnpack4_o24; /* '<S1>/CAN Unpack4' */
  63. real_T CANUnpack4_o25; /* '<S1>/CAN Unpack4' */
  64. real_T CANUnpack4_o26; /* '<S1>/CAN Unpack4' */
  65. real_T CANUnpack4_o27; /* '<S1>/CAN Unpack4' */
  66. real_T CANUnpack1_o3; /* '<S1>/CAN Unpack1' */
  67. real_T CANUnpack1_o4; /* '<S1>/CAN Unpack1' */
  68. real_T CANUnpack1_o6; /* '<S1>/CAN Unpack1' */
  69. real_T CANUnpack1_o7; /* '<S1>/CAN Unpack1' */
  70. uint8_T TCAN_Data[8]; /* '<S1>/MATLAB Function8' */
  71. uint8_T TCAN_Data_n[8]; /* '<S1>/MATLAB Function1' */
  72. } B_CAN2PSC_T;
  73. /* Block states (default storage) for system '<Root>' */
  74. /*系统'<Root>'的块状态(默认存储)*/
  75. typedef struct {
  76. int_T CANUnpack4_ModeSignalID; /* '<S1>/CAN Unpack4' */
  77. int_T CANUnpack4_StatusPortID; /* '<S1>/CAN Unpack4' */
  78. int_T CANUnpack1_ModeSignalID; /* '<S1>/CAN Unpack1' */
  79. int_T CANUnpack1_StatusPortID; /* '<S1>/CAN Unpack1' */
  80. DW_MATLABFunction1_CAN2PSC_T sf_MATLABFunction8;/* '<S1>/MATLAB Function8' */
  81. DW_MATLABFunction1_CAN2PSC_T sf_MATLABFunction1;/* '<S1>/MATLAB Function1' */
  82. } DW_CAN2PSC_T;
  83. /* Real-time Model Data Structure */
  84. /*实时模型数据结构*/
  85. struct tag_RTM_CAN2PSC_T {
  86. const char_T *errorStatus;
  87. };
  88. /* Block signals (default storage) */
  89. extern B_CAN2PSC_T CAN2PSC_B;
  90. /* Block states (default storage) */
  91. extern DW_CAN2PSC_T CAN2PSC_DW;
  92. /* Model entry point functions */
  93. /*模型入口点函数*/
  94. extern void CAN2PSC_initialize(void);
  95. extern void CAN2PSCFunc(void);
  96. extern void CAN2PSC_terminate(void);
  97. /* Real-time Model object */
  98. /*实时模型对象*/
  99. extern RT_MODEL_CAN2PSC_T *const CAN2PSC_M;
  100. /* Exported data declaration */
  101. /*导出的数据声明*/
  102. /* Declaration for custom storage class: Global */
  103. /*自定义存储类的声明:全局*/
  104. extern real_T PDC1_Status_DistanceFL_Lvl;/* '<S1>/CAN Unpack4' */
  105. extern real_T PDC1_Status_DistanceFML_Lvl;/* '<S1>/CAN Unpack4' */
  106. extern real_T PDC1_Status_DistanceFMR_Lvl;/* '<S1>/CAN Unpack4' */
  107. extern real_T PDC1_Status_DistanceFR_Lvl;/* '<S1>/CAN Unpack4' */
  108. extern real_T PDC1_Status_DistanceRL_Lvl;/* '<S1>/CAN Unpack4' */
  109. extern real_T PDC1_Status_DistanceRML_Lvl;/* '<S1>/CAN Unpack4' */
  110. extern real_T PDC1_Status_DistanceRMR_Lvl;/* '<S1>/CAN Unpack4' */
  111. extern real_T PDC1_Status_DistanceRR_Lvl;/* '<S1>/CAN Unpack4' */
  112. extern real_T PSC2_Status_FlankDistanceFL_Lvl;/* '<S1>/CAN Unpack1' */
  113. extern real_T PSC2_Status_FlankDistanceFR_Lvl;/* '<S1>/CAN Unpack1' */
  114. extern real_T PSC2_Status_FlankDistanceRL_Lvl;/* '<S1>/CAN Unpack1' */
  115. extern real_T PSC2_Status_FlankDistanceRR_Lvl;/* '<S1>/CAN Unpack1' */
  116. extern uint8_T PSC_UDP_Data[26]; /* '<Root>/In1' */
  117. /*-
  118. * The generated code includes comments that allow you to trace directly
  119. * back to the appropriate location in the model. The basic format
  120. * is <system>/block_name, where system is the system number (uniquely
  121. * assigned by Simulink) and block_name is the name of the block.
  122. *
  123. * Use the MATLAB hilite_system command to trace the generated code back
  124. * to the model. For example,
  125. *
  126. * hilite_system('<S3>') - opens system 3
  127. * hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
  128. *
  129. * Here is the system hierarchy for this model
  130. *
  131. * '<Root>' : 'CAN2PSC'
  132. * '<S1>' : 'CAN2PSC/CAN2_PSC'
  133. * '<S2>' : 'CAN2PSC/CAN2_PSC/MATLAB Function1'
  134. * '<S3>' : 'CAN2PSC/CAN2_PSC/MATLAB Function8'
  135. */
  136. /*-
  137. *生成的代码包括注释,这些注释允许您直接追溯到模型中的适当位置。基本格式为<system>/block_name,其中system是系统编号(由Simulink唯一分配),block_name是块的名称。
  138. *
  139. *使用MATLAB hilite_system命令将生成的代码追溯到模型。例如
  140. *
  141. *hilite_system('<S3>')-打开系统3
  142. *hilite_system('<S3>/Kp')-打开并选择驻留在S3中的块Kp
  143. *
  144. *以下是此模型的系统层次结构
  145. *
  146. *'<Root>':'CAN2PSC'
  147. *“<S1>”:“CAN2PSC/CAN2_PSC”
  148. *“<S2>”:“CAN2PSC/CAN2_PSC/MATLAB函数1”
  149. *“<S3>”:“CAN2PSC/CAN2_PSC/MATLAB函数8”
  150. */
  151. #endif /* RTW_HEADER_CAN2PSC_h_ */
  152. /*
  153. * File trailer for generated code.
  154. *
  155. * [EOF]
  156. */

CAN2PSC.c文件:

  1. /*
  2. * File: CAN2PSC.c
  3. *
  4. * Code generated for Simulink model 'CAN2PSC'.
  5. *
  6. * Model version : 1.3
  7. * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. * C/C++ source code generated on : Mon Jun 12 16:10:53 2023
  9. *
  10. * Target selection: ert.tlc
  11. * Embedded hardware selection: ARM Compatible->ARM Cortex
  12. * Code generation objectives: Unspecified
  13. * Validation result: Not run
  14. */
  15. #include "CAN2PSC.h"
  16. #include "CAN2PSC_private.h"
  17. /* Block signals (default storage) */
  18. B_CAN2PSC_T CAN2PSC_B;
  19. /* Block states (default storage) */
  20. DW_CAN2PSC_T CAN2PSC_DW;
  21. /* Real-time model */
  22. static RT_MODEL_CAN2PSC_T CAN2PSC_M_;
  23. RT_MODEL_CAN2PSC_T *const CAN2PSC_M = &CAN2PSC_M_;
  24. /* Exported data definition */
  25. /* Definition for custom storage class: Global */
  26. real_T PDC1_Status_DistanceFL_Lvl; /* '<S1>/CAN Unpack4' */
  27. real_T PDC1_Status_DistanceFML_Lvl; /* '<S1>/CAN Unpack4' */
  28. real_T PDC1_Status_DistanceFMR_Lvl; /* '<S1>/CAN Unpack4' */
  29. real_T PDC1_Status_DistanceFR_Lvl; /* '<S1>/CAN Unpack4' */
  30. real_T PDC1_Status_DistanceRL_Lvl; /* '<S1>/CAN Unpack4' */
  31. real_T PDC1_Status_DistanceRML_Lvl; /* '<S1>/CAN Unpack4' */
  32. real_T PDC1_Status_DistanceRMR_Lvl; /* '<S1>/CAN Unpack4' */
  33. real_T PDC1_Status_DistanceRR_Lvl; /* '<S1>/CAN Unpack4' */
  34. real_T PSC2_Status_FlankDistanceFL_Lvl;/* '<S1>/CAN Unpack1' */
  35. real_T PSC2_Status_FlankDistanceFR_Lvl;/* '<S1>/CAN Unpack1' */
  36. real_T PSC2_Status_FlankDistanceRL_Lvl;/* '<S1>/CAN Unpack1' */
  37. real_T PSC2_Status_FlankDistanceRR_Lvl;/* '<S1>/CAN Unpack1' */
  38. uint8_T PSC_UDP_Data[26]; /* '<Root>/In1' */
  39. /*
  40. * Output and update for atomic system:
  41. * '<S1>/MATLAB Function1'
  42. * '<S1>/MATLAB Function8'
  43. */
  44. void CAN2PSC_MATLABFunction1(const uint8_T rtu_UDP[26], real_T rtu_Num, real_T
  45. rtu_TCANid, uint8_T rty_TCAN_Data[8], DW_MATLABFunction1_CAN2PSC_T *localDW)
  46. {
  47. real_T j;
  48. int32_T i;
  49. int32_T i_0;
  50. for (i = 0; i < 8; i++) {
  51. rty_TCAN_Data[i] = 0U;
  52. }
  53. for (i = 0; i < (int32_T)(rtu_Num - 1.0); i++) {
  54. j = ((real_T)i + 1.0) * 13.0 + 2.0;
  55. if ((((rtu_UDP[(int32_T)(j + 1.0) - 1] << 16) + ((uint32_T)rtu_UDP[(int32_T)
  56. j - 1] << 24)) + (rtu_UDP[(int32_T)(j + 2.0) - 1] << 8)) + rtu_UDP
  57. [(int32_T)(j + 3.0) - 1] == rtu_TCANid) {
  58. for (i_0 = 0; i_0 < 8; i_0++) {
  59. rty_TCAN_Data[i_0] = rtu_UDP[(int32_T)(((real_T)i_0 + 4.0) + j) - 1];
  60. localDW->TCAN_Last[i_0] = rty_TCAN_Data[i_0];
  61. }
  62. } else {
  63. for (i_0 = 0; i_0 < 8; i_0++) {
  64. rty_TCAN_Data[i_0] = localDW->TCAN_Last[i_0];
  65. }
  66. }
  67. }
  68. }
  69. /* Model step function */
  70. void CAN2PSCFunc(void)
  71. {
  72. /* MATLAB Function: '<S1>/MATLAB Function8' incorporates:
  73. * Constant: '<S1>/Tid2'
  74. * Constant: '<S1>/Tid8'
  75. * Inport: '<Root>/In1'
  76. */
  77. CAN2PSC_MATLABFunction1((&(PSC_UDP_Data[0])), 2.0, 608.0, CAN2PSC_B.TCAN_Data,
  78. &CAN2PSC_DW.sf_MATLABFunction8);
  79. /* MATLAB Function: '<S1>/MATLAB Function1' incorporates:
  80. * Constant: '<S1>/Tid1'
  81. * Constant: '<S1>/Tid2'
  82. * Inport: '<Root>/In1'
  83. */
  84. CAN2PSC_MATLABFunction1((&(PSC_UDP_Data[0])), 2.0, 1073.0,
  85. CAN2PSC_B.TCAN_Data_n, &CAN2PSC_DW.sf_MATLABFunction1);
  86. /* S-Function (scanpack): '<S1>/CAN Pack3' */
  87. /* S-Function (scanpack): '<S1>/CAN Pack3' */
  88. CAN2PSC_B.CANPack3.ID = 608U;
  89. CAN2PSC_B.CANPack3.Length = 8U;
  90. CAN2PSC_B.CANPack3.Extended = 0U;
  91. CAN2PSC_B.CANPack3.Remote = 0;
  92. CAN2PSC_B.CANPack3.Data[0] = 0;
  93. CAN2PSC_B.CANPack3.Data[1] = 0;
  94. CAN2PSC_B.CANPack3.Data[2] = 0;
  95. CAN2PSC_B.CANPack3.Data[3] = 0;
  96. CAN2PSC_B.CANPack3.Data[4] = 0;
  97. CAN2PSC_B.CANPack3.Data[5] = 0;
  98. CAN2PSC_B.CANPack3.Data[6] = 0;
  99. CAN2PSC_B.CANPack3.Data[7] = 0;
  100. {
  101. (void) memcpy((CAN2PSC_B.CANPack3.Data), &CAN2PSC_B.TCAN_Data[0],
  102. 8 * sizeof(uint8_T));
  103. }
  104. /* S-Function (scanunpack): '<S1>/CAN Unpack4' */
  105. {
  106. /* S-Function (scanunpack): '<S1>/CAN Unpack4' */
  107. if ((8 == CAN2PSC_B.CANPack3.Length) && (CAN2PSC_B.CANPack3.ID !=
  108. INVALID_CAN_ID) ) {
  109. if ((608 == CAN2PSC_B.CANPack3.ID) && (0U == CAN2PSC_B.CANPack3.Extended) )
  110. {
  111. {
  112. /* --------------- START Unpacking signal 0 ------------------
  113. * startBit = 0
  114. * length = 1
  115. * desiredSignalByteLayout = BIGENDIAN
  116. * dataType = UNSIGNED
  117. * factor = 1.0
  118. * offset = 0.0
  119. * -----------------------------------------------------------------------*/
  120. /*
  121. * Signal is not connected or connected to terminator.
  122. * No unpacking code generated.
  123. */
  124. /* --------------- START Unpacking signal 1 ------------------
  125. * startBit = 52
  126. * length = 1
  127. * desiredSignalByteLayout = BIGENDIAN
  128. * dataType = UNSIGNED
  129. * factor = 1.0
  130. * offset = 0.0
  131. * -----------------------------------------------------------------------*/
  132. /*
  133. * Signal is not connected or connected to terminator.
  134. * No unpacking code generated.
  135. */
  136. /* --------------- START Unpacking signal 2 ------------------
  137. * startBit = 2
  138. * length = 1
  139. * desiredSignalByteLayout = BIGENDIAN
  140. * dataType = UNSIGNED
  141. * factor = 1.0
  142. * offset = 0.0
  143. * -----------------------------------------------------------------------*/
  144. /*
  145. * Signal is not connected or connected to terminator.
  146. * No unpacking code generated.
  147. */
  148. /* --------------- START Unpacking signal 3 ------------------
  149. * startBit = 3
  150. * length = 1
  151. * desiredSignalByteLayout = BIGENDIAN
  152. * dataType = UNSIGNED
  153. * factor = 1.0
  154. * offset = 0.0
  155. * -----------------------------------------------------------------------*/
  156. /*
  157. * Signal is not connected or connected to terminator.
  158. * No unpacking code generated.
  159. */
  160. /* --------------- START Unpacking signal 4 ------------------
  161. * startBit = 1
  162. * length = 1
  163. * desiredSignalByteLayout = BIGENDIAN
  164. * dataType = UNSIGNED
  165. * factor = 1.0
  166. * offset = 0.0
  167. * -----------------------------------------------------------------------*/
  168. /*
  169. * Signal is not connected or connected to terminator.
  170. * No unpacking code generated.
  171. */
  172. /* --------------- START Unpacking signal 5 ------------------
  173. * startBit = 53
  174. * length = 1
  175. * desiredSignalByteLayout = BIGENDIAN
  176. * dataType = UNSIGNED
  177. * factor = 1.0
  178. * offset = 0.0
  179. * -----------------------------------------------------------------------*/
  180. /*
  181. * Signal is not connected or connected to terminator.
  182. * No unpacking code generated.
  183. */
  184. /* --------------- START Unpacking signal 6 ------------------
  185. * startBit = 4
  186. * length = 1
  187. * desiredSignalByteLayout = BIGENDIAN
  188. * dataType = UNSIGNED
  189. * factor = 1.0
  190. * offset = 0.0
  191. * -----------------------------------------------------------------------*/
  192. /*
  193. * Signal is not connected or connected to terminator.
  194. * No unpacking code generated.
  195. */
  196. /* --------------- START Unpacking signal 7 ------------------
  197. * startBit = 54
  198. * length = 1
  199. * desiredSignalByteLayout = BIGENDIAN
  200. * dataType = UNSIGNED
  201. * factor = 1.0
  202. * offset = 0.0
  203. * -----------------------------------------------------------------------*/
  204. /*
  205. * Signal is not connected or connected to terminator.
  206. * No unpacking code generated.
  207. */
  208. /* --------------- START Unpacking signal 8 ------------------
  209. * startBit = 5
  210. * length = 1
  211. * desiredSignalByteLayout = BIGENDIAN
  212. * dataType = UNSIGNED
  213. * factor = 1.0
  214. * offset = 0.0
  215. * -----------------------------------------------------------------------*/
  216. /*
  217. * Signal is not connected or connected to terminator.
  218. * No unpacking code generated.
  219. */
  220. /* --------------- START Unpacking signal 9 ------------------
  221. * startBit = 6
  222. * length = 1
  223. * desiredSignalByteLayout = BIGENDIAN
  224. * dataType = UNSIGNED
  225. * factor = 1.0
  226. * offset = 0.0
  227. * -----------------------------------------------------------------------*/
  228. /*
  229. * Signal is not connected or connected to terminator.
  230. * No unpacking code generated.
  231. */
  232. /* --------------- START Unpacking signal 10 ------------------
  233. * startBit = 7
  234. * length = 1
  235. * desiredSignalByteLayout = BIGENDIAN
  236. * dataType = UNSIGNED
  237. * factor = 1.0
  238. * offset = 0.0
  239. * -----------------------------------------------------------------------*/
  240. /*
  241. * Signal is not connected or connected to terminator.
  242. * No unpacking code generated.
  243. */
  244. /* --------------- START Unpacking signal 11 ------------------
  245. * startBit = 55
  246. * length = 1
  247. * desiredSignalByteLayout = BIGENDIAN
  248. * dataType = UNSIGNED
  249. * factor = 1.0
  250. * offset = 0.0
  251. * -----------------------------------------------------------------------*/
  252. /*
  253. * Signal is not connected or connected to terminator.
  254. * No unpacking code generated.
  255. */
  256. /* --------------- START Unpacking signal 12 ------------------
  257. * startBit = 10
  258. * length = 2
  259. * desiredSignalByteLayout = BIGENDIAN
  260. * dataType = UNSIGNED
  261. * factor = 1.0
  262. * offset = 0.0
  263. * -----------------------------------------------------------------------*/
  264. /*
  265. * Signal is not connected or connected to terminator.
  266. * No unpacking code generated.
  267. */
  268. /* --------------- START Unpacking signal 13 ------------------
  269. * startBit = 49
  270. * length = 3
  271. * desiredSignalByteLayout = BIGENDIAN
  272. * dataType = UNSIGNED
  273. * factor = 1.0
  274. * offset = 0.0
  275. * -----------------------------------------------------------------------*/
  276. /*
  277. * Signal is not connected or connected to terminator.
  278. * No unpacking code generated.
  279. */
  280. /* --------------- START Unpacking signal 14 ------------------
  281. * startBit = 56
  282. * length = 3
  283. * desiredSignalByteLayout = BIGENDIAN
  284. * dataType = UNSIGNED
  285. * factor = 1.0
  286. * offset = 0.0
  287. * -----------------------------------------------------------------------*/
  288. /*
  289. * Signal is not connected or connected to terminator.
  290. * No unpacking code generated.
  291. */
  292. /* --------------- START Unpacking signal 15 ------------------
  293. * startBit = 16
  294. * length = 4
  295. * desiredSignalByteLayout = BIGENDIAN
  296. * dataType = UNSIGNED
  297. * factor = 1.0
  298. * offset = 0.0
  299. * -----------------------------------------------------------------------*/
  300. {
  301. real64_T outValue = 0;
  302. {
  303. uint8_T unpackedValue = 0;
  304. {
  305. uint8_T tempValue = (uint8_T) (0);
  306. {
  307. tempValue = tempValue | (uint8_T)((uint8_T)
  308. (CAN2PSC_B.CANPack3.Data[2]) & (uint8_T)(0xFU));
  309. }
  310. unpackedValue = tempValue;
  311. }
  312. outValue = (real64_T) (unpackedValue);
  313. }
  314. {
  315. real64_T result = (real64_T) outValue;
  316. PDC1_Status_DistanceFL_Lvl = result;
  317. }
  318. }
  319. /* --------------- START Unpacking signal 16 ------------------
  320. * startBit = 24
  321. * length = 4
  322. * desiredSignalByteLayout = BIGENDIAN
  323. * dataType = UNSIGNED
  324. * factor = 1.0
  325. * offset = 0.0
  326. * -----------------------------------------------------------------------*/
  327. {
  328. real64_T outValue = 0;
  329. {
  330. uint8_T unpackedValue = 0;
  331. {
  332. uint8_T tempValue = (uint8_T) (0);
  333. {
  334. tempValue = tempValue | (uint8_T)((uint8_T)
  335. (CAN2PSC_B.CANPack3.Data[3]) & (uint8_T)(0xFU));
  336. }
  337. unpackedValue = tempValue;
  338. }
  339. outValue = (real64_T) (unpackedValue);
  340. }
  341. {
  342. real64_T result = (real64_T) outValue;
  343. PDC1_Status_DistanceFML_Lvl = result;
  344. }
  345. }
  346. /* --------------- START Unpacking signal 17 ------------------
  347. * startBit = 28
  348. * length = 4
  349. * desiredSignalByteLayout = BIGENDIAN
  350. * dataType = UNSIGNED
  351. * factor = 1.0
  352. * offset = 0.0
  353. * -----------------------------------------------------------------------*/
  354. {
  355. real64_T outValue = 0;
  356. {
  357. uint8_T unpackedValue = 0;
  358. {
  359. uint8_T tempValue = (uint8_T) (0);
  360. {
  361. tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
  362. (CAN2PSC_B.CANPack3.Data[3]) & (uint8_T)(0xF0U)) >> 4);
  363. }
  364. unpackedValue = tempValue;
  365. }
  366. outValue = (real64_T) (unpackedValue);
  367. }
  368. {
  369. real64_T result = (real64_T) outValue;
  370. PDC1_Status_DistanceFMR_Lvl = result;
  371. }
  372. }
  373. /* --------------- START Unpacking signal 18 ------------------
  374. * startBit = 20
  375. * length = 4
  376. * desiredSignalByteLayout = BIGENDIAN
  377. * dataType = UNSIGNED
  378. * factor = 1.0
  379. * offset = 0.0
  380. * -----------------------------------------------------------------------*/
  381. {
  382. real64_T outValue = 0;
  383. {
  384. uint8_T unpackedValue = 0;
  385. {
  386. uint8_T tempValue = (uint8_T) (0);
  387. {
  388. tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
  389. (CAN2PSC_B.CANPack3.Data[2]) & (uint8_T)(0xF0U)) >> 4);
  390. }
  391. unpackedValue = tempValue;
  392. }
  393. outValue = (real64_T) (unpackedValue);
  394. }
  395. {
  396. real64_T result = (real64_T) outValue;
  397. PDC1_Status_DistanceFR_Lvl = result;
  398. }
  399. }
  400. /* --------------- START Unpacking signal 19 ------------------
  401. * startBit = 32
  402. * length = 4
  403. * desiredSignalByteLayout = BIGENDIAN
  404. * dataType = UNSIGNED
  405. * factor = 1.0
  406. * offset = 0.0
  407. * -----------------------------------------------------------------------*/
  408. {
  409. real64_T outValue = 0;
  410. {
  411. uint8_T unpackedValue = 0;
  412. {
  413. uint8_T tempValue = (uint8_T) (0);
  414. {
  415. tempValue = tempValue | (uint8_T)((uint8_T)
  416. (CAN2PSC_B.CANPack3.Data[4]) & (uint8_T)(0xFU));
  417. }
  418. unpackedValue = tempValue;
  419. }
  420. outValue = (real64_T) (unpackedValue);
  421. }
  422. {
  423. real64_T result = (real64_T) outValue;
  424. PDC1_Status_DistanceRL_Lvl = result;
  425. }
  426. }
  427. /* --------------- START Unpacking signal 20 ------------------
  428. * startBit = 36
  429. * length = 4
  430. * desiredSignalByteLayout = BIGENDIAN
  431. * dataType = UNSIGNED
  432. * factor = 1.0
  433. * offset = 0.0
  434. * -----------------------------------------------------------------------*/
  435. {
  436. real64_T outValue = 0;
  437. {
  438. uint8_T unpackedValue = 0;
  439. {
  440. uint8_T tempValue = (uint8_T) (0);
  441. {
  442. tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
  443. (CAN2PSC_B.CANPack3.Data[4]) & (uint8_T)(0xF0U)) >> 4);
  444. }
  445. unpackedValue = tempValue;
  446. }
  447. outValue = (real64_T) (unpackedValue);
  448. }
  449. {
  450. real64_T result = (real64_T) outValue;
  451. PDC1_Status_DistanceRML_Lvl = result;
  452. }
  453. }
  454. /* --------------- START Unpacking signal 21 ------------------
  455. * startBit = 40
  456. * length = 4
  457. * desiredSignalByteLayout = BIGENDIAN
  458. * dataType = UNSIGNED
  459. * factor = 1.0
  460. * offset = 0.0
  461. * -----------------------------------------------------------------------*/
  462. {
  463. real64_T outValue = 0;
  464. {
  465. uint8_T unpackedValue = 0;
  466. {
  467. uint8_T tempValue = (uint8_T) (0);
  468. {
  469. tempValue = tempValue | (uint8_T)((uint8_T)
  470. (CAN2PSC_B.CANPack3.Data[5]) & (uint8_T)(0xFU));
  471. }
  472. unpackedValue = tempValue;
  473. }
  474. outValue = (real64_T) (unpackedValue);
  475. }
  476. {
  477. real64_T result = (real64_T) outValue;
  478. PDC1_Status_DistanceRMR_Lvl = result;
  479. }
  480. }
  481. /* --------------- START Unpacking signal 22 ------------------
  482. * startBit = 44
  483. * length = 4
  484. * desiredSignalByteLayout = BIGENDIAN
  485. * dataType = UNSIGNED
  486. * factor = 1.0
  487. * offset = 0.0
  488. * -----------------------------------------------------------------------*/
  489. {
  490. real64_T outValue = 0;
  491. {
  492. uint8_T unpackedValue = 0;
  493. {
  494. uint8_T tempValue = (uint8_T) (0);
  495. {
  496. tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
  497. (CAN2PSC_B.CANPack3.Data[5]) & (uint8_T)(0xF0U)) >> 4);
  498. }
  499. unpackedValue = tempValue;
  500. }
  501. outValue = (real64_T) (unpackedValue);
  502. }
  503. {
  504. real64_T result = (real64_T) outValue;
  505. PDC1_Status_DistanceRR_Lvl = result;
  506. }
  507. }
  508. /* --------------- START Unpacking signal 23 ------------------
  509. * startBit = 9
  510. * length = 1
  511. * desiredSignalByteLayout = BIGENDIAN
  512. * dataType = UNSIGNED
  513. * factor = 1.0
  514. * offset = 0.0
  515. * -----------------------------------------------------------------------*/
  516. /*
  517. * Signal is not connected or connected to terminator.
  518. * No unpacking code generated.
  519. */
  520. /* --------------- START Unpacking signal 24 ------------------
  521. * startBit = 8
  522. * length = 1
  523. * desiredSignalByteLayout = BIGENDIAN
  524. * dataType = UNSIGNED
  525. * factor = 1.0
  526. * offset = 0.0
  527. * -----------------------------------------------------------------------*/
  528. /*
  529. * Signal is not connected or connected to terminator.
  530. * No unpacking code generated.
  531. */
  532. /* --------------- START Unpacking signal 25 ------------------
  533. * startBit = 59
  534. * length = 3
  535. * desiredSignalByteLayout = BIGENDIAN
  536. * dataType = UNSIGNED
  537. * factor = 1.0
  538. * offset = 0.0
  539. * -----------------------------------------------------------------------*/
  540. /*
  541. * Signal is not connected or connected to terminator.
  542. * No unpacking code generated.
  543. */
  544. /* --------------- START Unpacking signal 26 ------------------
  545. * startBit = 12
  546. * length = 4
  547. * desiredSignalByteLayout = BIGENDIAN
  548. * dataType = UNSIGNED
  549. * factor = 1.0
  550. * offset = 0.0
  551. * -----------------------------------------------------------------------*/
  552. /*
  553. * Signal is not connected or connected to terminator.
  554. * No unpacking code generated.
  555. */
  556. }
  557. }
  558. }
  559. }
  560. /* S-Function (scanpack): '<S1>/CAN Pack1' */
  561. /* S-Function (scanpack): '<S1>/CAN Pack1' */
  562. CAN2PSC_B.CANPack1.ID = 1073U;
  563. CAN2PSC_B.CANPack1.Length = 8U;
  564. CAN2PSC_B.CANPack1.Extended = 0U;
  565. CAN2PSC_B.CANPack1.Remote = 0;
  566. CAN2PSC_B.CANPack1.Data[0] = 0;
  567. CAN2PSC_B.CANPack1.Data[1] = 0;
  568. CAN2PSC_B.CANPack1.Data[2] = 0;
  569. CAN2PSC_B.CANPack1.Data[3] = 0;
  570. CAN2PSC_B.CANPack1.Data[4] = 0;
  571. CAN2PSC_B.CANPack1.Data[5] = 0;
  572. CAN2PSC_B.CANPack1.Data[6] = 0;
  573. CAN2PSC_B.CANPack1.Data[7] = 0;
  574. {
  575. (void) memcpy((CAN2PSC_B.CANPack1.Data), &CAN2PSC_B.TCAN_Data_n[0],
  576. 8 * sizeof(uint8_T));
  577. }
  578. /* S-Function (scanunpack): '<S1>/CAN Unpack1' */
  579. {
  580. /* S-Function (scanunpack): '<S1>/CAN Unpack1' */
  581. if ((8 == CAN2PSC_B.CANPack1.Length) && (CAN2PSC_B.CANPack1.ID !=
  582. INVALID_CAN_ID) ) {
  583. if ((1073 == CAN2PSC_B.CANPack1.ID) && (0U == CAN2PSC_B.CANPack1.Extended)
  584. ) {
  585. {
  586. /* --------------- START Unpacking signal 0 ------------------
  587. * startBit = 2
  588. * length = 3
  589. * desiredSignalByteLayout = BIGENDIAN
  590. * dataType = UNSIGNED
  591. * factor = 1.0
  592. * offset = 0.0
  593. * -----------------------------------------------------------------------*/
  594. {
  595. real64_T outValue = 0;
  596. {
  597. uint8_T unpackedValue = 0;
  598. {
  599. uint8_T tempValue = (uint8_T) (0);
  600. {
  601. tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
  602. (CAN2PSC_B.CANPack1.Data[0]) & (uint8_T)(0x1CU)) >> 2);
  603. }
  604. unpackedValue = tempValue;
  605. }
  606. outValue = (real64_T) (unpackedValue);
  607. }
  608. {
  609. real64_T result = (real64_T) outValue;
  610. PSC2_Status_FlankDistanceFL_Lvl = result;
  611. }
  612. }
  613. /* --------------- START Unpacking signal 1 ------------------
  614. * startBit = 5
  615. * length = 3
  616. * desiredSignalByteLayout = BIGENDIAN
  617. * dataType = UNSIGNED
  618. * factor = 1.0
  619. * offset = 0.0
  620. * -----------------------------------------------------------------------*/
  621. {
  622. real64_T outValue = 0;
  623. {
  624. uint8_T unpackedValue = 0;
  625. {
  626. uint8_T tempValue = (uint8_T) (0);
  627. {
  628. tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
  629. (CAN2PSC_B.CANPack1.Data[0]) & (uint8_T)(0xE0U)) >> 5);
  630. }
  631. unpackedValue = tempValue;
  632. }
  633. outValue = (real64_T) (unpackedValue);
  634. }
  635. {
  636. real64_T result = (real64_T) outValue;
  637. PSC2_Status_FlankDistanceFR_Lvl = result;
  638. }
  639. }
  640. /* --------------- START Unpacking signal 2 ------------------
  641. * startBit = 15
  642. * length = 3
  643. * desiredSignalByteLayout = BIGENDIAN
  644. * dataType = UNSIGNED
  645. * factor = 1.0
  646. * offset = 0.0
  647. * -----------------------------------------------------------------------*/
  648. /*
  649. * Signal is not connected or connected to terminator.
  650. * No unpacking code generated.
  651. */
  652. /* --------------- START Unpacking signal 3 ------------------
  653. * startBit = 16
  654. * length = 3
  655. * desiredSignalByteLayout = BIGENDIAN
  656. * dataType = UNSIGNED
  657. * factor = 1.0
  658. * offset = 0.0
  659. * -----------------------------------------------------------------------*/
  660. /*
  661. * Signal is not connected or connected to terminator.
  662. * No unpacking code generated.
  663. */
  664. /* --------------- START Unpacking signal 4 ------------------
  665. * startBit = 9
  666. * length = 3
  667. * desiredSignalByteLayout = BIGENDIAN
  668. * dataType = UNSIGNED
  669. * factor = 1.0
  670. * offset = 0.0
  671. * -----------------------------------------------------------------------*/
  672. {
  673. real64_T outValue = 0;
  674. {
  675. uint8_T unpackedValue = 0;
  676. {
  677. uint8_T tempValue = (uint8_T) (0);
  678. {
  679. tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
  680. (CAN2PSC_B.CANPack1.Data[1]) & (uint8_T)(0xEU)) >> 1);
  681. }
  682. unpackedValue = tempValue;
  683. }
  684. outValue = (real64_T) (unpackedValue);
  685. }
  686. {
  687. real64_T result = (real64_T) outValue;
  688. PSC2_Status_FlankDistanceRL_Lvl = result;
  689. }
  690. }
  691. /* --------------- START Unpacking signal 5 ------------------
  692. * startBit = 19
  693. * length = 3
  694. * desiredSignalByteLayout = BIGENDIAN
  695. * dataType = UNSIGNED
  696. * factor = 1.0
  697. * offset = 0.0
  698. * -----------------------------------------------------------------------*/
  699. /*
  700. * Signal is not connected or connected to terminator.
  701. * No unpacking code generated.
  702. */
  703. /* --------------- START Unpacking signal 6 ------------------
  704. * startBit = 22
  705. * length = 3
  706. * desiredSignalByteLayout = BIGENDIAN
  707. * dataType = UNSIGNED
  708. * factor = 1.0
  709. * offset = 0.0
  710. * -----------------------------------------------------------------------*/
  711. /*
  712. * Signal is not connected or connected to terminator.
  713. * No unpacking code generated.
  714. */
  715. /* --------------- START Unpacking signal 7 ------------------
  716. * startBit = 12
  717. * length = 3
  718. * desiredSignalByteLayout = BIGENDIAN
  719. * dataType = UNSIGNED
  720. * factor = 1.0
  721. * offset = 0.0
  722. * -----------------------------------------------------------------------*/
  723. {
  724. real64_T outValue = 0;
  725. {
  726. uint8_T unpackedValue = 0;
  727. {
  728. uint8_T tempValue = (uint8_T) (0);
  729. {
  730. tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
  731. (CAN2PSC_B.CANPack1.Data[1]) & (uint8_T)(0x70U)) >> 4);
  732. }
  733. unpackedValue = tempValue;
  734. }
  735. outValue = (real64_T) (unpackedValue);
  736. }
  737. {
  738. real64_T result = (real64_T) outValue;
  739. PSC2_Status_FlankDistanceRR_Lvl = result;
  740. }
  741. }
  742. }
  743. }
  744. }
  745. }
  746. }
  747. /* Model initialize function */
  748. void CAN2PSC_initialize(void)
  749. {
  750. /* Start for S-Function (scanunpack): '<S1>/CAN Unpack4' */
  751. /*-----------S-Function Block: <S1>/CAN Unpack4 -----------------*/
  752. /* Start for S-Function (scanunpack): '<S1>/CAN Unpack1' */
  753. /*-----------S-Function Block: <S1>/CAN Unpack1 -----------------*/
  754. }
  755. /* Model terminate function */
  756. void CAN2PSC_terminate(void)
  757. {
  758. /* (no terminate code required) */
  759. }
  760. /*
  761. * File trailer for generated code.
  762. *
  763. * [EOF]
  764. */

rtmodel.c文件:

  1. /*
  2. * File: rtmodel.h
  3. *
  4. * Code generated for Simulink model 'CAN2PSC'.
  5. *
  6. * Model version : 1.3
  7. * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. * C/C++ source code generated on : Mon Jun 12 16:10:53 2023
  9. *
  10. * Target selection: ert.tlc
  11. * Embedded hardware selection: ARM Compatible->ARM Cortex
  12. * Code generation objectives: Unspecified
  13. * Validation result: Not run
  14. */
  15. #ifndef RTW_HEADER_rtmodel_h_
  16. #define RTW_HEADER_rtmodel_h_
  17. #include "CAN2PSC.h"
  18. /* Macros generated for backwards compatibility */
  19. #ifndef rtmGetStopRequested
  20. #define rtmGetStopRequested
  21. (rtm) ((void*) 0)
  22. #endif
  23. #endif /* RTW_HEADER_rtmodel_h_ */
  24. /*
  25. * File trailer for generated code.
  26. *
  27. * [EOF]
  28. */

 rtwtypes.h文件:

  1. /*
  2. * File: rtwtypes.h
  3. *
  4. * Code generated for Simulink model 'CAN2PSC'.
  5. *
  6. * Model version : 1.3
  7. * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. * C/C++ source code generated on : Mon Jun 12 16:10:53 2023
  9. *
  10. * Target selection: ert.tlc
  11. * Embedded hardware selection: ARM Compatible->ARM Cortex
  12. * Code generation objectives: Unspecified
  13. * Validation result: Not run
  14. */
  15. #ifndef RTWTYPES_H
  16. #define RTWTYPES_H
  17. /* Logical type definitions */
  18. #if (!defined(__cplusplus))
  19. #ifndef false
  20. #define false (0U)
  21. #endif
  22. #ifndef true
  23. #define true (1U)
  24. #endif
  25. #endif
  26. /*=======================================================================*
  27. * Target hardware information
  28. * Device type: ARM Compatible->ARM Cortex
  29. * Number of bits: char: 8 short: 16 int: 32
  30. * long: 32 long long: 64
  31. * native word size: 32
  32. * Byte ordering: LittleEndian
  33. * Signed integer division rounds to: Zero
  34. * Shift right on a signed integer as arithmetic shift: on
  35. *=======================================================================*/
  36. /*=======================================================================*
  37. * Fixed width word size data types: *
  38. * int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers *
  39. * uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers *
  40. * real32_T, real64_T - 32 and 64 bit floating point numbers *
  41. *=======================================================================*/
  42. typedef signed char int8_T;
  43. typedef unsigned char uint8_T;
  44. typedef short int16_T;
  45. typedef unsigned short uint16_T;
  46. typedef int int32_T;
  47. typedef unsigned int uint32_T;
  48. typedef long long int64_T;
  49. typedef unsigned long long uint64_T;
  50. typedef float real32_T;
  51. typedef double real64_T;
  52. /*===========================================================================*
  53. * Generic type definitions: boolean_T, char_T, byte_T, int_T, uint_T, *
  54. * real_T, time_T, ulong_T, ulonglong_T. *
  55. *===========================================================================*/
  56. typedef double real_T;
  57. typedef double time_T;
  58. typedef unsigned char boolean_T;
  59. typedef int int_T;
  60. typedef unsigned int uint_T;
  61. typedef unsigned long ulong_T;
  62. typedef unsigned long long ulonglong_T;
  63. typedef char char_T;
  64. typedef unsigned char uchar_T;
  65. typedef char_T byte_T;
  66. /*===========================================================================*
  67. * Complex number type definitions *
  68. *===========================================================================*/
  69. #define CREAL_T
  70. typedef struct {
  71. real32_T re;
  72. real32_T im;
  73. } creal32_T;
  74. typedef struct {
  75. real64_T re;
  76. real64_T im;
  77. } creal64_T;
  78. typedef struct {
  79. real_T re;
  80. real_T im;
  81. } creal_T;
  82. #define CINT8_T
  83. typedef struct {
  84. int8_T re;
  85. int8_T im;
  86. } cint8_T;
  87. #define CUINT8_T
  88. typedef struct {
  89. uint8_T re;
  90. uint8_T im;
  91. } cuint8_T;
  92. #define CINT16_T
  93. typedef struct {
  94. int16_T re;
  95. int16_T im;
  96. } cint16_T;
  97. #define CUINT16_T
  98. typedef struct {
  99. uint16_T re;
  100. uint16_T im;
  101. } cuint16_T;
  102. #define CINT32_T
  103. typedef struct {
  104. int32_T re;
  105. int32_T im;
  106. } cint32_T;
  107. #define CUINT32_T
  108. typedef struct {
  109. uint32_T re;
  110. uint32_T im;
  111. } cuint32_T;
  112. #define CINT64_T
  113. typedef struct {
  114. int64_T re;
  115. int64_T im;
  116. } cint64_T;
  117. #define CUINT64_T
  118. typedef struct {
  119. uint64_T re;
  120. uint64_T im;
  121. } cuint64_T;
  122. /*=======================================================================*
  123. * Min and Max: *
  124. * int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers *
  125. * uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers *
  126. *=======================================================================*/
  127. #define MAX_int8_T ((int8_T)(127))
  128. #define MIN_int8_T ((int8_T)(-128))
  129. #define MAX_uint8_T ((uint8_T)(255U))
  130. #define MAX_int16_T ((int16_T)(32767))
  131. #define MIN_int16_T ((int16_T)(-32768))
  132. #define MAX_uint16_T ((uint16_T)(65535U))
  133. #define MAX_int32_T ((int32_T)(2147483647))
  134. #define MIN_int32_T ((int32_T)(-2147483647-1))
  135. #define MAX_uint32_T ((uint32_T)(0xFFFFFFFFU))
  136. #define MAX_int64_T ((int64_T)(9223372036854775807LL))
  137. #define MIN_int64_T ((int64_T)(-9223372036854775807LL-1LL))
  138. #define MAX_uint64_T ((uint64_T)(0xFFFFFFFFFFFFFFFFULL))
  139. /* Block D-Work pointer type */
  140. typedef void * pointer_T;
  141. #endif /* RTWTYPES_H */
  142. /*
  143. * File trailer for generated code.
  144. *
  145. * [EOF]
  146. */

核心代码部分CAN2PSC.c文件解析:

在声明一些变量后,先定义了函数CAN2PSC_MATLABFunction1,即为模型中的Matlab Function。上面的注释为:原子系统的输出和更新:代码为Simulink显示对应使用的,点击即可高亮出对应模型部分内容。

 可以对比看看,他这将输出、状态值也当成输入,给了函数,然后对输出进行赋0操作。本来M代码是使用永久变量来存上次数据,这里对应的是状态变量。

状态(States)是离散系统运算过程中必不可少的元素。

我们知道,离散系统是在每一个离散的时间点上, 运行一次Step函数。某一时刻运行一次Step函数,除了需要输入数据(通过外部输入信号输入)以外,往往还需要上一个时刻的运算结果,甚至之前连续几个时刻的运算结果。

在嵌入式系统中,这些结果需要一个变量来存储,这个变量即为状态变量

在Simulink模型库中,凡是包含离散因子“z”的模块,全部具有状态变量。这些模块在生成代码时,都会生成一个名为“模型名_DW”的变量来保存状态变量。

来源:MBD的Simulink使用技巧②:Simulink代码生成的基本概念 - 知乎

 然后就是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内容

 除了CAN2PSC_types.h其他应该没啥差别,多了#include "rtwtypes.h"和

typedef struct P_CAN2PSC_T_ P_CAN2PSC_T;

  1. /*
  2. * File: CAN2PSC_types.h
  3. *
  4. * Code generated for Simulink model 'CAN2PSC'.
  5. *
  6. * Model version : 1.4
  7. * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. * C/C++ source code generated on : Tue Jun 13 09:58:54 2023
  9. *
  10. * Target selection: ert.tlc
  11. * Embedded hardware selection: ARM Compatible->ARM Cortex
  12. * Code generation objectives: Unspecified
  13. * Validation result: Not run
  14. */
  15. #ifndef RTW_HEADER_CAN2PSC_types_h_
  16. #define RTW_HEADER_CAN2PSC_types_h_
  17. #include "rtwtypes.h"
  18. /* Model Code Variants */
  19. /* Parameters (default storage) */
  20. typedef struct P_CAN2PSC_T_ P_CAN2PSC_T;
  21. /* Forward declaration for rtModel */
  22. typedef struct tag_RTM_CAN2PSC_T RT_MODEL_CAN2PSC_T;
  23. #endif /* RTW_HEADER_CAN2PSC_types_h_ */
  24. /*
  25. * File trailer for generated code.
  26. *
  27. * [EOF]
  28. */

ert_main.c的内容

  1. /*
  2. * File: ert_main.c
  3. *
  4. * Code generated for Simulink model 'CAN2PSC'.
  5. *
  6. * Model version : 1.4
  7. * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. * C/C++ source code generated on : Tue Jun 13 09:58:54 2023
  9. *
  10. * Target selection: ert.tlc
  11. * Embedded hardware selection: ARM Compatible->ARM Cortex
  12. * Code generation objectives: Unspecified
  13. * Validation result: Not run
  14. */
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include "CAN2PSC.h"
  18. #include "CAN2PSC_private.h"
  19. #include "rtwtypes.h"
  20. #include "limits.h"
  21. #include "MW_raspi_init.h"
  22. #include "MW_Pyserver_control.h"
  23. #include "linuxinitialize.h"
  24. #define UNUSED(x) x = x
  25. #define NAMELEN 16
  26. /* Function prototype declaration*/
  27. /*函数原型声明*/
  28. void exitFcn(int sig);
  29. void *terminateTask(void *arg);
  30. void *baseRateTask(void *arg);
  31. void *subrateTask(void *arg);
  32. volatile boolean_T stopRequested = false;
  33. volatile boolean_T runModel = true;
  34. sem_t stopSem;
  35. sem_t baserateTaskSem;
  36. pthread_t schedulerThread;
  37. pthread_t baseRateThread;
  38. void *threadJoinStatus;
  39. int terminatingmodel = 0;
  40. void *baseRateTask(void *arg)
  41. {
  42. runModel = (rtmGetErrorStatus(CAN2PSC_M) == (NULL));
  43. while (runModel) {
  44. sem_wait(&baserateTaskSem);
  45. CAN2PSCFunc();
  46. /* Get model outputs here */
  47. stopRequested = !((rtmGetErrorStatus(CAN2PSC_M) == (NULL)));
  48. }
  49. runModel = 0;
  50. terminateTask(arg);
  51. pthread_exit((void *)0);
  52. return NULL;
  53. }
  54. void exitFcn(int sig)
  55. {
  56. UNUSED(sig);
  57. rtmSetErrorStatus(CAN2PSC_M, "stopping the model");
  58. runModel = 0;
  59. }
  60. void *terminateTask(void *arg)
  61. {
  62. UNUSED(arg);
  63. terminatingmodel = 1;
  64. {
  65. runModel = 0;
  66. }
  67. MW_killPyserver();
  68. mwRaspiTerminate();
  69. /* Disable rt_OneStep() here */
  70. /* Terminate model */
  71. CAN2PSC_terminate();
  72. sem_post(&stopSem);
  73. return NULL;
  74. }
  75. int main(int argc, char **argv)
  76. {
  77. UNUSED(argc);
  78. UNUSED(argv);
  79. mwRaspiInit();
  80. MW_launchPyserver();
  81. rtmSetErrorStatus(CAN2PSC_M, 0);
  82. /* Initialize model */
  83. CAN2PSC_initialize();
  84. /* Call RTOS Initialization function */
  85. myRTOSInit(0.01, 0);
  86. /* Wait for stop semaphore */
  87. sem_wait(&stopSem);
  88. #if (MW_NUMBER_TIMER_DRIVEN_TASKS > 0)
  89. {
  90. int i;
  91. for (i=0; i < MW_NUMBER_TIMER_DRIVEN_TASKS; i++) {
  92. CHECK_STATUS(sem_destroy(&timerTaskSem[i]), 0, "sem_destroy");
  93. }
  94. }
  95. #endif
  96. return 0;
  97. }
  98. /*
  99. * File trailer for generated code.
  100. *
  101. * [EOF]
  102. */

 CAN2PSC_data.c内容

  1. /*
  2. * File: CAN2PSC_data.c
  3. *
  4. * Code generated for Simulink model 'CAN2PSC'.
  5. *
  6. * Model version : 1.4
  7. * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. * C/C++ source code generated on : Tue Jun 13 09:58:54 2023
  9. *
  10. * Target selection: ert.tlc
  11. * Embedded hardware selection: ARM Compatible->ARM Cortex
  12. * Code generation objectives: Unspecified
  13. * Validation result: Not run
  14. */
  15. #include "CAN2PSC.h"
  16. #include "CAN2PSC_private.h"
  17. /* Block parameters (default storage) */
  18. P_CAN2PSC_T CAN2PSC_P = {
  19. /* Expression: 2
  20. * Referenced by: '<S1>/Tid2'
  21. */
  22. 2.0,
  23. /* Expression: 608
  24. * Referenced by: '<S1>/Tid8'
  25. */
  26. 608.0,
  27. /* Expression: 1073
  28. * Referenced by: '<S1>/Tid1'
  29. */
  30. 1073.0
  31. };
  32. /*
  33. * File trailer for generated code.
  34. *
  35. * [EOF]
  36. */

rtmodel.h内容

  1. /*
  2. * File: rtmodel.h
  3. *
  4. * Code generated for Simulink model 'CAN2PSC'.
  5. *
  6. * Model version : 1.4
  7. * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
  8. * C/C++ source code generated on : Tue Jun 13 09:58:54 2023
  9. *
  10. * Target selection: ert.tlc
  11. * Embedded hardware selection: ARM Compatible->ARM Cortex
  12. * Code generation objectives: Unspecified
  13. * Validation result: Not run
  14. */
  15. #ifndef RTW_HEADER_rtmodel_h_
  16. #define RTW_HEADER_rtmodel_h_
  17. #include "CAN2PSC.h"
  18. /* Macros generated for backwards compatibility */
  19. #ifndef rtmGetStopRequested
  20. #define rtmGetStopRequested(rtm) ((void*) 0)
  21. #endif
  22. #endif /* RTW_HEADER_rtmodel_h_ */
  23. /*
  24. * File trailer for generated code.
  25. *
  26. * [EOF]
  27. */

剩下的应该是在树莓派上运行需要的内容。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/735326?site
推荐阅读
相关标签
  

闽ICP备14008679号