加ai
This commit is contained in:
parent
b5b1219f4a
commit
b8698147d5
@ -335,6 +335,7 @@ void USART1_IRQHandler(void)
|
||||
/* USER CODE END USART1_IRQn 0 */
|
||||
HAL_UART_IRQHandler(&huart1);
|
||||
/* USER CODE BEGIN USART1_IRQn 1 */
|
||||
BSP_UART_IRQHandler(&huart1);
|
||||
|
||||
/* USER CODE END USART1_IRQn 1 */
|
||||
}
|
||||
|
||||
@ -129,4 +129,8 @@ uart:
|
||||
devices:
|
||||
- instance: USART3
|
||||
name: DR16
|
||||
- instance: USART6
|
||||
name: AI
|
||||
- instance: USART1
|
||||
name: REF
|
||||
enabled: true
|
||||
|
||||
@ -25,6 +25,10 @@ static void (*UART_Callback[BSP_UART_NUM][BSP_UART_CB_NUM])(void);
|
||||
static BSP_UART_t UART_Get(UART_HandleTypeDef *huart) {
|
||||
if (huart->Instance == USART3)
|
||||
return BSP_UART_DR16;
|
||||
else if (huart->Instance == USART6)
|
||||
return BSP_UART_AI;
|
||||
else if (huart->Instance == USART1)
|
||||
return BSP_UART_REF;
|
||||
else
|
||||
return BSP_UART_ERR;
|
||||
}
|
||||
@ -115,6 +119,10 @@ UART_HandleTypeDef *BSP_UART_GetHandle(BSP_UART_t uart) {
|
||||
switch (uart) {
|
||||
case BSP_UART_DR16:
|
||||
return &huart3;
|
||||
case BSP_UART_AI:
|
||||
return &huart6;
|
||||
case BSP_UART_REF:
|
||||
return &huart1;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -28,6 +28,8 @@ extern "C" {
|
||||
/* UART实体枚举,与设备对应 */
|
||||
typedef enum {
|
||||
BSP_UART_DR16,
|
||||
BSP_UART_AI,
|
||||
BSP_UART_REF,
|
||||
BSP_UART_NUM,
|
||||
BSP_UART_ERR,
|
||||
} BSP_UART_t;
|
||||
|
||||
138
User/device/ai.c
138
User/device/ai.c
@ -1,91 +1,93 @@
|
||||
// /*
|
||||
// AI
|
||||
// */
|
||||
/*
|
||||
AI
|
||||
*/
|
||||
|
||||
// /* Includes ----------------------------------------------------------------- */
|
||||
// #include "ai.h"
|
||||
/* Includes ----------------------------------------------------------------- */
|
||||
#include "ai.h"
|
||||
|
||||
// #include <string.h>
|
||||
#include <string.h>
|
||||
|
||||
// #include "bsp/time.h"
|
||||
// #include "bsp/uart.h"
|
||||
// #include "component/crc16.h"
|
||||
// #include "component/crc8.h"
|
||||
// #include "component/user_math.h"
|
||||
// #include "component/filter.h"
|
||||
#include "bsp/time.h"
|
||||
#include "bsp/uart.h"
|
||||
#include "component/crc16.h"
|
||||
#include "component/crc8.h"
|
||||
#include "component/user_math.h"
|
||||
#include "component/filter.h"
|
||||
|
||||
|
||||
// /* Private define ----------------------------------------------------------- */
|
||||
// #define AI_LEN_RX_BUFF (sizeof(Protocol_DownPackage_t))
|
||||
/* Private define ----------------------------------------------------------- */
|
||||
#define AI_LEN_RX_BUFF (sizeof(AI_DownPackage_t))
|
||||
|
||||
// /* Private macro ------------------------------------------------------------ */
|
||||
// /* Private typedef ---------------------------------------------------------- */
|
||||
// /* Private variables -------------------------------------------------------- */
|
||||
// static volatile uint32_t drop_message = 0;
|
||||
/* Private macro ------------------------------------------------------------ */
|
||||
/* Private typedef ---------------------------------------------------------- */
|
||||
/* Private variables -------------------------------------------------------- */
|
||||
|
||||
// static uint8_t rxbuf[AI_LEN_RX_BUFF];
|
||||
static uint8_t rxbuf[AI_LEN_RX_BUFF];
|
||||
|
||||
// static bool inited = false;
|
||||
static bool inited = false;
|
||||
|
||||
// static osThreadId_t thread_alert;
|
||||
static osThreadId_t thread_alert;
|
||||
|
||||
// /* Private function -------------------------------------------------------- */
|
||||
static uint32_t drop_message = 0;
|
||||
|
||||
// static void Ai_RxCpltCallback(void) {
|
||||
// osThreadFlagsSet(thread_alert, SIGNAL_AI_RAW_REDY);
|
||||
// }
|
||||
/* Private function -------------------------------------------------------- */
|
||||
|
||||
// static void Ai_IdleLineCallback(void) {
|
||||
// osThreadFlagsSet(thread_alert, SIGNAL_AI_RAW_REDY);
|
||||
// }
|
||||
static void Ai_RxCpltCallback(void) {
|
||||
osThreadFlagsSet(thread_alert, SIGNAL_AI_RAW_REDY);
|
||||
}
|
||||
|
||||
// /* Exported functions ------------------------------------------------------- */
|
||||
// int8_t AI_Init(AI_t *ai) {
|
||||
// UNUSED(ai);
|
||||
// ASSERT(ai);
|
||||
// if (inited) return DEVICE_ERR_INITED;
|
||||
// VERIFY((thread_alert = osThreadGetId()) != NULL);
|
||||
static void Ai_IdleLineCallback(void) {
|
||||
osThreadFlagsSet(thread_alert, SIGNAL_AI_RAW_REDY);
|
||||
}
|
||||
|
||||
// BSP_UART_RegisterCallback(BSP_UART_AI, BSP_UART_RX_CPLT_CB,
|
||||
// Ai_RxCpltCallback);
|
||||
// BSP_UART_RegisterCallback(BSP_UART_AI, BSP_UART_IDLE_LINE_CB,
|
||||
// Ai_IdleLineCallback);
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
int8_t AI_Init(AI_t *ai) {
|
||||
UNUSED(ai);
|
||||
if (inited) return DEVICE_ERR_INITED;
|
||||
thread_alert = osThreadGetId();
|
||||
|
||||
BSP_UART_RegisterCallback(BSP_UART_AI, BSP_UART_RX_CPLT_CB,
|
||||
Ai_RxCpltCallback);
|
||||
BSP_UART_RegisterCallback(BSP_UART_AI, BSP_UART_IDLE_LINE_CB,
|
||||
Ai_IdleLineCallback);
|
||||
|
||||
// inited = true;
|
||||
// return 0;
|
||||
// }
|
||||
inited = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// int8_t AI_Restart(void) {
|
||||
// __HAL_UART_DISABLE(BSP_UART_GetHandle(BSP_UART_AI));
|
||||
// __HAL_UART_ENABLE(BSP_UART_GetHandle(BSP_UART_AI));
|
||||
// return DEVICE_OK;
|
||||
// }
|
||||
int8_t AI_Restart(AI_t *ai) {
|
||||
UNUSED(ai);
|
||||
__HAL_UART_DISABLE(BSP_UART_GetHandle(BSP_UART_AI));
|
||||
__HAL_UART_ENABLE(BSP_UART_GetHandle(BSP_UART_AI));
|
||||
return DEVICE_OK;
|
||||
}
|
||||
|
||||
// int8_t AI_StartReceiving(AI_t *ai) {
|
||||
// UNUSED(ai);
|
||||
// if (HAL_UART_Receive_DMA(BSP_UART_GetHandle(BSP_UART_AI), rxbuf,
|
||||
// AI_LEN_RX_BUFF) == HAL_OK)
|
||||
// return DEVICE_OK;
|
||||
// return DEVICE_ERR;
|
||||
// }
|
||||
int8_t AI_StartReceiving(AI_t *ai) {
|
||||
UNUSED(ai);
|
||||
if (HAL_UART_Receive_DMA(BSP_UART_GetHandle(BSP_UART_AI), rxbuf,
|
||||
AI_LEN_RX_BUFF) == HAL_OK)
|
||||
return DEVICE_OK;
|
||||
return DEVICE_ERR;
|
||||
}
|
||||
|
||||
// bool AI_WaitDmaCplt(void) {
|
||||
// return (osThreadFlagsWait(SIGNAL_AI_RAW_REDY, osFlagsWaitAll, 0) ==
|
||||
// SIGNAL_AI_RAW_REDY);
|
||||
// }
|
||||
bool AI_WaitDmaCplt(uint32_t timeout) {
|
||||
return (osThreadFlagsWait(SIGNAL_AI_RAW_REDY, osFlagsWaitAll, timeout) ==
|
||||
SIGNAL_AI_RAW_REDY);
|
||||
}
|
||||
|
||||
// int8_t AI_ParseHost(AI_t *ai) {
|
||||
// if (!CRC16_Verify((const uint8_t *)&(rxbuf), sizeof(ai->from_host)))
|
||||
// goto error;
|
||||
// ai->ai_online = true;
|
||||
// memcpy(&(ai->from_host), rxbuf, sizeof(ai->from_host));
|
||||
// memset(rxbuf, 0, AI_LEN_RX_BUFF);
|
||||
// return DEVICE_OK;
|
||||
int8_t AI_ParseHost(AI_t *ai) {
|
||||
if (!CRC16_Verify((const uint8_t *)&(rxbuf), sizeof(ai->from_host)))
|
||||
goto error;
|
||||
ai->header.online = true;
|
||||
ai->header.last_online_time = BSP_TIME_Get();
|
||||
memcpy(&(ai->from_host), rxbuf, sizeof(ai->from_host));
|
||||
memset(rxbuf, 0, AI_LEN_RX_BUFF);
|
||||
return DEVICE_OK;
|
||||
|
||||
// error:
|
||||
// drop_message++;
|
||||
// return DEVICE_ERR;
|
||||
// }
|
||||
error:
|
||||
drop_message++;
|
||||
return DEVICE_ERR;
|
||||
}
|
||||
|
||||
// void AI_PackCmd(AI_t *ai, CMD_Host_t *cmd_host) {
|
||||
// cmd_host->gimbal_delta.yaw = ai->from_host.data.gimbal.yaw;
|
||||
|
||||
@ -58,7 +58,7 @@ typedef struct __packed {
|
||||
/* 视觉 -> 电控 数据包 */
|
||||
typedef struct __packed {
|
||||
uint8_t id; /* 包ID */
|
||||
AI_Protucol_DownData_t package; /* 数据包 */
|
||||
AI_Protocol_DownData_t package; /* 数据包 */
|
||||
uint16_t crc16; /* CRC16校验 */
|
||||
} AI_DownPackage_t;
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ extern "C" {
|
||||
/* AUTO GENERATED SIGNALS END */
|
||||
|
||||
/* USER SIGNALS BEGIN */
|
||||
|
||||
#define SIGNAL_AI_RAW_REDY (1u << 5)
|
||||
/* USER SIGNALS END */
|
||||
/*设备层通用Header*/
|
||||
typedef struct {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user