From 42b44ee5fb9503f99917f37d09017d6d33d57b89 Mon Sep 17 00:00:00 2001 From: caiodasilva2005 Date: Thu, 22 Feb 2024 20:36:37 -0500 Subject: [PATCH] Fixed issues with monitor functions and threads --- Core/Src/main.c | 11 +++++++---- MSB/api/monitor_msb.h | 6 +++--- MSB/monitor_msb.c | 22 +++++++++++++++++++--- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Core/Src/main.c b/Core/Src/main.c index 2d6141e..223e619 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -111,8 +111,11 @@ int main(void) MX_FDCAN1_Init(); MX_I2C3_Init(); MX_USART2_UART_Init(); - /* USER CODE BEGIN 2 */ + /* USER CODE BEGIN 2 */ + msb_temp_t *temp_data; + msb_knuckle_t *knuckle_data; + msb_central_t *central_data; /* USER CODE END 2 */ /* Init scheduler */ @@ -139,9 +142,9 @@ int main(void) defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes); /* USER CODE BEGIN RTOS_THREADS */ - osThreadId_t tempThread = osThreadNew(monitor_temp_msb, NULL, NULL); - osThreadId_t imuThread = osThreadNew(monitor_knuckle_msb, NULL, NULL); - osThreadId_t centralThread = osThreadNew(monitor_central_msb, NULL, NULL); + osThreadId_t tempThread = osThreadNew(monitor_temp_msb, temp_data, NULL); + osThreadId_t imuThread = osThreadNew(monitor_knuckle_msb, knuckle_data, NULL); + osThreadId_t centralThread = osThreadNew(monitor_central_msb, central_data, NULL); /* USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_EVENTS */ diff --git a/MSB/api/monitor_msb.h b/MSB/api/monitor_msb.h index 5941d39..c088abc 100644 --- a/MSB/api/monitor_msb.h +++ b/MSB/api/monitor_msb.h @@ -5,8 +5,8 @@ #include "msb_knuckle.h" #include "msb_central.h" -void monitor_temp_msb(msb_temp_t* msb, temp_data_t* out); -void monitor_knuckle_msb(msb_knuckle_t* msb, knuckle_data_t* out); -void monitor_central_msb(msb_central_t* msb, central_data_t* msb_central_data); +void monitor_temp_msb(void* arg); +void monitor_knuckle_msb(void* arg); +void monitor_central_msb(void* arg); #endif \ No newline at end of file diff --git a/MSB/monitor_msb.c b/MSB/monitor_msb.c index df84130..78159a0 100644 --- a/MSB/monitor_msb.c +++ b/MSB/monitor_msb.c @@ -1,9 +1,14 @@ #include "cmsis_os.h" #include +#include #include "api/monitor_msb.h" -void monitor_temp_msb(msb_temp_t* msb, temp_data_t* out) { +void monitor_temp_msb(void* arg) { + + msb_temp_t* msb = (msb_temp_t*)arg; + + temp_data_t* out = malloc(sizeof(temp_data_t)); char status[100]; for (;;) { @@ -15,9 +20,14 @@ void monitor_temp_msb(msb_temp_t* msb, temp_data_t* out) { push_can_queue(status); osDelay(500); } + free(out); //Check if this works } -void monitor_knuckle_msb(msb_knuckle_t* msb, knuckle_data_t* out) { +void monitor_knuckle_msb(void* arg) { + + msb_knuckle_t* msb = (msb_knuckle_t*)arg; + + knuckle_data_t* out = malloc(sizeof(knuckle_data_t)); char status[100]; for (;;) { @@ -30,9 +40,14 @@ void monitor_knuckle_msb(msb_knuckle_t* msb, knuckle_data_t* out) { push_can_queue(status); osDelay(500); } + free(out); //Check if this works } -void monitor_central_msb(msb_central_t* msb, central_data_t* out) { +void monitor_central_msb(void* arg) { + + msb_central_t* msb = (msb_central_t*)arg; + + central_data_t* out = malloc(sizeof(msb_central_t)); char status[100]; for (;;) { @@ -53,6 +68,7 @@ void monitor_central_msb(msb_central_t* msb, central_data_t* out) { push_can_queue(status); osDelay(500); } + free(out); //Check if this works }