|
|
|
|
/******************************************************************************
|
|
|
|
|
|
|
|
|
|
版权所有 (C), 2018-2099, Radkil
|
|
|
|
|
|
|
|
|
|
******************************************************************************
|
|
|
|
|
文 件 名 : drv_interface.c
|
|
|
|
|
版 本 号 : 初稿
|
|
|
|
|
作 者 : radkil
|
|
|
|
|
生成日期 : 2026年5月27日
|
|
|
|
|
最近修改 :
|
|
|
|
|
功能描述 : 对外接口层
|
|
|
|
|
|
|
|
|
|
修改历史 :
|
|
|
|
|
1.日 期 : 2026年5月27日
|
|
|
|
|
作 者 : radkil
|
|
|
|
|
修改内容 : 创建文件
|
|
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
#include "BHBF.h"
|
|
|
|
|
|
|
|
|
|
#include "cmsis_os.h"
|
|
|
|
|
#include "FreeRTOS.h"
|
|
|
|
|
#include "bsp_EEPROM.h"
|
|
|
|
|
#include "msg_center.h"
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
|
* 外部变量说明 *
|
|
|
|
|
*----------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
|
* 外部函数原型说明 *
|
|
|
|
|
*----------------------------------------------*/
|
|
|
|
|
extern TComCtrl *g_ptUartCtrl;
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
|
* 内部函数原型说明 *
|
|
|
|
|
*----------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
|
* 全局变量 *
|
|
|
|
|
*----------------------------------------------*/
|
|
|
|
|
TComCtrl *g_apstUart[COM_MAX] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
|
|
|
|
|
|
|
|
|
|
TComCtrl *g_ptCAN1 = NULL;
|
|
|
|
|
TComCtrl *g_ptCAN2 = NULL;
|
|
|
|
|
|
|
|
|
|
CV_struct_define g_stCV = {0};
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
|
* 模块级变量 *
|
|
|
|
|
*----------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
|
* 常量定义 *
|
|
|
|
|
*----------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/*----------------------------------------------*
|
|
|
|
|
* 宏定义 *
|
|
|
|
|
*----------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
int RS485_1_Send(char *_pBuffer, uint32_t _iSize)
|
|
|
|
|
{
|
|
|
|
|
HAL_GPIO_WritePin(RS485_1_DIR_GPIO_Port, RS485_1_DIR_Pin, GPIO_PIN_SET);
|
|
|
|
|
TUartUserData *ptUartUserData = (TUartUserData *)g_apstUart[COM_RS485_1]->m_pUserData;
|
|
|
|
|
int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100);
|
|
|
|
|
HAL_GPIO_WritePin(RS485_1_DIR_GPIO_Port, RS485_1_DIR_Pin, GPIO_PIN_RESET);
|
|
|
|
|
return iRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int LTE_7S0_Send(char *_pBuffer, uint32_t _iSize)
|
|
|
|
|
{
|
|
|
|
|
TUartUserData *ptUartUserData = (TUartUserData *)g_apstUart[COM_LTE_7S0]->m_pUserData;
|
|
|
|
|
int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100);
|
|
|
|
|
return iRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int RS485_2_Send(char *_pBuffer, uint32_t _iSize)
|
|
|
|
|
{
|
|
|
|
|
HAL_GPIO_WritePin(RS485_2_DIR_GPIO_Port, RS485_2_DIR_Pin, GPIO_PIN_SET);
|
|
|
|
|
TUartUserData *ptUartUserData = (TUartUserData *)g_apstUart[COM_RS485_2]->m_pUserData;
|
|
|
|
|
int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100);
|
|
|
|
|
HAL_GPIO_WritePin(RS485_2_DIR_GPIO_Port, RS485_2_DIR_Pin, GPIO_PIN_RESET);
|
|
|
|
|
return iRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int InterCall_Send(char *_pBuffer, uint32_t _iSize)
|
|
|
|
|
{
|
|
|
|
|
TUartUserData *ptUartUserData = (TUartUserData *)g_apstUart[COM_INTERCALL]->m_pUserData;
|
|
|
|
|
int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100);
|
|
|
|
|
return iRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int E28_SBUS_Send(char *_pBuffer, uint32_t _iSize)
|
|
|
|
|
{
|
|
|
|
|
TUartUserData *ptUartUserData = (TUartUserData *)g_apstUart[COM_SBUS]->m_pUserData;
|
|
|
|
|
int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100);
|
|
|
|
|
return iRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int RS485_3_Send(char *_pBuffer, uint32_t _iSize)
|
|
|
|
|
{
|
|
|
|
|
HAL_GPIO_WritePin(RS485_3_DIR_GPIO_Port, RS485_3_DIR_Pin, GPIO_PIN_SET);
|
|
|
|
|
TUartUserData *ptUartUserData = (TUartUserData *)g_apstUart[COM_RS485_3]->m_pUserData;
|
|
|
|
|
int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100);
|
|
|
|
|
HAL_GPIO_WritePin(RS485_3_DIR_GPIO_Port, RS485_3_DIR_Pin, GPIO_PIN_RESET);
|
|
|
|
|
return iRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int RS485_4_Send(char *_pBuffer, uint32_t _iSize)
|
|
|
|
|
{
|
|
|
|
|
HAL_GPIO_WritePin(RS485_4_DIR_GPIO_Port, RS485_4_DIR_Pin, GPIO_PIN_SET);
|
|
|
|
|
TUartUserData *ptUartUserData = (TUartUserData *)g_apstUart[COM_RS485_4]->m_pUserData;
|
|
|
|
|
int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100);
|
|
|
|
|
HAL_GPIO_WritePin(RS485_4_DIR_GPIO_Port, RS485_4_DIR_Pin, GPIO_PIN_RESET);
|
|
|
|
|
return iRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int LPUART_Send(char *_pBuffer, uint32_t _iSize)
|
|
|
|
|
{
|
|
|
|
|
TUartUserData *ptUartUserData = (TUartUserData *)g_apstUart[COM_LPUART]->m_pUserData;
|
|
|
|
|
int iRet = HAL_UART_Transmit(ptUartUserData->m_uart, (uint8_t *)_pBuffer, _iSize, 100);
|
|
|
|
|
return iRet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FDCAN1_Send(char *_pBuffer, uint32_t _iSize)
|
|
|
|
|
{
|
|
|
|
|
return CAN_TX_FIFOQ(g_ptCAN1, _pBuffer, _iSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FDCAN2_Send(char *_pBuffer, uint32_t _iSize)
|
|
|
|
|
{
|
|
|
|
|
return CAN_TX_FIFOQ(g_ptCAN2, _pBuffer, _iSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef CONFIG_UART_IT_IDLEDMA
|
|
|
|
|
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
|
|
|
|
|
{
|
|
|
|
|
if (huart->Instance == USART1)
|
|
|
|
|
{
|
|
|
|
|
UART_RX_IRQHandler(g_apstUart[COM_RS485_1]);
|
|
|
|
|
}
|
|
|
|
|
else if (huart->Instance == USART2)
|
|
|
|
|
{
|
|
|
|
|
UART_RX_IRQHandler(g_apstUart[COM_LTE_7S0]);
|
|
|
|
|
}
|
|
|
|
|
else if (huart->Instance == USART3)
|
|
|
|
|
{
|
|
|
|
|
#ifdef USE_PRINT
|
|
|
|
|
UART_RX_IRQHandler(g_ptUartCtrl);
|
|
|
|
|
#else
|
|
|
|
|
#ifdef USE_LUA_ST_UART
|
|
|
|
|
extern TComCtrl *g_ptCom1;
|
|
|
|
|
UART_RX_IRQHandler(g_ptCom1);
|
|
|
|
|
#else
|
|
|
|
|
UART_RX_IRQHandler(g_apstUart[COM_RS485_2]);
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else if (huart->Instance == UART4)
|
|
|
|
|
{
|
|
|
|
|
UART_RX_IRQHandler(g_apstUart[COM_INTERCALL]);
|
|
|
|
|
}
|
|
|
|
|
else if (huart->Instance == UART5)
|
|
|
|
|
{
|
|
|
|
|
UART_RX_IRQHandler(g_apstUart[COM_SBUS]);
|
|
|
|
|
}
|
|
|
|
|
else if (huart->Instance == USART6)
|
|
|
|
|
{
|
|
|
|
|
UART_RX_IRQHandler(g_apstUart[COM_RS485_3]);
|
|
|
|
|
}
|
|
|
|
|
else if (huart->Instance == UART7)
|
|
|
|
|
{
|
|
|
|
|
UART_RX_IRQHandler(g_apstUart[COM_RS485_4]);
|
|
|
|
|
}
|
|
|
|
|
else if (huart->Instance == LPUART1)
|
|
|
|
|
{
|
|
|
|
|
UART_RX_IRQHandler(g_apstUart[COM_LPUART]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
|
|
|
|
{
|
|
|
|
|
if (huart->Instance == USART1) //**RS485_1
|
|
|
|
|
{
|
|
|
|
|
HAL_GPIO_WritePin(RS485_1_DIR_GPIO_Port, RS485_1_DIR_Pin,
|
|
|
|
|
GPIO_PIN_RESET);
|
|
|
|
|
}
|
|
|
|
|
else if (huart->Instance == USART3) //**RS485_2
|
|
|
|
|
{
|
|
|
|
|
HAL_GPIO_WritePin(RS485_2_DIR_GPIO_Port, RS485_2_DIR_Pin,
|
|
|
|
|
GPIO_PIN_RESET);
|
|
|
|
|
}
|
|
|
|
|
else if (huart->Instance == USART6) //**RS485_3
|
|
|
|
|
{
|
|
|
|
|
HAL_GPIO_WritePin(RS485_3_DIR_GPIO_Port,
|
|
|
|
|
RS485_3_DIR_Pin, GPIO_PIN_RESET);
|
|
|
|
|
}
|
|
|
|
|
else if (huart->Instance == UART7) //**RS485_4
|
|
|
|
|
{
|
|
|
|
|
HAL_GPIO_WritePin(RS485_4_DIR_GPIO_Port,
|
|
|
|
|
RS485_4_DIR_Pin, GPIO_PIN_RESET);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HAL_FDCAN_ErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t ErrorStatusITs)
|
|
|
|
|
{
|
|
|
|
|
if (hfdcan->Instance == FDCAN1)
|
|
|
|
|
{
|
|
|
|
|
MX_FDCAN1_Init();
|
|
|
|
|
}
|
|
|
|
|
else if (hfdcan->Instance == FDCAN2)
|
|
|
|
|
{
|
|
|
|
|
MX_FDCAN2_Init();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
|
|
|
|
|
{
|
|
|
|
|
if (hfdcan->Instance == FDCAN1)
|
|
|
|
|
{
|
|
|
|
|
CAN_RX_IRQHandler(g_ptCAN1);
|
|
|
|
|
}
|
|
|
|
|
else if (hfdcan->Instance == FDCAN2)
|
|
|
|
|
{
|
|
|
|
|
CAN_RX_IRQHandler(g_ptCAN2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void lpuart_task(void *argument)
|
|
|
|
|
{
|
|
|
|
|
char pcBuffer[64] = {0};
|
|
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
rd_ComRead(g_apstUart[COM_LPUART], pcBuffer, 64);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CAN1_task(void *argument)
|
|
|
|
|
{
|
|
|
|
|
char pcBuffer[32] = {0};
|
|
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
rd_ComRead(g_ptCAN1, pcBuffer, 32);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Sbus_task(void *argument)
|
|
|
|
|
{
|
|
|
|
|
char pcBuffer[52] = {0};
|
|
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
rd_ComRead(g_apstUart[COM_SBUS], pcBuffer, 25);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void rs485_1_task(void *argument)
|
|
|
|
|
{
|
|
|
|
|
char pcBuffer[64] = {0};
|
|
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
|
{
|
|
|
|
|
rd_ComRead(g_apstUart[COM_RS485_1], pcBuffer, 64);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern void MotorTask(void *argument);
|
|
|
|
|
extern int check_PV(char *_pBuffer, uint32_t _iSize);
|
|
|
|
|
extern void decode_PV(const char *buf, uint32_t _iSize);
|
|
|
|
|
extern void ground_manger_init(void);
|
|
|
|
|
extern void Custom_Task(void *argument);
|
|
|
|
|
void client_setting_Init(void);
|
|
|
|
|
void TL720D_Init(void);
|
|
|
|
|
void RBcore_Init(void);
|
|
|
|
|
void controller_init(void);
|
|
|
|
|
void daemon_Init(void);
|
|
|
|
|
void Timer_Init(void);
|
|
|
|
|
|
|
|
|
|
void Drv_InterfaceInit(void)
|
|
|
|
|
{
|
|
|
|
|
GF_BSP_EEPROM_Init();
|
|
|
|
|
MsgCenter_Init();
|
|
|
|
|
GF_BSP_EEPROM_ReadBytes((uint8_t *)&g_stCV, GF_BSP_EEPROM_CV_struct_define_Start_Address, sizeof(CV_struct_define));
|
|
|
|
|
|
|
|
|
|
client_setting_Init();
|
|
|
|
|
// ground_manger_init();
|
|
|
|
|
|
|
|
|
|
const osThreadAttr_t Custom_attributes = {
|
|
|
|
|
.name = MODULE_NAME_CUSTOM,
|
|
|
|
|
.stack_size = THREAD_DEFAULT_STACK,
|
|
|
|
|
.priority = (osPriority_t) osPriorityRealtime1,
|
|
|
|
|
};
|
|
|
|
|
(void)osThreadNew(Custom_Task, NULL, &Custom_attributes);
|
|
|
|
|
|
|
|
|
|
// 创建电机任务
|
|
|
|
|
const osThreadAttr_t motor_task_attributes = {
|
|
|
|
|
.name = MODULE_NAME_MOTOR,
|
|
|
|
|
.stack_size = THREAD_DEFAULT_STACK,
|
|
|
|
|
.priority = (osPriority_t) osPriorityRealtime2,
|
|
|
|
|
};
|
|
|
|
|
(void)osThreadNew(MotorTask, NULL, &motor_task_attributes);
|
|
|
|
|
|
|
|
|
|
const osThreadAttr_t CAN1_task_attributes = {
|
|
|
|
|
.name = "CAN1_task",
|
|
|
|
|
.stack_size = THREAD_DEFAULT_STACK,
|
|
|
|
|
.priority = (osPriority_t) osPriorityRealtime1,
|
|
|
|
|
};
|
|
|
|
|
(void)osThreadNew(CAN1_task, NULL, &CAN1_task_attributes);
|
|
|
|
|
|
|
|
|
|
RBcore_Init();
|
|
|
|
|
|
|
|
|
|
controller_init();
|
|
|
|
|
|
|
|
|
|
const osThreadAttr_t Sbus_task_attributes = {
|
|
|
|
|
.name = "Sbus_task",
|
|
|
|
|
.stack_size = THREAD_DEFAULT_STACK,
|
|
|
|
|
.priority = (osPriority_t) osPriorityRealtime1,
|
|
|
|
|
};
|
|
|
|
|
(void)osThreadNew(Sbus_task, NULL, &Sbus_task_attributes);
|
|
|
|
|
|
|
|
|
|
const osThreadAttr_t lpuart_task_attributes = {
|
|
|
|
|
.name = "lpuart_task",
|
|
|
|
|
.stack_size = THREAD_DEFAULT_STACK,
|
|
|
|
|
.priority = (osPriority_t) osPriorityRealtime1,
|
|
|
|
|
};
|
|
|
|
|
(void)osThreadNew(lpuart_task, NULL, &lpuart_task_attributes);
|
|
|
|
|
|
|
|
|
|
TL720D_Init();
|
|
|
|
|
|
|
|
|
|
const osThreadAttr_t rs485_1_task_attributes = {
|
|
|
|
|
.name = "rs485_1_task",
|
|
|
|
|
.stack_size = THREAD_DEFAULT_STACK,
|
|
|
|
|
.priority = (osPriority_t) osPriorityRealtime1,
|
|
|
|
|
};
|
|
|
|
|
(void)osThreadNew(rs485_1_task, NULL, &rs485_1_task_attributes);
|
|
|
|
|
|
|
|
|
|
daemon_Init();
|
|
|
|
|
|
|
|
|
|
//Timer_Init();
|
|
|
|
|
log_i("BingooRobot Init success\nversion: %s", Rd_GetBuildTime());
|
|
|
|
|
}
|