CANNet.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /********************************************************************************
  2. * 常州易控汽车电子股份有限公司
  3. * (c) Copyright 2009-2015 ECTEK
  4. * 保留所有权利
  5. ********************************************************************************
  6. * 工程名称:整车管理
  7. * 文件名: CANNet.c
  8. * 功能描述 : CAN总线管理
  9. * 引用记录:
  10. * 备注:
  11. * 修订记录:
  12. * 日期 版本 作者 描述
  13. * 2011.07.14 00.01.00 李中 第一版
  14. *******************************************************************************/
  15. #include <CanProtocolFunc.h>
  16. #include <CanProtocolFunc.h>
  17. #include "HardwareLib.h"
  18. #include "CANNet.h"
  19. #include "AccPedCD.h"
  20. MCANDrv_infoMsgConfS_TYPE CANNet_infoMsgTxConfSA[3];
  21. MCAN_stRetE_TYPE CAN1Result;
  22. uint16 CANNet_idxSchedUB;
  23. MCANDrv_infoMsgConfS_TYPE CANNet_InfoRxMsgConfSA[128];
  24. uint8 CANNet_datRxMsgBufM[128][9];
  25. void CANNet_Init(void)
  26. {
  27. /*示例代码*/
  28. /*各个CAN节点初始化*/
  29. MCANDrv_SetBaudrate(_CAN_INDEX_CAN0, 250000);
  30. MCANDrv_SetCANMode(_CAN_INDEX_CAN0, MCAN_NODEMODE_BUF);
  31. MCANDrv_SetCallbackFunc(_CAN_INDEX_CAN0, (pFunc_RxMsgCallback)CANNet_RecvMsgCAN0, NULL_PTR);
  32. MCANDrv_SetBaudrate(_CAN_INDEX_CAN1, 250000);
  33. MCANDrv_SetCANMode(_CAN_INDEX_CAN1, MCAN_NODEMODE_BUF);
  34. MCANDrv_SetCallbackFunc(_CAN_INDEX_CAN1, (pFunc_RxMsgCallback)CANNet_RecvMsgCAN1, NULL_PTR);
  35. /*第2路CAN用于CCP、UDS协议,由底层配置*/
  36. // MCANDrv_SetCallbackFunc(_CAN_INDEX_CAN2, (pFunc_RxMsgCallback)CANNet_RecvMsgCAN2, NULL_PTR);
  37. /*接收报文初始化,主要配置CAN2*/
  38. CANNet_InfoRxMsgConfSA[0].infoMsgIDUI = 0x1CEF0000UL;
  39. CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.CAN = 2;
  40. CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.MO = 3;
  41. CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.DIR = _MCAN_DIR_RX;
  42. CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.DLC = 8;
  43. CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.IDE = _MCAN_IDE_EXT;
  44. MCANDrv_SetMsgObj(CANNet_InfoRxMsgConfSA[0], CANNet_RecvMsgCAN2);
  45. CANNet_InfoRxMsgConfSA[1].infoMsgIDUI = 0x1C00ECEAUL;
  46. CANNet_InfoRxMsgConfSA[1].infoMsgParU.B.CAN = 2;
  47. CANNet_InfoRxMsgConfSA[1].infoMsgParU.B.MO = 4;
  48. CANNet_InfoRxMsgConfSA[1].infoMsgParU.B.DIR = _MCAN_DIR_RX;
  49. CANNet_InfoRxMsgConfSA[1].infoMsgParU.B.DLC = 8;
  50. CANNet_InfoRxMsgConfSA[1].infoMsgParU.B.IDE = _MCAN_IDE_EXT;
  51. MCANDrv_SetMsgObj(CANNet_InfoRxMsgConfSA[1], CANNet_RecvMsgCAN2);
  52. /*发送报文初始化*/
  53. CANNet_infoMsgTxConfSA[0].infoMsgIDUI = 0x1F000024UL;
  54. CANNet_infoMsgTxConfSA[0].infoMsgParU.B.CAN = 0;
  55. CANNet_infoMsgTxConfSA[0].infoMsgParU.B.MO = 0;
  56. CANNet_infoMsgTxConfSA[0].infoMsgParU.B.DIR = _MCAN_DIR_TX;
  57. CANNet_infoMsgTxConfSA[0].infoMsgParU.B.DLC = 8;
  58. CANNet_infoMsgTxConfSA[0].infoMsgParU.B.IDE = _MCAN_IDE_EXT;
  59. // MCANDrv_SetMsgObj(CANNet_infoMsgTxConfSA[0], NULL_PTR);
  60. CANNet_infoMsgTxConfSA[1].infoMsgIDUI = 0x1F000025UL;
  61. CANNet_infoMsgTxConfSA[1].infoMsgParU.B.CAN = 1;
  62. CANNet_infoMsgTxConfSA[1].infoMsgParU.B.MO = 1;
  63. CANNet_infoMsgTxConfSA[1].infoMsgParU.B.DIR = _MCAN_DIR_TX;
  64. CANNet_infoMsgTxConfSA[1].infoMsgParU.B.DLC = 8;
  65. CANNet_infoMsgTxConfSA[1].infoMsgParU.B.IDE = _MCAN_IDE_EXT;
  66. // MCANDrv_SetMsgObj(CANNet_infoMsgTxConfSA[1], NULL_PTR);
  67. CANNet_infoMsgTxConfSA[2].infoMsgIDUI = 0x1F000026UL;
  68. CANNet_infoMsgTxConfSA[2].infoMsgParU.B.CAN = 2;
  69. CANNet_infoMsgTxConfSA[2].infoMsgParU.B.MO = 2;
  70. CANNet_infoMsgTxConfSA[2].infoMsgParU.B.DIR = _MCAN_DIR_TX;
  71. CANNet_infoMsgTxConfSA[2].infoMsgParU.B.DLC = 8;
  72. CANNet_infoMsgTxConfSA[2].infoMsgParU.B.IDE = _MCAN_IDE_EXT;
  73. }
  74. // CAN0接收消息处理函数 VCU
  75. void CANNet_RecvMsgCAN0(MCANDrv_infoMsgS_TYPE infoMsgS)
  76. {
  77. Can0Decode(infoMsgS.infoConfS.infoMsgIDUI, infoMsgS.datMsgUBA);
  78. }
  79. // CAN1接收消息处理函数
  80. void CANNet_RecvMsgCAN1(MCANDrv_infoMsgS_TYPE infoMsgS)
  81. {
  82. Can1Decode(infoMsgS.infoConfS.infoMsgIDUI, infoMsgS.datMsgUBA);
  83. }
  84. /*备注,CAN2接收报文时,需要配置接收报文的MO号,如果不配置,将进入不了CAN中断*/
  85. void CANNet_RecvMsgCAN2(MCANDrv_infoMsgS_TYPE infoMsgS)
  86. {
  87. }
  88. //发送消息管理
  89. void CAN0Net_Manage1ms(void)
  90. {
  91. }
  92. void CAN1Net_Manage1ms(void)
  93. {
  94. static UINT32 Can1TimerCounter = 0;
  95. static UINT8 BcuIDIdx = 0;
  96. static BOOL BcuChkFlg = FALSE;
  97. MCANDrv_infoMsgS_TYPE infoMsgS;
  98. if (Can1TimerCounter % 100 == 0)
  99. {
  100. if (Can1TimerCounter % (Can1OutTable[BcuIDIdx][1]) == 0)
  101. {
  102. CANNet_infoMsgTxConfSA[1].infoMsgIDUI = Can1OutTable[BcuIDIdx][0];
  103. infoMsgS.infoConfS = CANNet_infoMsgTxConfSA[1];
  104. memset(infoMsgS.datMsgUBA, 0x00, 8);
  105. Can1Encode(Can1OutTable[BcuIDIdx][0], &(infoMsgS.datMsgUBA[0]));
  106. MCANDrv_SendMsg(infoMsgS);
  107. }
  108. BcuIDIdx++;
  109. BcuChkFlg = FALSE;
  110. }
  111. if (BcuIDIdx >= (sizeof(Can1OutTable) / 8))
  112. {
  113. BcuIDIdx = 0;
  114. BcuChkFlg = TRUE;
  115. }
  116. if (BcuChkFlg)
  117. {
  118. Can1TimerCounter = Can1TimerCounter + 1;
  119. }
  120. }
  121. void CAN2Net_Manage1ms(void)
  122. {
  123. }