diff --git a/Core/Inc/state_machine.h b/Core/Inc/state_machine.h index 714a29c..e48eb1f 100644 --- a/Core/Inc/state_machine.h +++ b/Core/Inc/state_machine.h @@ -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" @@ -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 */ diff --git a/Core/Src/main.c b/Core/Src/main.c index b8d5865..d026c71 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -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 */ diff --git a/Core/Src/monitor.c b/Core/Src/monitor.c index 6312038..7b98dca 100644 --- a/Core/Src/monitor.c +++ b/Core/Src/monitor.c @@ -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); diff --git a/Core/Src/state_machine.c b/Core/Src/state_machine.c index f3c9dec..1846e15 100644 --- a/Core/Src/state_machine.c +++ b/Core/Src/state_machine.c @@ -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 #include +#include #define STATE_TRANS_QUEUE_SIZE 4 #define STATE_TRANSITION_FLAG 1U @@ -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,