-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dylan Donahue
committed
Dec 16, 2023
1 parent
20f0843
commit 1576590
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef CAN_HANDLER_H | ||
#define CAN_HANDLER_H | ||
|
||
#include "stm32f4xx_hal.h" | ||
|
||
can_t can1; | ||
can_t can2; | ||
|
||
/* Shepherd hanbdles both can busses the same way */ | ||
void can_receive_callback(CAN_HandleTypeDef *hcan); | ||
|
||
void get_can_msg(); | ||
|
||
#endif // CAN_HANDLER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "can_handler.h" | ||
#include "can.h" | ||
#include "ringbuffer.h" | ||
|
||
#define NUM_INBOUND_CAN1_IDS 1 | ||
#define NUM_INBOUND_CAN2_IDS 1 | ||
|
||
ringbuffer_t can_receive_queue; | ||
|
||
|
||
|
||
static const uint16_t i can1_id_list[NUM_INBOUND_CAN1_IDS] = { | ||
//CANID_X, | ||
NULL | ||
}; | ||
|
||
static const uint16_t i can2_id_list[NUM_INBOUND_CAN2_IDS] = { | ||
//CANID_X, | ||
NULL | ||
}; | ||
|
||
void can_receive_callback(CAN_HandleTypeDef *hcan) | ||
{ | ||
CAN_RxHeaderTypeDef rx_header; | ||
can_msg_t new_msg; | ||
/* Read in CAN message */ | ||
if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &rx_header, new_msg.data) != HAL_OK) { | ||
|
||
// TODO add non crtical fault capability - could create one for failed can receieve | ||
return; | ||
} | ||
|
||
new_msg.len = rx_header.DLC; | ||
new_msg.id = rx_header.StdId; | ||
|
||
enqueue(can_receive_queue, new_msg.data); | ||
} | ||
|