67 lines
2.0 KiB
C
67 lines
2.0 KiB
C
#ifndef FM_UART_DEV_H_
|
||
#define FM_UART_DEV_H_
|
||
|
||
#include "ch32v30x.h"
|
||
#include "HD_UART.h"
|
||
#include "comm_types.h"
|
||
#include "ring_queue.h"
|
||
|
||
/* 是否使用中断发送,后期可能改为DMA发送 */
|
||
#define UARTINTERRUPTSEND
|
||
|
||
#define ASCII_CHAR_BACKSPACE 0x08 /* '\b' */
|
||
#define ASCII_CHAR_CHARACTER_TABULATION 0x09 /* '\t' */
|
||
#define ASCII_CHAR_LINE_FEED 0x0A /* '\n' */
|
||
#define ASCII_CHAR_LINE_TABULATION 0x0B /* '\v' */
|
||
#define ASCII_CHAR_FORM_FEED 0x0C /* '\f' */
|
||
#define ASCII_CHAR_CARRIAGE_RETURN 0x0D /* '\r' */
|
||
|
||
typedef enum{
|
||
J1_485_INDEX = 6,
|
||
J2_485_INDEX = 7,
|
||
J3_485_INDEX = 2,
|
||
J4_485_INDEX = 8,
|
||
J5_0_485_INDEX = 3,
|
||
Upward_UART_INDEX = 5,
|
||
}uartIndex_e;
|
||
|
||
typedef struct _uartSendInfo {
|
||
uint8_t *data; //指向数据
|
||
#ifdef UARTINTERRUPTSEND
|
||
uint16_t count; //已经发送数据字节个数
|
||
uint16_t len; //数据长度
|
||
#endif
|
||
}uartSendInfo;
|
||
|
||
/* UART 驱动数据结构,对应一个uart设备 */
|
||
typedef struct _uart_device_info{
|
||
uint8_t init;
|
||
uartIndex_e uart_index;
|
||
uint32_t uart_baudrate;
|
||
RingQueue uart_ring_queue;
|
||
uartSendInfo uart_send_data;
|
||
}uart_device_info;
|
||
|
||
typedef uint32_t device_handle;
|
||
extern device_handle g_J1_uart6_handle;
|
||
extern device_handle g_J2_uart7_handle;
|
||
extern device_handle g_J3_usart2_handle;
|
||
extern device_handle g_J4_uart8_handle;
|
||
extern device_handle g_J5_0_usart3_handle;
|
||
extern device_handle g_Upward_uart5_handle;
|
||
|
||
uint8_t uart_dev_in_char(device_handle device);
|
||
int uart_dev_char_present(device_handle device);
|
||
void Init_J1_485(uint32_t baud);
|
||
void Init_J2_485(uint32_t baud);
|
||
void Init_J3_485(uint32_t baud);
|
||
void Init_J4_485(uint32_t baud);
|
||
void Init_J5_0_485(uint32_t baud);
|
||
void Init_Upward_uart(uint32_t baud);
|
||
|
||
#ifdef UARTINTERRUPTSEND
|
||
uint8_t uartInterruptSend(device_handle device, uint8_t *data, uint16_t len);
|
||
#endif
|
||
|
||
#endif
|