diff --git a/Core/Inc/FreeRTOSConfig.h b/Core/Inc/FreeRTOSConfig.h index 04f18da..b86cf90 100644 --- a/Core/Inc/FreeRTOSConfig.h +++ b/Core/Inc/FreeRTOSConfig.h @@ -1,32 +1,10 @@ -/* USER CODE BEGIN Header */ -/* - * FreeRTOS Kernel V10.3.1 - * Portion Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * Portion Copyright (C) 2019 StMicroelectronics, Inc. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://www.FreeRTOS.org - * http://aws.amazon.com/freertos - * - * 1 tab == 4 spaces! - */ -/* USER CODE END Header */ +/************************************************ +* @file FreeRTOSConfig.h +* @author APBashara +* @date 9/2024 +* +* @brief FreeRTOS Configuration File +***********************************************/ #ifndef FREERTOS_CONFIG_H #define FREERTOS_CONFIG_H @@ -43,10 +21,6 @@ * See http://www.freertos.org/a00110.html *----------------------------------------------------------*/ -/* USER CODE BEGIN Includes */ -/* Section where include file can be added */ -/* USER CODE END Includes */ - /* Ensure definitions are only used by the compiler, and not by the assembler. */ #if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__) #include @@ -78,11 +52,9 @@ #define configUSE_RECURSIVE_MUTEXES 1 #define configUSE_COUNTING_SEMAPHORES 1 #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 -/* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */ /* Defaults to size_t for backward compatibility, but can be changed if lengths will always be less than the number of bytes in a size_t. */ #define configMESSAGE_BUFFER_LENGTH_TYPE size_t -/* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */ /* Co-routine definitions. */ #define configUSE_CO_ROUTINES 0 @@ -151,9 +123,7 @@ See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */ /* Normal assert() semantics without relying on the provision of an assert.h header file. */ -/* USER CODE BEGIN 1 */ #define configASSERT( x ) if ((x) == 0) {taskDISABLE_INTERRUPTS(); for( ;; );} -/* USER CODE END 1 */ /* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS standard names. */ @@ -164,8 +134,4 @@ standard names. */ #define USE_CUSTOM_SYSTICK_HANDLER_IMPLEMENTATION 1 -/* USER CODE BEGIN Defines */ -/* Section where parameter definitions can be added (for instance, to override default ones in FreeRTOS.h) */ -/* USER CODE END Defines */ - #endif /* FREERTOS_CONFIG_H */ diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 14cab30..5546c48 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -25,9 +25,15 @@ extern "C" { #endif /* Includes -----------------------------------------------------------------*/ +// OS Specific Includes +#include "FreeRTOS.h" /* Must come first. */ +#include "task.h" /* RTOS task related API prototypes. */ +#include "queue.h" /* RTOS queue related API prototypes. */ +#include "timers.h" /* Software timer related API prototypes. */ +#include "semphr.h" /* Semaphore related API prototypes. */ +// Hardware Specific Includes #include "stm32f4xx_hal.h" #include "stm32f415xx.h" -#include "cmsis_os2.h" #include @@ -62,6 +68,11 @@ typedef struct { } Telemetry; /* Functions prototypes -----------------------------------------------------*/ + +/** + * @brief Handles Systems Errors + * @note Currently holds LED on in infinite loop + */ void Error_Handler(void); /** diff --git a/Core/Src/main.c b/Core/Src/main.c index 1964ee8..ce12370 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -11,32 +11,11 @@ /* Global Variables ---------------------------------------------------------*/ Telemetry telemetry; -/* Thread Attributes --------------------------------------------------------*/ -osThreadId_t StatusLED; -const osThreadAttr_t StatusLED_attr = { - .name = "Status_Task", - .priority = osPriorityBelowNormal, - .stack_size = 128 * 4 -}; - -osThreadId_t CANTask; -const osThreadAttr_t CANTask_attr = { - .name = "CAN_Task", - .priority = osPriorityNormal, - .stack_size = 128 * 4 -}; - -osThreadId_t GPSTask; -const osThreadAttr_t GPSTask_attr = { - .name = "GPS_Task", - .priority = osPriorityNormal, - .stack_size = 128 * 4 -}; - +/* Function Calls -----------------------------------------------------------*/ void main() { - osKernelInitialize(); // Initialize FreeRTOS + uint8_t Task_Status = 1; - // Initialize Peripherals + // Initialize Hardware Sysclk_168(); LED_Init(); I2C1_Init(); @@ -44,12 +23,17 @@ void main() { CAN_Filters_Init(); CAN_Start(); - // Create FreeRTOS Threads - StatusLED = osThreadNew(Status_LED, NULL, &StatusLED_attr); - CANTask = osThreadNew(CAN_Task, NULL, &CANTask_attr); - GPSTask = osThreadNew(GPS_Task, NULL, &GPSTask_attr); + // Create FreeRTOS Tasks + Task_Status &= xTaskCreate(Status_LED, "Status_Task", 128, NULL, 1, NULL); + Task_Status &= xTaskCreate(CAN_Task, "CAN_Task", 128, NULL, 1, NULL); + Task_Status &= xTaskCreate(GPS_Task, "GPS_Task", 128, NULL, 1, NULL); + + if (Task_Status != pdPASS) { + Error_Handler(); + } + + vTaskStartScheduler(); // Start FreeRTOS Scheduler - osKernelStart(); // Start FreeRTOS while(1); } @@ -89,4 +73,9 @@ void GPS_Task() { while(1) { osDelay(1000); } +} + +void Error_Handler() { + Set_Pin(GPIOC, STATUS_LED_PIN); + while(1); } \ No newline at end of file