You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
122 lines
3.7 KiB
122 lines
3.7 KiB
|
3 weeks ago
|
/*
|
||
|
|
* bsp_UART.h
|
||
|
|
*
|
||
|
|
* Created on: Oct 26, 2023
|
||
|
|
* Author: shiya
|
||
|
|
*/
|
||
|
|
|
||
|
|
#ifndef INC_BSP_UART_H_
|
||
|
|
#define INC_BSP_UART_H_
|
||
|
|
#include "bsp_hardware_hash_table.h"
|
||
|
|
#include "BSP/bsp_include.h"
|
||
|
|
#include <stdlib.h>
|
||
|
|
#include "bsp_com_helper.h"
|
||
|
|
|
||
|
|
#define UART_Transmit_MAX_NUM 1024
|
||
|
|
#define UART_Receive_MAX_NUM 100
|
||
|
|
|
||
|
|
|
||
|
|
extern struct UARTHandler RS_485_1_UART_Handler;
|
||
|
|
extern struct UARTHandler RS_485_2_UART_Handler;
|
||
|
|
extern struct UARTHandler RS_485_3_UART_Handler;
|
||
|
|
extern struct UARTHandler RS_485_4_UART_Handler;
|
||
|
|
extern struct UARTHandler InterCall_DEBUG_UART_Handler;
|
||
|
|
extern struct UARTHandler E28_SBUS_UART_Handler;
|
||
|
|
extern struct UARTHandler E22_Serial_UART_Handler;
|
||
|
|
|
||
|
|
void GF_BSP_UARTHandlers_Intialize();
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
uint8_t GF_BSP_UART_Init(void);
|
||
|
|
|
||
|
|
//串行发送完成后才能发送第二帧数据,没有做缓冲,如未发送完成,第二次发送无效,丢弃发送数据
|
||
|
|
void GF_BSP_UART_Transmit(const uint8_t RS485_Index,const uint8_t *pData, uint16_t Size);
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
typedef struct _UARTSendHandler
|
||
|
|
{
|
||
|
|
uint16_t TxCount;
|
||
|
|
uint8_t Tx_Buf[512];
|
||
|
|
void (*UART_Decode)(uint8_t*, uint16_t); // 发送缓存
|
||
|
|
struct _UARTSendHandler* pNext;
|
||
|
|
}UARTSendHandler;
|
||
|
|
|
||
|
|
|
||
|
|
struct UARTHandler
|
||
|
|
{
|
||
|
|
char startCountFlag; //indicate that to start counting
|
||
|
|
char send_finished;//indicate decode finished or not
|
||
|
|
char decode_finished;//indicate decode finished or not
|
||
|
|
uint8_t tmp_Rx_Buf[2]; // temporary data to store received data
|
||
|
|
uint32_t Wait_time; // the time to wait
|
||
|
|
uint32_t Send_time;
|
||
|
|
//uint32_t count;
|
||
|
|
uint32_t Wait_Time_Count;
|
||
|
|
uint32_t Send_Time_Count;
|
||
|
|
|
||
|
|
UART_HandleTypeDef* uart; //UART to use
|
||
|
|
unsigned char timeSpan; // timer elapsed time
|
||
|
|
uint8_t Rx_Buf[2048]; // 接收缓存,最大256字节
|
||
|
|
uint8_t Tx_Buf[2048]; //发送缓存 157,864
|
||
|
|
uint16_t TxCount;
|
||
|
|
uint16_t RxCount;
|
||
|
|
|
||
|
|
|
||
|
|
void (*UART_Tx)(struct UARTHandler*); //void UART_Tx(uint8_t *Tx_Buf,uint16_t TxCount);
|
||
|
|
void (*UART_Rx)(struct UARTHandler*);
|
||
|
|
void (*UART_Decode)(uint8_t*, uint16_t); //Decode Rx_Buf
|
||
|
|
|
||
|
|
UARTSendHandler *pCurrentUARTSendHadler; //
|
||
|
|
void (*AddSendList)(struct UARTHandler*, uint8_t*, uint16_t, void (*UART_Decode)(uint8_t*, uint16_t));
|
||
|
|
int16_t UARTSendHadlerListNum;
|
||
|
|
|
||
|
|
//got a dispacher alone
|
||
|
|
// Dispatcher *pHead;// = NULL; //环形链表中的数据头指针
|
||
|
|
// Dispatcher *pTail;// = NULL; //环形链表中的数据尾指针
|
||
|
|
// uint16_t DispacherNumber;// = 0;
|
||
|
|
// uint16_t DispacherCallTimeCount; //= 100; //2ms 一次,
|
||
|
|
// uint16_t counter;// = 0;
|
||
|
|
// uint16_t Dispacher_Enable;// = 0;
|
||
|
|
// void(*Add_Dispatcher_List)(struct UARTHandler *uartHandler,void (*dispache)(void));//UART的调度程序
|
||
|
|
// void(*Dispatcher_Run)(struct UARTHandler *uartHandler);//UART的调度程序
|
||
|
|
|
||
|
|
|
||
|
|
DispacherController* dispacherController;
|
||
|
|
HardWareController* uartHardWareController;
|
||
|
|
|
||
|
|
// uint16_t HardWare_Check_Counter;
|
||
|
|
// ComHardWare *pComHWHead;
|
||
|
|
// ComHardWare *pComHWTail;
|
||
|
|
// void(*Add_PCOMHardWare)(struct UARTHandler*,char *,char);
|
||
|
|
// void(*PCOMHardWare_Check)(struct UARTHandler*);
|
||
|
|
// int (*Set_PCOMHardWare)(struct UARTHandler * ,char* ,char );
|
||
|
|
};
|
||
|
|
|
||
|
|
typedef struct _UARTHandlerHelper
|
||
|
|
{
|
||
|
|
struct UARTHandler *UART_Handler;
|
||
|
|
DispacherController* disp;
|
||
|
|
HardWareController* hardWares;
|
||
|
|
|
||
|
|
}UARTHandlerHelper;
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
void UARTHandlerTx(struct UARTHandler *uartHandler);
|
||
|
|
void UARTHandlerRX(struct UARTHandler *uartHandler);
|
||
|
|
//void IntializeUARTHandler(struct UARTHandler *uartHandler, UART_HandleTypeDef uart,int32_t WaitTime,unsigned char timeSpan);
|
||
|
|
void Counting(struct UARTHandler *uartHandler);
|
||
|
|
void IntializeUARTHandler(struct UARTHandler *uartHandler,
|
||
|
|
UART_HandleTypeDef* uart, int32_t WaitTime, unsigned char timeSpan);
|
||
|
|
void GF_BSP_UART_Timer();
|
||
|
|
|
||
|
|
extern void uartHandler_intialize(UARTHandlerHelper* helper ,struct UARTHandler *Handler,int WaitTime);
|
||
|
|
|
||
|
|
|
||
|
|
#endif /* INC_BSP_UART_H_ */
|