-
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.
* big branch of dumb shit * changed ioc and makefile and fixed dumb stuff * shame * minor change * Created can.c, added receive_msg function, initialed CAN * idk what changes i made * Added functionality to receiving CAN IDs (#21) --------- Co-authored-by: Scott A <[email protected]> Co-authored-by: caiodasilva2005 <[email protected]> Co-authored-by: caiodasilva2005 <[email protected]>
- Loading branch information
1 parent
3bb73d7
commit 3d9fed2
Showing
19 changed files
with
438 additions
and
94 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 |
---|---|---|
|
@@ -74,4 +74,7 @@ ctrlp.root | |
*.html | ||
|
||
#DS_Store | ||
.DS_Store | ||
.DS_Store | ||
|
||
#misc | ||
scott.txt |
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include <stdint.h> | ||
#include "stm32g4xx_hal.h" | ||
#include "fdcan.h" | ||
|
||
HAL_StatusTypeDef receive_msg(can_t *hcan); |
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,12 @@ | ||
#ifndef IROH_TASKS_H | ||
#define IROH_TASKS_H | ||
|
||
#include "cmsis_os.h" | ||
#include "seven_segment.h" | ||
#include "fdcan.h" | ||
|
||
void vSendBmsData(void* pv_params); | ||
extern osThreadId_t send_bms_data_handle; | ||
extern const osThreadAttr_t send_bms_data_attributes; | ||
|
||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef QUEUES_H | ||
#define QUEUES_H | ||
|
||
#include "cmsis_os.h" | ||
|
||
#define BMS_DATA_QUEUE_SIZE 8 | ||
|
||
typedef struct { | ||
uint8_t SoC; | ||
uint8_t current; | ||
} bms_data_t; | ||
|
||
extern osMessageQueueId_t bms_data_queue; | ||
|
||
#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
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,43 @@ | ||
#include "can.h" | ||
#include "queues.h" | ||
|
||
//Arbitrary CAN IDs | ||
#define CAN_ID 0x69 | ||
|
||
bms_data_t bms_data; | ||
|
||
|
||
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); | ||
} | ||
|
||
HAL_StatusTypeDef receive_msg(can_t *can) | ||
{ | ||
|
||
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 | ||
} | ||
} | ||
return HAL_ERROR; | ||
} | ||
return HAL_BUSY; | ||
} | ||
|
||
|
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,27 @@ | ||
/* All RTOS tasks are defined here */ | ||
|
||
#include "iroh_tasks.h" | ||
#include "queues.h" | ||
#include "seven_segment.h" | ||
|
||
static I2C_HandleTypeDef* hi2c; | ||
|
||
osThreadId_t send_bms_data_handle; | ||
const osThreadAttr_t send_bms_data_attributes = { | ||
.name = "SendBmsData", | ||
.stack_size = 128 * 8, | ||
.priority = (osPriority_t)osPriorityAboveNormal4 | ||
}; | ||
|
||
void vSendBmsData(void* pv_params) { | ||
|
||
hi2c = (I2C_HandleTypeDef*)pv_params; | ||
bms_data_t bms_data; | ||
|
||
for (;;) { | ||
if (osMessageQueueGet(bms_data_queue, &bms_data, NULL, 0U)) { | ||
write_current(hi2c, bms_data.current); | ||
write_charge(hi2c, bms_data.SoC); | ||
} | ||
} | ||
} |
Oops, something went wrong.