Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed callback handling #44

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading