drv_usart.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2006-2025, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-08-20 BruceOu first implementation
  9. */
  10. #ifndef __DRV_USART_H__
  11. #define __DRV_USART_H__
  12. #include <rthw.h>
  13. #include <rtthread.h>
  14. #include <board.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #ifndef SOC_SERIES_GD32H7xx
  19. #undef RT_SERIAL_USING_DMA
  20. #endif
  21. #define UART_ENABLE_IRQ(n) NVIC_EnableIRQ((n))
  22. #define UART_DISABLE_IRQ(n) NVIC_DisableIRQ((n))
  23. #ifdef RT_SERIAL_USING_DMA
  24. typedef struct
  25. {
  26. /* dma peripheral */
  27. uint32_t dma_periph;
  28. /* dma channel */
  29. dma_channel_enum dma_ch;
  30. #ifdef SOC_SERIES_GD32H7xx
  31. /* rx dma request */
  32. uint32_t dma_mux_req_rx;
  33. #endif
  34. /* dma flag */
  35. uint32_t rx_flag;
  36. /* dma irq channel */
  37. uint8_t rx_irq_ch;
  38. /* setting receive len */
  39. rt_size_t setting_recv_len;
  40. /* last receive index */
  41. rt_size_t last_recv_index;
  42. } gd32_uart_dma;
  43. #endif
  44. /* GD32 uart driver */
  45. /* Todo: compress uart info */
  46. struct gd32_uart
  47. {
  48. uint32_t uart_periph; /* Todo: 3bits */
  49. IRQn_Type irqn; /* Todo: 7bits */
  50. rcu_periph_enum per_clk; /* Todo: 5bits */
  51. rcu_periph_enum tx_gpio_clk; /* Todo: 5bits */
  52. rcu_periph_enum rx_gpio_clk; /* Todo: 5bits */
  53. uint32_t tx_port; /* Todo: 4bits */
  54. #if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32H7xx || defined SOC_SERIES_GD32F5xx || defined SOC_SERIES_GD32E23x
  55. uint16_t tx_af; /* Todo: 4bits */
  56. #elif defined SOC_SERIES_GD32E50x
  57. uint32_t tx_af; /* alternate1 cfg */
  58. #endif
  59. uint16_t tx_pin; /* Todo: 4bits */
  60. uint32_t rx_port; /* Todo: 4bits */
  61. #if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32H7xx || defined SOC_SERIES_GD32F5xx || defined SOC_SERIES_GD32E23x
  62. uint16_t rx_af; /* Todo: 4bits */
  63. #elif defined SOC_SERIES_GD32E50x
  64. uint32_t rx_af; /* alternate1 cfg */
  65. #endif
  66. uint16_t rx_pin; /* Todo: 4bits */
  67. #if defined SOC_SERIES_GD32E50x
  68. uint32_t uart_remap; /* remap */
  69. #endif
  70. #ifdef RT_SERIAL_USING_DMA
  71. gd32_uart_dma *uart_dma;
  72. #ifdef RT_SERIAL_USING_TX_DMA
  73. gd32_uart_dma *uart_tx_dma;
  74. #endif
  75. #endif
  76. struct rt_serial_device * serial;
  77. char *device_name;
  78. };
  79. int rt_hw_usart_init(void);
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. #endif /* __DRV_USART_H__ */