新增:首次提交
首次提交,上传Launcher工程
This commit is contained in:
100
MCU_Driver/inc/uart.h
Normal file
100
MCU_Driver/inc/uart.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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 MCU485_EN1_H GPIOD_SetBits(GPIO_Pin_21)
|
||||
#define MCU485_EN1_L GPIOD_ResetBits(GPIO_Pin_21)
|
||||
#define MCU485_EN2_H GPIOB_SetBits(GPIO_Pin_15)
|
||||
#define MCU485_EN2_L GPIOB_ResetBits(GPIO_Pin_15)
|
||||
|
||||
#define UART_COMMBUSY_IDLE_Flag 0x00
|
||||
#define UART_COMMBUSY_RECV_Flag 0x01
|
||||
#define UART_COMMBUSY_SEND_Flag 0x02
|
||||
|
||||
#define Recv_2400_TimeOut 10 //ms
|
||||
#define Recv_9600_TimeOut 5 //ms
|
||||
#define Recv_115200_TimeOut 3 //ms
|
||||
#define Recv_512000_TimeOut 3 //ms
|
||||
|
||||
#define USART_BUFFER_SIZE 512
|
||||
|
||||
|
||||
typedef void (*Uart_prt)(uint8_t * ,uint16_t );
|
||||
typedef uint8_t (*Uart_set_prt)(uint32_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 deal_buff[USART_BUFFER_SIZE];
|
||||
uint8_t ackBuffer[USART_BUFFER_SIZE];
|
||||
uint8_t SendBuffer[USART_BUFFER_SIZE];
|
||||
|
||||
uint8_t SendCount; //<2F>ܷ<EFBFBD><DCB7>ʹ<EFBFBD><CDB4><EFBFBD>
|
||||
uint8_t SendCnt; //<2F><>ǰ<EFBFBD><C7B0><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD>
|
||||
uint8_t CommBusy; //ͨѶ<CDA8><D1B6>æ״̬
|
||||
|
||||
uint8_t Receiving;
|
||||
uint8_t sn;
|
||||
uint8_t pc_addr;
|
||||
uint8_t cmd;
|
||||
|
||||
uint8_t appFlag;
|
||||
uint8_t writeFlag;
|
||||
uint8_t ChangeBaudFlag; //<2F>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>־λ
|
||||
|
||||
uint16_t RecvLen;
|
||||
uint16_t deal_len;
|
||||
uint16_t ackLen;
|
||||
uint16_t SendLen; //<2F><><EFBFBD>ͳ<EFBFBD><CDB3><EFBFBD>
|
||||
|
||||
uint32_t CommBaud; //ͨѶ<CDA8><D1B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD> - <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱʹ<CAB1><CAB9>
|
||||
uint32_t ackValidity; //<2F><><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD>Ч<EFBFBD><D0A7>
|
||||
uint32_t SendValidDuration; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чʱ<D0A7><CAB1>
|
||||
uint32_t SendValidTick; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Чʱ<D0A7><CAB1><EFBFBD><EFBFBD>
|
||||
uint32_t SendInterval; //<2F><><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>
|
||||
uint32_t SendTick; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
|
||||
uint32_t RecvTimeout;
|
||||
uint32_t RecvIdleTiming;
|
||||
uint32_t SendIdleTick; //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
|
||||
|
||||
Uart_prt send_data_cf;
|
||||
Uart_set_prt set_baud_cf;
|
||||
}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_Task(void);
|
||||
|
||||
#endif /* MCU_DRIVER_INC_UART_H_ */
|
||||
Reference in New Issue
Block a user