83 lines
2.0 KiB
C
83 lines
2.0 KiB
C
|
|
/*
|
||
|
|
* uart.h
|
||
|
|
*
|
||
|
|
* Created on: May 14, 2025
|
||
|
|
* Author: cc
|
||
|
|
*/
|
||
|
|
|
||
|
|
#ifndef MCU_DRIVER_INC_UART_H_
|
||
|
|
#define MCU_DRIVER_INC_UART_H_
|
||
|
|
|
||
|
|
#include "ch564.h"
|
||
|
|
|
||
|
|
#define Recv_2400_TimeOut 10 //ms
|
||
|
|
#define Recv_9600_TimeOut 5 //ms
|
||
|
|
#define Recv_115200_TimeOut 3 //ms
|
||
|
|
|
||
|
|
#define USART_BUFFER_NUM 3
|
||
|
|
#define USART_BUFFER_SIZE 100
|
||
|
|
|
||
|
|
#define MCU485_EN1_H
|
||
|
|
#define MCU485_EN1_L
|
||
|
|
#define MCU485_EN2_H
|
||
|
|
#define MCU485_EN2_L
|
||
|
|
#define MCU485_EN3_H
|
||
|
|
#define MCU485_EN3_L
|
||
|
|
|
||
|
|
typedef uint8_t (*Uart_prt)(uint8_t *,uint16_t);
|
||
|
|
|
||
|
|
typedef enum
|
||
|
|
{
|
||
|
|
UART_0,
|
||
|
|
UART_1,
|
||
|
|
UART_2,
|
||
|
|
UART_3,
|
||
|
|
UART_MAX,
|
||
|
|
}UART_IDX;
|
||
|
|
|
||
|
|
typedef struct{
|
||
|
|
uint8_t RecvBuffer[USART_BUFFER_SIZE];
|
||
|
|
uint8_t Receiving;
|
||
|
|
uint16_t RecvLen;
|
||
|
|
|
||
|
|
uint32_t RecvTimeout;
|
||
|
|
uint32_t RecvIdleTiming;
|
||
|
|
|
||
|
|
uint32_t TX_Buffer_WriteAddr;
|
||
|
|
uint32_t TX_Buffer_ReadAddr;
|
||
|
|
uint32_t RX_Buffer_WriteAddr;
|
||
|
|
uint32_t RX_Buffer_ReadAddr;
|
||
|
|
}__attribute__((packed)) UART_t;
|
||
|
|
|
||
|
|
extern UART_t g_uart[UART_MAX];
|
||
|
|
|
||
|
|
void UARTx_Init(UART_IDX uart_id, uint32_t buad);
|
||
|
|
void Set_Uart_recvTimeout(UART_t *set_uart,uint32_t baud);
|
||
|
|
|
||
|
|
void UART0_RECEIVE(void);
|
||
|
|
void UART1_RECEIVE(void);
|
||
|
|
void UART2_RECEIVE(void);
|
||
|
|
void UART3_RECEIVE(void);
|
||
|
|
|
||
|
|
uint8_t UART0_ChangeBaud(uint32_t baudrate);
|
||
|
|
uint8_t UART1_ChangeBaud(uint32_t baudrate);
|
||
|
|
uint8_t UART2_ChangeBaud(uint32_t baudrate);
|
||
|
|
uint8_t UART3_ChangeBaud(uint32_t baudrate);
|
||
|
|
|
||
|
|
void Uart0_Flush(uint16_t over_time);
|
||
|
|
void Uart1_Flush(uint16_t over_time);
|
||
|
|
void Uart2_Flush(uint16_t over_time);
|
||
|
|
void Uart3_Flush(uint16_t over_time);
|
||
|
|
|
||
|
|
void Uart_SendString(uint8_t uart_id,uint8_t* buff,uint16_t len);
|
||
|
|
void MCU485_SendString_1(uint8_t *buf, uint16_t len);
|
||
|
|
void MCU485_SendString_2(uint8_t *buf, uint16_t len);
|
||
|
|
void MCU485_SendString_3(uint8_t *buf, uint16_t len);
|
||
|
|
void MCU485_SendString(uint8_t uart_id,uint8_t* buff,uint16_t len);
|
||
|
|
void MCU485_SendSRAMData(uint8_t uart_id,uint32_t data_addr,uint16_t len);
|
||
|
|
void Write_Uart_SendBuff(uint8_t uart_id,uint8_t uart_outime,uint8_t* buff,uint16_t len);
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
#endif /* MCU_DRIVER_INC_UART_H_ */
|