can.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /**
  2. ******************************************************************************
  3. * File Name : CAN.h
  4. * Description : This file provides code for the configuration
  5. * of the CAN instances.
  6. ******************************************************************************
  7. ** This notice applies to any and all portions of this file
  8. * that are not between comment pairs USER CODE BEGIN and
  9. * USER CODE END. Other portions of this file, whether
  10. * inserted by the user or by software development tools
  11. * are owned by their respective copyright owners.
  12. *
  13. * COPYRIGHT(c) 2019 STMicroelectronics
  14. *
  15. * Redistribution and use in source and binary forms, with or without modification,
  16. * are permitted provided that the following conditions are met:
  17. * 1. Redistributions of source code must retain the above copyright notice,
  18. * this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  23. * may be used to endorse or promote products derived from this software
  24. * without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  27. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  29. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  30. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  32. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  33. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  34. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. ******************************************************************************
  38. */
  39. /* Define to prevent recursive inclusion -------------------------------------*/
  40. #ifndef __can_H
  41. #define __can_H
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. /* Includes ------------------------------------------------------------------*/
  46. #include "stm32f1xx_hal.h"
  47. #include "main.h"
  48. /* USER CODE BEGIN Includes */
  49. /* USER CODE END Includes */
  50. extern CAN_HandleTypeDef hcan;
  51. /* USER CODE BEGIN Private defines */
  52. #define ID_MC_BC 0x710
  53. #define ID_MC_TO_BMS 0x712
  54. #define ID_MC_TO_PBU 0x713
  55. #define ID_MC_TO_HMI 0x714
  56. #define ID_MC_TO_CDL 0x715
  57. #define ID_MC_TE_TO_CDL 0x615
  58. #define ID_BMS_BC 0x720
  59. #define ID_BMS_TO_MC 0x721
  60. #define ID_BMS_TO_PBU 0x723
  61. #define ID_BMS_TO_HMI 0x724
  62. #define ID_BMS_TO_CDL 0x725
  63. #define ID_PBU_BC 0x730
  64. #define ID_PBU_TO_MC 0x731
  65. #define ID_PBU_TO_BMS 0x732
  66. #define ID_PBU_TO_HMI 0x734
  67. #define ID_PBU_TO_CDL 0x735
  68. #define ID_PBU_TE_TO_CDL 0x635
  69. #define ID_HMI_BC 0x740
  70. #define ID_HMI_TO_MC 0x741
  71. #define ID_HMI_TO_BMS 0x742
  72. #define ID_HMI_TO_PBU 0x743
  73. #define ID_HMI_TO_CDL 0x745
  74. #define ID_CDL_BC 0x750
  75. #define ID_CDL_TO_MC 0x751
  76. #define ID_CDL_TO_BMS 0x752
  77. #define ID_CDL_TO_PBU 0x753
  78. #define ID_CDL_TO_HMI 0x754
  79. #define ID_CDL_TO_MC_TE 0x651
  80. #define ID_CDL_TO_PBU_TE 0x653
  81. #define ID_FILTER (uint16_t)(0x700) //过滤,相同通过
  82. #define ID_MASK (uint16_t)(0x788) //屏蔽,0-过滤位不起作用,1-过滤位生效
  83. typedef struct
  84. {
  85. uint16_t ucBufID;
  86. uint16_t ucBufSize; //缓冲区数组:缓冲区大小
  87. uint16_t ucBufWrInde; //缓冲区数组:写指针
  88. uint16_t ucBufRdInde; //缓冲区数组:读指针
  89. uint16_t ucBufCnt; //缓冲区数组:数据计数
  90. uint8_t ucBufOvf; //缓冲区数组:溢出标志,注意清零
  91. uint8_t * pcBufAddr; //缓冲区数组:首地址指针变量
  92. uint32_t DelayTimeCnt; //超时计时
  93. TrueOrFalse_Flag_Struct_t IsWaitRX_Flag; //超时等待数据标志
  94. }CAN_Buf_TypeDef;
  95. /* USER CODE END Private defines */
  96. extern void _Error_Handler(char *, int);
  97. void MX_CAN_Init(void);
  98. /* USER CODE BEGIN Prototypes */
  99. #define CAN_BUFF_SIZE 512
  100. #define CAN_ID_NUM 22
  101. extern uint8_t CAN_RxBuf[CAN_ID_NUM][CAN_BUFF_SIZE];
  102. extern CAN_Buf_TypeDef CAN_RxBuf_Struct[CAN_ID_NUM];
  103. extern void CAN_RxBuf_Init(void);
  104. extern void CAN_SendData(uint16_t ID, uint8_t *Data, uint16_t Length);
  105. extern void CANFilterConfig_Scale32_IdMask_StandardIdOnly(void);
  106. /* USER CODE END Prototypes */
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. #endif /*__ can_H */
  111. /**
  112. * @}
  113. */
  114. /**
  115. * @}
  116. */
  117. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/