|
|
|
/*
|
|
|
|
* @Author: your name
|
|
|
|
* @Date: 2021-06-01 17:04:59
|
|
|
|
* @LastEditTime: 2021-09-08 10:54:12
|
|
|
|
* @LastEditors: Please set LastEditors
|
|
|
|
* @Description: In User Settings Edit
|
|
|
|
* @FilePath: \flow-radar-convertor\BSP\bsp_common.c
|
|
|
|
*/
|
|
|
|
#include "bsp_common.h"
|
|
|
|
#include "stdarg.h"
|
|
|
|
|
|
|
|
uint8_t hart1_rev_buff[BUFFER_SIZE];
|
|
|
|
uint8_t hart2_rev_buff[BUFFER_SIZE];
|
|
|
|
uint32_t last_usart1_rev_tick = 0;
|
|
|
|
extern DMA_HandleTypeDef hdma_usart1_rx;
|
|
|
|
extern DMA_HandleTypeDef hdma_usart1_tx;
|
|
|
|
|
|
|
|
uint32_t usart_rev_tick;
|
|
|
|
|
|
|
|
|
|
|
|
void avtion_do_can_back(CAN_HandleTypeDef *hcan);
|
|
|
|
|
|
|
|
void open_timer(TIM_HandleTypeDef *htim)
|
|
|
|
{
|
|
|
|
if (htim == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
__HAL_TIM_SetCounter(htim, 0);
|
|
|
|
__HAL_TIM_CLEAR_FLAG(htim, TIM_SR_UIF);
|
|
|
|
HAL_TIM_Base_Start_IT(htim);
|
|
|
|
}
|
|
|
|
|
|
|
|
void close_timer(TIM_HandleTypeDef *htim)
|
|
|
|
{
|
|
|
|
if (htim == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
HAL_TIM_Base_Stop_IT(htim);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
|
|
|
{
|
|
|
|
avtion_do_can_back(hcan);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
|
|
|
{
|
|
|
|
avtion_do_can_back(hcan);
|
|
|
|
}
|
|
|
|
|
|
|
|
void avtion_do_can_back(CAN_HandleTypeDef *hcan)
|
|
|
|
{
|
|
|
|
uavcan_rev_t can_rev = {0};
|
|
|
|
can_rev.tick_ms = HAL_GetTick();
|
|
|
|
if (canardSTM32Receive(&can_rev.canard_CAN_frame) > 0)
|
|
|
|
{
|
|
|
|
if (uavcan_rev_queueHandle != NULL)
|
|
|
|
{
|
|
|
|
osStatus status = myOsMessageQueuePut(uavcan_rev_queueHandle, &can_rev, 0U, 0U);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void active_uasrt_irq(uint8_t instance)
|
|
|
|
{
|
|
|
|
switch (instance)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
HAL_UARTEx_ReceiveToIdle_DMA(&huart1, (uint8_t *)hart1_rev_buff, BUFFER_SIZE);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
HAL_UARTEx_ReceiveToIdle_DMA(&huart2, (uint8_t *)hart2_rev_buff, BUFFER_SIZE);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
|
|
|
|
{
|
|
|
|
if (huart->Instance == USART1)
|
|
|
|
{
|
|
|
|
HAL_UARTEx_ReceiveToIdle_DMA(&huart1, (uint8_t *)hart1_rev_buff, BUFFER_SIZE);
|
|
|
|
}
|
|
|
|
else if (huart->Instance == USART2)
|
|
|
|
{
|
|
|
|
HAL_UARTEx_ReceiveToIdle_DMA(&huart2, (uint8_t *)hart2_rev_buff, BUFFER_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
|
|
|
|
{
|
|
|
|
// uint8_t data_length = BUFFER_SIZE - __HAL_DMA_GET_COUNTER(&hdma_usart1_rx);
|
|
|
|
if (huart->Instance == USART1)
|
|
|
|
{
|
|
|
|
usart_data_t msg = {0};
|
|
|
|
|
|
|
|
msg.len = Size;
|
|
|
|
msg.usart_instance = USART_INSTANCE_U1;
|
|
|
|
|
|
|
|
if (Size > BUFFER_SIZE)
|
|
|
|
{
|
|
|
|
Size = BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
memcpy(&msg.data, &hart1_rev_buff[0], msg.len);
|
|
|
|
|
|
|
|
if (usart_rev_queueHandle != NULL && msg.len > 0)
|
|
|
|
{
|
|
|
|
myOsMessageQueuePut(usart_rev_queueHandle, &msg, NULL, 0U);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&hart1_rev_buff[0], 0, sizeof(hart1_rev_buff));
|
|
|
|
|
|
|
|
active_uasrt_irq(1);
|
|
|
|
}
|
|
|
|
else if (huart->Instance == USART2)
|
|
|
|
{
|
|
|
|
usart_data_t msg = {0};
|
|
|
|
|
|
|
|
msg.len = Size;
|
|
|
|
msg.usart_instance = USART_INSTANCE_U2;
|
|
|
|
|
|
|
|
if (Size > BUFFER_SIZE)
|
|
|
|
{
|
|
|
|
Size = BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
memcpy(&msg.data, &hart2_rev_buff[0], msg.len);
|
|
|
|
|
|
|
|
if (usart_rev_queueHandle != NULL && msg.len > 0)
|
|
|
|
{
|
|
|
|
myOsMessageQueuePut(usart_rev_queueHandle, &msg, NULL, 0U);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&hart2_rev_buff[0], 0, sizeof(hart2_rev_buff));
|
|
|
|
|
|
|
|
active_uasrt_irq(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------
|
|
|
|
|