drv_can.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2006-2023, 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. * 2019-06-17 YLZ modify struct stm32_drv_can.
  13. */
  14. #ifndef __DRV_CAN_H__
  15. #define __DRV_CAN_H__
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. #include <board.h>
  20. #include <rtdevice.h>
  21. #define BS1SHIFT 16
  22. #define BS2SHIFT 20
  23. #define RRESCLSHIFT 0
  24. #define SJWSHIFT 24
  25. #define BS1MASK ((0x0F) << BS1SHIFT )
  26. #define BS2MASK ((0x07) << BS2SHIFT )
  27. #define RRESCLMASK (0x3FF << RRESCLSHIFT )
  28. #define SJWMASK (0x3 << SJWSHIFT )
  29. struct stm32_baud_rate_tab
  30. {
  31. rt_uint32_t baud_rate;
  32. rt_uint32_t config_data;
  33. };
  34. #define BAUD_DATA(TYPE,NO) ((can_baud_rate_tab[NO].config_data & TYPE##MASK))
  35. /* stm32 can device */
  36. struct stm32_can
  37. {
  38. char *name;
  39. CAN_HandleTypeDef CanHandle;
  40. CAN_FilterTypeDef FilterConfig;
  41. struct rt_can_device device; /* inherit from can device */
  42. };
  43. int rt_hw_can_init(void);
  44. #ifdef __cplusplus
  45. }
  46. #endif
  47. #endif /*__DRV_CAN_H__ */
  48. /************************** end of file ******************/