Skip to content

Commit

Permalink
Merge branch 'main' into spareFreeRTOSCheckout
Browse files Browse the repository at this point in the history
  • Loading branch information
Skptak authored Oct 19, 2023
2 parents 8c18fcd + b32aafe commit 89f7069
Show file tree
Hide file tree
Showing 9 changed files with 1,130 additions and 364 deletions.
28 changes: 28 additions & 0 deletions cmake_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.15)

project(example)

set(FREERTOS_KERNEL_PATH "../")

# Add the freertos_config for FreeRTOS-Kernel
add_library(freertos_config INTERFACE)

target_include_directories(freertos_config
INTERFACE
../sample_configuration
)

# Select the heap port. values between 1-4 will pick a heap.
# set(FREERTOS_HEAP "4" CACHE STRING "" FORCE)

# Select the native compile PORT
set(FREERTOS_PORT "TEMPLATE" CACHE STRING "" FORCE)

# Adding the FreeRTOS-Kernel subdirectory
add_subdirectory(${FREERTOS_KERNEL_PATH} FreeRTOS-Kernel)

add_executable(${PROJECT_NAME}
main.c
)

target_link_libraries(${PROJECT_NAME} freertos_kernel freertos_config)
111 changes: 111 additions & 0 deletions cmake_example/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* FreeRTOS Kernel <DEVELOPMENT BRANCH>
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* 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.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/

/*
* This is a simple main that will start the FreeRTOS-Kernel and run a periodic task
* that only delays if compiled with the template port, this project will do nothing.
* For more information on getting started please look here:
* https://freertos.org/FreeRTOS-quick-start-guide.html
*/

#include <FreeRTOS.h>
#include <task.h>
#include <queue.h>
#include <timers.h>
#include <semphr.h>

#include <stdio.h>

static StaticTask_t exampleTaskTCB;
static StackType_t exampleTaskStack[ configMINIMAL_STACK_SIZE ];

static StaticTask_t xTimerTaskTCB;
static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];

static StaticTask_t xIdleTaskTCB;
static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];

void exampleTask( void * parameters )
{
/* Unused parameters. */
( void ) parameters;

for( ; ; )
{
/* Example Task Code */
vTaskDelay( 100 ); /* delay 100 ticks */
}
}

void main( void )
{
printf( "Example FreeRTOS Project\n" );

xTaskCreateStatic( exampleTask,
"example",
configMINIMAL_STACK_SIZE,
NULL,
configMAX_PRIORITIES - 1,
exampleTaskStack,
&exampleTaskTCB );

/* Start the scheduler. */
vTaskStartScheduler();

for( ; ; )
{
/* Should not reach here. */
}
}

void vApplicationStackOverflowHook( TaskHandle_t xTask,
char * pcTaskName )
{
/* Check pcTaskName for the name of the offending task,
* or pxCurrentTCB if pcTaskName has itself been corrupted. */
( void ) xTask;
( void ) pcTaskName;
}

void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
StackType_t ** ppxTimerTaskStackBuffer,
uint32_t * pulTimerTaskStackSize )
{
*ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
*ppxTimerTaskStackBuffer = uxTimerTaskStack;
*pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
}

void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
uint32_t * pulIdleTaskStackSize )
{
*ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
*ppxIdleTaskStackBuffer = uxIdleTaskStack;
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
}
68 changes: 61 additions & 7 deletions include/FreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@
#endif

#if ( configNUMBER_OF_CORES > 1 )
#ifndef configUSE_MINIMAL_IDLE_HOOK
#error Missing definition: configUSE_MINIMAL_IDLE_HOOK must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details.
#ifndef configUSE_PASSIVE_IDLE_HOOK
#error Missing definition: configUSE_PASSIVE_IDLE_HOOK must be defined in FreeRTOSConfig.h as either 1 or 0. See the Configuration section of the FreeRTOS API documentation for details.
#endif
#endif

Expand Down Expand Up @@ -473,9 +473,9 @@
#define configUSE_CORE_AFFINITY 0
#endif /* configUSE_CORE_AFFINITY */

#ifndef configUSE_MINIMAL_IDLE_HOOK
#define configUSE_MINIMAL_IDLE_HOOK 0
#endif /* configUSE_MINIMAL_IDLE_HOOK */
#ifndef configUSE_PASSIVE_IDLE_HOOK
#define configUSE_PASSIVE_IDLE_HOOK 0
#endif /* configUSE_PASSIVE_IDLE_HOOK */

/* The timers module relies on xTaskGetSchedulerState(). */
#if configUSE_TIMERS == 1
Expand Down Expand Up @@ -1610,6 +1610,14 @@
#define traceRETURN_xTaskCreateStatic( xReturn )
#endif

#ifndef traceENTER_xTaskCreateStaticAffinitySet
#define traceENTER_xTaskCreateStaticAffinitySet( pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, puxStackBuffer, pxTaskBuffer, uxCoreAffinityMask )
#endif

#ifndef traceRETURN_xTaskCreateStaticAffinitySet
#define traceRETURN_xTaskCreateStaticAffinitySet( xReturn )
#endif

#ifndef traceENTER_xTaskCreateRestrictedStatic
#define traceENTER_xTaskCreateRestrictedStatic( pxTaskDefinition, pxCreatedTask )
#endif
Expand All @@ -1618,6 +1626,14 @@
#define traceRETURN_xTaskCreateRestrictedStatic( xReturn )
#endif

#ifndef traceENTER_xTaskCreateRestrictedStaticAffinitySet
#define traceENTER_xTaskCreateRestrictedStaticAffinitySet( pxTaskDefinition, uxCoreAffinityMask, pxCreatedTask )
#endif

#ifndef traceRETURN_xTaskCreateRestrictedStaticAffinitySet
#define traceRETURN_xTaskCreateRestrictedStaticAffinitySet( xReturn )
#endif

#ifndef traceENTER_xTaskCreateRestricted
#define traceENTER_xTaskCreateRestricted( pxTaskDefinition, pxCreatedTask )
#endif
Expand All @@ -1626,6 +1642,14 @@
#define traceRETURN_xTaskCreateRestricted( xReturn )
#endif

#ifndef traceENTER_xTaskCreateRestrictedAffinitySet
#define traceENTER_xTaskCreateRestrictedAffinitySet( pxTaskDefinition, uxCoreAffinityMask, pxCreatedTask )
#endif

#ifndef traceRETURN_xTaskCreateRestrictedAffinitySet
#define traceRETURN_xTaskCreateRestrictedAffinitySet( xReturn )
#endif

#ifndef traceENTER_xTaskCreate
#define traceENTER_xTaskCreate( pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask )
#endif
Expand All @@ -1634,6 +1658,14 @@
#define traceRETURN_xTaskCreate( xReturn )
#endif

#ifndef traceENTER_xTaskCreateAffinitySet
#define traceENTER_xTaskCreateAffinitySet( pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, uxCoreAffinityMask, pxCreatedTask )
#endif

#ifndef traceRETURN_xTaskCreateAffinitySet
#define traceRETURN_xTaskCreateAffinitySet( xReturn )
#endif

#ifndef traceENTER_vTaskDelete
#define traceENTER_vTaskDelete( xTaskToDelete )
#endif
Expand Down Expand Up @@ -1682,6 +1714,22 @@
#define traceRETURN_uxTaskPriorityGetFromISR( uxReturn )
#endif

#ifndef traceENTER_uxTaskBasePriorityGet
#define traceENTER_uxTaskBasePriorityGet( xTask )
#endif

#ifndef traceRETURN_uxTaskBasePriorityGet
#define traceRETURN_uxTaskBasePriorityGet( uxReturn )
#endif

#ifndef traceENTER_uxTaskBasePriorityGetFromISR
#define traceENTER_uxTaskBasePriorityGetFromISR( xTask )
#endif

#ifndef traceRETURN_uxTaskBasePriorityGetFromISR
#define traceRETURN_uxTaskBasePriorityGetFromISR( uxReturn )
#endif

#ifndef traceENTER_vTaskPrioritySet
#define traceENTER_vTaskPrioritySet( xTask, uxNewPriority )
#endif
Expand Down Expand Up @@ -1834,8 +1882,14 @@
#define traceRETURN_uxTaskGetSystemState( uxTask )
#endif

#ifndef traceENTER_xTaskGetIdleTaskHandle
#define traceENTER_xTaskGetIdleTaskHandle()
#if ( configNUMBER_OF_CORES == 1 )
#ifndef traceENTER_xTaskGetIdleTaskHandle
#define traceENTER_xTaskGetIdleTaskHandle()
#endif
#else
#ifndef traceENTER_xTaskGetIdleTaskHandle
#define traceENTER_xTaskGetIdleTaskHandle( xCoreID )
#endif
#endif

#ifndef traceRETURN_xTaskGetIdleTaskHandle
Expand Down
2 changes: 2 additions & 0 deletions include/mpu_prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ BaseType_t MPU_xTaskGetStaticBuffers( TaskHandle_t xTask,
StackType_t ** ppuxStackBuffer,
StaticTask_t ** ppxTaskBuffer ) PRIVILEGED_FUNCTION;
UBaseType_t MPU_uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
UBaseType_t MPU_uxTaskBasePriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
UBaseType_t MPU_uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
BaseType_t MPU_xTaskResumeFromISR( TaskHandle_t xTaskToResume ) PRIVILEGED_FUNCTION;
TaskHookFunction_t MPU_xTaskGetApplicationTaskTagFromISR( TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
BaseType_t MPU_xTaskGenericNotifyFromISR( TaskHandle_t xTaskToNotify,
Expand Down
2 changes: 2 additions & 0 deletions include/mpu_wrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
#define vTaskAllocateMPURegions MPU_vTaskAllocateMPURegions
#define xTaskGetStaticBuffers MPU_xTaskGetStaticBuffers
#define uxTaskPriorityGetFromISR MPU_uxTaskPriorityGetFromISR
#define uxTaskBasePriorityGet MPU_uxTaskBasePriorityGet
#define uxTaskBasePriorityGetFromISR MPU_uxTaskBasePriorityGetFromISR
#define xTaskResumeFromISR MPU_xTaskResumeFromISR
#define xTaskGetApplicationTaskTagFromISR MPU_xTaskGetApplicationTaskTagFromISR
#define xTaskGenericNotifyFromISR MPU_xTaskGenericNotifyFromISR
Expand Down
88 changes: 83 additions & 5 deletions include/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,37 @@ UBaseType_t uxTaskPriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;
*/
UBaseType_t uxTaskPriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;

/**
* task. h
* @code{c}
* UBaseType_t uxTaskBasePriorityGet( const TaskHandle_t xTask );
* @endcode
*
* INCLUDE_uxTaskPriorityGet and configUSE_MUTEXES must be defined as 1 for this
* function to be available. See the configuration section for more information.
*
* Obtain the base priority of any task.
*
* @param xTask Handle of the task to be queried. Passing a NULL
* handle results in the base priority of the calling task being returned.
*
* @return The base priority of xTask.
*
* \defgroup uxTaskPriorityGet uxTaskBasePriorityGet
* \ingroup TaskCtrl
*/
UBaseType_t uxTaskBasePriorityGet( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;

/**
* task. h
* @code{c}
* UBaseType_t uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask );
* @endcode
*
* A version of uxTaskBasePriorityGet() that can be used from an ISR.
*/
UBaseType_t uxTaskBasePriorityGetFromISR( const TaskHandle_t xTask ) PRIVILEGED_FUNCTION;

/**
* task. h
* @code{c}
Expand Down Expand Up @@ -1930,6 +1961,8 @@ configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVIL

#if ( configSUPPORT_STATIC_ALLOCATION == 1 )

#if ( configNUMBER_OF_CORES == 1 )

/**
* task.h
* @code{c}
Expand All @@ -1943,10 +1976,41 @@ configSTACK_DEPTH_TYPE uxTaskGetStackHighWaterMark2( TaskHandle_t xTask ) PRIVIL
* @param ppxIdleTaskStackBuffer A handle to a statically allocated Stack buffer for the idle task
* @param pulIdleTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer
*/
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
uint32_t * pulIdleTaskStackSize ); /*lint !e526 Symbol not defined as it is an application callback. */
#endif
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
uint32_t * pulIdleTaskStackSize ); /*lint !e526 Symbol not defined as it is an application callback. */
#else /* #if ( configNUMBER_OF_CORES == 1 ) */

/**
* task.h
* @code{c}
* void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer, StackType_t ** ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize, BaseType_t xCoreID )
* @endcode
*
* This function is used to provide a statically allocated block of memory to FreeRTOS to hold the Idle Tasks TCB. This function is required when
* configSUPPORT_STATIC_ALLOCATION is set. For more information see this URI: https://www.FreeRTOS.org/a00110.html#configSUPPORT_STATIC_ALLOCATION
*
* In the FreeRTOS SMP, there are a total of configNUMBER_OF_CORES idle tasks:
* 1. 1 Active idle task which does all the housekeeping.
* 2. ( configNUMBER_OF_CORES - 1 ) Passive idle tasks which do nothing.
* These idle tasks are created to ensure that each core has an idle task to run when
* no other task is available to run.
*
* The function vApplicationGetIdleTaskMemory is called with xCoreID 0 to get the
* memory for Active idle task. It is called with xCoreID 1, 2 ... ( configNUMBER_OF_CORES - 1 )
* to get memory for passive idle tasks.
*
* @param ppxIdleTaskTCBBuffer A handle to a statically allocated TCB buffer
* @param ppxIdleTaskStackBuffer A handle to a statically allocated Stack buffer for the idle task
* @param pulIdleTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer
* @param xCoreId The core index of the idle task buffer
*/
void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
StackType_t ** ppxIdleTaskStackBuffer,
uint32_t * pulIdleTaskStackSize, /*lint !e526 Symbol not defined as it is an application callback. */
BaseType_t xCoreID );
#endif /* #if ( configNUMBER_OF_CORES == 1 ) */
#endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */

/**
* task.h
Expand All @@ -1970,8 +2034,22 @@ BaseType_t xTaskCallApplicationTaskHook( TaskHandle_t xTask,
*
* Simply returns the handle of the idle task. It is not valid to call
* xTaskGetIdleTaskHandle() before the scheduler has been started.
*
* In the FreeRTOS SMP, there are a total of configNUMBER_OF_CORES idle tasks:
* 1. 1 Active idle task which does all the housekeeping.
* 2. ( configNUMBER_OF_CORES - 1 ) Passive idle tasks which do nothing.
* These idle tasks are created to ensure that each core has an idle task to run when
* no other task is available to run.
*
* Set xCoreID to 0 to get the Active idle task handle. Set xCoreID to
* 1,2 ... ( configNUMBER_OF_CORES - 1 ) to get the Passive idle task
* handles.
*/
TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
#if ( configNUMBER_OF_CORES == 1 )
TaskHandle_t xTaskGetIdleTaskHandle( void ) PRIVILEGED_FUNCTION;
#else /* #if ( configNUMBER_OF_CORES == 1 ) */
TaskHandle_t xTaskGetIdleTaskHandle( BaseType_t xCoreID ) PRIVILEGED_FUNCTION;
#endif /* #if ( configNUMBER_OF_CORES == 1 ) */

/**
* configUSE_TRACE_FACILITY must be defined as 1 in FreeRTOSConfig.h for
Expand Down
Loading

0 comments on commit 89f7069

Please sign in to comment.