Skip to content

Commit

Permalink
190 structs for task arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabramz committed Aug 9, 2024
1 parent 435be9c commit f3f5415
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
7 changes: 7 additions & 0 deletions Core/Inc/state_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "cmsis_os.h"
#include "fault.h"
#include "nero.h"
#include "dti.h"
#include "pdu.h"

/*
* This is a hierarchical state machine, with "drive modes"
Expand Down Expand Up @@ -45,6 +47,11 @@ typedef struct {
extern osThreadId_t sm_director_handle;
extern const osThreadAttr_t sm_director_attributes;

typedef struct {
pdu_t *pdu;
dti_t *mc;
} sm_director_args_t;

void vStateMachineDirector(void *pv_params);

/* Retrieves the current functional state */
Expand Down
10 changes: 4 additions & 6 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,11 @@ int main(void)
fault_handle = osThreadNew(vFaultHandler, NULL, &fault_handle_attributes);
assert(fault_handle);

uint32_t *state_machine_args = malloc(sizeof(uint32_t) * 2);

state_machine_args[0] = (uint32_t) pdu;
state_machine_args[1] = (uint32_t) mc;
sm_director_handle = osThreadNew(vStateMachineDirector, state_machine_args, &sm_director_attributes);
sm_director_args_t *sm_args = malloc(sizeof(sm_director_args_t));
sm_args->pdu = pdu;
sm_args->mc = mc;
sm_director_handle = osThreadNew(vStateMachineDirector, sm_args, &sm_director_attributes);
assert(sm_director_handle);
free(state_machine_args);
brakelight_control_thread = osThreadNew(vBrakelightControl, pdu, &brakelight_monitor_attributes);;
assert(brakelight_control_thread);
/* USER CODE END RTOS_THREADS */
Expand Down
1 change: 1 addition & 0 deletions Core/Src/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ void vDataCollection(void *pv_params)
mpu_t *mpu = args->mpu;
pdu_t *pdu = args->pdu;
steeringio_t *wheel = args->wheel;
free(args);
static const uint8_t delay = 20;

tsms_reading_mutex = osMutexNew(NULL);
Expand Down
9 changes: 5 additions & 4 deletions Core/Src/state_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
#include "can_handler.h"
#include "fault.h"
#include "nero.h"
#include "pdu.h"
#include "queues.h"
#include "monitor.h"
#include "serial_monitor.h"
#include "nero.h"
#include "queues.h"
#include "processing.h"
#include "dti.h"
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

#define STATE_TRANS_QUEUE_SIZE 4
#define STATE_TRANSITION_FLAG 1U
Expand Down Expand Up @@ -259,8 +258,10 @@ void vStateMachineDirector(void *pv_params)

state_req_t new_state_req;

pdu_t *pdu = (pdu_t *)((uint32_t *)pv_params)[0];
dti_t *mc = (dti_t *)((uint32_t *)pv_params)[1];
sm_director_args_t *args = (sm_director_args_t *)pv_params;
pdu_t *pdu = args->pdu;
dti_t *mc = args->mc;
free(args);

for (;;) {
osThreadFlagsWait(STATE_TRANSITION_FLAG, osFlagsWaitAny,
Expand Down

0 comments on commit f3f5415

Please sign in to comment.