From 73548042e94bff03cfc6fb0d7bc06168214a71e6 Mon Sep 17 00:00:00 2001 From: Evan Date: Thu, 8 Feb 2024 19:39:01 -0500 Subject: [PATCH] Simple main and CAN task --- Core/Src/main.c | 7 +-- MSB/api/msb_can.h | 11 +++++ MSB/api/msb_central.h | 15 ++++++ MSB/api/msb_common.h | 7 +++ MSB/api/msb_knuckle.h | 13 ++++++ MSB/api/msb_main.h | 7 +++ MSB/api/msb_temp.h | 13 ++++++ MSB/msb_can.c | 27 +++++++++++ MSB/msb_main.c | 22 +++++++++ Makefile | 104 +++++++++++++++++++++--------------------- 10 files changed, 170 insertions(+), 56 deletions(-) create mode 100644 MSB/api/msb_can.h create mode 100644 MSB/api/msb_central.h create mode 100644 MSB/api/msb_common.h create mode 100644 MSB/api/msb_knuckle.h create mode 100644 MSB/api/msb_main.h create mode 100644 MSB/api/msb_temp.h create mode 100644 MSB/msb_can.c create mode 100644 MSB/msb_main.c diff --git a/Core/Src/main.c b/Core/Src/main.c index fd78886..4eb7fbe 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -22,7 +22,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ - +#include "../../MSB/api/msb_main.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -440,10 +440,7 @@ void StartDefaultTask(void *argument) { /* USER CODE BEGIN 5 */ /* Infinite loop */ - for(;;) - { - osDelay(1); - } + start_msb(); /* USER CODE END 5 */ } diff --git a/MSB/api/msb_can.h b/MSB/api/msb_can.h new file mode 100644 index 0000000..f5b17b9 --- /dev/null +++ b/MSB/api/msb_can.h @@ -0,0 +1,11 @@ + +#ifndef MSB_CAN_H +#define MSB_CAN_H + +void loop_publish_can(); + +void start_can_publisher(); + +void stop_can_publisher(); + +#endif diff --git a/MSB/api/msb_central.h b/MSB/api/msb_central.h new file mode 100644 index 0000000..6c9b1bd --- /dev/null +++ b/MSB/api/msb_central.h @@ -0,0 +1,15 @@ + +#ifndef MSB_CENTRAL_H +#define MSB_CENTRAL_H + +#include "api/msb_common.h" + +typedef struct msb_central { + const short id; +} msb_central_t; + +void monitor_strain_gauge(msb_central_t* msb); +void monitor_potentiometer(msb_central_t* msb); +void monitor_tof(msb_central_t* msb); + +#endif diff --git a/MSB/api/msb_common.h b/MSB/api/msb_common.h new file mode 100644 index 0000000..b57b9d9 --- /dev/null +++ b/MSB/api/msb_common.h @@ -0,0 +1,7 @@ + +#ifndef MSB_COMMON_H +#define MSB_COMMON_H + +void push_can_queue(string message); + +#endif diff --git a/MSB/api/msb_knuckle.h b/MSB/api/msb_knuckle.h new file mode 100644 index 0000000..6d3d67d --- /dev/null +++ b/MSB/api/msb_knuckle.h @@ -0,0 +1,13 @@ + +#ifndef MSB_KNUCKLE_H +#define MSB_KNUCKLE_H + +#include "api/msb_common.h" + +typedef struct msb_knuckle { + const short id; +} msb_knuckle_t; + +void monitor_imu(msb_knuckle_t* msb); + +#endif diff --git a/MSB/api/msb_main.h b/MSB/api/msb_main.h new file mode 100644 index 0000000..9d58eb2 --- /dev/null +++ b/MSB/api/msb_main.h @@ -0,0 +1,7 @@ + +#ifndef MSB_MAIN_H +#define MSB_MAIN_H + +void start_msb(); + +#endif diff --git a/MSB/api/msb_temp.h b/MSB/api/msb_temp.h new file mode 100644 index 0000000..920873a --- /dev/null +++ b/MSB/api/msb_temp.h @@ -0,0 +1,13 @@ + +#ifndef MSB_TEMP_H +#define MSB_TEMP_H + +#include "api/msb_common.h" + +typedef struct msb_temp { + const short id; +} msb_temp_t; + +void monitor_temp(msb_temp_t* msb); + +#endif diff --git a/MSB/msb_can.c b/MSB/msb_can.c new file mode 100644 index 0000000..a2e2138 --- /dev/null +++ b/MSB/msb_can.c @@ -0,0 +1,27 @@ + +#include "api/msb_common.h" +#include "api/msb_can.h" + +char* queue[25]; +int queue_index; +int running = 0; + +void loop_publish_can() { + while (running) { + // every x amount of time, output queue to can + // for now just print each string + } +} + +void start_can_publisher() { + running = 1; + loop_publish_can(); +} + +void stop_can_publisher() { + running = 0; +} + +void push_can_queue(string message) { + queue[queue_index++] = message; +} diff --git a/MSB/msb_main.c b/MSB/msb_main.c new file mode 100644 index 0000000..67b0b99 --- /dev/null +++ b/MSB/msb_main.c @@ -0,0 +1,22 @@ + +#include "api/msb_main.h" +#include "api/msb_can.h" + +osThreadId_t canTaskHandle; + +void init_msb() { + // spawn CAN output thread + // canTaskHandle = osThreadNew(start_can_publisher, NULL, NULL); + start_can_publisher(); +} + +void start_msb() { + + init_msb(); + + while (1) { + // loop query tasks + } + +} + diff --git a/Makefile b/Makefile index cdfa200..aaba8fa 100644 --- a/Makefile +++ b/Makefile @@ -35,48 +35,50 @@ BUILD_DIR = build # source ###################################### # C sources -C_SOURCES = \ -Core/Src/main.c \ -Core/Src/app_freertos.c \ -Core/Src/stm32g4xx_it.c \ -Core/Src/stm32g4xx_hal_msp.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_adc.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_adc_ex.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_adc.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc_ex.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ex.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ramfunc.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_gpio.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_exti.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma_ex.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr_ex.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_cortex.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_fdcan.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_i2c.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_i2c_ex.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim_ex.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart.c \ -Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart_ex.c \ -Core/Src/system_stm32g4xx.c \ -Middlewares/Third_Party/FreeRTOS/Source/croutine.c \ -Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \ -Middlewares/Third_Party/FreeRTOS/Source/list.c \ -Middlewares/Third_Party/FreeRTOS/Source/queue.c \ -Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c \ -Middlewares/Third_Party/FreeRTOS/Source/tasks.c \ -Middlewares/Third_Party/FreeRTOS/Source/timers.c \ -Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c \ -Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c \ -Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c +C_SOURCES = \ +Core/Src/main.c \ +Core/Src/app_freertos.c \ +Core/Src/stm32g4xx_it.c \ +Core/Src/stm32g4xx_hal_msp.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_adc.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_adc_ex.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_ll_adc.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc_ex.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ex.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_flash_ramfunc.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_gpio.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_exti.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_dma_ex.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_pwr_ex.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_cortex.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_fdcan.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_i2c.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_i2c_ex.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_tim_ex.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart.c \ +Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_uart_ex.c \ +Core/Src/system_stm32g4xx.c \ +Middlewares/Third_Party/FreeRTOS/Source/croutine.c \ +Middlewares/Third_Party/FreeRTOS/Source/event_groups.c \ +Middlewares/Third_Party/FreeRTOS/Source/list.c \ +Middlewares/Third_Party/FreeRTOS/Source/queue.c \ +Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.c \ +Middlewares/Third_Party/FreeRTOS/Source/tasks.c \ +Middlewares/Third_Party/FreeRTOS/Source/timers.c \ +Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c \ +Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c \ +Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c \ +MSB/msb_main.c \ +MSB/msb_can.c # ASM sources -ASM_SOURCES = \ +ASM_SOURCES = \ startup_stm32g431xx.s # ASM sources @@ -123,24 +125,24 @@ MCU = $(CPU) -mthumb $(FPU) $(FLOAT-ABI) AS_DEFS = # C defines -C_DEFS = \ --DUSE_HAL_DRIVER \ +C_DEFS = \ +-DUSE_HAL_DRIVER \ -DSTM32G431xx # AS includes -AS_INCLUDES = \ +AS_INCLUDES = \ -ICore/Inc # C includes -C_INCLUDES = \ --ICore/Inc \ --IDrivers/STM32G4xx_HAL_Driver/Inc \ --IDrivers/STM32G4xx_HAL_Driver/Inc/Legacy \ --IMiddlewares/Third_Party/FreeRTOS/Source/include \ --IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \ --IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F \ --IDrivers/CMSIS/Device/ST/STM32G4xx/Include \ +C_INCLUDES = \ +-ICore/Inc \ +-IDrivers/STM32G4xx_HAL_Driver/Inc \ +-IDrivers/STM32G4xx_HAL_Driver/Inc/Legacy \ +-IMiddlewares/Third_Party/FreeRTOS/Source/include \ +-IMiddlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 \ +-IMiddlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F \ +-IDrivers/CMSIS/Device/ST/STM32G4xx/Include \ -IDrivers/CMSIS/Include