added sm_test_cycle_states();
This commit is contained in:
		@ -1,11 +1,8 @@
 | 
			
		||||
#include "state_machine.h"
 | 
			
		||||
#include "ADBMS_LL_Driver.h"
 | 
			
		||||
#include "TMP1075.h"
 | 
			
		||||
#include "common_defs.h"
 | 
			
		||||
#include <math.h>
 | 
			
		||||
#include "stm32f3xx_hal.h"
 | 
			
		||||
 | 
			
		||||
StateHandle state;
 | 
			
		||||
static int16_t timestamp;
 | 
			
		||||
static uint32_t timestamp;
 | 
			
		||||
 | 
			
		||||
void sm_init(){
 | 
			
		||||
  state.current_state = STATE_INACTIVE;
 | 
			
		||||
@ -16,7 +13,7 @@ void sm_init(){
 | 
			
		||||
void sm_update(){
 | 
			
		||||
  RELAY_BAT_SIDE_VOLTAGE = module.auxVoltages[0];
 | 
			
		||||
  RELAY_ESC_SIDE_VOLTAGE = module.auxVoltages[1];
 | 
			
		||||
  CURRENT_MEASUREMENT_VOLTAGE = module.auxVoltages[2];
 | 
			
		||||
  CURRENT_MEASUREMENT = module.auxVoltages[2];
 | 
			
		||||
  
 | 
			
		||||
  switch (state.current_state) {
 | 
			
		||||
    case STATE_INACTIVE:
 | 
			
		||||
@ -232,3 +229,30 @@ void sm_check_errors(){
 | 
			
		||||
    state.error_source = (1 << 10);
 | 
			
		||||
  }
 | 
			
		||||
}  
 | 
			
		||||
 | 
			
		||||
void sm_test_cycle_states(){
 | 
			
		||||
  if (timestamp > HAL_GetTick())
 | 
			
		||||
    return;
 | 
			
		||||
  switch (state.current_state) {
 | 
			
		||||
    case STATE_INACTIVE:
 | 
			
		||||
      state.current_state = STATE_PRECHARGE;
 | 
			
		||||
      timestamp = HAL_GetTick() + 10000;
 | 
			
		||||
      return;
 | 
			
		||||
    case STATE_PRECHARGE:
 | 
			
		||||
      state.current_state = STATE_READY;
 | 
			
		||||
      timestamp = HAL_GetTick() + 10000;
 | 
			
		||||
      return;
 | 
			
		||||
    case STATE_READY:
 | 
			
		||||
      state.current_state = STATE_ACTIVE;
 | 
			
		||||
      timestamp = HAL_GetTick() + 10000;
 | 
			
		||||
      return;
 | 
			
		||||
    case STATE_ACTIVE:
 | 
			
		||||
      state.current_state = STATE_DISCHARGE;
 | 
			
		||||
      timestamp = HAL_GetTick() + 10000;
 | 
			
		||||
      return;
 | 
			
		||||
    case STATE_DISCHARGE:
 | 
			
		||||
      state.current_state = STATE_INACTIVE;
 | 
			
		||||
      timestamp = HAL_GetTick() + 10000;
 | 
			
		||||
      return;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user