serial.h 2.2 KB
Newer Older
Y
yangfasheng 已提交
1
/*
2
 * Copyright (c) 2006-2021, RT-Thread Development Team
Y
yangfasheng 已提交
3
 *
4
 * SPDX-License-Identifier: Apache-2.0
Y
yangfasheng 已提交
5 6 7 8
 *
 * Change Logs:
 * Date           Author       Notes
 * 2006-03-13     Bernard      first version
9
 * 2011-05-15     lgnq         modified according bernard's implementaion.
Y
yangfasheng 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
 */

#ifndef __RT_HW_SERIAL_H__
#define __RT_HW_SERIAL_H__

#include <rthw.h>
#include <rtthread.h>

#include "board.h"

#define SMR_SOE          0x01U
#define SMR_BDS          0x04U
#define SMR_SBL          0x08U
#define SMR_WUCR         0x10U
#define SMR_MD_UART      0x00U
#define SMR_MD_UART_MP   0x20U
#define SMR_MD_SIO       0x40U
#define SMR_MD_LIN       0x60U
#define SMR_MD_I2C       0x80U

#define SCR_TXE          0x01U
#define SCR_RXE          0x02U
#define SCR_TBIE         0x04U
#define SCR_TIE          0x08U
#define SCR_RIE          0x10U
#define SCR_UPGL         0x80U

#define SSR_TBI          0x01U
#define SSR_TDRE         0x02U
#define SSR_RDRF         0x04U
#define SSR_ORE          0x08U
#define SSR_FRE          0x10U
#define SSR_PE           0x20U
#define SSR_REC          0x80U

#define ESCR_P           0x08U
#define ESCR_PEN         0x10U
#define ESCR_INV         0x20U
#define ESCR_ESBL        0x40U
#define ESCR_FLWEN       0x80U
#define ESCR_DATABITS_8  0x00U
#define ESCR_DATABITS_5  0x01U
#define ESCR_DATABITS_6  0x02U
#define ESCR_DATABITS_7  0x03U
#define ESCR_DATABITS_9  0x04U

56
#define BPS                 115200  /* serial baudrate */
Y
yangfasheng 已提交
57

58 59
#define UART_RX_BUFFER_SIZE     128
#define UART_TX_BUFFER_SIZE     128
Y
yangfasheng 已提交
60 61 62

struct serial_int_rx
{
63 64
    rt_uint8_t  rx_buffer[UART_RX_BUFFER_SIZE];
    rt_uint32_t read_index, save_index;
Y
yangfasheng 已提交
65 66 67 68
};

struct serial_int_tx
{
69 70
    rt_uint8_t  tx_buffer[UART_TX_BUFFER_SIZE];
    rt_uint32_t write_index, save_index;
Y
yangfasheng 已提交
71 72 73 74 75 76 77 78 79 80 81
};

/*
 *  Enable/DISABLE Interrupt Controller
 */
/* deviation from MISRA-C:2004 Rule 19.7 */
#define UART_ENABLE_IRQ(n)            NVIC_EnableIRQ((n))
#define UART_DISABLE_IRQ(n)           NVIC_DisableIRQ((n))

struct serial_device
{
82 83 84 85 86 87 88 89 90
    FM4_MFS_TypeDef* uart_device;
    /* irq number */
    IRQn_Type rx_irq;
    IRQn_Type tx_irq;

    /* rx structure */
    struct serial_int_rx* int_rx;
    /* tx structure */
    struct serial_int_tx* int_tx;
Y
yangfasheng 已提交
91 92 93 94 95 96
};

void rt_hw_serial_isr(rt_device_t device);
void rt_hw_serial_init(void);

#endif