Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ get_filename_component(ProjectId ${CMAKE_CURRENT_LIST_DIR} NAME)
string(REPLACE " " "_" ProjectId ${ProjectId})
project(${ProjectId})

target_link_libraries(${PROJECT_NAME}.elf PRIVATE "-T${CMAKE_CURRENT_SOURCE_DIR}/main/linker_libif.ld")

include(cmake/git_rev_parse.cmake)

git_describe(GIT_COMMIT_HASH ".")
Expand Down
3 changes: 3 additions & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(COMPONENT_PRIV_REQUIRES )
set(COMPONENT_SRCS
"main.c"
"buffer.c"
"conf_custom.c"
"comm_uart.c"
"comm_usb.c"
"comm_can.c"
Expand All @@ -24,6 +25,7 @@ set(COMPONENT_SRCS
"bms.c"
"log_comm.c"
"digital_filter.c"
"crypto.c"

"config/confsrc.c"
"hwconf/hw.c"
Expand Down Expand Up @@ -57,6 +59,7 @@ set(COMPONENT_SRCS
"lispBM/src/extensions/string_extensions.c"
"lispBM/src/extensions/display_extensions.c"
"lispBM/src/extensions/tjpgd.c"
"lispBM/src/extensions/vesc_c_if.c"
"lispBM/src/extensions/mutex_extensions.c"
"lispBM/src/extensions/lbm_dyn_lib.c"
"lispBM/src/extensions/ttf_extensions.c"
Expand Down
46 changes: 41 additions & 5 deletions main/comm_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ static volatile bool use_vesc_decoder = true;

static volatile int rx_recovery_cnt = 0;

// Function pointers
static bool(*sid_callback)(uint32_t id, uint8_t *data, uint8_t len) = 0;
static bool(*eid_callback)(uint32_t id, uint8_t *data, uint8_t len) = 0;

// Private functions
static void update_baud(CAN_BAUD baudrate);

Expand Down Expand Up @@ -610,6 +614,12 @@ static void process_task(void *arg) {
}

lispif_process_can(msg->identifier, msg->data, msg->data_length_code, msg->extd);
const bool extd = msg->extd;
if (extd) {
if (eid_callback) eid_callback(msg->identifier, msg->data, msg->data_length_code);
} else {
if (sid_callback) sid_callback(msg->identifier, msg->data, msg->data_length_code);
}

if (use_vesc_decoder) {
if (!bms_process_can_frame(msg->identifier, msg->data, msg->data_length_code, msg->extd)) {
Expand Down Expand Up @@ -748,7 +758,7 @@ static void update_baud(CAN_BAUD baudrate) {
case CAN_BAUD_75K: {
// Invalid
} break;

case CAN_BAUD_100K: {
twai_timing_config_t t_config2 = TWAI_TIMING_CONFIG_100KBITS();
t_config = t_config2;
Expand Down Expand Up @@ -883,11 +893,11 @@ void comm_can_update_baudrate(int delay_msec) {

twai_stop();
twai_driver_uninstall();

if (delay_msec > 0) {
vTaskDelay(delay_msec / portTICK_PERIOD_MS);
}

update_baud(backup.config.can_baud_rate);
twai_driver_install(&g_config, &t_config, &f_config);
twai_start();
Expand Down Expand Up @@ -958,7 +968,7 @@ void comm_can_transmit_eid(uint32_t id, const uint8_t *data, uint8_t len) {
}

twai_transmit(&tx_msg, 5);

xSemaphoreGive(send_mutex);
}

Expand Down Expand Up @@ -986,10 +996,36 @@ void comm_can_transmit_sid(uint32_t id, const uint8_t *data, uint8_t len) {
}

twai_transmit(&tx_msg, 5);

xSemaphoreGive(send_mutex);
}

/**
* Set function to be called when standard CAN frames are received.
*
* The callback should return true if the frame was used by the application, false otherwise. if
* the frame was used, no further processing will be done here.
*
* @param p_func
* Pointer to the function.
*/
void comm_can_set_sid_rx_callback(bool (*p_func)(uint32_t id, uint8_t *data, uint8_t len)) {
sid_callback = p_func;
}

/**
* Set function to be called when extended CAN frames are received.
*
* The callback should return true if the frame was used by the application, false otherwise. if
* the frame was used, no further processing will be done here.
*
* @param p_func
* Pointer to the function.
*/
void comm_can_set_eid_rx_callback(bool (*p_func)(uint32_t id, uint8_t *data, uint8_t len)) {
eid_callback = p_func;
}

/**
* Send a buffer up to RX_BUFFER_SIZE bytes as fragments. If the buffer is 6 bytes or less
* it will be sent in a single CAN frame, otherwise it will be split into
Expand Down
2 changes: 2 additions & 0 deletions main/comm_can.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ void comm_can_update_baudrate(int delay_msec);
void comm_can_change_pins(int tx, int rx);
void comm_can_transmit_eid(uint32_t id, const uint8_t *data, uint8_t len);
void comm_can_transmit_sid(uint32_t id, const uint8_t *data, uint8_t len);
void comm_can_set_sid_rx_callback(bool (*p_func)(uint32_t id, uint8_t *data, uint8_t len));
void comm_can_set_eid_rx_callback(bool (*p_func)(uint32_t id, uint8_t *data, uint8_t len));
void comm_can_send_buffer(uint8_t controller_id, uint8_t *data, unsigned int len, uint8_t send);
bool comm_can_ping(uint8_t controller_id, HW_TYPE *hw_type);

Expand Down
Loading