Commit 0757830d authored by Oliver Horst's avatar Oliver Horst
Browse files

[merge] Integrated 'feature/sched-ext' branch

parents cdbc9e8e c9ed2377
#include "freertos/FreeRTOS.h"
/* We only want to include the specific headers of that scheduler extension that was enabled in the config, if any. */
#if ( 1 == ENABLE_SchedulerExtensions )
#if ( 1 == ENABLE_SchedulerExtension_ESFree )
#include "freertos+/sched-ext/esfree/scheduler.h"
#if ( 1 == ENABLE_SchedulerExtension_HST )
#include "freertos+/sched-ext/hst/scheduler.h"
#endif /* ( 1 == ENABLE_SchedulerExtensions ) */
/* NOTE: This file has to be included from within 'freertos/FreeRTOSConfig.h' as very last statement, to ensure that
* all required configuration options are set appropriately.
#if ( 1 == ENABLE_SchedulerExtensions )
/* In case more than a single EDF scheduler implementation was enabled, we stop compilation with an error. */
#if ( ( 1 == ENABLE_SchedulerExtension_ESFree ) && \
( 1 == ENABLE_SchedulerExtension_HST ) )
#error "More than one EDF scheduler implementation enabled!"
/* We default to 'ENABLE_SchedulerExtension_ESFree = 1' if no specific scheduler extension was selected */
#if ( 1 != ENABLE_SchedulerExtension_ESFree ) && \
( 1 != ENABLE_SchedulerExtension_HST )
#define ENABLE_SchedulerExtension_ESFree 1
/* The available scheduling policies the user chose among. Please be aware that not every scheduler extensions
* supports the same policies. */
#define schedSCHEDULING_POLICY_MANUAL 0 /* The priority of tasks are set by the user. */
#define schedSCHEDULING_POLICY_RMS 1 /* Rate-monotonic scheduling */
#define schedSCHEDULING_POLICY_DMS 2 /* Deadline-monotonic scheduling */
#define schedSCHEDULING_POLICY_EDF 3 /* Earliest deadline first */
#define schedSCHEDULING_POLICY_DP 4 /* Dual priority scheduling */
#define schedSCHEDULING_POLICY_SS 5 /* Rate-monotonic scheduling with slack stealing */
#define schedSCHEDULER_INTEGRATION_EFFICIENT 0 /* Integrate the scheduler extension through trace macros */
#define schedSCHEDULER_INTEGRATION_NAIVE 1 /* Integrate the schedulerextensions without modifying the FreeRTOS kernel */
/* Both EDF scheduler implementations require that the time slicing feature of FreeRTOS is turned off */
#ifdef configUSE_TIME_SLICING
#undef configUSE_TIME_SLICING
#define configUSE_TIME_SLICING 0
#if ( 1 == ENABLE_SchedulerExtension_HST )
/* Enable FreeRTOS features required by HST */
#ifdef INCLUDE_pcTaskGetTaskName
#undef INCLUDE_pcTaskGetTaskName
#define INCLUDE_pcTaskGetTaskName 1
/* Include the HST specific config */
#include "freertos+/sched-ext/HSTConfig.h"
/* HST only supports one of the following scheduling policies: schedSCHEDULING_POLICY_RMS,
#error "HST only supports one of the following scheduling policies: RMS, EDF, DP, or SS!"
/* Inlcude the HST specific trace macros */
#include "freertos+/sched-ext/hst/trace-macros.h"
#if ( 1 == ENABLE_SchedulerExtension_ESFree )
/* Include the ESFree specific config */
#include "freertos+/sched-ext/ESFreeConfig.h"
/* ESFree only supports one of the following scheduling policies: schedSCHEDULING_POLICY_MANUAL,
#error "ESFree only supports one of the following scheduling policies: MANUAL, RMS, DMS, or EDF!"
/* ESFree only supports one of the following integration strategies: schedSCHEDULER_INTEGRATION_EFFICIENT or
#error "ESFree only supports one of the following integration strategies: EFFICIENT or NAIVE!"
/* Inlcude the ESFree specific trace macros */
#include "freertos+/sched-ext/esfree/trace-macros.h"
#endif /* ( 1 == ENABLE_SchedulerExtensions ) */
ESFree V1.0 - Copyright (C) 2016 Robin Kase
All rights reserved
This file is part of ESFree.
ESFree is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public licence (version 2) as published by the
Free Software Foundation AND MODIFIED BY one exception.
>>! NOTE: The modification to the GPL is included to allow you to !<<
>>! distribute a combined work that includes ESFree without being !<<
>>! obliged to provide the source code for proprietary components !<<
>>! outside of ESFree. !<<
ESFree 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. Full license text can be found on license.txt.
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
/* If the scheduling policy is EDF, the implementation can be chosen between
* naive implementation or efficient implementation.
* Naive implementation: Large overhead during context switch.
* Efficient implementation: Lower overhead during context switch, however trace macros needs to be configured. */
/* One of these defines must be set to 1, and the other one must be set to 0. */
#define schedEDF_NAIVE 0 /* Naive EDF implementation. */
#define schedEDF_EFFICIENT 1 /* Efficient EDF implementation. */
#define schedEDF_NAIVE 1 /* Naive EDF implementation. */
#define schedEDF_EFFICIENT 0 /* Efficient EDF implementation. */
#if( schedUSE_APERIODIC_JOBS == 1 || schedUSE_SPORADIC_JOBS == 1 )
/* Enable Polling Server. */
#define schedUSE_POLLING_SERVER 1
/* Disable Polling Server. */
#define schedUSE_POLLING_SERVER 0
#endif /* schedUSE_APERIODIC_JOBS || schedUSE_SPORADIC_JOBS */
/* Set this define to 1 to enable the scheduler task. This define must be set to 1
* when using following features:
* EDF scheduling policy, Timing-Error-Detection of execution time,
* Timing-Error-Detection of deadline, Polling Server. */
#define schedUSE_SCHEDULER_TASK 1
#define schedUSE_SCHEDULER_TASK 0
#if( schedUSE_SCHEDULER_TASK == 1 )
/* Priority of the scheduler task. */
#define schedSCHEDULER_PRIORITY ( configMAX_PRIORITIES - 1 )
/* Stack size of the scheduler task. */
/* The period of the scheduler task in software ticks. */
/* This define needs to be configured port specifically. For some ports
* it is portYIELD_FROM_ISR and for others it is portEND_SWITCHING_ISR. */
#define schedYIELD_FROM_ISR( xSwitchingRequired ) portEND_SWITCHING_ISR( xSwitchingRequired )
#endif /* schedUSE_SCHEDULER_TASK */
#if( schedUSE_POLLING_SERVER == 1 )
/* The period of the Polling Server. */
/* Deadline of Polling Server will only be used for setting priority if
* scheduling policy is DMS or EDF. Polling Server will not be preempted
* when exceeding deadline if Timing-Error-Detection for deadline is
* enabled. */
/* Stack size of the Polling Server. */
/* Execution budget of the Polling Server. */
/* Priority of the Polling Server if scheduling policy is manual. */
#endif /* schedUSE_POLLING_SERVER */
/* Functions that must be defined by trace macros if efficient EDF is used. */
#if( schedEDF_EFFICIENT == 1 )
/* traceTASK_DELAY_UNTIL must define this function. */
void vSchedulerSuspendTrace( TaskHandle_t xTaskHandle );
* traceTASK_DELAY_UNTIL must define this function. */
void vSchedulerBlockTrace( void );
/* traceTASK_SWITCHED_IN must define this function. */
void vSchedulerReadyTrace( TaskHandle_t xTaskHandle );
#endif /* schedEDF_EFFICIENT */
/* This function must be called before any other function call from scheduler.h. */
void vSchedulerInit( void );
/* Creates a periodic task.
* pvTaskCode: The task function.
* pcName: Name of the task.
* usStackDepth: Stack size of the task in words, not bytes.
* pvParameters: Parameters to the task function.
* uxPriority: Priority of the task. (Only used when scheduling policy is set to manual)
* pxCreatedTask: Pointer to the task handle.
* xPhaseTick: Phase given in software ticks. Counted from when vSchedulerStart is called.
* xPeriodTick: Period given in software ticks.
* xMaxExecTimeTick: Worst-case execution time given in software ticks.
* xDeadlineTick: Relative deadline given in software ticks.
* */
void vSchedulerPeriodicTaskCreate( TaskFunction_t pvTaskCode, const char *pcName, UBaseType_t uxStackDepth, void *pvParameters, UBaseType_t uxPriority,
TaskHandle_t *pxCreatedTask, TickType_t xPhaseTick, TickType_t xPeriodTick, TickType_t xMaxExecTimeTick, TickType_t xDeadlineTick );
/* Deletes a periodic task associated with the given task handle. */
void vSchedulerPeriodicTaskDelete( TaskHandle_t xTaskHandle );
/* Starts scheduling tasks. */
void vSchedulerStart( void );
#if ( schedUSE_APERIODIC_JOBS == 1 )
/* Creates an aperiodic job.
* pvTaskCode: The job function.
* pcName: Name of the job.
* pvParameters: Parameters to the job function.
* xMaxExecTimeTick: Worst-case execution time given in software ticks.
* */
void vSchedulerAperiodicJobCreate( TaskFunction_t pvTaskCode, const char *pcName, void *pvParameters, TickType_t xMaxExecTimeTick );
#endif /* schedUSE_APERIODIC_JOBS */
#if ( schedUSE_SPORADIC_JOBS == 1 )
/* Creates a sporadic job.
* pvTaskCode: The job function.
* pcName: Name of the job.
* pvParameters: Parameters to the job function.
* xMaxExecTimeTick: Worst-case execution time given in software ticks.
* xDeadlineTick: Relative deadline given in software ticks.
* */
BaseType_t xSchedulerSporadicJobCreate( TaskFunction_t pvTaskCode, const char *pcName, void *pvParameters, TickType_t xMaxExecTimeTick, TickType_t xDeadlineTick );
#endif /* schedUSE_SPORADIC_JOBS */
#if( schedUSE_POLLING_SERVER == 1 )
TaskHandle_t xGetPollingServerHandle();
#endif /* schedUSE_POLLING_SERVER */
#error "Please include 'freertos+/edf-sched/config.h' instead of the implementation specific header!"
#ifndef __ASSEMBLER__
/* Prototypes of used ESFree methods */
extern void vSchedulerSuspendTrace( void *xTaskHandle );
extern void vSchedulerBlockTrace( void );
extern void vSchedulerReadyTrace( void *xTaskHandle );
/* Trace macro mapping for ESFree Efficient */
#define traceBLOCKING_ON_QUEUE_RECEIVE( xQueue ) vSchedulerBlockTrace();
#define traceBLOCKING_ON_QUEUE_SEND( xQueue ) vSchedulerBlockTrace();
#define traceTASK_DELAY_UNTIL( x ) vSchedulerBlockTrace();
#define traceTASK_SUSPEND( xTask ) vSchedulerSuspendTrace( xTask );
#define traceMOVED_TASK_TO_READY_STATE( xTask ) vSchedulerReadyTrace( xTask );
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
/* Periodic task info. TCB for application scheduler. */
struct TaskInfo
TaskHandle_t xHandle; /* FreeRTOS task reference. */
// ----------------------
ListItem_t xGenericListItem; /* Points to the app scheduled list. */
ListItem_t xReadyListItem; /* Points to the scheduler ready list. */
// ----------------------
BaseType_t xFinished; /* 0: running. 1: suspended (called vTaskDelayUntil). */
// ----------------------
UBaseType_t xPriority; /* Priority. */
TickType_t xPeriod; /* Period. */
TickType_t xDeadline; /* Relative deadline. */
TickType_t xAbsolutDeadline; /* Absolute deadline of the current release. */
TickType_t xRelease; /* Most recent task release absolute time. */
// ----------------------
TickType_t xWcet; /* Worst case execution time. */
TickType_t xWcrt; /* Worst case response time. */
// ----------------------
UBaseType_t uxReleaseCount; /* Release counter. */
// ----------------------
TickType_t xCur; /* Current release tick count. */
// ----------------------
void* vExt; /* Pointer to a scheduling policy specific structure. */
extern List_t * pxAllTasksList;
#if defined (__cplusplus)
extern "C" {
/* Trace blocking and suspended tasks. */
void vSchedulerTaskDelay( void );
void vSchedulerTaskReady( void* pxTask );
void vSchedulerTaskBlock( void* pxResource );
void vSchedulerTaskSuspend( void* pxTask );
* Application scheduler setup.
void vSchedulerSetup( void );
* Task scheduler start.
void vSchedulerInit( void );
* Create a application scheduled task.
BaseType_t xSchedulerTaskCreate( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, struct TaskInfo ** const pxCreatedTask, TickType_t xPeriod, TickType_t xDeadline, TickType_t xWcet );
* Create a aperiodic application scheduled task.
#define xSchedulerAperiodicTaskCreate( pxTaskCode, pcName, usStackDepth, pvParameters, pxCreatedTask ) xSchedulerTaskCreate( ( pxTaskCode ), ( pcName ), ( usStackDepth ), ( pvParameters ), ( TASK_PRIORITY ), ( pxCreatedTask ), ( 0 ), ( 0 ), ( 0 ) )
* Suspend the caller task until its next period.
void vSchedulerWaitForNextPeriod( void );
/* --- AppSched_Logic -------------------------------------------------- */
void vSchedulerLogicSetup( void );
void vSchedulerTaskSchedulerStartLogic( void );
void vSchedulerLogicAddTask( struct TaskInfo * xTask );
void vSchedulerLogicAddTaskToReadyList( struct TaskInfo *xTask );
void vSchedulerLogicRemoveTaskFromReadyList( struct TaskInfo *xTask );
void vSchedulerTaskSchedulerLogic( struct TaskInfo **xCurrentTask );
struct TaskInfo* xSchedulerGetTaskTCBe( TaskHandle_t xTask );
BaseType_t vSchedulerTaskSchedulerTickLogic( void );
/* --------------------------------------------------------------------- */
__attribute__((weak)) void vSchedulerDeadlineMissHook( struct TaskInfo * xTask, const TickType_t xTickCount );
__attribute__((weak)) void vSchedulerNegativeSlackHook( TickType_t xTickCount, BaseType_t xSlack );
#if defined (__cplusplus)
#error "Please include 'freertos+/edf-sched/config.h' instead of the implementation specific header!"
#ifndef __ASSEMBLER__
/* Prototypes of used HST methods */
extern void vSchedulerTaskDelay( void );
extern void vSchedulerTaskReady( void* xTask );
extern void vSchedulerTaskBlock( void* xResource );
extern void vSchedulerTaskSuspend( void* xTask );
/* Trace macro mapping for HST */
#define traceBLOCKING_ON_QUEUE_RECEIVE(xQueue) vSchedulerTaskBlock( xQueue );
#define traceBLOCKING_ON_QUEUE_SEND(xQueue) vSchedulerTaskBlock( xQueue );
#define traceTASK_DELAY() vSchedulerTaskDelay();
#define traceTASK_DELAY_UNTIL(TickType_t) vSchedulerTaskDelay();
#define traceTASK_SUSPEND(xTask) vSchedulerTaskSuspend( xTask );
#define traceMOVED_TASK_TO_READY_STATE(xTask) vSchedulerTaskReady( xTask );
/* Function returning the minimum between a and b */
#define min( a, b ) \
( { __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; } )
/* Unsigned ceiling function */
#define uceil(X) ( ( X-(uint32_t)( X ) ) > 0 ? (uint32_t)( X+1 ) : (uint32_t)( X ) )
......@@ -2,3 +2,4 @@ cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
NOTE: The modification to the GPL is included to allow you to distribute a
combined work that includes ESFree without being obliged to provide the source
code for proprietary components.
The ESFree GPL exception text follows:
Any ESFree source code, whether modified or in it's original release form,
or whether in whole or in part, can only be distributed by you under the terms
of the GNU General Public License plus this exception. An independent module is
a module which is not derived from or based on ESFree.
Clause 1:
Linking ESFree with other modules is making a combined work based on ESFree.
Thus, the terms and conditions of the GNU General Public License V2 cover the
whole combination.
As a special exception, the copyright holder of ESFree give you permission to
link ESFree with independent modules to produce a statically linked
executable, regardless of the license terms of these independent modules, and to
copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the terms and
conditions of the license of that module. An independent module is a module
which is not derived from or based on ESFree.
The standard GPL V2 text:
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under