Compare commits
2 Commits
e45c1c2878
...
535e311e23
Author | SHA1 | Date | |
---|---|---|---|
535e311e23 | |||
6e46c4f470 |
19
AMS_Master_Code/.vscode/launch.json
vendored
19
AMS_Master_Code/.vscode/launch.json
vendored
@ -58,6 +58,25 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": true,
|
||||
"cwd": "c:/lene/fasttube/FT25/03_ams/ams-master/AMS_Master_Code/Core/Src",
|
||||
"program": "c:/lene/fasttube/FT25/03_ams/ams-master/AMS_Master_Code/Core/Src/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -41,6 +41,14 @@ extern "C" {
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
extern int sdc_closed;
|
||||
extern int sdc_closed_nodelay;
|
||||
extern int ts_error;
|
||||
extern int hv_active;
|
||||
extern int neg_air_closed;
|
||||
extern int pos_air_closed;
|
||||
extern int precharge_closed;
|
||||
extern int precharge_opened;
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "imd_monitoring.h"
|
||||
#include "main.h"
|
||||
#include "shunt_monitoring.h"
|
||||
#include "slave_monitoring.h"
|
||||
//#include "slave_monitoring.h"
|
||||
#include "soc_estimation.h"
|
||||
#include "ts_state_machine.h"
|
||||
|
||||
@ -15,17 +15,17 @@
|
||||
void can_init(FDCAN_HandleTypeDef *handle) {
|
||||
ftcan_init(handle);
|
||||
ftcan_add_filter(CAN_ID_SHUNT_BASE, 0xFF0);
|
||||
ftcan_add_filter(CAN_ID_AMS_IN, 0xFFF);
|
||||
ftcan_add_filter(CAN_ID_SLAVE_PANIC, 0xFFF);
|
||||
ftcan_add_filter(CAN_ID_SLAVE_STATUS_BASE, 0xFF0);
|
||||
ftcan_add_filter(CAN_ID_SLAVE_LOG, 0xFFF);
|
||||
// ftcan_add_filter(CAN_ID_AMS_IN, 0xFFF);
|
||||
// ftcan_add_filter(CAN_ID_SLAVE_PANIC, 0xFFF);
|
||||
// ftcan_add_filter(CAN_ID_SLAVE_STATUS_BASE, 0xFF0);
|
||||
// ftcan_add_filter(CAN_ID_SLAVE_LOG, 0xFFF);
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef can_send_status() {
|
||||
uint8_t data[8];
|
||||
data[0] = ts_state.current_state | (sdc_closed << 7);
|
||||
data[1] = roundf(current_soc);
|
||||
ftcan_marshal_unsigned(&data[2], min_voltage, 2);
|
||||
ftcan_marshal_unsigned(&data[2], min_voltage, 2); //was declared in slave_monitoring.c
|
||||
ftcan_marshal_signed(&data[4], max_temp, 2);
|
||||
data[6] = imd_data.state | (imd_data.ok << 7);
|
||||
if (imd_data.r_iso < 0xFFF) {
|
||||
@ -54,19 +54,20 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
|
||||
if ((id & 0xFF0) == CAN_ID_SHUNT_BASE) {
|
||||
shunt_handle_can_msg(id, data);
|
||||
return;
|
||||
} else if ((id & 0xFF0) == CAN_ID_SLAVE_STATUS_BASE) {
|
||||
slaves_handle_status(data);
|
||||
return;
|
||||
}
|
||||
switch (id) {
|
||||
case CAN_ID_SLAVE_PANIC:
|
||||
slaves_handle_panic(data);
|
||||
break;
|
||||
case CAN_ID_SLAVE_LOG:
|
||||
slaves_handle_log(data);
|
||||
break;
|
||||
case CAN_ID_AMS_IN:
|
||||
ts_sm_handle_ams_in(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// else if ((id & 0xFF0) == CAN_ID_SLAVE_STATUS_BASE) {
|
||||
// slaves_handle_status(data);
|
||||
// return;
|
||||
// }
|
||||
// switch (id) {
|
||||
// case CAN_ID_SLAVE_PANIC:
|
||||
// slaves_handle_panic(data);
|
||||
// break;
|
||||
// case CAN_ID_SLAVE_LOG:
|
||||
// slaves_handle_log(data);
|
||||
// break;
|
||||
// case CAN_ID_AMS_IN:
|
||||
// ts_sm_handle_ams_in(data);
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
|
@ -25,6 +25,16 @@
|
||||
#include "config_ADBMS6830.h"
|
||||
#include "swo_log.h"
|
||||
#include <string.h>
|
||||
|
||||
//copied from master23
|
||||
#include "can.h"
|
||||
#include "imd_monitoring.h"
|
||||
#include "shunt_monitoring.h"
|
||||
#include "soc_estimation.h"
|
||||
#include "ts_state_machine.h"
|
||||
#include "status_led.h"
|
||||
|
||||
#include "stm32h7xx_hal.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@ -55,6 +65,15 @@ TIM_HandleTypeDef htim15;
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
int sdc_closed = 0;
|
||||
int sdc_closed_nodelay = 0;
|
||||
int ts_error;
|
||||
int hv_active;
|
||||
int neg_air_closed;
|
||||
int pos_air_closed;
|
||||
int precharge_closed;
|
||||
int pre_and_air_open; // used to be:int precharge_opened = 0; now we read if PC is open from the pin -> high if open
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
@ -74,6 +93,42 @@ static void MX_ADC2_Init(void);
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
uint32_t volatile logging_mask = 0b11111; // no LOG_LEVEL_NOISY
|
||||
|
||||
#define MAIN_LOOP_PERIOD 50
|
||||
|
||||
static void loop_delay() {
|
||||
static uint32_t last_loop = 0;
|
||||
uint32_t dt = HAL_GetTick() - last_loop;
|
||||
if (dt < MAIN_LOOP_PERIOD) {
|
||||
HAL_Delay(MAIN_LOOP_PERIOD - dt);
|
||||
//HAL_GPIO_WritePin(STATUS2_GPIO_Port, STATUS2_Pin, GPIO_PIN_RESET);
|
||||
} else {
|
||||
//HAL_GPIO_WritePin(STATUS2_GPIO_Port, STATUS2_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
last_loop = HAL_GetTick();
|
||||
}
|
||||
|
||||
static void update_sdc() {
|
||||
static int last[2] = {0, 0};
|
||||
sdc_closed_nodelay = HAL_GPIO_ReadPin(SDC_VOLTAGE_GPIO_Port, SDC_VOLTAGE_Pin) == GPIO_PIN_SET;
|
||||
if (last[0] == last[1] && last[0] == sdc_closed_nodelay) {
|
||||
sdc_closed = sdc_closed_nodelay;
|
||||
}
|
||||
last[0] = last[1];
|
||||
last[1] = sdc_closed_nodelay;
|
||||
}
|
||||
|
||||
static void update_tsal_signals() {
|
||||
ts_error = HAL_GPIO_ReadPin(TS_ERROR_GPIO_Port, TS_ERROR_Pin) == GPIO_PIN_SET;
|
||||
hv_active = HAL_GPIO_ReadPin(HV_ACTIVE_GPIO_Port, HV_ACTIVE_Pin) == GPIO_PIN_SET;
|
||||
neg_air_closed = HAL_GPIO_ReadPin(NEG_AIR_CLOSED_GPIO_Port,
|
||||
NEG_AIR_CLOSED_Pin) == GPIO_PIN_SET;
|
||||
pos_air_closed = HAL_GPIO_ReadPin(POS_AIR_CLOSED_GPIO_Port,
|
||||
POS_AIR_CLOSED_Pin) == GPIO_PIN_SET;
|
||||
pre_and_air_open = HAL_GPIO_ReadPin(PRE_and_AIR__open_GPIO_Port,
|
||||
PRE_and_AIR__open_Pin) == GPIO_PIN_SET;
|
||||
}
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
@ -126,6 +181,16 @@ int main(void)
|
||||
HAL_Delay(2000);
|
||||
}
|
||||
}
|
||||
|
||||
//init fot master functions
|
||||
can_init(&hfdcan1);
|
||||
//slaves_init();
|
||||
shunt_init();
|
||||
ts_sm_init();
|
||||
soc_init();
|
||||
imd_init(&htim15);
|
||||
HAL_GPIO_WritePin(AMS_NERROR_GPIO_Port, AMS_NERROR_Pin, GPIO_PIN_SET);
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
@ -134,6 +199,7 @@ int main(void)
|
||||
int error_count = 0;
|
||||
while (1)
|
||||
{
|
||||
//left over from slave communication test, could be nicer and in an additional function !!
|
||||
if (error_count > 25) {
|
||||
debug_log(LOG_LEVEL_ERROR, "Too many errors, restarting BMS...");
|
||||
status = AMS_Init(&hspi1);
|
||||
@ -274,7 +340,18 @@ int main(void)
|
||||
// get time difference
|
||||
debug_log(LOG_LEVEL_INFO, " Time since last update: %d ms", HAL_GetTick() - lastTimestamp);
|
||||
}
|
||||
HAL_Delay(100);
|
||||
|
||||
update_sdc();
|
||||
update_tsal_signals();
|
||||
|
||||
//slaves_check();
|
||||
shunt_check();
|
||||
ts_sm_update();
|
||||
soc_update();
|
||||
imd_update();
|
||||
can_send_status();
|
||||
|
||||
loop_delay();
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user