uart.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef __UART_H__
  2. #define __UART_H__
  3. #include <rthw.h>
  4. #include <rtthread.h>
  5. #include "cy_device_headers.h"
  6. #include "board.h"
  7. #include "cy_pdl.h"
  8. #define UART_RX_BUFFER_SIZE 128u
  9. #define UART_TX_BUFFER_SIZE 128u
  10. #define UART_ENABLE_IRQ(n) NVIC_EnableIRQ((n))
  11. #define UART_DISABLE_IRQ(n) NVIC_DisableIRQ((n))
  12. struct uart_int_rx
  13. {
  14. rt_uint8_t rx_buffer[UART_RX_BUFFER_SIZE];
  15. rt_uint32_t read_index, save_index;
  16. };
  17. struct uart_int_tx
  18. {
  19. rt_uint8_t tx_buffer[UART_TX_BUFFER_SIZE];
  20. rt_uint32_t write_index, save_index;
  21. };
  22. struct uart_device
  23. {
  24. CySCB_Type* scb_device;
  25. /* uart config */
  26. cy_stc_scb_uart_config_t const *uart_config;
  27. /* uart context */
  28. cy_stc_scb_uart_context_t *uart_context;
  29. /* uart interrupt */
  30. const cy_stc_sysint_t *uart_int;
  31. /* irq number */
  32. IRQn_Type rx_irq;
  33. IRQn_Type tx_irq;
  34. /* rx structure */
  35. struct uart_int_rx* int_rx;
  36. /* tx structure */
  37. struct uart_int_tx* int_tx;
  38. };
  39. void rt_hw_uart_init(void);
  40. #endif