drv_can.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * File : drv_can.h
  3. * This file is part of RT-Thread RTOS
  4. * Copyright (c) 2006-2025, RT-Thread Development Team
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. *
  8. * Change Logs:
  9. * Date Author Notes
  10. * 2025-18-03 Dmitriy Chernov first implementation
  11. * 2025-09-24 CYFS add support for GD32F5xx
  12. */
  13. #ifndef __DRV_CAN_H__
  14. #define __DRV_CAN_H__
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <board.h>
  19. #include <rtdevice.h>
  20. #define BS1SHIFT 16
  21. #define BS2SHIFT 20
  22. #define RRESCLSHIFT 0
  23. #define SJWSHIFT 24
  24. #define BS1MASK ((0x0F) << BS1SHIFT )
  25. #define BS2MASK ((0x07) << BS2SHIFT )
  26. #define RRESCLMASK (0x3FF << RRESCLSHIFT )
  27. #define SJWMASK (0x3 << SJWSHIFT )
  28. struct gd32_can
  29. {
  30. rcu_periph_enum can_clk;
  31. rcu_periph_enum tx_clk;
  32. rcu_periph_enum rx_clk;
  33. #if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32F5xx
  34. uint32_t alt_func_num;
  35. #endif
  36. rt_base_t tx_pin;
  37. rt_base_t rx_pin;
  38. };
  39. struct gd32_baudrate_tbl
  40. {
  41. rt_uint32_t baudrate;
  42. rt_uint32_t sjw;
  43. rt_uint32_t tseg1;
  44. rt_uint32_t tseg2;
  45. rt_uint32_t prescaler;
  46. };
  47. /* gd32 can device */
  48. struct gd32_can_device
  49. {
  50. char *name;
  51. rt_uint32_t can_x;
  52. can_filter_parameter_struct filter_config;
  53. struct rt_can_device device; /* inherit from can device */
  54. };
  55. int rt_hw_can_init(void);
  56. #ifdef __cplusplus
  57. }
  58. #endif
  59. #endif /*__DRV_CAN_H__ */
  60. /************************** end of file ******************/