serial.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2006-03-13 Bernard first version
  9. * 2011-05-15 lgnq modified according bernard's implementaion.
  10. */
  11. #ifndef __RT_HW_SERIAL_H__
  12. #define __RT_HW_SERIAL_H__
  13. #include <rthw.h>
  14. #include <rtthread.h>
  15. #include "board.h"
  16. #define SMR_SOE 0x01U
  17. #define SMR_BDS 0x04U
  18. #define SMR_SBL 0x08U
  19. #define SMR_WUCR 0x10U
  20. #define SMR_MD_UART 0x00U
  21. #define SMR_MD_UART_MP 0x20U
  22. #define SMR_MD_SIO 0x40U
  23. #define SMR_MD_LIN 0x60U
  24. #define SMR_MD_I2C 0x80U
  25. #define SCR_TXE 0x01U
  26. #define SCR_RXE 0x02U
  27. #define SCR_TBIE 0x04U
  28. #define SCR_TIE 0x08U
  29. #define SCR_RIE 0x10U
  30. #define SCR_UPGL 0x80U
  31. #define SSR_TBI 0x01U
  32. #define SSR_TDRE 0x02U
  33. #define SSR_RDRF 0x04U
  34. #define SSR_ORE 0x08U
  35. #define SSR_FRE 0x10U
  36. #define SSR_PE 0x20U
  37. #define SSR_REC 0x80U
  38. #define ESCR_P 0x08U
  39. #define ESCR_PEN 0x10U
  40. #define ESCR_INV 0x20U
  41. #define ESCR_ESBL 0x40U
  42. #define ESCR_FLWEN 0x80U
  43. #define ESCR_DATABITS_8 0x00U
  44. #define ESCR_DATABITS_5 0x01U
  45. #define ESCR_DATABITS_6 0x02U
  46. #define ESCR_DATABITS_7 0x03U
  47. #define ESCR_DATABITS_9 0x04U
  48. #define BPS 115200 /* serial baudrate */
  49. #define UART_RX_BUFFER_SIZE 64
  50. #define UART_TX_BUFFER_SIZE 64
  51. struct serial_int_rx
  52. {
  53. rt_uint8_t rx_buffer[UART_RX_BUFFER_SIZE];
  54. rt_uint32_t read_index, save_index;
  55. };
  56. struct serial_int_tx
  57. {
  58. rt_uint8_t tx_buffer[UART_TX_BUFFER_SIZE];
  59. rt_uint32_t write_index, save_index;
  60. };
  61. /*
  62. * Enable/DISABLE Interrupt Controller
  63. */
  64. /* deviation from MISRA-C:2004 Rule 19.7 */
  65. #define UART_ENABLE_IRQ(n) NVIC_EnableIRQ((n))
  66. #define UART_DISABLE_IRQ(n) NVIC_DisableIRQ((n))
  67. struct serial_device
  68. {
  69. FM3_MFS03_UART_TypeDef* uart_device;
  70. /* irq number */
  71. IRQn_Type rx_irq, tx_irq;
  72. /* rx structure */
  73. struct serial_int_rx* int_rx;
  74. /* tx structure */
  75. struct serial_int_tx* int_tx;
  76. };
  77. void rt_hw_serial_isr(rt_device_t device);
  78. void rt_hw_serial_init(void);
  79. #endif