-
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
Showing
6 changed files
with
62 additions
and
35 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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
#ifndef CAN_H | ||
#define CAN_H | ||
|
||
#include <stdint.h> | ||
#include "stm32g4xx_hal.h" | ||
#include "fdcan.h" | ||
|
||
HAL_StatusTypeDef receive_msg(can_t *hcan); | ||
void init_iroh_can(FDCAN_HandleTypeDef *hcan); | ||
|
||
#endif |
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
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 |
---|---|---|
@@ -1,43 +1,52 @@ | ||
#include "can.h" | ||
#include "queues.h" | ||
#include "string.h" | ||
|
||
//Arbitrary CAN IDs | ||
#define CAN_ID 0x69 | ||
|
||
bms_data_t bms_data; | ||
#define BMS_DATA_CAN_ID 0x80 | ||
|
||
void receive_msg(FDCAN_HandleTypeDef *hfdcan) | ||
{ | ||
|
||
void init_iroh_can(FDCAN_HandleTypeDef *hcan) { | ||
can_t fdcan; | ||
fdcan.callback = receive_msg; | ||
fdcan.id_list = 0; | ||
fdcan.id_list_len = 0; | ||
fdcan.hcan = hcan; | ||
bms_data_t bms_data; | ||
iroh_error_t e; | ||
|
||
can_init(&fdcan); | ||
} | ||
FDCAN_RxHeaderTypeDef *rx_header; | ||
uint8_t *rx_data; | ||
|
||
HAL_StatusTypeDef receive_msg(can_t *can) | ||
{ | ||
if (!HAL_FDCAN_GetRxFifoFillLevel(hfdcan, FDCAN_RX_FIFO0)) { | ||
e.code = 1; | ||
strcpy(e.msg, "No msg Recieved"); | ||
osMessageQueuePut(error_queue, &e, 0, 2000); | ||
return; | ||
} | ||
|
||
FDCAN_RxHeaderTypeDef rx_header; | ||
uint8_t rx_data[8]; //array of 8 bytes | ||
|
||
if (HAL_FDCAN_GetRxFifoFillLevel(can->hcan, FDCAN_RX_FIFO0) > 0) { //Check if messages are available | ||
if (HAL_FDCAN_GetRxMessage(can->hcan,FDCAN_RX_FIFO0,&rx_header,rx_data) == HAL_OK) { | ||
uint32_t message_id = rx_header.Identifier; | ||
if (message_id == CAN_ID) { | ||
bms_data.SoC = (uint8_t) rx_data[0]; | ||
bms_data.current = (uint8_t) rx_data[1]; | ||
if (osStatus_t osMessageQueuePut(bms_data_queue *bms_data, 0, 2000) == osOK) //timeout is 2000 ms | ||
return HAL_OK; | ||
else | ||
return HAL_ERROR | ||
} | ||
if (!HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, rx_header, rx_data)) { | ||
e.code = 2; | ||
strcpy(e.msg, "Cannot get msg"); | ||
osMessageQueuePut(error_queue, &e, 0, 2000); | ||
return; | ||
} | ||
|
||
uint32_t message_id = rx_header->Identifier; | ||
|
||
if (message_id == BMS_DATA_CAN_ID) { | ||
bms_data.SoC = rx_data[0]; | ||
bms_data.current = rx_data[1]; | ||
if (!osMessageQueuePut(bms_data_queue, &bms_data, 0, 2000)) { | ||
e.code = 3; | ||
strcpy(e.msg, "BMS data MQ err"); | ||
osMessageQueuePut(error_queue, &e, 0, 2000); | ||
return; | ||
} | ||
return HAL_ERROR; | ||
} | ||
return HAL_BUSY; | ||
} | ||
} | ||
|
||
|
||
void init_iroh_can(FDCAN_HandleTypeDef *hcan) { | ||
can_t *fdcan; | ||
fdcan->callback = receive_msg; | ||
fdcan->id_list = 0; | ||
fdcan->id_list_len = 0; | ||
fdcan->hcan = hcan; | ||
|
||
can_init(fdcan); | ||
} |
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
Submodule Embedded-Base
updated
13 files
+10 −17 | dev/Dockerfile | |
+39 −0 | dev/scripts/alias.sh | |
+2 −0 | dev/scripts/emulate.sh | |
+6 −0 | dev/scripts/flash.sh | |
+8 −0 | dev/scripts/gdb.sh | |
+11 −0 | dev/scripts/ody-connect.sh | |
+2 −0 | dev/scripts/serial.sh | |
+19 −0 | general/include/mcp23008.h | |
+35 −0 | general/src/mcp23008.c | |
+52 −0 | middleware/include/pid.h | |
+67 −0 | middleware/src/pid.c | |
+3 −4 | platforms/stm32g431/include/fdcan.h | |
+0 −7 | platforms/stm32g431/src/fdcan.c |
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