RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
dev_serial.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2024 RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2012-05-15 lgnq first version.
9 * 2012-05-28 bernard change interfaces
10 * 2013-02-20 bernard use RT_SERIAL_RB_BUFSZ to define
11 * the size of ring buffer.
12 */
13
14#ifndef __DEV_SERIAL_H__
15#define __DEV_SERIAL_H__
16
17#include <rtthread.h>
111
112
117#define BAUD_RATE_2400 2400
118#define BAUD_RATE_4800 4800
119#define BAUD_RATE_9600 9600
120#define BAUD_RATE_19200 19200
121#define BAUD_RATE_38400 38400
122#define BAUD_RATE_57600 57600
123#define BAUD_RATE_115200 115200
124#define BAUD_RATE_230400 230400
125#define BAUD_RATE_460800 460800
126#define BAUD_RATE_500000 500000
127#define BAUD_RATE_576000 576000
128#define BAUD_RATE_921600 921600
129#define BAUD_RATE_1000000 1000000
130#define BAUD_RATE_1152000 1152000
131#define BAUD_RATE_1500000 1500000
132#define BAUD_RATE_2000000 2000000
133#define BAUD_RATE_2500000 2500000
134#define BAUD_RATE_3000000 3000000
135#define BAUD_RATE_3500000 3500000
136#define BAUD_RATE_4000000 4000000
137
138#define DATA_BITS_5 5
139#define DATA_BITS_6 6
140#define DATA_BITS_7 7
141#define DATA_BITS_8 8
142#define DATA_BITS_9 9
143
144#define STOP_BITS_1 0
145#define STOP_BITS_2 1
146#define STOP_BITS_3 2
147#define STOP_BITS_4 3
148
149#ifdef _WIN32
150#include <windows.h>
151#else
152#define PARITY_NONE 0
153#define PARITY_ODD 1
154#define PARITY_EVEN 2
155#endif
156
157#define BIT_ORDER_LSB 0
158#define BIT_ORDER_MSB 1
159
160#define NRZ_NORMAL 0 /* Non Return to Zero : normal mode */
161#define NRZ_INVERTED 1 /* Non Return to Zero : inverted mode */
162
163#ifndef RT_SERIAL_RB_BUFSZ
164#define RT_SERIAL_RB_BUFSZ 64
165#endif
166
167#define RT_SERIAL_EVENT_RX_IND 0x01 /* Rx indication */
168#define RT_SERIAL_EVENT_TX_DONE 0x02 /* Tx complete */
169#define RT_SERIAL_EVENT_RX_DMADONE 0x03 /* Rx DMA transfer done */
170#define RT_SERIAL_EVENT_TX_DMADONE 0x04 /* Tx DMA transfer done */
171#define RT_SERIAL_EVENT_RX_TIMEOUT 0x05 /* Rx timeout */
172
173#define RT_SERIAL_DMA_RX 0x01
174#define RT_SERIAL_DMA_TX 0x02
175
176#define RT_SERIAL_RX_INT 0x01
177#define RT_SERIAL_TX_INT 0x02
178
179#define RT_SERIAL_ERR_OVERRUN 0x01
180#define RT_SERIAL_ERR_FRAMING 0x02
181#define RT_SERIAL_ERR_PARITY 0x03
182
183#define RT_SERIAL_TX_DATAQUEUE_SIZE 2048
184#define RT_SERIAL_TX_DATAQUEUE_LWM 30
185
186#define RT_SERIAL_FLOWCONTROL_CTSRTS 1
187#define RT_SERIAL_FLOWCONTROL_NONE 0
188
189/* Default config for serial_configure structure */
190#define RT_SERIAL_CONFIG_DEFAULT \
191{ \
192 BAUD_RATE_115200, /* 115200 bits/s */ \
193 DATA_BITS_8, /* 8 databits */ \
194 STOP_BITS_1, /* 1 stopbit */ \
195 PARITY_NONE, /* No parity */ \
196 BIT_ORDER_LSB, /* LSB first sent */ \
197 NRZ_NORMAL, /* Normal mode */ \
198 RT_SERIAL_RB_BUFSZ, /* Buffer size */ \
199 RT_SERIAL_FLOWCONTROL_NONE, /* Off flowcontrol */ \
200 0 \
201}
202
209
223
224/*
225 * Serial FIFO mode
226 */
228{
229 /* software fifo */
231
233
235};
236
238{
239 struct rt_completion completion;
240};
241
242/*
243 * Serial DMA mode
244 */
249
251{
253 struct rt_data_queue data_queue;
254};
255
257{
259
260 const struct rt_uart_ops *ops;
262
265
267#ifdef RT_USING_SERIAL_BYPASS
268 struct rt_serial_bypass* bypass;
269#endif
271};
273
278{
279 rt_err_t (*configure)(struct rt_serial_device *serial, struct serial_configure *cfg);
280 rt_err_t (*control)(struct rt_serial_device *serial, int cmd, void *arg);
281
282 int (*putc)(struct rt_serial_device *serial, char c);
283 int (*getc)(struct rt_serial_device *serial);
284
285 rt_ssize_t (*dma_transmit)(struct rt_serial_device *serial, rt_uint8_t *buf, rt_size_t size, int direction);
286};
287
294void rt_hw_serial_isr(struct rt_serial_device *serial, int event);
295
309 const char *name,
310 rt_uint32_t flag,
311 void *data);
312
322
324
325#endif
struct rt_device * rt_device_t
#define RT_OBJECT_HOOKLIST_DECLARE(handler_type, name)
rt_err_t rt_hw_serial_register(struct rt_serial_device *serial, const char *name, rt_uint32_t flag, void *data)
Register a serial device to device list
void(* rt_hw_serial_rxind_hookproto_t)(rt_device_t dev, rt_size_t size)
Sets a hook function when RX indicate is called
rt_err_t rt_hw_serial_register_tty(struct rt_serial_device *serial)
register a serial device to system device list and add a device object to system object list
struct rt_serial_device rt_serial_t
void rt_hw_serial_isr(struct rt_serial_device *serial, int event)
Serial interrupt service routine
rt_base_t rt_ssize_t
int rt_bool_t
rt_base_t rt_err_t
unsigned char rt_uint8_t
unsigned short rt_uint16_t
rt_ubase_t rt_size_t
unsigned int rt_uint32_t
serial device structure
struct rt_device parent
const struct rt_uart_ops * ops
struct rt_device_notify rx_notify
struct rt_spinlock spinlock
struct serial_configure config
Serial Receive FIFO mode
struct rt_data_queue data_queue
Serial Transmit FIFO mode
struct rt_completion completion
Configure the serial device
rt_err_t(* configure)(struct rt_serial_device *serial, struct serial_configure *cfg)
rt_err_t(* control)(struct rt_serial_device *serial, int cmd, void *arg)
rt_ssize_t(* dma_transmit)(struct rt_serial_device *serial, rt_uint8_t *buf, rt_size_t size, int direction)
int(* getc)(struct rt_serial_device *serial)
int(* putc)(struct rt_serial_device *serial, char c)
rt_uint32_t flowcontrol