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.
131 lines
3.1 KiB
131 lines
3.1 KiB
/* |
|
* @Author: your name |
|
* @Date: 2021-06-01 17:04:59 |
|
* @LastEditTime: 2021-08-10 17:28:33 |
|
* @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; |
|
|
|
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) |
|
{ |
|
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 = osMessageQueuePut(uavcan_rev_queueHandle, &can_rev, 0U, 0U); |
|
// if(status==osOK) |
|
// { |
|
// } |
|
} |
|
} |
|
} |
|
|
|
//-----------usart funtion------- |
|
|
|
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 = 1; |
|
|
|
if (Size > BUFFER_SIZE) |
|
{ |
|
Size = BUFFER_SIZE; |
|
} |
|
memcpy(&msg.data, &hart1_rev_buff[0], msg.len); |
|
|
|
if (usart_rev_queueHandle != NULL && msg.len > 0) |
|
{ |
|
osMessageQueuePut(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 = 2; |
|
|
|
if (Size > BUFFER_SIZE) |
|
{ |
|
Size = BUFFER_SIZE; |
|
} |
|
memcpy(&msg.data, &hart2_rev_buff[0], msg.len); |
|
|
|
if (usart_rev_queueHandle != NULL && msg.len > 0) |
|
{ |
|
osMessageQueuePut(usart_rev_queueHandle, &msg, NULL, 0U); |
|
} |
|
|
|
memset(&hart2_rev_buff[0], 0, sizeof(hart2_rev_buff)); |
|
|
|
active_uasrt_irq(2); |
|
} |
|
} |
|
|
|
//-------------------------------------------- |
|
|
|
|