Skip to content

Commit

Permalink
Added task stack param and updated brake light function to prv_ function
Browse files Browse the repository at this point in the history
  • Loading branch information
vagrant committed Jan 28, 2024
1 parent a758d63 commit 4ab697c
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions libraries/ms-common/inc/fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ typedef struct Fsm {
// Creates the FSM structure with the supplied number of states
// and initializes its associated FSM task
// num_states must be a defined constant
#define FSM(name, num_fsm_states) \
Fsm *name##_fsm = &((Fsm){ \
.num_states = num_fsm_states, \
}); \
TASK(name, TASK_STACK_256) { \
_fsm_task(context); \
#define FSM(name, num_fsm_states, stack_size) \
Fsm *name##_fsm = &((Fsm){ \
.num_states = num_fsm_states, \
}); \
TASK(name, stack_size) { \
_fsm_task(context); \
}

// Creates state with associated id in a state list
Expand Down
2 changes: 1 addition & 1 deletion projects/centre_console/src/drive_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "centre_console_getters.h"
#include "centre_console_setters.h"

FSM(drive, NUM_DRIVE_STATES);
FSM(drive, NUM_DRIVE_STATES, TASK_STACK_512);

#define NUM_DRIVE_FSM_BUTTONS 3

Expand Down
2 changes: 1 addition & 1 deletion projects/fsm_demo/src/fsm1.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "notify.h"
#include "task.h"

FSM(fsm1, NUM_FSM1_STATES);
FSM(fsm1, NUM_FSM1_STATES, TASK_STACK_512);

// Input functions are executed each iteration of run_cycle, and
// Output functions are executed only when a state is transitioned to
Expand Down
2 changes: 1 addition & 1 deletion projects/fsm_demo/src/fsm2.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// FSM2 Lags one cycle behind FSM1, so it will transition to state X
// When FSM1 finishes state X
FSM(fsm2, NUM_FSM2_STATES);
FSM(fsm2, NUM_FSM2_STATES, TASK_STACK_512);

static void prv_fsm2_state0_output(void *context) {
LOG_DEBUG("Transitioned to FSM2 state0\n");
Expand Down
1 change: 0 additions & 1 deletion projects/fsm_demo/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ void run_medium_cycle() {
wait_tasks(1);
fsm_run_cycle(fsm2);
wait_tasks(1);
delay_ms(1000);
}

int main(void) {
Expand Down
19 changes: 10 additions & 9 deletions projects/power_distribution/src/lights_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
#include "outputs.h"
#include "power_distribution_getters.h"

#define brake_lights() \
if (get_pedal_output_brake_output()) \
pd_set_output_group(OUTPUT_GROUP_BRAKE, OUTPUT_STATE_ON); \
else \
prv_brake_lights() {
if (get_pedal_output_brake_output())
pd_set_output_group(OUTPUT_GROUP_BRAKE, OUTPUT_STATE_ON);
else
pd_set_output_group(OUTPUT_GROUP_BRAKE, OUTPUT_STATE_OFF);
}

// Placeholder GPIO Address, will be updated
GpioAddress RIGHT_LIGHT_ADDR = { .port = GPIO_PORT_B, .pin = 5 };
Expand All @@ -18,7 +19,7 @@ GpioAddress LEFT_LIGHT_ADDR = { .port = GPIO_PORT_A, .pin = 15 };
static SoftTimer s_timer_single;
static EELightType light_id_callback;

FSM(lights, NUM_LIGHTS_STATES);
FSM(lights, NUM_LIGHTS_STATES, TASK_STACK_512);
static OutputState left_signal_state = OUTPUT_STATE_OFF;
static OutputState right_signal_state = OUTPUT_STATE_OFF;
static LightsStateId fsm_prev_state = INIT_STATE;
Expand Down Expand Up @@ -61,7 +62,7 @@ static void prv_lights_signal_blinker(SoftTimerId id) {
}

static void prv_init_state_input(Fsm *fsm, void *context) {
brake_lights();
prv_brake_lights();
// can transition to LEFT, RIGHT, HAZARD
EELightType light_event = get_steering_info_input_lights();
HazardStatus hazard_status = get_cc_power_control_hazard_enabled();
Expand All @@ -82,7 +83,7 @@ static void prv_init_state_output(void *context) {
}

static void prv_left_signal_input(Fsm *fsm, void *context) {
brake_lights();
prv_brake_lights();
// can transition to INIT, RIGHT, HAZARD
EELightType light_event = get_steering_info_input_lights();
HazardStatus hazard_status = get_cc_power_control_hazard_enabled();
Expand All @@ -107,7 +108,7 @@ static void prv_left_signal_output(void *context) {
}

static void prv_right_signal_input(Fsm *fsm, void *context) {
brake_lights();
prv_brake_lights();
// can transition to INIT, LEFT, HAZARD
EELightType light_event = get_steering_info_input_lights();
HazardStatus hazard_status = get_cc_power_control_hazard_enabled();
Expand All @@ -132,7 +133,7 @@ static void prv_right_signal_output(void *context) {
}

static void prv_hazard_input(Fsm *fsm, void *context) {
brake_lights();
prv_brake_lights();
// can transition to INIT, BPS_FAULT
EELightType light_event = get_steering_info_input_lights();
HazardStatus hazard_status = get_cc_power_control_hazard_enabled();
Expand Down
2 changes: 1 addition & 1 deletion projects/power_distribution/src/power_seq_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
return; \
}

FSM(power_seq, NUM_POWER_STATES);
FSM(power_seq, NUM_POWER_STATES, TASK_STACK_256);

static PowerFsmContext power_context = { 0 };

Expand Down

0 comments on commit 4ab697c

Please sign in to comment.