Compare commits
	
		
			4 Commits
		
	
	
		
			ft23
			...
			status-led
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						ba05bb5ff4
	
				 | 
					
					
						|||
| 
						
						
							
						
						c5343f9cdd
	
				 | 
					
					
						|||
| 
						
						
							
						
						8db96bb9ca
	
				 | 
					
					
						|||
| 
						
						
							
						
						b24fc66caf
	
				 | 
					
					
						
@ -12,7 +12,6 @@
 | 
			
		||||
#define CAN_ID_AMS_IN 0x00B
 | 
			
		||||
#define CAN_ID_AMS_ERROR 0x00C
 | 
			
		||||
#define CAN_ID_SLAVE_STATUS_BASE 0x080
 | 
			
		||||
#define CAN_ID_SLAVE_STATUS_FUCKED 0x0A0
 | 
			
		||||
#define CAN_ID_SLAVE_LOG 0x4F4
 | 
			
		||||
#define CAN_ID_SHUNT_BASE 0x520
 | 
			
		||||
#define CAN_ID_SHUNT_CURRENT 0x521
 | 
			
		||||
 | 
			
		||||
@ -5,10 +5,9 @@
 | 
			
		||||
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
#define SHUNT_TIMEOUT 300                    // ms
 | 
			
		||||
#define SHUNT_THRESH_OVERCURRENT 300000      // mA
 | 
			
		||||
#define SHUNT_THRESH_OVERCURRENT_REGEN 50000 // mA
 | 
			
		||||
#define SHUNT_THRESH_OVERTEMP 1000           // 1/10 °C
 | 
			
		||||
#define SHUNT_TIMEOUT 300               // ms
 | 
			
		||||
#define SHUNT_THRESH_OVERCURRENT 300000 // mA
 | 
			
		||||
#define SHUNT_THRESH_OVERTEMP 1000      // 1/10 °C
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
  int32_t current;     // mA
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								Core/Inc/status_led.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								Core/Inc/status_led.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,10 @@
 | 
			
		||||
#ifndef INC_STATUS_LED_H
 | 
			
		||||
#define INC_STATUS_LED_H
 | 
			
		||||
 | 
			
		||||
#include "ts_state_machine.h"
 | 
			
		||||
 | 
			
		||||
void status_led_init();
 | 
			
		||||
 | 
			
		||||
void status_led_state(TSState state, TSErrorKind error);
 | 
			
		||||
 | 
			
		||||
#endif // INC_STATUS_LED_H
 | 
			
		||||
@ -4,6 +4,7 @@
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
 | 
			
		||||
// Minimum vehicle side voltage to exit precharge
 | 
			
		||||
#define MIN_VEHICLE_SIDE_VOLTAGE 150000 // mV
 | 
			
		||||
@ -37,13 +38,17 @@ typedef enum {
 | 
			
		||||
  TS_ERRORKIND_SHUNT_OVERCURRENT = 0x04,
 | 
			
		||||
  TS_ERRORKIND_SHUNT_OVERTEMP = 0x05
 | 
			
		||||
} TSErrorKind;
 | 
			
		||||
#define TS_ERROR_SOURCE_SHUNT (1 << 0)
 | 
			
		||||
#define TS_ERROR_SOURCE_SLAVES (1 << 1)
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
  TS_ERROR_SOURCE_SHUNT = (1 << 0),
 | 
			
		||||
  TS_ERROR_SOURCE_SLAVES = (1 << 1)
 | 
			
		||||
} TSErrorSource;
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
  TSState current_state;
 | 
			
		||||
  TSState target_state;
 | 
			
		||||
  uint32_t error;
 | 
			
		||||
  uint16_t error_source; // TSErrorSource (bitmask)
 | 
			
		||||
  uint16_t error_type; // TSErrorKind
 | 
			
		||||
} TSStateHandle;
 | 
			
		||||
 | 
			
		||||
extern TSStateHandle ts_state;
 | 
			
		||||
@ -66,6 +71,6 @@ void ts_sm_check_close_wait(int *is_closed, int should_close);
 | 
			
		||||
 | 
			
		||||
void ts_sm_handle_ams_in(const uint8_t *data);
 | 
			
		||||
 | 
			
		||||
void ts_sm_set_error_source(uint32_t flag, int state);
 | 
			
		||||
void ts_sm_set_error_source(TSErrorSource source, TSErrorKind error_type, bool is_errored);
 | 
			
		||||
 | 
			
		||||
#endif // INC_TS_STATE_MACHINE_H
 | 
			
		||||
 | 
			
		||||
@ -18,7 +18,6 @@ void can_init(CAN_HandleTypeDef *handle) {
 | 
			
		||||
  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_STATUS_FUCKED, 0xFFF);
 | 
			
		||||
  ftcan_add_filter(CAN_ID_SLAVE_LOG, 0xFFF);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -51,8 +50,6 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
 | 
			
		||||
  } else if ((id & 0xFF0) == CAN_ID_SLAVE_STATUS_BASE) {
 | 
			
		||||
    slaves_handle_status(data);
 | 
			
		||||
    return;
 | 
			
		||||
  } else if (id == CAN_ID_SLAVE_STATUS_FUCKED) {
 | 
			
		||||
    slaves_handle_status(data);
 | 
			
		||||
  }
 | 
			
		||||
  switch (id) {
 | 
			
		||||
  case CAN_ID_SLAVE_PANIC:
 | 
			
		||||
 | 
			
		||||
@ -27,6 +27,7 @@
 | 
			
		||||
#include "slave_monitoring.h"
 | 
			
		||||
#include "soc_estimation.h"
 | 
			
		||||
#include "ts_state_machine.h"
 | 
			
		||||
#include "status_led.h"
 | 
			
		||||
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
#include "stm32f3xx_hal_gpio.h"
 | 
			
		||||
@ -487,6 +488,9 @@ static void MX_GPIO_Init(void) {
 | 
			
		||||
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 | 
			
		||||
  HAL_GPIO_Init(PRECHARGE_CTRL_GPIO_Port, &GPIO_InitStruct);
 | 
			
		||||
 | 
			
		||||
  /*Configure GPIO pins for Status LEDs */
 | 
			
		||||
  status_led_init();
 | 
			
		||||
 | 
			
		||||
  /* USER CODE BEGIN MX_GPIO_Init_2 */
 | 
			
		||||
  /* USER CODE END MX_GPIO_Init_2 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -25,18 +25,21 @@ void shunt_init() {
 | 
			
		||||
 | 
			
		||||
void shunt_check() {
 | 
			
		||||
  int is_error = 0;
 | 
			
		||||
  TSErrorKind error_type = TS_ERRORKIND_NONE;
 | 
			
		||||
  if (HAL_GetTick() - shunt_data.last_message > SHUNT_TIMEOUT) {
 | 
			
		||||
    is_error = 1;
 | 
			
		||||
    error_type = TS_ERRORKIND_SHUNT_TIMEOUT;
 | 
			
		||||
    can_send_error(TS_ERRORKIND_SHUNT_TIMEOUT, 0);
 | 
			
		||||
  } else if (shunt_data.current >= SHUNT_THRESH_OVERCURRENT ||
 | 
			
		||||
             shunt_data.current <= -SHUNT_THRESH_OVERCURRENT_REGEN) {
 | 
			
		||||
  } else if (shunt_data.current >= SHUNT_THRESH_OVERCURRENT) {
 | 
			
		||||
    is_error = 1;
 | 
			
		||||
    error_type = TS_ERRORKIND_SHUNT_OVERCURRENT;
 | 
			
		||||
    can_send_error(TS_ERRORKIND_SHUNT_OVERCURRENT, 0);
 | 
			
		||||
  } else if (shunt_data.busbartemp >= SHUNT_THRESH_OVERTEMP) {
 | 
			
		||||
    is_error = 1;
 | 
			
		||||
    error_type = TS_ERRORKIND_SHUNT_OVERTEMP;
 | 
			
		||||
    can_send_error(TS_ERRORKIND_SHUNT_OVERTEMP, 0);
 | 
			
		||||
  }
 | 
			
		||||
  ts_sm_set_error_source(TS_ERROR_SOURCE_SHUNT, is_error);
 | 
			
		||||
  ts_sm_set_error_source(TS_ERROR_SOURCE_SHUNT, error_type, is_error);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void shunt_handle_can_msg(uint16_t id, const uint8_t *data) {
 | 
			
		||||
 | 
			
		||||
@ -57,9 +57,12 @@ void slaves_init() {
 | 
			
		||||
 | 
			
		||||
void slaves_check() {
 | 
			
		||||
  int any_slave_error = 0;
 | 
			
		||||
  TSErrorKind slave_error = TS_ERRORKIND_NONE;
 | 
			
		||||
 | 
			
		||||
  uint32_t now = HAL_GetTick();
 | 
			
		||||
  uint16_t min_voltage_new = 0xFFFF;
 | 
			
		||||
  int16_t max_temp_new = 0xFFFF;
 | 
			
		||||
 | 
			
		||||
  for (int i = 0; i < N_SLAVES; i++) {
 | 
			
		||||
    // Update timeout errors
 | 
			
		||||
    if (now - slaves[i].last_message >= SLAVE_TIMEOUT) {
 | 
			
		||||
@ -82,12 +85,13 @@ void slaves_check() {
 | 
			
		||||
 | 
			
		||||
    if (slaves[i].error.kind != SLAVE_ERR_NONE) {
 | 
			
		||||
      any_slave_error = 1;
 | 
			
		||||
      slave_error = (slaves[i].error.kind == SLAVE_ERR_TIMEOUT) ? TS_ERRORKIND_SLAVE_TIMEOUT : TS_ERRORKIND_SLAVE_PANIC;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  min_voltage = min_voltage_new;
 | 
			
		||||
  max_temp = max_temp_new;
 | 
			
		||||
 | 
			
		||||
  ts_sm_set_error_source(TS_ERROR_SOURCE_SLAVES, any_slave_error);
 | 
			
		||||
  ts_sm_set_error_source(TS_ERROR_SOURCE_SLAVES, slave_error, any_slave_error);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void slaves_handle_panic(const uint8_t *data) {
 | 
			
		||||
@ -111,7 +115,7 @@ void slaves_handle_panic(const uint8_t *data) {
 | 
			
		||||
  }
 | 
			
		||||
  slaves[idx].error.data = ftcan_unmarshal_unsigned(&data, 4);
 | 
			
		||||
  slaves[idx].last_message = HAL_GetTick();
 | 
			
		||||
  ts_sm_set_error_source(TS_ERROR_SOURCE_SLAVES, 1);
 | 
			
		||||
  ts_sm_set_error_source(TS_ERROR_SOURCE_SLAVES, TS_ERRORKIND_SLAVE_PANIC, 1);
 | 
			
		||||
  can_send_error(TS_ERRORKIND_SLAVE_PANIC, slave_id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -32,7 +32,7 @@ void soc_init() {
 | 
			
		||||
 | 
			
		||||
void soc_update() {
 | 
			
		||||
  uint32_t now = HAL_GetTick();
 | 
			
		||||
  if (abs(shunt_data.current) >= SOC_ESTIMATION_NO_CURRENT_THRESH) {
 | 
			
		||||
  if (shunt_data.current >= SOC_ESTIMATION_NO_CURRENT_THRESH) {
 | 
			
		||||
    last_current_time = now;
 | 
			
		||||
    if (!current_was_flowing) {
 | 
			
		||||
      soc_before_current = current_soc;
 | 
			
		||||
@ -52,7 +52,7 @@ void soc_update() {
 | 
			
		||||
    // Otherwise, use the current counter to update SoC
 | 
			
		||||
    float as_delta = shunt_data.current_counter - mAs_before_current;
 | 
			
		||||
    float soc_delta = as_delta / SOC_ESTIMATION_BATTERY_CAPACITY * 100;
 | 
			
		||||
    current_soc = soc_before_current - soc_delta;
 | 
			
		||||
    current_soc = soc_before_current + soc_delta;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										133
									
								
								Core/Src/status_led.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										133
									
								
								Core/Src/status_led.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,133 @@
 | 
			
		||||
#include "status_led.h"
 | 
			
		||||
#include "stm32f3xx_hal_gpio.h"
 | 
			
		||||
#include "ts_state_machine.h"
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#define STATUS_LED_GPIO_PORT GPIOA //TODO: change to correct values for the board
 | 
			
		||||
 | 
			
		||||
#define STATUS_LED_1_RED_PIN GPIO_PIN_10 //TODO: change to correct values for the board
 | 
			
		||||
#define STATUS_LED_1_GREEN_PIN GPIO_PIN_11
 | 
			
		||||
#define STATUS_LED_1_BLUE_PIN GPIO_PIN_12
 | 
			
		||||
 | 
			
		||||
#define STATUS_LED_2_RED_PIN GPIO_PIN_13 //TODO: change to correct values for the board
 | 
			
		||||
#define STATUS_LED_2_GREEN_PIN GPIO_PIN_14
 | 
			
		||||
#define STATUS_LED_2_BLUE_PIN GPIO_PIN_15
 | 
			
		||||
 | 
			
		||||
//TODO: change to correct values for the board
 | 
			
		||||
#error "GPIO pins for status LEDs are not set correctly"
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
    uint8_t red : 1;
 | 
			
		||||
    uint8_t green : 1;
 | 
			
		||||
    uint8_t blue : 1;
 | 
			
		||||
} LedColor;
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
    LED_1,
 | 
			
		||||
    LED_2
 | 
			
		||||
} LedId;
 | 
			
		||||
 | 
			
		||||
void status_led_init() {
 | 
			
		||||
    GPIO_InitTypeDef GPIO_InitStruct = {0};
 | 
			
		||||
 | 
			
		||||
    GPIO_InitStruct.Pin = STATUS_LED_1_RED_PIN | STATUS_LED_1_GREEN_PIN | STATUS_LED_1_BLUE_PIN | STATUS_LED_2_RED_PIN | STATUS_LED_2_GREEN_PIN | STATUS_LED_2_BLUE_PIN;
 | 
			
		||||
    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 | 
			
		||||
    GPIO_InitStruct.Pull = GPIO_NOPULL;
 | 
			
		||||
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
 | 
			
		||||
 | 
			
		||||
    HAL_GPIO_Init(STATUS_LED_GPIO_PORT, &GPIO_InitStruct);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void set_led_color(LedId id, LedColor color) {
 | 
			
		||||
    GPIO_PinState red = color.red ? GPIO_PIN_SET : GPIO_PIN_RESET;
 | 
			
		||||
    GPIO_PinState green = color.green ? GPIO_PIN_SET : GPIO_PIN_RESET;
 | 
			
		||||
    GPIO_PinState blue = color.blue ? GPIO_PIN_SET : GPIO_PIN_RESET;
 | 
			
		||||
 | 
			
		||||
    switch (id) {
 | 
			
		||||
        case LED_1:
 | 
			
		||||
            HAL_GPIO_WritePin(STATUS_LED_GPIO_PORT, STATUS_LED_1_RED_PIN, red);
 | 
			
		||||
            HAL_GPIO_WritePin(STATUS_LED_GPIO_PORT, STATUS_LED_1_GREEN_PIN, green);
 | 
			
		||||
            HAL_GPIO_WritePin(STATUS_LED_GPIO_PORT, STATUS_LED_1_BLUE_PIN, blue);
 | 
			
		||||
            break;
 | 
			
		||||
        case LED_2:
 | 
			
		||||
            HAL_GPIO_WritePin(STATUS_LED_GPIO_PORT, STATUS_LED_2_RED_PIN, red);
 | 
			
		||||
            HAL_GPIO_WritePin(STATUS_LED_GPIO_PORT, STATUS_LED_2_GREEN_PIN, green);
 | 
			
		||||
            HAL_GPIO_WritePin(STATUS_LED_GPIO_PORT, STATUS_LED_2_BLUE_PIN, blue);
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
  * @brief Sets the status LEDs to the given state
 | 
			
		||||
  * 
 | 
			
		||||
  * @param state The state to set the LEDs to
 | 
			
		||||
  *
 | 
			
		||||
  * State -> Color mapping:
 | 
			
		||||
  * TS_INACTIVE       -> LED_1:   off, LED_2: off
 | 
			
		||||
  * TS_ACTIVE         -> LED_1:  blue, LED_2: off
 | 
			
		||||
  * TS_PRECHARGE      -> LED_1:  blue, LED_2: cyan
 | 
			
		||||
  * TS_DISCHARGE      -> LED_1:  blue, LED_2: magenta
 | 
			
		||||
  * TS_ERROR          -> LED_1:   red, LED_2: <see below>
 | 
			
		||||
  * TS_CHARGING_CHECK -> LED_1: green, LED_2: cyan
 | 
			
		||||
  * TS_CHARGING       -> LED_1: green, LED_2: off
 | 
			
		||||
  *
 | 
			
		||||
  * Error -> LED_2 mapping:
 | 
			
		||||
  * TS_ERRORKIND_NONE              -> off
 | 
			
		||||
  * TS_ERRORKIND_SLAVE_TIMEOUT     -> blue
 | 
			
		||||
  * TS_ERRORKIND_SLAVE_PANIC       -> magenta
 | 
			
		||||
  * TS_ERRORKIND_SHUNT_TIMEOUT     -> green
 | 
			
		||||
  * TS_ERRORKIND_SHUNT_OVERCURRENT -> yellow
 | 
			
		||||
  * TS_ERRORKIND_SHUNT_OVERTEMP    -> red
 | 
			
		||||
  */
 | 
			
		||||
 | 
			
		||||
void status_led_state(TSState state, TSErrorKind error) {
 | 
			
		||||
    switch (state) {
 | 
			
		||||
        case TS_INACTIVE:
 | 
			
		||||
            set_led_color(LED_1, (LedColor) {.red = 0, .green = 0, .blue = 0});
 | 
			
		||||
            set_led_color(LED_2, (LedColor) {.red = 0, .green = 0, .blue = 0});
 | 
			
		||||
            break;
 | 
			
		||||
        case TS_ACTIVE:
 | 
			
		||||
            set_led_color(LED_1, (LedColor) {.red = 0, .green = 0, .blue = 1});
 | 
			
		||||
            set_led_color(LED_2, (LedColor) {.red = 0, .green = 0, .blue = 0});
 | 
			
		||||
            break;
 | 
			
		||||
        case TS_PRECHARGE:
 | 
			
		||||
            set_led_color(LED_1, (LedColor) {.red = 0, .green = 0, .blue = 1});
 | 
			
		||||
            set_led_color(LED_2, (LedColor) {.red = 0, .green = 1, .blue = 1});
 | 
			
		||||
            break;
 | 
			
		||||
        case TS_DISCHARGE:
 | 
			
		||||
            set_led_color(LED_1, (LedColor) {.red = 0, .green = 0, .blue = 1});
 | 
			
		||||
            set_led_color(LED_2, (LedColor) {.red = 1, .green = 0, .blue = 1});
 | 
			
		||||
            break;
 | 
			
		||||
        case TS_ERROR:
 | 
			
		||||
            set_led_color(LED_1, (LedColor) {.red = 1, .green = 0, .blue = 0});
 | 
			
		||||
            switch (error) {
 | 
			
		||||
                case TS_ERRORKIND_NONE:
 | 
			
		||||
                    set_led_color(LED_2, (LedColor) {.red = 0, .green = 0, .blue = 0});
 | 
			
		||||
                    break;
 | 
			
		||||
                case TS_ERRORKIND_SLAVE_TIMEOUT:
 | 
			
		||||
                    set_led_color(LED_2, (LedColor) {.red = 0, .green = 0, .blue = 1});
 | 
			
		||||
                    break;
 | 
			
		||||
                case TS_ERRORKIND_SLAVE_PANIC:
 | 
			
		||||
                    set_led_color(LED_2, (LedColor) {.red = 1, .green = 0, .blue = 1});
 | 
			
		||||
                    break;
 | 
			
		||||
                case TS_ERRORKIND_SHUNT_TIMEOUT:
 | 
			
		||||
                    set_led_color(LED_2, (LedColor) {.red = 0, .green = 1, .blue = 0});
 | 
			
		||||
                    break;
 | 
			
		||||
                case TS_ERRORKIND_SHUNT_OVERCURRENT:
 | 
			
		||||
                    set_led_color(LED_2, (LedColor) {.red = 1, .green = 1, .blue = 0});
 | 
			
		||||
                    break;
 | 
			
		||||
                case TS_ERRORKIND_SHUNT_OVERTEMP:
 | 
			
		||||
                    set_led_color(LED_2, (LedColor) {.red = 1, .green = 0, .blue = 0});
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        case TS_CHARGING_CHECK:
 | 
			
		||||
            set_led_color(LED_1, (LedColor) {.red = 0, .green = 1, .blue = 0});
 | 
			
		||||
            set_led_color(LED_2, (LedColor) {.red = 0, .green = 1, .blue = 1});
 | 
			
		||||
            break;
 | 
			
		||||
        case TS_CHARGING:
 | 
			
		||||
            set_led_color(LED_1, (LedColor) {.red = 0, .green = 1, .blue = 0});
 | 
			
		||||
            set_led_color(LED_2, (LedColor) {.red = 0, .green = 0, .blue = 0});
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -4,6 +4,7 @@
 | 
			
		||||
#include "shunt_monitoring.h"
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
#include "stm32f3xx_hal_gpio.h"
 | 
			
		||||
#include "status_led.h"
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
TSStateHandle ts_state;
 | 
			
		||||
@ -15,11 +16,11 @@ static uint32_t discharge_begin_timestamp = 0;
 | 
			
		||||
void ts_sm_init() {
 | 
			
		||||
  ts_state.current_state = TS_INACTIVE;
 | 
			
		||||
  ts_state.target_state = TS_INACTIVE;
 | 
			
		||||
  ts_state.error = 0;
 | 
			
		||||
  ts_state.error_source = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ts_sm_update() {
 | 
			
		||||
  if (ts_state.error) {
 | 
			
		||||
  if (ts_state.error_source) {
 | 
			
		||||
    ts_state.current_state = TS_ERROR;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -48,6 +49,7 @@ void ts_sm_update() {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ts_sm_set_relay_positions(ts_state.current_state);
 | 
			
		||||
  status_led_state(ts_state.current_state, (TSErrorKind) ts_state.error_type);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TSState ts_sm_update_inactive() {
 | 
			
		||||
@ -89,7 +91,7 @@ TSState ts_sm_update_precharge() {
 | 
			
		||||
    uint32_t now = HAL_GetTick();
 | 
			
		||||
    if (precharge_95_reached_timestamp == 0) {
 | 
			
		||||
      precharge_95_reached_timestamp = now;
 | 
			
		||||
    } else if (now - precharge_95_reached_timestamp >= PRECHARGE_95_DURATION) {
 | 
			
		||||
    } else if ((now - precharge_95_reached_timestamp) >= PRECHARGE_95_DURATION) {
 | 
			
		||||
      precharge_95_reached_timestamp = 0;
 | 
			
		||||
      return TS_ACTIVE;
 | 
			
		||||
    }
 | 
			
		||||
@ -108,7 +110,7 @@ TSState ts_sm_update_discharge() {
 | 
			
		||||
 | 
			
		||||
TSState ts_sm_update_error() {
 | 
			
		||||
  static uint32_t no_error_since = 0;
 | 
			
		||||
  if (ts_state.error == 0) {
 | 
			
		||||
  if (ts_state.error_source == 0) {
 | 
			
		||||
    uint32_t now = HAL_GetTick();
 | 
			
		||||
    if (no_error_since == 0) {
 | 
			
		||||
      no_error_since = now;
 | 
			
		||||
@ -220,10 +222,12 @@ void ts_sm_handle_ams_in(const uint8_t *data) {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ts_sm_set_error_source(uint32_t flag, int state) {
 | 
			
		||||
  if (state) {
 | 
			
		||||
    ts_state.error |= flag;
 | 
			
		||||
void ts_sm_set_error_source(TSErrorSource source, TSErrorKind error_type, bool is_errored) {
 | 
			
		||||
  if (is_errored) {
 | 
			
		||||
    ts_state.error_source |= source;
 | 
			
		||||
    ts_state.error_type = error_type;
 | 
			
		||||
  } else {
 | 
			
		||||
    ts_state.error &= ~flag;
 | 
			
		||||
    ts_state.error_source &= ~source;
 | 
			
		||||
    ts_state.error_type = ~error_type;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -40,7 +40,7 @@ cxxDefinitionsFile:
 | 
			
		||||
asDefinitionsFile:
 | 
			
		||||
 | 
			
		||||
# Compiler flags
 | 
			
		||||
cFlags: []
 | 
			
		||||
cFlags: [-Wall, -Wextra, -Wno-unused-parameter]
 | 
			
		||||
cxxFlags: []
 | 
			
		||||
assemblyFlags: []
 | 
			
		||||
linkerFlags:
 | 
			
		||||
 | 
			
		||||
@ -43,6 +43,7 @@ Core/Src/main.c \
 | 
			
		||||
Core/Src/shunt_monitoring.c \
 | 
			
		||||
Core/Src/slave_monitoring.c \
 | 
			
		||||
Core/Src/soc_estimation.c \
 | 
			
		||||
Core/Src/status_led.c \
 | 
			
		||||
Core/Src/stm32f3xx_hal_msp.c \
 | 
			
		||||
Core/Src/stm32f3xx_it.c \
 | 
			
		||||
Core/Src/system_stm32f3xx.c \
 | 
			
		||||
@ -86,7 +87,7 @@ PREFIX = arm-none-eabi-
 | 
			
		||||
POSTFIX = "
 | 
			
		||||
# The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx)
 | 
			
		||||
# either it can be added to the PATH environment variable.
 | 
			
		||||
GCC_PATH="/home/jasper/.config/Code/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/arm-none-eabi-gcc/11.3.1-1.1.2/.content/bin
 | 
			
		||||
GCC_PATH="/home/kbracher/.vscode-server/data/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/arm-none-eabi-gcc/12.3.1-1.2.1/.content/bin
 | 
			
		||||
ifdef GCC_PATH
 | 
			
		||||
CXX = $(GCC_PATH)/$(PREFIX)g++$(POSTFIX)
 | 
			
		||||
CC = $(GCC_PATH)/$(PREFIX)gcc$(POSTFIX)
 | 
			
		||||
@ -162,7 +163,7 @@ CXXFLAGS += -g -gdwarf -ggdb
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
# Add additional flags
 | 
			
		||||
CFLAGS += 
 | 
			
		||||
CFLAGS += -Wall -Wextra -Wno-unused-parameter 
 | 
			
		||||
ASFLAGS += 
 | 
			
		||||
CXXFLAGS += 
 | 
			
		||||
 | 
			
		||||
@ -242,13 +243,13 @@ $(BUILD_DIR):
 | 
			
		||||
# flash
 | 
			
		||||
#######################################
 | 
			
		||||
flash: $(BUILD_DIR)/$(TARGET).elf
 | 
			
		||||
	"/home/jasper/.config/Code/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/openocd/0.11.0-5.1/.content/bin/openocd" -f ./openocd.cfg -c "program $(BUILD_DIR)/$(TARGET).elf verify reset exit"
 | 
			
		||||
	"/home/kbracher/.vscode-server/data/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/openocd/0.12.0-2.1/.content/bin/openocd" -f ./openocd.cfg -c "program $(BUILD_DIR)/$(TARGET).elf verify reset exit"
 | 
			
		||||
 | 
			
		||||
#######################################
 | 
			
		||||
# erase
 | 
			
		||||
#######################################
 | 
			
		||||
erase: $(BUILD_DIR)/$(TARGET).elf
 | 
			
		||||
	"/home/jasper/.config/Code/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/openocd/0.11.0-5.1/.content/bin/openocd" -f ./openocd.cfg -c "init; reset halt; stm32f3x mass_erase 0; exit"
 | 
			
		||||
	"/home/kbracher/.vscode-server/data/User/globalStorage/bmd.stm32-for-vscode/@xpack-dev-tools/openocd/0.12.0-2.1/.content/bin/openocd" -f ./openocd.cfg -c "init; reset halt; stm32f3x mass_erase 0; exit"
 | 
			
		||||
 | 
			
		||||
#######################################
 | 
			
		||||
# clean up
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										1159
									
								
								compile_commands.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1159
									
								
								compile_commands.json
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user