usart.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #ifndef USART_H
  2. #define USART_H
  3. #include "gd32f10x.h"
  4. typedef struct usart_data_buf_s
  5. {
  6. uint8_t data[256];
  7. uint16_t data_cnt;
  8. } usart_data_buf_t;
  9. #define DE485_PIN GPIO_PIN_8
  10. #define DE485_GPIO_PORT GPIOA
  11. #define DE485_GPIO_CLK RCU_GPIOB
  12. #define EC800M_PER_PIN GPIO_PIN_1
  13. #define EC800M_PER_GPIO_PORT GPIOC
  14. #define EC800M_PER_GPIO_CLK RCU_GPIOC
  15. #define EC800M_RST_PIN GPIO_PIN_8
  16. #define EC800M_RST_GPIO_PORT GPIOB
  17. #define EC800M_RST_GPIO_CLK RCU_GPIOB
  18. #define COMn 3U
  19. #define COM_EC800 USART0 //USART1 EC800
  20. #define COM_EC800_CLK RCU_USART0
  21. #define COM_EC800_TX_PIN GPIO_PIN_9
  22. #define COM_EC800_RX_PIN GPIO_PIN_10
  23. #define COM_EC800_GPIO_PORT GPIOA
  24. #define COM_EC800_GPIO_CLK RCU_GPIOA
  25. #define COM_EC800_IT_HANDLER USART0_IRQn
  26. #define COM_EC800_BAUDRATE 115200
  27. #define COM_485 USART1 //UART2 J2 RS485
  28. #define COM_485_CLK RCU_USART1
  29. #define COM_485_TX_PIN GPIO_PIN_2
  30. #define COM_485_RX_PIN GPIO_PIN_3
  31. #define COM_485_GPIO_PORT GPIOA
  32. #define COM_485_GPIO_CLK RCU_GPIOA
  33. #define COM_485_IT_HANDLER USART1_IRQn
  34. #define COM_485_BAUDRATE 2400
  35. #define COM_232 USART2 //UART3 J3
  36. #define COM_232_CLK RCU_USART2
  37. #define COM_232_TX_PIN GPIO_PIN_8
  38. #define COM_232_RX_PIN GPIO_PIN_9
  39. #define COM_232_GPIO_PORT GPIOD
  40. #define COM_232_GPIO_CLK RCU_GPIOD
  41. #define COM_232_IT_HANDLER USART2_IRQn
  42. #define COM_232_BAUDRATE 115200
  43. //extern usart_data_buf_t usart0_rx_buf;
  44. //extern usart_data_buf_t usart0_tx_buf;
  45. //extern usart_data_buf_t usart1_rx_buf;
  46. //extern usart_data_buf_t usart1_tx_buf;
  47. /* configure COM port */
  48. void gd_com_init(uint32_t com);
  49. void gd_EC800M_pin_init(void);
  50. void gd_pull_EC800M_pwr_up(void);
  51. void gd_pull_EC800M_pwr_down(void);
  52. void gd_pull_EC800M_rst_up(void);
  53. void gd_pull_EC800M_rst_down(void);
  54. void dma_config(void);
  55. void Clear_DMA_Buffer(void);
  56. #define UART0_RX_LEN 1024 * 4
  57. extern uint8_t UART0_RX_BUF[UART0_RX_LEN];
  58. extern uint8_t UART0_RX_STAT ;
  59. extern uint32_t UART0_RX_NUM ;
  60. extern uint8_t UART0_RX_MQTT_SUB_STAT;
  61. void gd_com_sendByte( uint8_t com, uint8_t ch);
  62. void gd_com_send( uint32_t com, uint8_t *Buf,uint16_t size);
  63. void nvic_config(void);
  64. void dma_config_change(char *dmaBuffer,uint32_t bufferSize);
  65. #endif