Skip to content

Commit

Permalink
fixed callback handling (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyldonahue authored Dec 14, 2023
1 parent edbb398 commit 7344ec0
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions platforms/stm32f405/src/can.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#include "can.h"

// function pointer type for the callback
typedef void (*CAN_Callback)(CAN_HandleTypeDef *hcan);
CAN_Callback myCANCallback;

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
// Handle CAN reception event
if (myCANCallback != NULL)
{
myCANCallback(hcan);
}
}
HAL_StatusTypeDef can_init(can_t *can)
{
/* set up filter */
Expand Down Expand Up @@ -36,17 +48,15 @@ HAL_StatusTypeDef can_init(can_t *can)
sFilterConfig.FilterActivation = ENABLE; // Enable the filter

uint8_t err = 0;
err = HAL_CAN_ConfigFilter(&hcan, &sFilterConfig) != HAL_OK);
err = HAL_CAN_ConfigFilter(&can->hcan, &sFilterConfig);
if (err != HAL_OK) return err;

/* set up interrupt & activate CAN */
err = HAL_CAN_Start(can->hcan);
if (err != HAL_OK) return err;

// Override the default callback for CAN_IT_RX_FIFO0_MSG_PENDING
err = HAL_CAN_RegisterCallback(can->hcan, HAL_CAN_RX_FIFO0_MSG_PENDING_CB_ID, can->can_callback);
if (err != HAL_OK) return err;

myCANCallback = can->can_callback;
err = HAL_CAN_ActivateNotification(can->hcan, CAN_IT_RX_FIFO0_MSG_PENDING);

return err;
Expand Down

0 comments on commit 7344ec0

Please sign in to comment.