firmware
IEM Firmware Documentation
Loading...
Searching...
No Matches
main.c File Reference

: Main program body More...

#include "main.h"
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include "stm32f4xx.h"
#include "stm32f4xx_hal.h"
#include "BMSconfig.h"
#include "Fault.h"
#include "LTC6811.h"
#include "PackCalculations.h"
#include "SPI.h"
#include "isoADC.h"
#include "can_1.h"
#include "can_2.h"
#include "stm32f4xx_hal_can.h"
#include "stm32f4xx_hal_gpio.h"
Include dependency graph for main.c:

Macros

#define CHARGER_OUT_ID   0x405
#define CAN_RX_MAILBOX_SIZE   3
#define CHARGER_IN_ID   0x1806E5F4
#define CHARGER_INFO_ID   0x700
#define CONSTANT_CAN_ENABLE   0
#define BMS_RX_MSG_ID   0x0300
#define BMS_RX_MSG_MASK   0x0F00
#define BALANCE_EN   0
#define THRESHOLD_BALANCE_EN   0
#define DISCHARGE_THRESHOLD   65535
#define MANUAL_BALANCING_ID   0x381
#define CAN_TX_TIMEOUT   2

Functions

void SystemClock_Config (void)
 System Clock Configuration.
static void MX_GPIO_Init (void)
 GPIO Initialization Function.
static void MX_CAN1_Init (void)
 CAN1 Initialization Function.
static void MX_SPI1_Init (void)
 SPI1 Initialization Function.
static void MX_SPI2_Init (void)
 SPI2 Initialization Function.
static void MX_SPI3_Init (void)
 SPI3 Initialization Function.
static void MX_TIM2_Init (void)
 TIM2 Initialization Function.
static void MX_TIM3_Init (void)
 TIM3 Initialization Function.
static void MX_CAN2_Init (void)
 CAN2 Initialization Function.
static void MX_TIM1_Init (void)
 TIM1 Initialization Function.
static void MX_TIM7_Init (void)
 TIM7 Initialization Function.
static void MX_TIM13_Init (void)
 TIM13 Initialization Function.
static bool transmit_can_message (CAN_HandleTypeDef *hcan, const CAN_TxHeaderTypeDef *tx_header, const uint8_t msg_data[])
static void transmit_cell_data_msg (CellData const bmsData[144])
static void transmit_bms_status_msg (BMS_critical_info_t const *bms, uint8_t const bmsStatus[6])
static void transmit_cell_vlt_msg (BMS_critical_info_t const *bms)
static void transmit_cell_temp_msg (BMS_critical_info_t const *bms)
void CHARGER_message ()
void resetChargerVariables ()
void process_balancing_msg ()
int main (void)
 The application entry point.
void HAL_CAN_RxFifo0MsgPendingCallback (CAN_HandleTypeDef *hcan)
void HAL_TIM_PeriodElapsedCallback (TIM_HandleTypeDef *htim)
void send_can_msg_from_irq ()
void send_cell_vals_polling ()
void Error_Handler (void)
 This function is executed in case of error occurrence.

Variables

CAN_HandleTypeDef hcan1
CAN_HandleTypeDef hcan2
SPI_HandleTypeDef hspi1
SPI_HandleTypeDef hspi2
SPI_HandleTypeDef hspi3
TIM_HandleTypeDef htim1
TIM_HandleTypeDef htim2
TIM_HandleTypeDef htim3
TIM_HandleTypeDef htim7
TIM_HandleTypeDef htim13
SPI_HandleTypeDef * ltc_spi = &hspi1
CAN_TxHeaderTypeDef tx_header
volatile CAN_RxHeaderTypeDef rx_header
uint8_t tx_data [8]
volatile uint8_t rx_data [8] = {0, 0, 0, 0, 0, 0, 0, 0}
uint32_t tx_mailbox
CAN_TxHeaderTypeDef charger_tx_header
uint8_t charger_tx_data [8]
uint8_t charge_rate = 2
uint8_t global_error_count = 0
uint8_t balance_counter = 0
uint8_t charging_msg_timeout = 1
int16_t poll_cell_temps = 0
int16_t poll_cell_voltages = 0
bool CHARGE_EN = 0
CellData bmsData [144]
uint8_t BMS_STATUS [6]
bool discharge [12][12]
bool full_discharge [12][12]
volatile manual_balancing_t manual_balancing_config
volatile bool bmsFault
SPI_HandleTypeDef * isoADC_SPI_ptr_g = &hspi2
GPIO_TypeDef * isoADC_SPI_cs_port_ptr_g = SPI_ADC_CS_GPIO_Port
uint16_t isoADC_SPI_cs_pin_g = GPIO_PIN_12
TIM_HandleTypeDef * isoADC_PWM_ptr_g = &htim3
uint32_t isoADC_PWM_ch_g = TIM_CHANNEL_1
BMS_critical_info_t BMSCriticalInfo
uint8_t isoADC_rdy_status = 0
uint8_t isoADC_period_miss = 0
uint8_t max_isoADC_period = 0
uint32_t cell_volt_timing = 0
uint32_t cell_temp_timing = 0
uint32_t volt_start_time = 0
uint32_t temp_start_time = 0
volatile bool pollingFlag = false
volatile uint8_t new_balance_msg = 0
volatile uint8_t can_tx_phase = 0
volatile uint8_t balancing_data_array [8]
uint32_t prevTime = 0
uint32_t timeBetween = 0
int32_t fault_timer = 2000
uint8_t error_cnt = 0
uint8_t error_voltage_read_count = 0
uint8_t error_temp_read_count = 0
float live_pack_voltage = 0
float live_pack_current = 0
bool live_precharge = false

Detailed Description

: Main program body

Attention

Copyright (c) 2024 STMicroelectronics. All rights reserved.

This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.

Macro Definition Documentation

◆ BALANCE_EN

#define BALANCE_EN   0

◆ BMS_RX_MSG_ID

#define BMS_RX_MSG_ID   0x0300

◆ BMS_RX_MSG_MASK

#define BMS_RX_MSG_MASK   0x0F00

◆ CAN_RX_MAILBOX_SIZE

#define CAN_RX_MAILBOX_SIZE   3

◆ CAN_TX_TIMEOUT

#define CAN_TX_TIMEOUT   2

◆ CHARGER_IN_ID

#define CHARGER_IN_ID   0x1806E5F4

◆ CHARGER_INFO_ID

#define CHARGER_INFO_ID   0x700

◆ CHARGER_OUT_ID

#define CHARGER_OUT_ID   0x405

◆ CONSTANT_CAN_ENABLE

#define CONSTANT_CAN_ENABLE   0

◆ DISCHARGE_THRESHOLD

#define DISCHARGE_THRESHOLD   65535

◆ MANUAL_BALANCING_ID

#define MANUAL_BALANCING_ID   0x381

◆ THRESHOLD_BALANCE_EN

#define THRESHOLD_BALANCE_EN   0

Function Documentation

◆ CHARGER_message()

void CHARGER_message ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Error_Handler()

void Error_Handler ( void )

This function is executed in case of error occurrence.

Return values
None
Here is the caller graph for this function:

◆ HAL_CAN_RxFifo0MsgPendingCallback()

void HAL_CAN_RxFifo0MsgPendingCallback ( CAN_HandleTypeDef * hcan)

◆ HAL_TIM_PeriodElapsedCallback()

void HAL_TIM_PeriodElapsedCallback ( TIM_HandleTypeDef * htim)
Here is the call graph for this function:

◆ main()

int main ( void )

The application entry point.

Return values
int

FUNCTION CALL OVERVIEW First: Call read6811 -> Voltages, Temps on 6811 Second: Check for Faults Third: Call balancing algorithm Fourth : Remaining CAN messages Last: :3

Here is the call graph for this function:

◆ MX_CAN1_Init()

void MX_CAN1_Init ( void )
static

CAN1 Initialization Function.

Parameters
None
Return values
None
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_CAN2_Init()

void MX_CAN2_Init ( void )
static

CAN2 Initialization Function.

Parameters
None
Return values
None
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_GPIO_Init()

void MX_GPIO_Init ( void )
static

GPIO Initialization Function.

Parameters
None
Return values
None
Here is the caller graph for this function:

◆ MX_SPI1_Init()

void MX_SPI1_Init ( void )
static

SPI1 Initialization Function.

Parameters
None
Return values
None
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_SPI2_Init()

void MX_SPI2_Init ( void )
static

SPI2 Initialization Function.

Parameters
None
Return values
None
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_SPI3_Init()

void MX_SPI3_Init ( void )
static

SPI3 Initialization Function.

Parameters
None
Return values
None
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_TIM13_Init()

void MX_TIM13_Init ( void )
static

TIM13 Initialization Function.

Parameters
None
Return values
None
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_TIM1_Init()

void MX_TIM1_Init ( void )
static

TIM1 Initialization Function.

Parameters
None
Return values
None
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_TIM2_Init()

void MX_TIM2_Init ( void )
static

TIM2 Initialization Function.

Parameters
None
Return values
None
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_TIM3_Init()

void MX_TIM3_Init ( void )
static

TIM3 Initialization Function.

Parameters
None
Return values
None
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MX_TIM7_Init()

void MX_TIM7_Init ( void )
static

TIM7 Initialization Function.

Parameters
None
Return values
None
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_balancing_msg()

void process_balancing_msg ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetChargerVariables()

void resetChargerVariables ( )
Here is the caller graph for this function:

◆ send_can_msg_from_irq()

void send_can_msg_from_irq ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_cell_vals_polling()

void send_cell_vals_polling ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SystemClock_Config()

void SystemClock_Config ( void )

System Clock Configuration.

Return values
None

Configure the main internal regulator output voltage

Initializes the RCC Oscillators according to the specified parameters in the RCC_OscInitTypeDef structure.

Initializes the CPU, AHB and APB buses clocks

Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_bms_status_msg()

void transmit_bms_status_msg ( BMS_critical_info_t const * bms,
uint8_t const bmsStatus[6] )
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_can_message()

bool transmit_can_message ( CAN_HandleTypeDef * hcan,
const CAN_TxHeaderTypeDef * tx_header,
const uint8_t msg_data[] )
static
Here is the caller graph for this function:

◆ transmit_cell_data_msg()

void transmit_cell_data_msg ( CellData const bmsData[144])
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_cell_temp_msg()

void transmit_cell_temp_msg ( BMS_critical_info_t const * bms)
static
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_cell_vlt_msg()

void transmit_cell_vlt_msg ( BMS_critical_info_t const * bms)
static
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ balance_counter

uint8_t balance_counter = 0

◆ balancing_data_array

volatile uint8_t balancing_data_array[8]

◆ BMS_STATUS

uint8_t BMS_STATUS[6]

◆ BMSCriticalInfo

BMS_critical_info_t BMSCriticalInfo

◆ bmsData

CellData bmsData[144]

◆ bmsFault

volatile bool bmsFault

◆ can_tx_phase

volatile uint8_t can_tx_phase = 0

◆ cell_temp_timing

uint32_t cell_temp_timing = 0

◆ cell_volt_timing

uint32_t cell_volt_timing = 0

◆ CHARGE_EN

bool CHARGE_EN = 0

◆ charge_rate

uint8_t charge_rate = 2

◆ charger_tx_data

uint8_t charger_tx_data[8]

◆ charger_tx_header

CAN_TxHeaderTypeDef charger_tx_header

◆ charging_msg_timeout

uint8_t charging_msg_timeout = 1

◆ discharge

bool discharge[12][12]

◆ error_cnt

uint8_t error_cnt = 0

◆ error_temp_read_count

uint8_t error_temp_read_count = 0

◆ error_voltage_read_count

uint8_t error_voltage_read_count = 0

◆ fault_timer

int32_t fault_timer = 2000

◆ full_discharge

bool full_discharge[12][12]

◆ global_error_count

uint8_t global_error_count = 0

◆ hcan1

CAN_HandleTypeDef hcan1

◆ hcan2

CAN_HandleTypeDef hcan2

◆ hspi1

SPI_HandleTypeDef hspi1

◆ hspi2

SPI_HandleTypeDef hspi2

◆ hspi3

SPI_HandleTypeDef hspi3

◆ htim1

TIM_HandleTypeDef htim1

◆ htim13

TIM_HandleTypeDef htim13

◆ htim2

TIM_HandleTypeDef htim2

◆ htim3

TIM_HandleTypeDef htim3

◆ htim7

TIM_HandleTypeDef htim7

◆ isoADC_period_miss

uint8_t isoADC_period_miss = 0

◆ isoADC_PWM_ch_g

uint32_t isoADC_PWM_ch_g = TIM_CHANNEL_1

◆ isoADC_PWM_ptr_g

TIM_HandleTypeDef* isoADC_PWM_ptr_g = &htim3

◆ isoADC_rdy_status

uint8_t isoADC_rdy_status = 0

◆ isoADC_SPI_cs_pin_g

uint16_t isoADC_SPI_cs_pin_g = GPIO_PIN_12

◆ isoADC_SPI_cs_port_ptr_g

GPIO_TypeDef* isoADC_SPI_cs_port_ptr_g = SPI_ADC_CS_GPIO_Port

◆ isoADC_SPI_ptr_g

SPI_HandleTypeDef* isoADC_SPI_ptr_g = &hspi2

◆ live_pack_current

float live_pack_current = 0

◆ live_pack_voltage

float live_pack_voltage = 0

◆ live_precharge

bool live_precharge = false

◆ ltc_spi

SPI_HandleTypeDef* ltc_spi = &hspi1

◆ manual_balancing_config

volatile manual_balancing_t manual_balancing_config

◆ max_isoADC_period

uint8_t max_isoADC_period = 0

◆ new_balance_msg

volatile uint8_t new_balance_msg = 0

◆ poll_cell_temps

int16_t poll_cell_temps = 0

◆ poll_cell_voltages

int16_t poll_cell_voltages = 0

◆ pollingFlag

volatile bool pollingFlag = false

◆ prevTime

uint32_t prevTime = 0

◆ rx_data

volatile uint8_t rx_data[8] = {0, 0, 0, 0, 0, 0, 0, 0}

◆ rx_header

volatile CAN_RxHeaderTypeDef rx_header

◆ temp_start_time

uint32_t temp_start_time = 0

◆ timeBetween

uint32_t timeBetween = 0

◆ tx_data

uint8_t tx_data[8]

◆ tx_header

CAN_TxHeaderTypeDef tx_header

◆ tx_mailbox

uint32_t tx_mailbox

◆ volt_start_time

uint32_t volt_start_time = 0