serial.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef __RT_HW_SERIAL_H__
  2. #define __RT_HW_SERIAL_H__
  3. #include <rthw.h>
  4. #include <rtthread.h>
  5. #define USTAT_RCV_READY 0x01 /* receive data ready */
  6. #define USTAT_TXB_EMPTY 0x02 /* tx buffer empty */
  7. #define BPS 115200 /* serial baudrate */
  8. #define UART_RX_BUFFER_SIZE 64
  9. #define UART_TX_BUFFER_SIZE 64
  10. struct serial_int_rx
  11. {
  12. rt_uint8_t rx_buffer[UART_RX_BUFFER_SIZE];
  13. rt_uint32_t read_index, save_index;
  14. };
  15. struct serial_int_tx
  16. {
  17. rt_uint8_t tx_buffer[UART_TX_BUFFER_SIZE];
  18. rt_uint32_t write_index, save_index;
  19. };
  20. typedef struct uartport
  21. {
  22. volatile rt_uint16_t rbr_thr; //receive buffer register and transmit hold register
  23. volatile rt_uint16_t reserved0;
  24. volatile rt_uint16_t reserved1;
  25. volatile rt_uint16_t reserved2;
  26. volatile rt_uint16_t reserved3;
  27. volatile rt_uint16_t reserved4;
  28. volatile rt_uint16_t reserved5;
  29. volatile rt_uint16_t reserved6;
  30. volatile rt_uint16_t reserved7;
  31. volatile rt_uint16_t reserved8;
  32. volatile rt_uint16_t lsr; //line status register
  33. }uartport;
  34. struct serial_device
  35. {
  36. uartport* uart_device;
  37. /* rx structure */
  38. struct serial_int_rx* int_rx;
  39. /* tx structure */
  40. struct serial_int_tx* int_tx;
  41. };
  42. rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_uint32_t flag, struct serial_device *serial);
  43. void rt_hw_serial_isr(rt_device_t device);
  44. #endif