Skip to content

Commit

Permalink
prelimnary can handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Donahue committed Dec 16, 2023
1 parent 20f0843 commit 1576590
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Core/Inc/can_handler.h
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
38 changes: 38 additions & 0 deletions Core/Src/can_handler.c
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);
}

0 comments on commit 1576590

Please sign in to comment.