serial.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 128
  50. #define UART_TX_BUFFER_SIZE 128
  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. FM4_MFS_TypeDef* uart_device;
  70. /* irq number */
  71. IRQn_Type rx_irq;
  72. IRQn_Type tx_irq;
  73. /* rx structure */
  74. struct serial_int_rx* int_rx;
  75. /* tx structure */
  76. struct serial_int_tx* int_tx;
  77. };
  78. void rt_hw_serial_isr(rt_device_t device);
  79. void rt_hw_serial_init(void);
  80. #endif