Create CAN helper functions

Get / Set CAN filter ID
Get / Set CAN filter mask
Get latest valid CAN frame in `can_frame` struct
This commit is contained in:
Aadi Desai 2023-06-04 12:42:03 +01:00
parent a000c35f46
commit 6cf6d0a643
No known key found for this signature in database
3 changed files with 59 additions and 1 deletions

View file

@ -3,7 +3,7 @@ BUILD_DIR?=../build/
include $(BUILD_DIR)/software/include/generated/variables.mak
include $(SOC_DIRECTORY)/software/common.mak
OBJECTS = crt0.o donut.o led.o main.o note.o
OBJECTS = can.o crt0.o donut.o led.o main.o note.o
CFLAGS += -DWITH_CXX

23
demo/can Normal file
View file

@ -0,0 +1,23 @@
#include <generated/csr.h>
#include <stdint.h>
#pragma once
// Struct Definition
struct can_frame {
uint16_t id;
uint8_t data[8];
};
// Function Declarations
uint32_t can_id_read(void);
void can_id_write(uint32_t value);
uint32_t can_mask_read(void);
void can_mask_write(uint32_t value);
can_frame can_read(void);

35
demo/can.cpp Normal file
View file

@ -0,0 +1,35 @@
#include "can"
#include <generated/csr.h>
#include <stdint.h>
#ifdef CSR_CAN_BASE
uint32_t can_id_read(void) {
return can_can_id_read();
}
void can_id_write(uint32_t value) {
can_can_id_write(value);
}
uint32_t can_mask_read(void) {
return can_id_mask_read();
}
void can_mask_write(uint32_t value) {
can_id_mask_write(value);
}
can_frame can_read(void) {
can_frame frame;
frame.id = can_can_id_read();
frame.data[0] = can_rcv_data0_read();
frame.data[1] = can_rcv_data1_read();
frame.data[2] = can_rcv_data2_read();
frame.data[3] = can_rcv_data3_read();
frame.data[4] = can_rcv_data4_read();
frame.data[5] = can_rcv_data5_read();
frame.data[6] = can_rcv_data6_read();
frame.data[7] = can_rcv_data7_read();
return frame;
}
#endif