DSP2803x_ECan.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. //###########################################################################
  2. //
  3. // FILE: DSP2803x_ECan.c
  4. //
  5. // TITLE: DSP2803x Enhanced CAN Initialization & Support Functions.
  6. //
  7. //###########################################################################
  8. // $TI Release: F2803x C/C++ Header Files and Peripheral Examples V130 $
  9. // $Release Date: May 8, 2015 $
  10. // $Copyright: Copyright (C) 2009-2015 Texas Instruments Incorporated -
  11. // http://www.ti.com/ ALL RIGHTS RESERVED $
  12. //###########################################################################
  13. #include "DSP2803x_Device.h" // DSP28 Headerfile Include File
  14. #include "DSP2803x_Examples.h" // DSP28 Examples Include File
  15. //---------------------------------------------------------------------------
  16. // InitECan:
  17. //---------------------------------------------------------------------------
  18. // This function initializes the eCAN module to a known state.
  19. //
  20. void InitECan(void)
  21. {
  22. InitECana();
  23. }
  24. void InitECana(void) // Initialize eCAN-A module
  25. {
  26. /* Create a shadow register structure for the CAN control registers. This is
  27. needed, since only 32-bit access is allowed to these registers. 16-bit access
  28. to these registers could potentially corrupt the register contents or return
  29. false data. This is especially true while writing to/reading from a bit
  30. (or group of bits) among bits 16 - 31 */
  31. struct ECAN_REGS ECanaShadow;
  32. EALLOW; // EALLOW enables access to protected bits
  33. /* Configure eCAN RX and TX pins for CAN operation using eCAN regs*/
  34. ECanaShadow.CANTIOC.all = ECanaRegs.CANTIOC.all;
  35. ECanaShadow.CANTIOC.bit.TXFUNC = 1;
  36. ECanaRegs.CANTIOC.all = ECanaShadow.CANTIOC.all;
  37. ECanaShadow.CANRIOC.all = ECanaRegs.CANRIOC.all;
  38. ECanaShadow.CANRIOC.bit.RXFUNC = 1;
  39. ECanaRegs.CANRIOC.all = ECanaShadow.CANRIOC.all;
  40. /* Configure eCAN for HECC mode - (reqd to access mailboxes 16 thru 31) */
  41. // HECC mode also enables time-stamping feature
  42. ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
  43. ECanaShadow.CANMC.bit.SCB = 1;
  44. ECanaShadow.CANMC.bit.ABO = 1;
  45. ECanaShadow.CANMC.bit.DBO = 1;
  46. ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
  47. /* Initialize all bits of 'Message Control Register' to zero */
  48. // Some bits of MSGCTRL register come up in an unknown state. For proper operation,
  49. // all bits (including reserved bits) of MSGCTRL must be initialized to zero
  50. ECanaMboxes.MBOX0.MSGCTRL.all = 0x00000000;
  51. ECanaMboxes.MBOX1.MSGCTRL.all = 0x00000000;
  52. ECanaMboxes.MBOX2.MSGCTRL.all = 0x00000000;
  53. ECanaMboxes.MBOX3.MSGCTRL.all = 0x00000000;
  54. ECanaMboxes.MBOX4.MSGCTRL.all = 0x00000000;
  55. ECanaMboxes.MBOX5.MSGCTRL.all = 0x00000000;
  56. ECanaMboxes.MBOX6.MSGCTRL.all = 0x00000000;
  57. ECanaMboxes.MBOX7.MSGCTRL.all = 0x00000000;
  58. ECanaMboxes.MBOX8.MSGCTRL.all = 0x00000000;
  59. ECanaMboxes.MBOX9.MSGCTRL.all = 0x00000000;
  60. ECanaMboxes.MBOX10.MSGCTRL.all = 0x00000000;
  61. ECanaMboxes.MBOX11.MSGCTRL.all = 0x00000000;
  62. ECanaMboxes.MBOX12.MSGCTRL.all = 0x00000000;
  63. ECanaMboxes.MBOX13.MSGCTRL.all = 0x00000000;
  64. ECanaMboxes.MBOX14.MSGCTRL.all = 0x00000000;
  65. ECanaMboxes.MBOX15.MSGCTRL.all = 0x00000000;
  66. ECanaMboxes.MBOX16.MSGCTRL.all = 0x00000000;
  67. ECanaMboxes.MBOX17.MSGCTRL.all = 0x00000000;
  68. ECanaMboxes.MBOX18.MSGCTRL.all = 0x00000000;
  69. ECanaMboxes.MBOX19.MSGCTRL.all = 0x00000000;
  70. ECanaMboxes.MBOX20.MSGCTRL.all = 0x00000000;
  71. ECanaMboxes.MBOX21.MSGCTRL.all = 0x00000000;
  72. ECanaMboxes.MBOX22.MSGCTRL.all = 0x00000000;
  73. ECanaMboxes.MBOX23.MSGCTRL.all = 0x00000000;
  74. ECanaMboxes.MBOX24.MSGCTRL.all = 0x00000000;
  75. ECanaMboxes.MBOX25.MSGCTRL.all = 0x00000000;
  76. ECanaMboxes.MBOX26.MSGCTRL.all = 0x00000000;
  77. ECanaMboxes.MBOX27.MSGCTRL.all = 0x00000000;
  78. ECanaMboxes.MBOX28.MSGCTRL.all = 0x00000000;
  79. ECanaMboxes.MBOX29.MSGCTRL.all = 0x00000000;
  80. ECanaMboxes.MBOX30.MSGCTRL.all = 0x00000000;
  81. ECanaMboxes.MBOX31.MSGCTRL.all = 0x00000000;
  82. // TAn, RMPn, GIFn bits are all zero upon reset and are cleared again
  83. // as a matter of precaution.
  84. ECanaRegs.CANTA.all = 0xFFFFFFFF; /* Clear all TAn bits */
  85. ECanaRegs.CANRMP.all = 0xFFFFFFFF; /* Clear all RMPn bits */
  86. ECanaRegs.CANGIF0.all = 0xFFFFFFFF; /* Clear all interrupt flag bits */
  87. ECanaRegs.CANGIF1.all = 0xFFFFFFFF;
  88. /* Configure bit timing parameters for eCANA*/
  89. ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
  90. ECanaShadow.CANMC.bit.CCR = 1 ; // Set CCR = 1
  91. ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
  92. ECanaShadow.CANES.all = ECanaRegs.CANES.all;
  93. // Wait until the CPU has been granted permission to change the configuration registers
  94. do
  95. {
  96. ECanaShadow.CANES.all = ECanaRegs.CANES.all;
  97. } while(ECanaShadow.CANES.bit.CCE != 1 ); // Wait for CCE bit to be set..
  98. ECanaShadow.CANBTC.all = 0;
  99. ECanaShadow.CANBTC.bit.BRPREG = 7;
  100. ECanaShadow.CANBTC.bit.TSEG2REG = 2;
  101. ECanaShadow.CANBTC.bit.TSEG1REG = 10;
  102. ECanaShadow.CANBTC.bit.SAM = 1;
  103. ECanaRegs.CANBTC.all = ECanaShadow.CANBTC.all;
  104. //==============================================================================================
  105. ECanaRegs.CANME.all = 0; // Required before writing the MSGIDs
  106. ECanaRegs.CANGAM.all = 0x80000000;
  107. //0x40000000:标准帧;0xC0000000:扩展帧
  108. //接收邮箱设置
  109. ECanaMboxes.MBOX0.MSGID.all = 0xC0000000;//0x40000000;
  110. ECanaMboxes.MBOX0.MSGCTRL.all = 0x00000008;
  111. ECanaLAMRegs.LAM0.all = 0x9FFFFFFF;
  112. ECanaMboxes.MBOX1.MSGID.all = 0xC0000000;//0x40000000;
  113. ECanaMboxes.MBOX1.MSGCTRL.all = 0x00000008;
  114. ECanaLAMRegs.LAM1.all = 0x9FFFFFFF;
  115. ECanaMboxes.MBOX2.MSGID.all = 0xC0000000;//0x40000000;
  116. ECanaMboxes.MBOX2.MSGCTRL.all = 0x00000008;
  117. ECanaLAMRegs.LAM2.all = 0x9FFFFFFF;
  118. ECanaMboxes.MBOX3.MSGID.all = 0xC0000000;//0x40000000;
  119. ECanaMboxes.MBOX3.MSGCTRL.all = 0x00000008;
  120. ECanaLAMRegs.LAM3.all = 0x9FFFFFFF;
  121. ECanaMboxes.MBOX4.MSGID.all = 0xC0000000;//0x40000000;
  122. ECanaMboxes.MBOX4.MSGCTRL.all = 0x00000008;
  123. ECanaLAMRegs.LAM4.all = 0x9FFFFFFF;
  124. ECanaMboxes.MBOX5.MSGID.all = 0xC0000000;//0x40000000;
  125. ECanaMboxes.MBOX5.MSGCTRL.all = 0x00000008;
  126. ECanaLAMRegs.LAM5.all = 0x9FFFFFFF;
  127. ECanaMboxes.MBOX6.MSGID.all = 0xC0000000;//0x40000000;
  128. ECanaMboxes.MBOX6.MSGCTRL.all = 0x00000008;
  129. ECanaLAMRegs.LAM6.all = 0x9FFFFFFF;
  130. ECanaMboxes.MBOX7.MSGID.all = 0xC0000000;//0x40000000;
  131. ECanaMboxes.MBOX7.MSGCTRL.all = 0x00000008;
  132. ECanaLAMRegs.LAM7.all = 0x9FFFFFFF;
  133. ECanaMboxes.MBOX8.MSGID.all = 0xC0000000;//0x40000000;
  134. ECanaMboxes.MBOX8.MSGCTRL.all = 0x00000008;
  135. ECanaLAMRegs.LAM8.all = 0x9FFFFFFF;
  136. ECanaMboxes.MBOX9.MSGID.all = 0xC0000000;//0x40000000;
  137. ECanaMboxes.MBOX9.MSGCTRL.all = 0x00000008;
  138. ECanaLAMRegs.LAM9.all = 0x9FFFFFFF;
  139. ECanaMboxes.MBOX10.MSGID.all = 0xC0000000;//0x40000000;
  140. ECanaMboxes.MBOX10.MSGCTRL.all = 0x00000008;
  141. ECanaLAMRegs.LAM10.all = 0x9FFFFFFF;
  142. ECanaMboxes.MBOX11.MSGID.all = 0xC0000000;//0x40000000;
  143. ECanaMboxes.MBOX11.MSGCTRL.all = 0x00000008;
  144. ECanaLAMRegs.LAM11.all = 0x9FFFFFFF;
  145. ECanaMboxes.MBOX12.MSGID.all = 0xC0000000;//0x40000000;
  146. ECanaMboxes.MBOX12.MSGCTRL.all = 0x00000008;
  147. ECanaLAMRegs.LAM12.all = 0x9FFFFFFF;
  148. ECanaMboxes.MBOX13.MSGID.all = 0xC0000000;//0x40000000;
  149. ECanaMboxes.MBOX13.MSGCTRL.all = 0x00000008;
  150. ECanaLAMRegs.LAM13.all = 0x9FFFFFFF;
  151. ECanaMboxes.MBOX14.MSGID.all = 0xC0000000;//0x40000000;
  152. ECanaMboxes.MBOX14.MSGCTRL.all = 0x00000008;
  153. ECanaLAMRegs.LAM14.all = 0x9FFFFFFF;
  154. ECanaMboxes.MBOX15.MSGID.all = 0xC0000000;//0x40000000;
  155. ECanaMboxes.MBOX15.MSGCTRL.all = 0x00000008;
  156. ECanaLAMRegs.LAM15.all = 0x9FFFFFFF;
  157. //发送邮箱设置
  158. ECanaMboxes.MBOX16.MSGID.all = 0x00040000;
  159. ECanaMboxes.MBOX16.MSGCTRL.all = 0x00000008;
  160. ECanaShadow.CANMD.all = 0x0000FFFF; //低16位为接收邮箱,高16位为发送邮箱
  161. ECanaRegs.CANMD.all = ECanaShadow.CANMD.all;
  162. ECanaShadow.CANME.all = 0xFFFFFFFF; //启用所有邮箱
  163. ECanaRegs.CANME.all = ECanaShadow.CANME.all;
  164. //==============================================================
  165. ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
  166. ECanaShadow.CANMC.bit.CCR = 0 ; // Set CCR = 0
  167. ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
  168. // Wait until the CPU no longer has permission to change the configuration registers
  169. do
  170. {
  171. ECanaShadow.CANES.all = ECanaRegs.CANES.all;
  172. } while(ECanaShadow.CANES.bit.CCE != 0 ); // Wait for CCE bit to be cleared..
  173. /* Disable all Mailboxes */
  174. //ECanaRegs.CANME.all = 0; // Required before writing the MSGIDs
  175. EDIS;
  176. }
  177. //---------------------------------------------------------------------------
  178. // Example: InitECanGpio:
  179. //---------------------------------------------------------------------------
  180. // This function initializes GPIO pins to function as eCAN pins
  181. //
  182. // Each GPIO pin can be configured as a GPIO pin or up to 3 different
  183. // peripheral functional pins. By default all pins come up as GPIO
  184. // inputs after reset.
  185. //
  186. // Caution:
  187. // Only one GPIO pin should be enabled for CANTXA operation.
  188. // Only one GPIO pin shoudl be enabled for CANRXA operation.
  189. // Comment out other unwanted lines.
  190. void InitECanGpio(void)
  191. {
  192. InitECanaGpio();
  193. }
  194. void InitECanaGpio(void)
  195. {
  196. EALLOW;
  197. /* Enable internal pull-up for the selected CAN pins */
  198. // Pull-ups can be enabled or disabled by the user.
  199. // This will enable the pullups for the specified pins.
  200. // Comment out other unwanted lines.
  201. GpioCtrlRegs.GPAPUD.bit.GPIO30 = 0; // Enable pull-up for GPIO30 (CANRXA)
  202. GpioCtrlRegs.GPAPUD.bit.GPIO31 = 0; // Enable pull-up for GPIO31 (CANTXA)
  203. /* Set qualification for selected CAN pins to asynch only */
  204. // Inputs are synchronized to SYSCLKOUT by default.
  205. // This will select asynch (no qualification) for the selected pins.
  206. GpioCtrlRegs.GPAQSEL2.bit.GPIO30 = 3; // Asynch qual for GPIO30 (CANRXA)
  207. /* Configure eCAN-A pins using GPIO regs*/
  208. // This specifies which of the possible GPIO pins will be eCAN functional pins.
  209. GpioCtrlRegs.GPAMUX2.bit.GPIO30 = 1; // Configure GPIO30 for CANRXA operation
  210. GpioCtrlRegs.GPAMUX2.bit.GPIO31 = 1; // Configure GPIO31 for CANTXA operation
  211. EDIS;
  212. }
  213. void ECanMboxSend(struct CANMBOX_USER_REGS *pRegs)
  214. {
  215. struct ECAN_REGS ECanaShadow;
  216. volatile struct MBOX *Mailbox;
  217. ECanaShadow.CANME.all = ECanaRegs.CANME.all;
  218. ECanaShadow.CANME.all &= ~((Uint32)1 << pRegs->MboxNum);
  219. ECanaRegs.CANME.all = ECanaShadow.CANME.all;
  220. Mailbox = &ECanaMboxes.MBOX0 + pRegs->MboxNum;
  221. Mailbox->MSGID.all = pRegs->MboxID | 0x80000000; //扩展帧
  222. // Mailbox->MSGID.all = pRegs->MboxID << 18; //标准帧
  223. // Mailbox->MDH.all = pRegs->MboxDataH;
  224. // Mailbox->MDL.all = pRegs->MboxDataL;
  225. Mailbox->MDL.word.LOW_WORD = pRegs->MboxWord1;
  226. Mailbox->MDL.word.HI_WORD = pRegs->MboxWord2;
  227. Mailbox->MDH.word.LOW_WORD = pRegs->MboxWord3;
  228. Mailbox->MDH.word.HI_WORD = pRegs->MboxWord4;
  229. Mailbox->MSGCTRL.all = pRegs->MboxDLC;
  230. ECanaShadow.CANME.all = ECanaRegs.CANME.all;
  231. ECanaShadow.CANME.all |= (Uint32)1 << pRegs->MboxNum;
  232. ECanaRegs.CANME.all = ECanaShadow.CANME.all;
  233. ECanaRegs.CANTRS.all = (Uint32)1 << pRegs->MboxNum;
  234. ECanaRegs.CANTA.all = (Uint32)1 << pRegs->MboxNum;
  235. }
  236. struct CANMBOX_USER_REGS ECanMboxRead(void)
  237. {
  238. struct CANMBOX_USER_REGS CanMboxUserRegs;
  239. if (ECanaRegs.CANRMP.bit.RMP0 == 1)
  240. {
  241. CanMboxUserRegs.MboxRxFlg = TRUE;
  242. CanMboxUserRegs.MboxNum = 0;
  243. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX0.MSGID.all & 0x1FFFFFFF; //扩展帧
  244. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX0.MSGCTRL.bit.DLC;
  245. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX0.MDL.word.LOW_WORD;
  246. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX0.MDL.word.HI_WORD;
  247. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX0.MDH.word.LOW_WORD;
  248. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX0.MDH.word.HI_WORD;
  249. ECanaRegs.CANRMP.bit.RMP0 = 1;
  250. }else if (ECanaRegs.CANRMP.bit.RMP1 == 1)
  251. {
  252. CanMboxUserRegs.MboxRxFlg = TRUE;
  253. CanMboxUserRegs.MboxNum = 1;
  254. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX1.MSGID.all & 0x1FFFFFFF; //扩展帧
  255. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX1.MSGCTRL.bit.DLC;
  256. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX1.MDL.word.LOW_WORD;
  257. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX1.MDL.word.HI_WORD;
  258. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX1.MDH.word.LOW_WORD;
  259. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX1.MDH.word.HI_WORD;
  260. ECanaRegs.CANRMP.bit.RMP1 = 1;
  261. }else if (ECanaRegs.CANRMP.bit.RMP2 == 1)
  262. {
  263. CanMboxUserRegs.MboxRxFlg = TRUE;
  264. CanMboxUserRegs.MboxNum = 2;
  265. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX2.MSGID.all & 0x1FFFFFFF; //扩展帧
  266. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX2.MSGCTRL.bit.DLC;
  267. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX2.MDL.word.LOW_WORD;
  268. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX2.MDL.word.HI_WORD;
  269. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX2.MDH.word.LOW_WORD;
  270. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX2.MDH.word.HI_WORD;
  271. ECanaRegs.CANRMP.bit.RMP2 = 1;
  272. }else if (ECanaRegs.CANRMP.bit.RMP3 == 1)
  273. {
  274. CanMboxUserRegs.MboxRxFlg = TRUE;
  275. CanMboxUserRegs.MboxNum = 3;
  276. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX3.MSGID.all & 0x1FFFFFFF; //扩展帧
  277. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX3.MSGCTRL.bit.DLC;
  278. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX3.MDL.word.LOW_WORD;
  279. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX3.MDL.word.HI_WORD;
  280. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX3.MDH.word.LOW_WORD;
  281. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX3.MDH.word.HI_WORD;
  282. ECanaRegs.CANRMP.bit.RMP3 = 1;
  283. }else if (ECanaRegs.CANRMP.bit.RMP4 == 1)
  284. {
  285. CanMboxUserRegs.MboxRxFlg = TRUE;
  286. CanMboxUserRegs.MboxNum = 4;
  287. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX4.MSGID.all & 0x1FFFFFFF; //扩展帧
  288. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX4.MSGCTRL.bit.DLC;
  289. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX4.MDL.word.LOW_WORD;
  290. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX4.MDL.word.HI_WORD;
  291. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX4.MDH.word.LOW_WORD;
  292. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX4.MDH.word.HI_WORD;
  293. ECanaRegs.CANRMP.bit.RMP4 = 1;
  294. }else if (ECanaRegs.CANRMP.bit.RMP5 == 1)
  295. {
  296. CanMboxUserRegs.MboxRxFlg = TRUE;
  297. CanMboxUserRegs.MboxNum = 5;
  298. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX5.MSGID.all & 0x1FFFFFFF; //扩展帧
  299. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX5.MSGCTRL.bit.DLC;
  300. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX5.MDL.word.LOW_WORD;
  301. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX5.MDL.word.HI_WORD;
  302. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX5.MDH.word.LOW_WORD;
  303. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX5.MDH.word.HI_WORD;
  304. ECanaRegs.CANRMP.bit.RMP5 = 1;
  305. }else if (ECanaRegs.CANRMP.bit.RMP6 == 1)
  306. {
  307. CanMboxUserRegs.MboxRxFlg = TRUE;
  308. CanMboxUserRegs.MboxNum = 6;
  309. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX6.MSGID.all & 0x1FFFFFFF; //扩展帧
  310. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX6.MSGCTRL.bit.DLC;
  311. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX6.MDL.word.LOW_WORD;
  312. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX6.MDL.word.HI_WORD;
  313. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX6.MDH.word.LOW_WORD;
  314. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX6.MDH.word.HI_WORD;
  315. ECanaRegs.CANRMP.bit.RMP6 = 1;
  316. }else if (ECanaRegs.CANRMP.bit.RMP7 == 1)
  317. {
  318. CanMboxUserRegs.MboxRxFlg = TRUE;
  319. CanMboxUserRegs.MboxNum = 7;
  320. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX7.MSGID.all & 0x1FFFFFFF; //扩展帧
  321. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX7.MSGCTRL.bit.DLC;
  322. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX7.MDL.word.LOW_WORD;
  323. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX7.MDL.word.HI_WORD;
  324. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX7.MDH.word.LOW_WORD;
  325. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX7.MDH.word.HI_WORD;
  326. ECanaRegs.CANRMP.bit.RMP7 = 1;
  327. }else if (ECanaRegs.CANRMP.bit.RMP8 == 1)
  328. {
  329. CanMboxUserRegs.MboxRxFlg = TRUE;
  330. CanMboxUserRegs.MboxNum = 8;
  331. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX8.MSGID.all & 0x1FFFFFFF; //扩展帧
  332. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX8.MSGCTRL.bit.DLC;
  333. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX8.MDL.word.LOW_WORD;
  334. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX8.MDL.word.HI_WORD;
  335. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX8.MDH.word.LOW_WORD;
  336. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX8.MDH.word.HI_WORD;
  337. ECanaRegs.CANRMP.bit.RMP8 = 1;
  338. }else if (ECanaRegs.CANRMP.bit.RMP9 == 1)
  339. {
  340. CanMboxUserRegs.MboxRxFlg = TRUE;
  341. CanMboxUserRegs.MboxNum = 9;
  342. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX9.MSGID.all & 0x1FFFFFFF; //扩展帧
  343. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX9.MSGCTRL.bit.DLC;
  344. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX9.MDL.word.LOW_WORD;
  345. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX9.MDL.word.HI_WORD;
  346. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX9.MDH.word.LOW_WORD;
  347. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX9.MDH.word.HI_WORD;
  348. ECanaRegs.CANRMP.bit.RMP9 = 1;
  349. }else if (ECanaRegs.CANRMP.bit.RMP10 == 1)
  350. {
  351. CanMboxUserRegs.MboxRxFlg = TRUE;
  352. CanMboxUserRegs.MboxNum = 10;
  353. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX10.MSGID.all & 0x1FFFFFFF; //扩展帧
  354. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX10.MSGCTRL.bit.DLC;
  355. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX10.MDL.word.LOW_WORD;
  356. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX10.MDL.word.HI_WORD;
  357. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX10.MDH.word.LOW_WORD;
  358. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX10.MDH.word.HI_WORD;
  359. ECanaRegs.CANRMP.bit.RMP10 = 1;
  360. }else if (ECanaRegs.CANRMP.bit.RMP11 == 1)
  361. {
  362. CanMboxUserRegs.MboxRxFlg = TRUE;
  363. CanMboxUserRegs.MboxNum = 11;
  364. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX11.MSGID.all & 0x1FFFFFFF; //扩展帧
  365. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX11.MSGCTRL.bit.DLC;
  366. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX11.MDL.word.LOW_WORD;
  367. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX11.MDL.word.HI_WORD;
  368. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX11.MDH.word.LOW_WORD;
  369. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX11.MDH.word.HI_WORD;
  370. ECanaRegs.CANRMP.bit.RMP11 = 1;
  371. }else if (ECanaRegs.CANRMP.bit.RMP12 == 1)
  372. {
  373. CanMboxUserRegs.MboxRxFlg = TRUE;
  374. CanMboxUserRegs.MboxNum = 12;
  375. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX12.MSGID.all & 0x1FFFFFFF; //扩展帧
  376. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX12.MSGCTRL.bit.DLC;
  377. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX12.MDL.word.LOW_WORD;
  378. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX12.MDL.word.HI_WORD;
  379. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX12.MDH.word.LOW_WORD;
  380. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX12.MDH.word.HI_WORD;
  381. ECanaRegs.CANRMP.bit.RMP12 = 1;
  382. }else if (ECanaRegs.CANRMP.bit.RMP13 == 1)
  383. {
  384. CanMboxUserRegs.MboxRxFlg = TRUE;
  385. CanMboxUserRegs.MboxNum = 13;
  386. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX13.MSGID.all & 0x1FFFFFFF; //扩展帧
  387. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX13.MSGCTRL.bit.DLC;
  388. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX13.MDL.word.LOW_WORD;
  389. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX13.MDL.word.HI_WORD;
  390. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX13.MDH.word.LOW_WORD;
  391. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX13.MDH.word.HI_WORD;
  392. ECanaRegs.CANRMP.bit.RMP13 = 1;
  393. }else if (ECanaRegs.CANRMP.bit.RMP14 == 1)
  394. {
  395. CanMboxUserRegs.MboxRxFlg = TRUE;
  396. CanMboxUserRegs.MboxNum = 14;
  397. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX14.MSGID.all & 0x1FFFFFFF; //扩展帧
  398. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX14.MSGCTRL.bit.DLC;
  399. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX14.MDL.word.LOW_WORD;
  400. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX14.MDL.word.HI_WORD;
  401. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX14.MDH.word.LOW_WORD;
  402. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX14.MDH.word.HI_WORD;
  403. ECanaRegs.CANRMP.bit.RMP14 = 1;
  404. }else if (ECanaRegs.CANRMP.bit.RMP15 == 1)
  405. {
  406. CanMboxUserRegs.MboxRxFlg = TRUE;
  407. CanMboxUserRegs.MboxNum = 15;
  408. CanMboxUserRegs.MboxID = ECanaMboxes.MBOX15.MSGID.all & 0x1FFFFFFF; //扩展帧
  409. CanMboxUserRegs.MboxDLC = ECanaMboxes.MBOX15.MSGCTRL.bit.DLC;
  410. CanMboxUserRegs.MboxWord1 = ECanaMboxes.MBOX15.MDL.word.LOW_WORD;
  411. CanMboxUserRegs.MboxWord2 = ECanaMboxes.MBOX15.MDL.word.HI_WORD;
  412. CanMboxUserRegs.MboxWord3 = ECanaMboxes.MBOX15.MDH.word.LOW_WORD;
  413. CanMboxUserRegs.MboxWord4 = ECanaMboxes.MBOX15.MDH.word.HI_WORD;
  414. ECanaRegs.CANRMP.bit.RMP15 = 1;
  415. }else
  416. {
  417. CanMboxUserRegs.MboxRxFlg = FALSE;
  418. }
  419. return CanMboxUserRegs;
  420. }
  421. /* Note: Bit timing parameters must be chosen based on the network parameters such as
  422. the sampling point desired and the propagation delay of the network. The propagation
  423. delay is a function of length of the cable, delay introduced by the
  424. transceivers and opto/galvanic-isolators (if any).
  425. The parameters used in this file must be changed taking into account the above mentioned
  426. factors in order to arrive at the bit-timing parameters suitable for a network.
  427. */
  428. //===========================================================================
  429. // End of file.
  430. //===========================================================================