diff --git a/software/dumber3/.cproject b/software/dumber3/.cproject index dcb431f..e89024b 100644 --- a/software/dumber3/.cproject +++ b/software/dumber3/.cproject @@ -22,6 +22,7 @@ + @@ -33,7 +34,7 @@ - + @@ -74,17 +75,6 @@ - - - - - - - - - - - diff --git a/software/dumber3/.settings/language.settings.xml b/software/dumber3/.settings/language.settings.xml index 04bbd36..3deb75d 100644 --- a/software/dumber3/.settings/language.settings.xml +++ b/software/dumber3/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + @@ -27,7 +27,7 @@ - + diff --git a/software/dumber3/Application/application.c b/software/dumber3/Application/application.c index 67b5b79..2833625 100644 --- a/software/dumber3/Application/application.c +++ b/software/dumber3/Application/application.c @@ -70,6 +70,7 @@ #include "battery.h" #include "panic.h" +#include "rtos_support.h" /** @addtogroup Application_Software * @{ @@ -127,7 +128,7 @@ StaticTask_t xTaskApplicationMain; /* Buffer that the task being created will use as its stack. Note this is an array of StackType_t variables. The size of StackType_t is dependent on the RTOS port. */ -StackType_t xStackApplicationMain[ STACK_SIZE ]; +StackType_t xStackApplicationMain[ STACK_SIZE*2 ]; TaskHandle_t xHandleApplicationMain = NULL; StaticTimer_t xBufferTimerTimeout; @@ -148,6 +149,9 @@ APPLICATION_Timeout systemTimeout = {0}; * @return None */ void APPLICATION_Init(void) { + /* Init du support RTOS (notamment le timer de run time) */ + //RTOS_SUPPORT_Init(); /* <- used for freertos run time usage */ + /* Init des messages box */ MESSAGE_Init(); @@ -163,7 +167,7 @@ void APPLICATION_Init(void) { xHandleApplicationMain = xTaskCreateStatic( APPLICATION_Thread, /* Function that implements the task. */ "APPLICATION Thread", /* Text name for the task. */ - STACK_SIZE, /* Number of indexes in the xStack array. */ + STACK_SIZE*2, /* Number of indexes in the xStack array. */ NULL, /* Parameter passed into the task. */ PriorityApplicationHandler,/* Priority at which the task is created. */ xStackApplicationMain, /* Array to use as the task's stack. */ diff --git a/software/dumber3/Application/application.h b/software/dumber3/Application/application.h index 971d2d4..bc6303e 100644 --- a/software/dumber3/Application/application.h +++ b/software/dumber3/Application/application.h @@ -41,6 +41,8 @@ #include "xbee.h" #include "commands.h" +#include "rtos_support.h" + #include "main.h" /** @addtogroup Application_Software diff --git a/software/dumber3/Application/config.h b/software/dumber3/Application/config.h index 31936ea..9889528 100644 --- a/software/dumber3/Application/config.h +++ b/software/dumber3/Application/config.h @@ -44,11 +44,11 @@ * Version in plain text and as a numeric value */ ///@{ -#define SYSTEM_VERSION_STR "2.2" -#define SYSTEM_VERSION 0x0202 // Upper byte: major version, lower byte: minor version +#define SYSTEM_VERSION_STR "2.3" +#define SYSTEM_VERSION 0x0203 // Upper byte: major version, lower byte: minor version ///@} -#define STACK_SIZE 0x100 +#define STACK_SIZE 64 /** @name Tasks priority constants * Priority is based on configMAX_PRIORITIES which represent highest task priority. diff --git a/software/dumber3/Application/messages.c b/software/dumber3/Application/messages.c index 541b953..e1ee24b 100644 --- a/software/dumber3/Application/messages.c +++ b/software/dumber3/Application/messages.c @@ -62,6 +62,12 @@ void MESSAGE_Init(void) { MOTORS_Mailbox = xQueueCreate(QUEUE_SIZE, sizeof(MESSAGE_Typedef)); APPLICATION_Mailbox = xQueueCreate(QUEUE_SIZE, sizeof(MESSAGE_Typedef)); XBEE_Mailbox = xQueueCreate(QUEUE_SIZE, sizeof(MESSAGE_Typedef)); + + /* Add queues to registry in order to view them in stm32cube ide */ + vQueueAddToRegistry(LEDS_Mailbox,"LEDS Mailbox"); + vQueueAddToRegistry(MOTORS_Mailbox,"MOTORS Mailbox"); + vQueueAddToRegistry(APPLICATION_Mailbox,"APPLICATION Mailbox"); + vQueueAddToRegistry(XBEE_Mailbox,"XBEE Mailbox"); } /** diff --git a/software/dumber3/Application/rtos_support.c b/software/dumber3/Application/rtos_support.c new file mode 100644 index 0000000..8dddfa9 --- /dev/null +++ b/software/dumber3/Application/rtos_support.c @@ -0,0 +1,115 @@ +/** + ****************************************************************************** + * @file motors.c + * @brief motors driver body + * @author S. DI MERCURIO (dimercur@insa-toulouse.fr) + * @date December 2023 + * + ****************************************************************************** + * @copyright Copyright 2023 INSA-GEI, Toulouse, France. All rights reserved. + * @copyright This project is released under the Lesser GNU Public License (LGPL-3.0-only). + * + * @copyright This file is part of "Dumber" project + * + * @copyright This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * @copyright This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + + * @copyright You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + ****************************************************************************** + */ + +#include "rtos_support.h" + +#include "stm32l0xx_ll_tim.h" + +/** @addtogroup Application_Software + * @{ + */ + +/** @addtogroup RTOS_SUPPORT + * RTOS support module provide several functions for task run time measurement. + * @{ + */ + +/** @addtogroup RTOS_SUPPORT_Private Private + * @{ + */ + +uint16_t RTOS_SUPPORT_counter16bitUpper=0; + +/** + * @brief TIM7 Initialization Function + */ +void RTOS_SUPPORT_Init(void) { + TIM_ClockConfigTypeDef sClockSourceConfig = { 0 }; + TIM_HandleTypeDef htim7; + + __HAL_RCC_TIM7_CLK_ENABLE(); + + htim7.Instance = TIM7; + htim7.Init.Prescaler = 0; + htim7.Init.CounterMode = TIM_COUNTERMODE_UP; + htim7.Init.Period = 65535; + htim7.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim7) != HAL_OK) + { + Error_Handler(); + } + + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim7, &sClockSourceConfig) != HAL_OK) { + Error_Handler(); + } + + /* TIM7 interrupt Init */ + LL_TIM_EnableIT_UPDATE(TIM7); + HAL_NVIC_SetPriority(TIM7_IRQn, 1, 0); + HAL_NVIC_EnableIRQ(TIM7_IRQn); + + RTOS_SUPPORT_counter16bitUpper=0; + LL_TIM_EnableCounter(TIM7); +} + +/** + * @brief Get 32bit emulated timer based on TIM7 + * + * @return 32bit timer + */ +uint32_t RTOS_SUPPORT_GetTimer(void) { + + uint16_t currentVal=LL_TIM_GetCounter(TIM7); + + return (uint32_t)((((uint32_t)RTOS_SUPPORT_counter16bitUpper)<<16) + (uint32_t)currentVal); +} + +/** + * @brief This function handles TIM7 update interrupt for 32bit + */ +void TIM7_IRQHandler(void) { + LL_TIM_ClearFlag_UPDATE(TIM7); + + RTOS_SUPPORT_counter16bitUpper++; +} + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ diff --git a/software/dumber3/Application/rtos_support.h b/software/dumber3/Application/rtos_support.h new file mode 100644 index 0000000..30e8cf4 --- /dev/null +++ b/software/dumber3/Application/rtos_support.h @@ -0,0 +1,40 @@ +/* + * rtos_support.h + * + * Created on: Jan 12, 2024 + * Author: dimercur + */ + +#ifndef RTOS_SUPPORT_H_ +#define RTOS_SUPPORT_H_ + +#include "application.h" + +/** @addtogroup Application_Software + * @{ + */ + +/** @addtogroup RTOS_SUPPORT + * @{ + */ + +/** @addtogroup RTOS_SUPPORT_Public Public + * @{ + */ + +void RTOS_SUPPORT_Init(void); +uint32_t RTOS_SUPPORT_GetTimer(void); + +/** + * @} + */ + +/** + * @} + */ + +/** + * @} + */ + +#endif /* RTOS_SUPPORT_H_ */ diff --git a/software/dumber3/Application/xbee.c b/software/dumber3/Application/xbee.c index 816c654..e663efa 100644 --- a/software/dumber3/Application/xbee.c +++ b/software/dumber3/Application/xbee.c @@ -103,7 +103,6 @@ StackType_t xStackXbeeRX[ STACK_SIZE ]; TaskHandle_t xHandleXbeeRX = NULL; uint8_t rxBuffer[XBEE_RX_BUFFER_MAX_LENGTH]={0}; -//uint8_t rxWaitForACK =0; uint8_t rxPhase; uint16_t rxCmdLength; uint16_t rxDataToReceive; @@ -129,6 +128,10 @@ void XBEE_Init(void) { xHandleSemaphoreRX = xSemaphoreCreateBinaryStatic( &xSemaphoreRx ); + /* Add semaphores to registry in order to view them in stm32cube ide */ + vQueueAddToRegistry(xHandleSemaphoreTX,"XBEE TX sem"); + vQueueAddToRegistry(xHandleSemaphoreRX,"XBEE RX sem"); + /* Create the task without using any dynamic memory allocation. */ xHandleXbeeRX = xTaskCreateStatic( XBEE_RxThread, /* Function that implements the task. */ diff --git a/software/dumber3/Core/Inc/FreeRTOSConfig.h b/software/dumber3/Core/Inc/FreeRTOSConfig.h index 8237fe0..ddd7ff7 100644 --- a/software/dumber3/Core/Inc/FreeRTOSConfig.h +++ b/software/dumber3/Core/Inc/FreeRTOSConfig.h @@ -31,6 +31,9 @@ #ifndef FREERTOS_CONFIG_H #define FREERTOS_CONFIG_H +extern void RTOS_SUPPORT_Init(void); +extern uint32_t RTOS_SUPPORT_GetTimer(void); + /*----------------------------------------------------------- * Application specific definitions. * @@ -62,9 +65,9 @@ #define configUSE_TICK_HOOK 0 #define configCPU_CLOCK_HZ ( SystemCoreClock ) #define configTICK_RATE_HZ ((TickType_t)1000) -#define configMAX_PRIORITIES ( 56 ) +#define configMAX_PRIORITIES ( 12 ) #define configMINIMAL_STACK_SIZE ((uint16_t)128) -#define configTOTAL_HEAP_SIZE ((size_t)1024) +#define configTOTAL_HEAP_SIZE ((size_t)10240) #define configMAX_TASK_NAME_LEN ( 25 ) #define configUSE_TRACE_FACILITY 1 #define configUSE_16_BIT_TICKS 0 @@ -82,13 +85,13 @@ /* Co-routine definitions. */ #define configUSE_CO_ROUTINES 0 -#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) +#define configMAX_CO_ROUTINE_PRIORITIES ( 1 ) /* Software timer definitions. */ #define configUSE_TIMERS 1 -#define configTIMER_TASK_PRIORITY ( 3 ) +#define configTIMER_TASK_PRIORITY ( 1 ) #define configTIMER_QUEUE_LENGTH 10 -#define configTIMER_TASK_STACK_DEPTH 256 +#define configTIMER_TASK_STACK_DEPTH 64 /* The following flag must be enabled only when using newlib */ #define configUSE_NEWLIB_REENTRANT 1 @@ -152,4 +155,8 @@ placed into the low power state respectively. */ #define configPOST_SLEEP_PROCESSING PostSleepProcessing #endif /* configUSE_TICKLESS_IDLE == 1 */ +#define configGENERATE_RUN_TIME_STATS 1 +#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() RTOS_SUPPORT_Init() +#define portGET_RUN_TIME_COUNTER_VALUE() RTOS_SUPPORT_GetTimer() + #endif /* FREERTOS_CONFIG_H */ diff --git a/software/dumber3/Core/Src/main.c b/software/dumber3/Core/Src/main.c index 7ae6d29..7035d57 100644 --- a/software/dumber3/Core/Src/main.c +++ b/software/dumber3/Core/Src/main.c @@ -55,12 +55,12 @@ TIM_HandleTypeDef htim3; TIM_HandleTypeDef htim21; /* Definitions for defaultTask */ -osThreadId_t defaultTaskHandle; -const osThreadAttr_t defaultTask_attributes = { - .name = "defaultTask", - .stack_size = 128 * 4, - .priority = (osPriority_t) osPriorityNormal, -}; +//osThreadId_t defaultTaskHandle; +//const osThreadAttr_t defaultTask_attributes = { +// .name = "defaultTask", +// .stack_size = 128 * 4, +// .priority = (osPriority_t) osPriorityNormal, +//}; /* USER CODE BEGIN PV */ /* USER CODE END PV */ @@ -146,7 +146,7 @@ int main(void) /* Create the thread(s) */ /* creation of defaultTask */ - defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes); +//defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes); /* USER CODE BEGIN RTOS_THREADS */ /* add threads, ... */ @@ -644,9 +644,9 @@ TickType_t msToTicks(TickType_t ms) { * @retval None */ /* USER CODE END Header_StartDefaultTask */ -void StartDefaultTask(void *argument) -{ - /* USER CODE BEGIN 5 */ +//void StartDefaultTask(void *argument) +//{ +// /* USER CODE BEGIN 5 */ // LEDS_State state = leds_off; // // /* Infinite loop */ @@ -660,8 +660,13 @@ void StartDefaultTask(void *argument) // // vTaskDelay(pdMS_TO_TICKS(5000)); // } - /* USER CODE END 5 */ -} +// /* USER CODE END 5 */ +// +// while (1) +// { +// //vTaskDelay(pdMS_TO_TICKS(50)); +// } +//} /** * @brief Period elapsed callback in non blocking mode