drv_can.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-08-05 Xeon Xu the first version
  9. * 2019-01-22 YLZ port from stm324xx-HAL to bsp stm3210x-HAL
  10. * 2019-01-26 YLZ redefine `struct stm32_drv_can` add member `Rx1Message`
  11. * 2019-02-19 YLZ port to BSP [stm32]
  12. */
  13. #ifndef __DRV_CAN_H__
  14. #define __DRV_CAN_H__
  15. #include "board.h"
  16. #include <rtdevice.h>
  17. #include <rthw.h>
  18. #include <rtthread.h>
  19. #define BS1SHIFT 16
  20. #define BS2SHIFT 20
  21. #define RRESCLSHIFT 0
  22. #define SJWSHIFT 24
  23. #define BS1MASK ( (0x0F) << BS1SHIFT )
  24. #define BS2MASK ( (0x07) << BS2SHIFT )
  25. #define RRESCLMASK ( 0x3FF << RRESCLSHIFT )
  26. #define SJWMASK ( 0x3 << SJWSHIFT )
  27. struct stm_baud_rate_tab
  28. {
  29. rt_uint32_t baud_rate;
  30. rt_uint32_t confdata;
  31. };
  32. /* STM32 can driver */
  33. struct stm32_drv_can
  34. {
  35. CAN_HandleTypeDef CanHandle;
  36. CAN_TxHeaderTypeDef TxMessage;
  37. CAN_RxHeaderTypeDef RxMessage;
  38. uint8_t RxMessage_Data[8];
  39. CAN_RxHeaderTypeDef Rx1Message;
  40. uint8_t Rx1Message_Data[8];
  41. CAN_FilterTypeDef FilterConfig;
  42. };
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. extern int rt_hw_can_init(void);
  47. #ifdef __cplusplus
  48. }
  49. #endif
  50. #endif /*__DRV_CAN_H__ */