usart.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. void gd_485_DE_pin_init(void);
  48. void gd_485_DE_tx(void);
  49. void gd_485_DE_rx(void);
  50. void gd_485_send(char* message, uint16_t size);
  51. /* configure COM port */
  52. void gd_com_init(uint32_t com);
  53. void gd_EC800M_pin_init(void);
  54. void gd_pull_EC800M_pwr_up(void);
  55. void gd_pull_EC800M_pwr_down(void);
  56. void gd_pull_EC800M_rst_up(void);
  57. void gd_pull_EC800M_rst_down(void);
  58. void gd_com_485_send(uint8_t *message,uint16_t size);
  59. void dma_config(void);
  60. void Clear_DMA_Buffer(void);
  61. #define UART0_RX_LEN 1024 * 4
  62. extern uint8_t UART0_RX_BUF[UART0_RX_LEN];
  63. extern uint8_t UART0_RX_STAT ;
  64. extern uint32_t UART0_RX_NUM ;
  65. extern uint8_t UART0_RX_MQTT_SUB_STAT;
  66. void gd_com_sendByte( uint8_t com, uint8_t ch);
  67. void gd_com_send( uint32_t com, uint8_t *Buf,uint16_t size);
  68. void config_485_port(uint32_t com,uint32_t baudrate, uint8_t databits, uint8_t stopbits, uint8_t parity);
  69. void nvic_config(void);
  70. void gd_com_232_Receive(void);
  71. void gd_com_232_send(uint8_t *message,uint16_t size);
  72. void dma_config_change(char *dmaBuffer,uint32_t bufferSize);
  73. #endif