Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9086bf3efb | |||
| 3bf5a8cc19 | |||
| b9c371ed58 | |||
| 9d96b3d4f2 |
+5
-8
@@ -49,19 +49,11 @@ void CAN_Logger_Init(CAN_HandleTypeDef *hcan1, CAN_HandleTypeDef *hcan2)
|
|||||||
filter.FilterActivation = ENABLE;
|
filter.FilterActivation = ENABLE;
|
||||||
filter.SlaveStartFilterBank = 14;
|
filter.SlaveStartFilterBank = 14;
|
||||||
|
|
||||||
HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 6, 0);
|
|
||||||
HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn);
|
|
||||||
|
|
||||||
HAL_NVIC_SetPriority(CAN2_RX0_IRQn, 6, 0);
|
|
||||||
HAL_NVIC_EnableIRQ(CAN2_RX0_IRQn);
|
|
||||||
|
|
||||||
filter.FilterBank = 0;
|
filter.FilterBank = 0;
|
||||||
if (HAL_CAN_ConfigFilter(hcan1, &filter) != HAL_OK) Error_Handler();
|
if (HAL_CAN_ConfigFilter(hcan1, &filter) != HAL_OK) Error_Handler();
|
||||||
if (HAL_CAN_Start(hcan1) != HAL_OK) Error_Handler();
|
|
||||||
|
|
||||||
filter.FilterBank = 14;
|
filter.FilterBank = 14;
|
||||||
if (HAL_CAN_ConfigFilter(hcan2, &filter) != HAL_OK) Error_Handler();
|
if (HAL_CAN_ConfigFilter(hcan2, &filter) != HAL_OK) Error_Handler();
|
||||||
if (HAL_CAN_Start(hcan2) != HAL_OK) Error_Handler();
|
|
||||||
}
|
}
|
||||||
/* END CAN_Logger_Init */
|
/* END CAN_Logger_Init */
|
||||||
|
|
||||||
@@ -120,8 +112,13 @@ void vCANListener(void *argument)
|
|||||||
osMessageQueueId_t queue = (hcan->Instance == CAN1) ? xCAN1RxQueue : xCAN2RxQueue;
|
osMessageQueueId_t queue = (hcan->Instance == CAN1) ? xCAN1RxQueue : xCAN2RxQueue;
|
||||||
CanMessage_t message;
|
CanMessage_t message;
|
||||||
|
|
||||||
|
if (HAL_CAN_Start(hcan) != HAL_OK) Error_Handler();
|
||||||
HAL_CAN_ActivateNotification(hcan, CAN_IT_RX_FIFO0_MSG_PENDING);
|
HAL_CAN_ActivateNotification(hcan, CAN_IT_RX_FIFO0_MSG_PENDING);
|
||||||
|
|
||||||
|
uint32_t irqn = (hcan->Instance == CAN1) ? CAN1_RX0_IRQn : CAN2_RX0_IRQn;
|
||||||
|
HAL_NVIC_SetPriority(irqn, 6, 0);
|
||||||
|
HAL_NVIC_EnableIRQ(irqn);
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
if (osMessageQueueGet(queue, &message, NULL, osWaitForever) == osOK)
|
if (osMessageQueueGet(queue, &message, NULL, osWaitForever) == osOK)
|
||||||
|
|||||||
+17
-13
@@ -101,23 +101,27 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
|||||||
*/
|
*/
|
||||||
void vUARTLogger(void *argument)
|
void vUARTLogger(void *argument)
|
||||||
{
|
{
|
||||||
CanMessage_t message;
|
CanMessage_t message;
|
||||||
char tx_buffer[45];
|
char tx_buffer[45];
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
|
{
|
||||||
|
DEBUG_PRINT("Waiting for CAN traffic...\r\n");
|
||||||
|
if (osMessageQueueGet(xUARTQueue, &message, NULL, osWaitForever) == osOK)
|
||||||
{
|
{
|
||||||
DEBUG_PRINT("Waiting for CAN traffic...\r\n");
|
osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever);
|
||||||
if (osMessageQueueGet(xUARTQueue, &message, NULL, osWaitForever) == osOK)
|
int len = format_can_message(tx_buffer, message.source, &message);
|
||||||
|
|
||||||
|
if (HAL_UART_Transmit_DMA(&huart1, (uint8_t*)tx_buffer, len) == HAL_OK)
|
||||||
{
|
{
|
||||||
DEBUG_PRINT("CAN frame detected\r\n");
|
DEBUG_PRINT("CAN frame sent via UART\r\n");
|
||||||
int len = format_can_message(tx_buffer, message.source, &message);
|
}
|
||||||
if (HAL_UART_Transmit_DMA(&huart1, (uint8_t*)tx_buffer, len) == HAL_OK)
|
else
|
||||||
{
|
{
|
||||||
osSemaphoreAcquire(xUARTDMASemaphore, osWaitForever);
|
osSemaphoreRelease(xUARTDMASemaphore);
|
||||||
DEBUG_PRINT("CAN frame sent via UART\r\n");
|
DEBUG_PRINT("HAL error, CAN frame NOT sent!\r\n");
|
||||||
}
|
|
||||||
else DEBUG_PRINT("HAL error, CAN frame NOT sent!\r\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* END vUARTLoggerListen */
|
/* END vUARTLoggerListen */
|
||||||
|
|||||||
+1
-1
@@ -176,7 +176,7 @@ int main(void)
|
|||||||
/* USER CODE END RTOS_MUTEX */
|
/* USER CODE END RTOS_MUTEX */
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||||
xUARTDMASemaphore = osSemaphoreNew(1, 0, NULL);
|
xUARTDMASemaphore = osSemaphoreNew(1, 1, NULL);
|
||||||
if (xUARTDMASemaphore == NULL) Error_Handler();
|
if (xUARTDMASemaphore == NULL) Error_Handler();
|
||||||
/* USER CODE END RTOS_SEMAPHORES */
|
/* USER CODE END RTOS_SEMAPHORES */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user