drv_usart.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (C) 2022-2024, Xiaohua Semiconductor Co., Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-04-28 CDT first version
  9. */
  10. #ifndef __DRV_USART_H__
  11. #define __DRV_USART_H__
  12. /*******************************************************************************
  13. * Include files
  14. ******************************************************************************/
  15. #include <rtthread.h>
  16. #include "rtdevice.h"
  17. #include "drv_irq.h"
  18. #include "drv_dma.h"
  19. /* C binding of definitions if building with C++ compiler */
  20. #ifdef __cplusplus
  21. extern "C"
  22. {
  23. #endif
  24. /*******************************************************************************
  25. * Global type definitions ('typedef')
  26. ******************************************************************************/
  27. struct hc32_uart_irq_config
  28. {
  29. struct hc32_irq_config irq_config;
  30. func_ptr_t irq_callback;
  31. };
  32. /* HC32 config Rx timeout */
  33. struct hc32_uart_rxto
  34. {
  35. CM_TMR0_TypeDef *TMR0_Instance;
  36. rt_uint32_t channel;
  37. rt_uint32_t clock;
  38. rt_size_t timeout_bits;
  39. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  40. struct hc32_irq_config irq_config;
  41. func_ptr_t irq_callback;
  42. #endif
  43. };
  44. /* HC32 config uart class */
  45. struct hc32_uart_config
  46. {
  47. const char *name;
  48. CM_USART_TypeDef *Instance;
  49. rt_uint32_t clock;
  50. #if defined (HC32F460) || defined (HC32F4A0) || defined (HC32F4A8)
  51. struct hc32_uart_irq_config rxerr_irq;
  52. struct hc32_uart_irq_config rx_irq;
  53. struct hc32_uart_irq_config tx_irq;
  54. #elif defined (HC32F448) || defined (HC32F472) || defined (HC32F334)
  55. IRQn_Type irq_num;
  56. en_int_src_t rxerr_int_src;
  57. en_int_src_t tx_int_src;
  58. en_int_src_t rx_int_src;
  59. #ifdef RT_SERIAL_USING_DMA
  60. en_int_src_t rxto_int_src;
  61. #endif
  62. #endif
  63. #ifdef RT_SERIAL_USING_DMA
  64. struct hc32_uart_rxto *rx_timeout;
  65. stc_dma_llp_descriptor_t llp_desc[2U];
  66. struct dma_config *dma_rx;
  67. struct hc32_uart_irq_config *tc_irq;
  68. struct dma_config *dma_tx;
  69. #endif
  70. };
  71. /* HC32 uart driver class */
  72. struct hc32_uart
  73. {
  74. struct hc32_uart_config *config;
  75. #ifdef RT_SERIAL_USING_DMA
  76. rt_size_t dma_rx_remaining_cnt;
  77. #endif
  78. rt_uint16_t uart_dma_flag;
  79. struct rt_serial_device serial;
  80. };
  81. /*******************************************************************************
  82. * Global pre-processor symbols/macros ('#define')
  83. ******************************************************************************/
  84. /*******************************************************************************
  85. * Global variable definitions ('extern')
  86. ******************************************************************************/
  87. /*******************************************************************************
  88. * Global function prototypes (definition in C source)
  89. ******************************************************************************/
  90. int rt_hw_usart_init(void);
  91. #ifdef __cplusplus
  92. }
  93. #endif
  94. #endif /* __DRV_USART_H__ */
  95. /*******************************************************************************
  96. * EOF (not truncated)
  97. ******************************************************************************/