Skip to content

Commit

Permalink
big branch of dumb shit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabramz committed Feb 2, 2024
1 parent 3bb73d7 commit 27de14a
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 7 deletions.
10 changes: 10 additions & 0 deletions Core/Inc/queues.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "cmsis_os.h"

#define BMS_DATA_QUEUE_SIZE 8

typedef struct {
uint16_t SoC;
uint16_t current;
} bms_data_t;

extern osMessageQueueId_t bms_data_queue;
7 changes: 7 additions & 0 deletions Core/Inc/tasks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#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;
8 changes: 5 additions & 3 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */

#include "queues.h"
#include "tasks.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
Expand Down Expand Up @@ -52,7 +53,7 @@ const osThreadAttr_t defaultTask_attributes = {
.priority = (osPriority_t)osPriorityNormal,
.stack_size = 128 * 4};
/* USER CODE BEGIN PV */

osMessageQueueId_t bms_data_queue;
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
Expand Down Expand Up @@ -121,14 +122,15 @@ int main(void)
/* USER CODE END RTOS_TIMERS */

/* USER CODE BEGIN RTOS_QUEUES */
bms_data_queue = osMessageQueueNew(BMS_DATA_QUEUE_SIZE, sizeof(bms_data_t), NULL);
/* USER CODE END RTOS_QUEUES */

/* Create the thread(s) */
/* creation of defaultTask */
defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes);

/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
send_bms_data_handle = osThreadNew(vSendBmsData, &hi2c2, &send_bms_data_attributes);
/* USER CODE END RTOS_THREADS */

/* USER CODE BEGIN RTOS_EVENTS */
Expand Down
2 changes: 2 additions & 0 deletions Core/Src/seven_segment.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* Drivers for the seven segment display */

#include "seven_segment.h"
#include <stdint.h>

Expand Down
10 changes: 6 additions & 4 deletions Core/Src/switch.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/* Controls for the switch on the Charger board */

#include "switch.h"

bool get_switch(GPIO_InitTypeDef init, uint8_t pin)
{
switch (pin)
{
case 1:
return HAL_GPIO_ReadPin(init, SWITCH_1_PIN);
return HAL_GPIO_ReadPin(&init, SWITCH_1_PIN);
case 2:
return HAL_GPIO_ReadPin(init, SWITCH_2_PIN);
return HAL_GPIO_ReadPin(&init, SWITCH_2_PIN);
case 3:
return HAL_GPIO_ReadPin(init, SWITCH_3_PIN);
return HAL_GPIO_ReadPin(&init, SWITCH_3_PIN);
case 4:
return HAL_GPIO_ReadPin(init, SWITCH_4_PIN);
return HAL_GPIO_ReadPin(&init, SWITCH_4_PIN);
default:
return false;
}
Expand Down
27 changes: 27 additions & 0 deletions Core/Src/tasks.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* All RTOS tasks are defined here */

#include "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_handle_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);
}
}
}
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Core/Src/app_freertos.c \
Core/Src/stm32g4xx_it.c \
Core/Src/stm32g4xx_hal_msp.c \
Core/Src/seven_segment.c \
Core/Src/switch.c \
Core/Src/tasks.c \
Drivers/Embedded-Base/platforms/stm32g431/src/fdcan.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc.c \
Expand All @@ -61,6 +63,7 @@ Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim_ex.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart_ex.c \
Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_fdcan.c \
Core/Src/system_stm32g4xx.c \
Middlewares/Third_Party/FreeRTOS/Source/croutine.c \
Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \
Expand Down

0 comments on commit 27de14a

Please sign in to comment.