Skip to content

Commit

Permalink
FWXV-214: pd smoke tests (#199)
Browse files Browse the repository at this point in the history
* updated smoke to use pd output config

* refactoring

* small typo fix

* pd sense working

* rebase

* refactoring

* small typo fix

* fix lint errors

* minor fix

* add comment

* merge front and rear pd projects

* updated smoke to use pd output config

* refactoring

* small typo fix

* pd sense working

* rebase

* refactoring

* small typo fix

* minor fix

* minor fix
  • Loading branch information
devAdhiraj authored Nov 13, 2023
1 parent f5195a3 commit 20e82bb
Show file tree
Hide file tree
Showing 33 changed files with 249 additions and 126 deletions.
9 changes: 0 additions & 9 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,6 @@ AddOption(
action='store'
)

# Only for the power distribution project to specify front or rear PD

AddOption(
'--location',
dest='location',
type='string',
action='store',
default='front',
)

# Adding Memory Report Argument to Environment Flags
# Note platform needs to be explicitly set to arm
Expand Down
3 changes: 1 addition & 2 deletions libraries/codegen/boards/boards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
- charger
- motor_controller
- pedal
- power_distribution_front
- power_distribution_rear
- power_distribution
- power_select
- solar_5_mppts
- solar_6_mppts
Expand Down
22 changes: 6 additions & 16 deletions libraries/codegen/boards/centre_console.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
set_bms_power:
id: 4
target:
power_distribution_front:
watchdog: 0
power_distribution_rear:
power_distribution:
watchdog: 0
critical: true
signals:
Expand All @@ -25,9 +23,7 @@
set_power_state:
id: 5
target:
power_distribution_front:
watchdog: 0
power_distribution_rear:
power_distribution:
watchdog: 0
critical: true
signals:
Expand Down Expand Up @@ -59,9 +55,7 @@
watchdog: 0
pedal:
watchdog: 0
power_distribution_front:
watchdog: 0
power_distribution_rear :
power_distribution:
watchdog: 0
critical: true
signals:
Expand All @@ -75,9 +69,7 @@
watchdog: 0
pedal:
watchdog: 0
power_distribution_front:
watchdog: 0
power_distribution_rear:
power_distribution:
watchdog: 0
critical: true
signals:
Expand All @@ -91,9 +83,7 @@
watchdog: 0
pedal:
watchdog: 0
power_distribution_front:
watchdog: 0
power_distribution_rear:
power_distribution:
watchdog: 0
critical: true
signals:
Expand Down Expand Up @@ -187,7 +177,7 @@
power_info:
id: 47
target:
power_distribution_front:
power_distribution:
watchdog: 0
signals:
hazard_state:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
signals:
signal1:
length: 8

front_current_measurement:
current_measurement:
id: 54
target:
centre_console:
Expand All @@ -29,8 +28,7 @@
length: 16
current:
length: 16

front_pd_fault:
pd_fault:
id: 62
target:
centre_console:
Expand All @@ -50,4 +48,11 @@
length: 8
lights_state:
length: 8

lights_sync:
id: 23
target:
lights_front:
watchdog: 0
signals:
signal1:
length: 8
46 changes: 0 additions & 46 deletions libraries/codegen/boards/power_distribution_rear.yaml

This file was deleted.

4 changes: 1 addition & 3 deletions libraries/codegen/boards/steering.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ Messages:
steering_info:
id: 21 # or some number
target:
power_distribution_front:
watchdog: 0
power_distribution_back:
power_distribution:
watchdog: 0
motor_controller:
watchdog: 0
Expand Down
13 changes: 11 additions & 2 deletions libraries/ms-common/src/arm/adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,18 @@ StatusCode adc_init(void) {
while (ADC_GetCalibrationStatus(ADC1)) {
}

// Initialize static variables
sem_init(&s_adc_status.converting, 1, 0);
DMA_ClearITPendingBit(DMA1_IT_TC1);
DMA_ClearITPendingBit(DMA1_IT_HT1);
DMA_ClearITPendingBit(DMA1_IT_GL1);

// Enable interrupts for the end of each full conversion
stm32f10x_interrupt_nvic_enable(DMA1_Channel1_IRQn, INTERRUPT_PRIORITY_LOW);

// Initialize static variables
sem_init(&s_adc_status.converting, 1, 0);
// goes into ISR after enabling interrupts so sem_wait here to reset semaphore
status_ok_or_return(sem_wait(&s_adc_status.converting, ADC_TIMEOUT_MS));

s_adc_status.initialized = true;

return STATUS_CODE_OK;
Expand Down Expand Up @@ -262,5 +269,7 @@ void DMA1_Channel1_IRQHandler() {
BaseType_t higher_prio;
xSemaphoreGiveFromISR(s_adc_status.converting.handle, &higher_prio);
DMA_ClearITPendingBit(DMA1_IT_TC1);
DMA_ClearITPendingBit(DMA1_IT_HT1);
DMA_ClearITPendingBit(DMA1_IT_GL1);
portYIELD_FROM_ISR(higher_prio);
}
4 changes: 2 additions & 2 deletions libraries/ms-drivers/inc/bts_load_switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ StatusCode bts_output_enable_output(BtsLoadSwitchOutput *loadSwitch);
// Disable output by pulling the IN pin low.
StatusCode bts_output_disable_output(BtsLoadSwitchOutput *loadSwitch);

// Returns whether the output is enabled or disabled.
StatusCode bts_output_get_enabled(BtsLoadSwitchOutput *loadSwitch);
// Stores the output state of the load in the pin_state variable. 0 for disabled, 1 for enabled
StatusCode bts_output_get_output_enabled(BtsLoadSwitchOutput *loadSwitch, uint8_t *pin_state);

// Read the latest current input current measurement, in mA.
StatusCode bts_output_get_current(BtsLoadSwitchOutput *loadSwitch, uint16_t *current);
28 changes: 17 additions & 11 deletions libraries/ms-drivers/src/bts_load_switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,23 @@ static StatusCode prv_bts_switch_disable_pin(Bts7xxxPin *pin) {
}

// Broad function to get whether the pin passed in is enabled.
static StatusCode prv_bts_switch_get_pin_enabled(Bts7xxxPin *pin) {
static StatusCode prv_bts_switch_get_pin_enabled(Bts7xxxPin *pin, uint8_t *pin_state) {
if (pin->pin_type == BTS7XXX_PIN_STM32) {
GpioState pin_state;
StatusCode status = gpio_get_state(pin->pin_stm32, &pin_state);
return (pin_state == GPIO_STATE_HIGH);
GpioState gpio_pin_state;
status_ok_or_return(gpio_get_state(pin->pin_stm32, &gpio_pin_state));
*pin_state = (gpio_pin_state == GPIO_STATE_HIGH);
} else {
Pca9555GpioState pin_state;
StatusCode status = pca9555_gpio_get_state(pin->pin_pca9555, &pin_state);
return (pin_state == PCA9555_GPIO_STATE_HIGH);
Pca9555GpioState pca_pin_state;
status_ok_or_return(pca9555_gpio_get_state(pin->pin_pca9555, &pca_pin_state));
*pin_state = (pca_pin_state == PCA9555_GPIO_STATE_HIGH);
}
return STATUS_CODE_OK;
}

static StatusCode prv_bts_switch_select_state(BtsLoadSwitchOutput *load_switch) {
if (load_switch->select_pin == NULL) {
return STATUS_CODE_OK; // if bts switch doesn't have select pin
}
switch (load_switch->select_pin->pin_type) {
case BTS7XXX_PIN_STM32:
return gpio_set_state(load_switch->select_pin->pin_stm32,
Expand All @@ -63,8 +67,9 @@ static StatusCode prv_bts_switch_select_state(BtsLoadSwitchOutput *load_switch)
}

StatusCode bts_output_init(BtsLoadSwitchOutput *load_switch) {
status_ok_or_return(gpio_init_pin(load_switch->sense_pin, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW));
status_ok_or_return(prv_bts_switch_init_pin(load_switch->select_pin));
if (load_switch->select_pin != NULL) {
status_ok_or_return(prv_bts_switch_init_pin(load_switch->select_pin));
}
return prv_bts_switch_init_pin(load_switch->enable_pin);
}

Expand All @@ -76,11 +81,12 @@ StatusCode bts_output_disable_output(BtsLoadSwitchOutput *load_switch) {
return prv_bts_switch_disable_pin(load_switch->enable_pin);
}

StatusCode bts_output_get_output_enabled(BtsLoadSwitchOutput *load_switch) {
return prv_bts_switch_get_pin_enabled(load_switch->enable_pin);
StatusCode bts_output_get_output_enabled(BtsLoadSwitchOutput *load_switch, uint8_t *pin_state) {
return prv_bts_switch_get_pin_enabled(load_switch->enable_pin, pin_state);
}

StatusCode bts_output_get_current(BtsLoadSwitchOutput *load_switch, uint16_t *current) {
status_ok_or_return(prv_bts_switch_select_state(load_switch));
status_ok_or_return(adc_run());
return adc_read_converted(*(load_switch->sense_pin), current);
}
3 changes: 1 addition & 2 deletions projects/centre_console/inc/power_fsm_can_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
#define AUX_FAULT_BITS 0xE0

// PD messages (Todo)
#define PD_FRONT_FAULT 0x00
#define PD_REAR_FAULT 0x00
#define PD_FAULT 0x00

// BMS send power notification (Todo)
#define SET_BMS_POWER_NOTIFY 0x01
Expand Down
8 changes: 3 additions & 5 deletions projects/centre_console/src/power_fsm_sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,11 @@ void power_fsm_send_pd_bms_output(void *context) {

void power_fsm_send_pd_bms_input(Fsm *fsm, void *context) {
// = (PowerFsmContext *)context;
FSM_CHECK_DATA_RECV(fsm, power_context, get_received_rear_pd_fault());
FSM_CHECK_DATA_RECV(fsm, power_context, get_received_front_pd_fault());
FSM_CHECK_DATA_RECV(fsm, power_context, get_received_pd_fault());

uint8_t rear_fault = get_rear_pd_fault_fault_data();
uint8_t front_fault = get_front_pd_fault_fault_data();
uint8_t pd_fault = get_pd_fault_fault_data();

if (rear_fault == PD_REAR_FAULT && front_fault == PD_FRONT_FAULT) {
if (pd_fault == PD_FAULT) {
// Reset cycle counter
s_cycle_timeout = CYCLES_TIMEOUT;
// Transition to next state
Expand Down
6 changes: 2 additions & 4 deletions projects/centre_console/test/test_power_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ void test_off_to_main(void) {
TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_SEND_PD_BMS);

// Transition to POWER_FSM_CONFIRM_BATTERY_STATUS
g_rx_struct.rear_pd_fault_fault_data = PD_REAR_FAULT;
g_rx_struct.front_pd_fault_fault_data = PD_FRONT_FAULT;
g_rx_struct.received_rear_pd_fault = true;
g_rx_struct.received_front_pd_fault = true;
g_rx_struct.pd_fault_fault_data = PD_FAULT;
g_rx_struct.received_pd_fault = true;
fsm_run_cycle(power);
wait_tasks(1);
TEST_ASSERT_EQUAL(power_fsm->curr_state, POWER_FSM_CONFIRM_BATTERY_STATUS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@
-->
# power_distribution

The power distribution project consists of two different boards, front and rear.
## Power Distribution Front
## Power Distribution

## Power Distribution Rear
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ typedef enum {
REAR_OUTPUT_SOLAR_SENSE,
REAR_OUTPUT_BPS_STROBE_LIGHT,
REAR_OUTPUT_FAN_1,
LEFT_REAR_CAMERA,
RIGHT_CAMERA,
// REAR_OUTPUT_FAN_2,
// REAR_OUTPUT_LEFT_REAR_TURN_LIGHT,
// REAR_OUTPUT_RIGHT_REAR_TURN_LIGHT,
Expand Down Expand Up @@ -87,6 +89,7 @@ typedef enum {
OUTPUT_GROUP_LEFT_TURN,
OUTPUT_GROUP_RIGHT_TURN,
OUTPUT_GROUP_HAZARD,
OUTPUT_GROUP_TEST,
NUM_OUTPUT_GROUPS,
} OutputGroup;

Expand All @@ -99,7 +102,7 @@ typedef struct OutputGroupDef {
Output outputs[];
} OutputGroupDef;

extern const BtsLoadSwitchOutput g_output_config[NUM_OUTPUTS];
extern BtsLoadSwitchOutput g_output_config[NUM_OUTPUTS];
extern const OutputGroupDef *g_output_group_map[NUM_OUTPUT_GROUPS];

// Initializes all outputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#define PD_I2C_PORT I2C_PORT_1
#define PD_PCA9555_I2C_ADDRESS_0 0x24
#define PD_PCA9555_I2C_ADDRESS_1 0x26
#define PD_I2C_SDA \
{ GPIO_PORT_B, 9 }
#define PD_I2C_SCL \
{ GPIO_PORT_B, 8 }
#define PCA9555_IO_INT1 \
{ GPIO_PORT_B, 14 }
#define PCA9555_IO_INT2 \
Expand Down Expand Up @@ -118,3 +122,12 @@

#define REAR_PIN_FAN_1_2_DSEL \
{ PD_PCA9555_I2C_ADDRESS_1, PCA9555_PIN_IO0_6 }

#define LEFT_REAR_CAMERA_EN \
{ PD_PCA9555_I2C_ADDRESS_0, PCA9555_PIN_IO1_6 }

#define RIGHT_CAMERA_EN \
{ PD_PCA9555_I2C_ADDRESS_0, PCA9555_PIN_IO0_7 }

#define REAR_RIGHT_CAMERA_DSEL \
{ PD_PCA9555_I2C_ADDRESS_0, PCA9555_PIN_IO1_7 }
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "lights_fsm.h"

#include "power_distribution_front_getters.h"
#include "power_distribution_getters.h"

// Placeholder GPIO Address, will be updated
GpioAddress RIGHT_LIGHT_ADDR = { .port = GPIO_PORT_A, .pin = 11 };
Expand Down
File renamed without changes.
Loading

0 comments on commit 20e82bb

Please sign in to comment.