hal_uart.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef __HAL_UART_H__
  2. #define __HAL_UART_H__
  3. #include "hc32_ll_usart.h"
  4. #include "hc32_ll_gpio.h"
  5. #include "hc32_ll_fcg.h"
  6. #include "hc32_ll_interrupts.h"
  7. #include "hc32_ll_tmr0.h"
  8. #include "hc32_ll_tmr4.h"
  9. #include "ring_buf.h"
  10. #include "hc32_ll_aos.h"
  11. #define RS485_TX_ENABLE GPIO_ResetPins(GPIO_PORT_A, GPIO_PIN_08)
  12. #define RS485_TX_DISABLE GPIO_SetPins(GPIO_PORT_A, GPIO_PIN_08)
  13. #define LL_PERIPH_SEL (LL_PERIPH_GPIO | LL_PERIPH_FCG | LL_PERIPH_PWC_CLK_RMU | \
  14. LL_PERIPH_EFM | LL_PERIPH_SRAM)
  15. /* DMA definition */
  16. #define RX_DMA_UNIT (CM_DMA1)
  17. #define RX_DMA_CH (DMA_CH0)
  18. #define RX_DMA_FCG_ENABLE() (FCG_Fcg0PeriphClockCmd(FCG0_PERIPH_DMA1, ENABLE))
  19. #define RX_DMA_TRIG_SEL (AOS_DMA1_0)
  20. #define RX_DMA_TRIG_EVT_SRC (EVT_SRC_USART2_RI)
  21. #define RX_DMA_RECONF_TRIG_SEL (AOS_DMA_RC)
  22. #define RX_DMA_RECONF_TRIG_EVT_SRC (EVT_SRC_AOS_STRG)
  23. #define RX_DMA_TC_INT (DMA_INT_TC_CH0)
  24. #define RX_DMA_TC_FLAG (DMA_FLAG_TC_CH0)
  25. #define RX_DMA_TC_IRQn (INT000_IRQn)
  26. #define RX_DMA_TC_INT_SRC (INT_SRC_DMA1_TC0)
  27. #define TX_DMA_UNIT (CM_DMA2)
  28. #define TX_DMA_CH (DMA_CH0)
  29. #define TX_DMA_FCG_ENABLE() (FCG_Fcg0PeriphClockCmd(FCG0_PERIPH_DMA2, ENABLE))
  30. #define TX_DMA_TRIG_SEL (AOS_DMA2_0)
  31. #define TX_DMA_TRIG_EVT_SRC (EVT_SRC_USART2_TI)
  32. #define TX_DMA_TC_INT (DMA_INT_TC_CH0)
  33. #define TX_DMA_TC_FLAG (DMA_FLAG_TC_CH0)
  34. #define TX_DMA_TC_IRQn (INT001_IRQn)
  35. #define TX_DMA_TC_INT_SRC (INT_SRC_DMA2_TC0)
  36. /* Timer0 unit & channel definition */
  37. #define TMR0_UNIT (CM_TMR0_1)
  38. #define TMR0_CH (TMR0_CH_B)
  39. #define TMR0_FCG_ENABLE() (FCG_Fcg2PeriphClockCmd(FCG2_PERIPH_TMR0_1, ENABLE))
  40. ///* USART RX/TX pin definition */
  41. #define USART_RX_PORT (GPIO_PORT_A) /* PA10: USART2_RX */
  42. #define USART_RX_PIN (GPIO_PIN_10)
  43. #define USART_RX_GPIO_FUNC (GPIO_FUNC_37)
  44. #define USART_TX_PORT (GPIO_PORT_A) /* PA9: USART2_TX */
  45. #define USART_TX_PIN (GPIO_PIN_09)
  46. #define USART_TX_GPIO_FUNC (GPIO_FUNC_36)
  47. /* USART unit definition */
  48. #define USART_UNIT (CM_USART2)
  49. #define USART_FCG_ENABLE() (FCG_Fcg3PeriphClockCmd(FCG3_PERIPH_USART2, ENABLE))
  50. /* USART baudrate definition */
  51. #define USART_BAUDRATE (115200UL)
  52. /* USART timeout bits definition */
  53. #define USART_TIMEOUT_BITS (2000U)
  54. /* USART interrupt definition */
  55. #define USART_TX_CPLT_IRQn (INT002_IRQn)
  56. #define USART_TX_CPLT_INT_SRC (INT_SRC_USART2_TCI)
  57. #define USART_RX_ERR_IRQn (INT003_IRQn)
  58. #define USART_RX_ERR_INT_SRC (INT_SRC_USART2_EI)
  59. #define USART_RX_TIMEOUT_IRQn (INT004_IRQn)
  60. #define USART_RX_TIMEOUT_INT_SRC (INT_SRC_USART2_RTO)
  61. /* Application frame length max definition */
  62. #define APP_FRAME_LEN_MAX (500U)
  63. void bsp_uart2_init(void);
  64. void test_task2(void *pvParameters);
  65. int32_t rs485_send_data(const void *pvBuf,uint32_t u32Len);
  66. #endif