AP05/uart_utils/uart_utils.h

117 lines
4.3 KiB
C
Raw Normal View History

2025-04-06 06:41:47 +00:00
#ifndef _UART_INIT_H_
#define _UART_INIT_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <termios.h>
typedef struct {
int uart_fd; //串口设备文件描述符
int saved;
struct termios option_back; //串口属性结构体
}uart_utils_t;
extern int uart_open(uart_utils_t *uart, char *dev_name);
extern void uart_print_attr(struct termios *options);
/*************************************************************
*
*
speed240048009600115200
data_bits5678
stop_bits12
check'N''O''E'
flow_ctrl0OFF1ON
options
*
**************************************************************/
extern struct termios *uart_set_attr(
int speed,
int data_bits,
int stop_bits,
int check,
int flow_ctrl,
struct termios *options);
/*************************************************************
*
*
echo01
*
**************************************************************/
extern void uart_set_echo(uart_utils_t *uart, int echo);
/*************************************************************
*
*
block01
*
**************************************************************/
extern void uart_set_block(uart_utils_t *uart, int block);
/*************************************************************
*
*
speed240048009600115200
data_bits5678
stop_bits12
check'N''O''E'
flow_ctrl0OFF1ON
*
**************************************************************/
extern int uart_init(uart_utils_t *uart,
int speed,
int data_bits,
int stop_bits,
int check,
int flow_ctrl);
/*************************************************************
*
*
*
**************************************************************/
extern void uart_uninit(uart_utils_t *uart);
/*************************************************************
*
* uart_fd
str
*
**************************************************************/
extern void uart_send_str(int uart_fd, char *str);
/*************************************************************
*
* uart_fd
buffer
len
until
timeout_ms(ms)
*
-1
**************************************************************/
extern int uart_read_until_char(int uart_fd, char *buffer, int len, unsigned char until, int timeout_ms);
/*************************************************************
*
* uart_fd
buffer
len
timeout_ms(ms)
*
-1
**************************************************************/
extern int uart_read_until_time(int uart_fd, char *buffer, int len, int timeout_first, int timeout_interval);
#ifdef __cplusplus
}
#endif
#endif