true
diff --git a/examples/chapter11_07/chapter11_07.vcxproj.filters b/examples/chapter11_07/chapter11_07.vcxproj.filters
index b701821dd..a73bb9eb2 100644
--- a/examples/chapter11_07/chapter11_07.vcxproj.filters
+++ b/examples/chapter11_07/chapter11_07.vcxproj.filters
@@ -159,9 +159,6 @@
src\os\FreeRTOS\Source
-
- src\os\FreeRTOS\Source
-
src\os\FreeRTOS\Source\portable\MSVC-MingW
diff --git a/examples/chapter11_07/src/app/led/app_led.cpp b/examples/chapter11_07/src/app/led/app_led.cpp
index 48b0373aa..4d33a19c6 100644
--- a/examples/chapter11_07/src/app/led/app_led.cpp
+++ b/examples/chapter11_07/src/app/led/app_led.cpp
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////
-// Copyright Christopher Kormanyos 2007 - 2024.
+// Copyright Christopher Kormanyos 2007 - 2025.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -24,14 +24,32 @@ namespace
extern "C"
void app_led_task_background(void*)
{
- // This background task runs perpetually without pause, break or yield.
- // This task has lowest priority and will be interrupted by the task
- // having higher priority.
+ // This background task runs perpetually without pause, break or yield
+ // (unless running on _MSC_VER, where there is a yield for task break).
+
+ // This task has lowest priority and will be interrupted by any other
+ // task having higher priority, such as the LED 1/2 Hz toggle task
+ // (i.e., app_led_timer_toggle_led0).
for(;;)
{
while((!app_led_timer_background.timeout()))
{
+ #if defined(_MSC_VER)
+ {
+ #if defined(__AVR__)
+ #error This code sequence is not intended fof __AVR__;
+ #endif
+
+ static unsigned prescaler { };
+
+ if(unsigned { ++prescaler % unsigned { UINT8_C(8) } } == unsigned { UINT8_C(0) })
+ {
+ OS_TASK_WAIT_YIELD(OS_TASK_MSEC(TickType_t { UINT8_C(3) }));
+ }
+ }
+ #endif
+
mcal::cpu::nop();
}
diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/application/application.c b/examples/chapter11_07/src/os/FreeRTOS/Source/application/application.c
index b8a3ba58a..ab29c7a28 100644
--- a/examples/chapter11_07/src/os/FreeRTOS/Source/application/application.c
+++ b/examples/chapter11_07/src/os/FreeRTOS/Source/application/application.c
@@ -33,23 +33,3 @@ void vApplicationGetIdleTaskMemory(StaticTask_t** ppxIdleTaskTCBBuffer,
// the stack and so not exists after this function exits.
StaticTask_t xTimerTaskTCB;
StackType_t uxTimerTaskStack[configMINIMAL_STACK_SIZE];
-
-// configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
-// application must provide an implementation of vApplicationGetTimerTaskMemory()
-// to provide the memory that is used by the Timer service task.
-void vApplicationGetTimerTaskMemory(StaticTask_t** ppxTimerTaskTCBBuffer,
- StackType_t** ppxTimerTaskStackBuffer,
- uint32_t* pulTimerTaskStackSize)
-{
- // Pass out a pointer to the StaticTask_t structure in which the Timer
- // task's state will be stored.
- *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
-
- // Pass out the array that will be used as the Timer task's stack.
- *ppxTimerTaskStackBuffer = uxTimerTaskStack;
-
- // Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
- // Note that, as the array is necessarily of type StackType_t,
- // configMINIMAL_STACK_SIZE is specified in words, not bytes.
- *pulTimerTaskStackSize = sizeof(uxTimerTaskStack) / sizeof(StackType_t);
-}
diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/include/timers.h b/examples/chapter11_07/src/os/FreeRTOS/Source/include/timers.h
index 419a0c48f..a130f8956 100644
--- a/examples/chapter11_07/src/os/FreeRTOS/Source/include/timers.h
+++ b/examples/chapter11_07/src/os/FreeRTOS/Source/include/timers.h
@@ -43,31 +43,6 @@
#endif
/* *INDENT-ON* */
-/*-----------------------------------------------------------
-* MACROS AND DEFINITIONS
-*----------------------------------------------------------*/
-
-/* IDs for commands that can be sent/received on the timer queue. These are to
- * be used solely through the macros that make up the public software timer API,
- * as defined below. The commands that are sent from interrupts must use the
- * highest numbers as tmrFIRST_FROM_ISR_COMMAND is used to determine if the task
- * or interrupt version of the queue send function should be used. */
-#define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR ( ( BaseType_t ) -2 )
-#define tmrCOMMAND_EXECUTE_CALLBACK ( ( BaseType_t ) -1 )
-#define tmrCOMMAND_START_DONT_TRACE ( ( BaseType_t ) 0 )
-#define tmrCOMMAND_START ( ( BaseType_t ) 1 )
-#define tmrCOMMAND_RESET ( ( BaseType_t ) 2 )
-#define tmrCOMMAND_STOP ( ( BaseType_t ) 3 )
-#define tmrCOMMAND_CHANGE_PERIOD ( ( BaseType_t ) 4 )
-#define tmrCOMMAND_DELETE ( ( BaseType_t ) 5 )
-
-#define tmrFIRST_FROM_ISR_COMMAND ( ( BaseType_t ) 6 )
-#define tmrCOMMAND_START_FROM_ISR ( ( BaseType_t ) 6 )
-#define tmrCOMMAND_RESET_FROM_ISR ( ( BaseType_t ) 7 )
-#define tmrCOMMAND_STOP_FROM_ISR ( ( BaseType_t ) 8 )
-#define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ( ( BaseType_t ) 9 )
-
-
/**
* Type by which software timers are referenced. For example, a call to
* xTimerCreate() returns an TimerHandle_t variable that can then be used to
@@ -86,1262 +61,7 @@ typedef void (* TimerCallbackFunction_t)( TimerHandle_t xTimer );
* Defines the prototype to which functions used with the
* xTimerPendFunctionCallFromISR() function must conform.
*/
-typedef void (* PendedFunction_t)( void *,
- uint32_t );
-
-/**
- * TimerHandle_t xTimerCreate( const char * const pcTimerName,
- * TickType_t xTimerPeriodInTicks,
- * UBaseType_t uxAutoReload,
- * void * pvTimerID,
- * TimerCallbackFunction_t pxCallbackFunction );
- *
- * Creates a new software timer instance, and returns a handle by which the
- * created software timer can be referenced.
- *
- * Internally, within the FreeRTOS implementation, software timers use a block
- * of memory, in which the timer data structure is stored. If a software timer
- * is created using xTimerCreate() then the required memory is automatically
- * dynamically allocated inside the xTimerCreate() function. (see
- * https://www.FreeRTOS.org/a00111.html). If a software timer is created using
- * xTimerCreateStatic() then the application writer must provide the memory that
- * will get used by the software timer. xTimerCreateStatic() therefore allows a
- * software timer to be created without using any dynamic memory allocation.
- *
- * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
- * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
- * xTimerChangePeriodFromISR() API functions can all be used to transition a
- * timer into the active state.
- *
- * @param pcTimerName A text name that is assigned to the timer. This is done
- * purely to assist debugging. The kernel itself only ever references a timer
- * by its handle, and never by its name.
- *
- * @param xTimerPeriodInTicks The timer period. The time is defined in tick
- * periods so the constant portTICK_PERIOD_MS can be used to convert a time that
- * has been specified in milliseconds. For example, if the timer must expire
- * after 100 ticks, then xTimerPeriodInTicks should be set to 100.
- * Alternatively, if the timer must expire after 500ms, then xPeriod can be set
- * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or
- * equal to 1000. Time timer period must be greater than 0.
- *
- * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
- * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.
- * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
- * enter the dormant state after it expires.
- *
- * @param pvTimerID An identifier that is assigned to the timer being created.
- * Typically this would be used in the timer callback function to identify which
- * timer expired when the same callback function is assigned to more than one
- * timer.
- *
- * @param pxCallbackFunction The function to call when the timer expires.
- * Callback functions must have the prototype defined by TimerCallbackFunction_t,
- * which is "void vCallbackFunction( TimerHandle_t xTimer );".
- *
- * @return If the timer is successfully created then a handle to the newly
- * created timer is returned. If the timer cannot be created because there is
- * insufficient FreeRTOS heap remaining to allocate the timer
- * structures then NULL is returned.
- *
- * Example usage:
- * @verbatim
- * #define NUM_TIMERS 5
- *
- * // An array to hold handles to the created timers.
- * TimerHandle_t xTimers[ NUM_TIMERS ];
- *
- * // An array to hold a count of the number of times each timer expires.
- * int32_t lExpireCounters[ NUM_TIMERS ] = { 0 };
- *
- * // Define a callback function that will be used by multiple timer instances.
- * // The callback function does nothing but count the number of times the
- * // associated timer expires, and stop the timer once the timer has expired
- * // 10 times.
- * void vTimerCallback( TimerHandle_t pxTimer )
- * {
- * int32_t lArrayIndex;
- * const int32_t xMaxExpiryCountBeforeStopping = 10;
- *
- * // Optionally do something if the pxTimer parameter is NULL.
- * configASSERT( pxTimer );
- *
- * // Which timer expired?
- * lArrayIndex = ( int32_t ) pvTimerGetTimerID( pxTimer );
- *
- * // Increment the number of times that pxTimer has expired.
- * lExpireCounters[ lArrayIndex ] += 1;
- *
- * // If the timer has expired 10 times then stop it from running.
- * if( lExpireCounters[ lArrayIndex ] == xMaxExpiryCountBeforeStopping )
- * {
- * // Do not use a block time if calling a timer API function from a
- * // timer callback function, as doing so could cause a deadlock!
- * xTimerStop( pxTimer, 0 );
- * }
- * }
- *
- * void main( void )
- * {
- * int32_t x;
- *
- * // Create then start some timers. Starting the timers before the scheduler
- * // has been started means the timers will start running immediately that
- * // the scheduler starts.
- * for( x = 0; x < NUM_TIMERS; x++ )
- * {
- * xTimers[ x ] = xTimerCreate( "Timer", // Just a text name, not used by the kernel.
- * ( 100 * x ), // The timer period in ticks.
- * pdTRUE, // The timers will auto-reload themselves when they expire.
- * ( void * ) x, // Assign each timer a unique id equal to its array index.
- * vTimerCallback // Each timer calls the same callback when it expires.
- * );
- *
- * if( xTimers[ x ] == NULL )
- * {
- * // The timer was not created.
- * }
- * else
- * {
- * // Start the timer. No block time is specified, and even if one was
- * // it would be ignored because the scheduler has not yet been
- * // started.
- * if( xTimerStart( xTimers[ x ], 0 ) != pdPASS )
- * {
- * // The timer could not be set into the Active state.
- * }
- * }
- * }
- *
- * // ...
- * // Create tasks here.
- * // ...
- *
- * // Starting the scheduler will start the timers running as they have already
- * // been set into the active state.
- * vTaskStartScheduler();
- *
- * // Should not reach here.
- * for( ;; );
- * }
- * @endverbatim
- */
-#if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
- TimerHandle_t xTimerCreate( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
- const TickType_t xTimerPeriodInTicks,
- const UBaseType_t uxAutoReload,
- void * const pvTimerID,
- TimerCallbackFunction_t pxCallbackFunction ) PRIVILEGED_FUNCTION;
-#endif
-
-/**
- * TimerHandle_t xTimerCreateStatic(const char * const pcTimerName,
- * TickType_t xTimerPeriodInTicks,
- * UBaseType_t uxAutoReload,
- * void * pvTimerID,
- * TimerCallbackFunction_t pxCallbackFunction,
- * StaticTimer_t *pxTimerBuffer );
- *
- * Creates a new software timer instance, and returns a handle by which the
- * created software timer can be referenced.
- *
- * Internally, within the FreeRTOS implementation, software timers use a block
- * of memory, in which the timer data structure is stored. If a software timer
- * is created using xTimerCreate() then the required memory is automatically
- * dynamically allocated inside the xTimerCreate() function. (see
- * https://www.FreeRTOS.org/a00111.html). If a software timer is created using
- * xTimerCreateStatic() then the application writer must provide the memory that
- * will get used by the software timer. xTimerCreateStatic() therefore allows a
- * software timer to be created without using any dynamic memory allocation.
- *
- * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
- * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
- * xTimerChangePeriodFromISR() API functions can all be used to transition a
- * timer into the active state.
- *
- * @param pcTimerName A text name that is assigned to the timer. This is done
- * purely to assist debugging. The kernel itself only ever references a timer
- * by its handle, and never by its name.
- *
- * @param xTimerPeriodInTicks The timer period. The time is defined in tick
- * periods so the constant portTICK_PERIOD_MS can be used to convert a time that
- * has been specified in milliseconds. For example, if the timer must expire
- * after 100 ticks, then xTimerPeriodInTicks should be set to 100.
- * Alternatively, if the timer must expire after 500ms, then xPeriod can be set
- * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or
- * equal to 1000. The timer period must be greater than 0.
- *
- * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
- * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.
- * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
- * enter the dormant state after it expires.
- *
- * @param pvTimerID An identifier that is assigned to the timer being created.
- * Typically this would be used in the timer callback function to identify which
- * timer expired when the same callback function is assigned to more than one
- * timer.
- *
- * @param pxCallbackFunction The function to call when the timer expires.
- * Callback functions must have the prototype defined by TimerCallbackFunction_t,
- * which is "void vCallbackFunction( TimerHandle_t xTimer );".
- *
- * @param pxTimerBuffer Must point to a variable of type StaticTimer_t, which
- * will be then be used to hold the software timer's data structures, removing
- * the need for the memory to be allocated dynamically.
- *
- * @return If the timer is created then a handle to the created timer is
- * returned. If pxTimerBuffer was NULL then NULL is returned.
- *
- * Example usage:
- * @verbatim
- *
- * // The buffer used to hold the software timer's data structure.
- * static StaticTimer_t xTimerBuffer;
- *
- * // A variable that will be incremented by the software timer's callback
- * // function.
- * UBaseType_t uxVariableToIncrement = 0;
- *
- * // A software timer callback function that increments a variable passed to
- * // it when the software timer was created. After the 5th increment the
- * // callback function stops the software timer.
- * static void prvTimerCallback( TimerHandle_t xExpiredTimer )
- * {
- * UBaseType_t *puxVariableToIncrement;
- * BaseType_t xReturned;
- *
- * // Obtain the address of the variable to increment from the timer ID.
- * puxVariableToIncrement = ( UBaseType_t * ) pvTimerGetTimerID( xExpiredTimer );
- *
- * // Increment the variable to show the timer callback has executed.
- * ( *puxVariableToIncrement )++;
- *
- * // If this callback has executed the required number of times, stop the
- * // timer.
- * if( *puxVariableToIncrement == 5 )
- * {
- * // This is called from a timer callback so must not block.
- * xTimerStop( xExpiredTimer, staticDONT_BLOCK );
- * }
- * }
- *
- *
- * void main( void )
- * {
- * // Create the software time. xTimerCreateStatic() has an extra parameter
- * // than the normal xTimerCreate() API function. The parameter is a pointer
- * // to the StaticTimer_t structure that will hold the software timer
- * // structure. If the parameter is passed as NULL then the structure will be
- * // allocated dynamically, just as if xTimerCreate() had been called.
- * xTimer = xTimerCreateStatic( "T1", // Text name for the task. Helps debugging only. Not used by FreeRTOS.
- * xTimerPeriod, // The period of the timer in ticks.
- * pdTRUE, // This is an auto-reload timer.
- * ( void * ) &uxVariableToIncrement, // A variable incremented by the software timer's callback function
- * prvTimerCallback, // The function to execute when the timer expires.
- * &xTimerBuffer ); // The buffer that will hold the software timer structure.
- *
- * // The scheduler has not started yet so a block time is not used.
- * xReturned = xTimerStart( xTimer, 0 );
- *
- * // ...
- * // Create tasks here.
- * // ...
- *
- * // Starting the scheduler will start the timers running as they have already
- * // been set into the active state.
- * vTaskStartScheduler();
- *
- * // Should not reach here.
- * for( ;; );
- * }
- * @endverbatim
- */
-#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
- TimerHandle_t xTimerCreateStatic( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
- const TickType_t xTimerPeriodInTicks,
- const UBaseType_t uxAutoReload,
- void * const pvTimerID,
- TimerCallbackFunction_t pxCallbackFunction,
- StaticTimer_t * pxTimerBuffer ) PRIVILEGED_FUNCTION;
-#endif /* configSUPPORT_STATIC_ALLOCATION */
-
-/**
- * void *pvTimerGetTimerID( TimerHandle_t xTimer );
- *
- * Returns the ID assigned to the timer.
- *
- * IDs are assigned to timers using the pvTimerID parameter of the call to
- * xTimerCreated() that was used to create the timer, and by calling the
- * vTimerSetTimerID() API function.
- *
- * If the same callback function is assigned to multiple timers then the timer
- * ID can be used as time specific (timer local) storage.
- *
- * @param xTimer The timer being queried.
- *
- * @return The ID assigned to the timer being queried.
- *
- * Example usage:
- *
- * See the xTimerCreate() API function example usage scenario.
- */
-void * pvTimerGetTimerID( const TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
-
-/**
- * void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID );
- *
- * Sets the ID assigned to the timer.
- *
- * IDs are assigned to timers using the pvTimerID parameter of the call to
- * xTimerCreated() that was used to create the timer.
- *
- * If the same callback function is assigned to multiple timers then the timer
- * ID can be used as time specific (timer local) storage.
- *
- * @param xTimer The timer being updated.
- *
- * @param pvNewID The ID to assign to the timer.
- *
- * Example usage:
- *
- * See the xTimerCreate() API function example usage scenario.
- */
-void vTimerSetTimerID( TimerHandle_t xTimer,
- void * pvNewID ) PRIVILEGED_FUNCTION;
-
-/**
- * BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer );
- *
- * Queries a timer to see if it is active or dormant.
- *
- * A timer will be dormant if:
- * 1) It has been created but not started, or
- * 2) It is an expired one-shot timer that has not been restarted.
- *
- * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
- * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
- * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the
- * active state.
- *
- * @param xTimer The timer being queried.
- *
- * @return pdFALSE will be returned if the timer is dormant. A value other than
- * pdFALSE will be returned if the timer is active.
- *
- * Example usage:
- * @verbatim
- * // This function assumes xTimer has already been created.
- * void vAFunction( TimerHandle_t xTimer )
- * {
- * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
- * {
- * // xTimer is active, do something.
- * }
- * else
- * {
- * // xTimer is not active, do something else.
- * }
- * }
- * @endverbatim
- */
-BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
-
-/**
- * TaskHandle_t xTimerGetTimerDaemonTaskHandle( void );
- *
- * Simply returns the handle of the timer service/daemon task. It it not valid
- * to call xTimerGetTimerDaemonTaskHandle() before the scheduler has been started.
- */
-TaskHandle_t xTimerGetTimerDaemonTaskHandle( void ) PRIVILEGED_FUNCTION;
-
-/**
- * BaseType_t xTimerStart( TimerHandle_t xTimer, TickType_t xTicksToWait );
- *
- * Timer functionality is provided by a timer service/daemon task. Many of the
- * public FreeRTOS timer API functions send commands to the timer service task
- * through a queue called the timer command queue. The timer command queue is
- * private to the kernel itself and is not directly accessible to application
- * code. The length of the timer command queue is set by the
- * configTIMER_QUEUE_LENGTH configuration constant.
- *
- * xTimerStart() starts a timer that was previously created using the
- * xTimerCreate() API function. If the timer had already been started and was
- * already in the active state, then xTimerStart() has equivalent functionality
- * to the xTimerReset() API function.
- *
- * Starting a timer ensures the timer is in the active state. If the timer
- * is not stopped, deleted, or reset in the mean time, the callback function
- * associated with the timer will get called 'n' ticks after xTimerStart() was
- * called, where 'n' is the timers defined period.
- *
- * It is valid to call xTimerStart() before the scheduler has been started, but
- * when this is done the timer will not actually start until the scheduler is
- * started, and the timers expiry time will be relative to when the scheduler is
- * started, not relative to when xTimerStart() was called.
- *
- * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStart()
- * to be available.
- *
- * @param xTimer The handle of the timer being started/restarted.
- *
- * @param xTicksToWait Specifies the time, in ticks, that the calling task should
- * be held in the Blocked state to wait for the start command to be successfully
- * sent to the timer command queue, should the queue already be full when
- * xTimerStart() was called. xTicksToWait is ignored if xTimerStart() is called
- * before the scheduler is started.
- *
- * @return pdFAIL will be returned if the start command could not be sent to
- * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
- * be returned if the command was successfully sent to the timer command queue.
- * When the command is actually processed will depend on the priority of the
- * timer service/daemon task relative to other tasks in the system, although the
- * timers expiry time is relative to when xTimerStart() is actually called. The
- * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
- * configuration constant.
- *
- * Example usage:
- *
- * See the xTimerCreate() API function example usage scenario.
- *
- */
-#define xTimerStart( xTimer, xTicksToWait ) \
- xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
-
-/**
- * BaseType_t xTimerStop( TimerHandle_t xTimer, TickType_t xTicksToWait );
- *
- * Timer functionality is provided by a timer service/daemon task. Many of the
- * public FreeRTOS timer API functions send commands to the timer service task
- * through a queue called the timer command queue. The timer command queue is
- * private to the kernel itself and is not directly accessible to application
- * code. The length of the timer command queue is set by the
- * configTIMER_QUEUE_LENGTH configuration constant.
- *
- * xTimerStop() stops a timer that was previously started using either of the
- * The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(),
- * xTimerChangePeriod() or xTimerChangePeriodFromISR() API functions.
- *
- * Stopping a timer ensures the timer is not in the active state.
- *
- * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStop()
- * to be available.
- *
- * @param xTimer The handle of the timer being stopped.
- *
- * @param xTicksToWait Specifies the time, in ticks, that the calling task should
- * be held in the Blocked state to wait for the stop command to be successfully
- * sent to the timer command queue, should the queue already be full when
- * xTimerStop() was called. xTicksToWait is ignored if xTimerStop() is called
- * before the scheduler is started.
- *
- * @return pdFAIL will be returned if the stop command could not be sent to
- * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
- * be returned if the command was successfully sent to the timer command queue.
- * When the command is actually processed will depend on the priority of the
- * timer service/daemon task relative to other tasks in the system. The timer
- * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
- * configuration constant.
- *
- * Example usage:
- *
- * See the xTimerCreate() API function example usage scenario.
- *
- */
-#define xTimerStop( xTimer, xTicksToWait ) \
- xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) )
-
-/**
- * BaseType_t xTimerChangePeriod( TimerHandle_t xTimer,
- * TickType_t xNewPeriod,
- * TickType_t xTicksToWait );
- *
- * Timer functionality is provided by a timer service/daemon task. Many of the
- * public FreeRTOS timer API functions send commands to the timer service task
- * through a queue called the timer command queue. The timer command queue is
- * private to the kernel itself and is not directly accessible to application
- * code. The length of the timer command queue is set by the
- * configTIMER_QUEUE_LENGTH configuration constant.
- *
- * xTimerChangePeriod() changes the period of a timer that was previously
- * created using the xTimerCreate() API function.
- *
- * xTimerChangePeriod() can be called to change the period of an active or
- * dormant state timer.
- *
- * The configUSE_TIMERS configuration constant must be set to 1 for
- * xTimerChangePeriod() to be available.
- *
- * @param xTimer The handle of the timer that is having its period changed.
- *
- * @param xNewPeriod The new period for xTimer. Timer periods are specified in
- * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
- * that has been specified in milliseconds. For example, if the timer must
- * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
- * if the timer must expire after 500ms, then xNewPeriod can be set to
- * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
- * or equal to 1000.
- *
- * @param xTicksToWait Specifies the time, in ticks, that the calling task should
- * be held in the Blocked state to wait for the change period command to be
- * successfully sent to the timer command queue, should the queue already be
- * full when xTimerChangePeriod() was called. xTicksToWait is ignored if
- * xTimerChangePeriod() is called before the scheduler is started.
- *
- * @return pdFAIL will be returned if the change period command could not be
- * sent to the timer command queue even after xTicksToWait ticks had passed.
- * pdPASS will be returned if the command was successfully sent to the timer
- * command queue. When the command is actually processed will depend on the
- * priority of the timer service/daemon task relative to other tasks in the
- * system. The timer service/daemon task priority is set by the
- * configTIMER_TASK_PRIORITY configuration constant.
- *
- * Example usage:
- * @verbatim
- * // This function assumes xTimer has already been created. If the timer
- * // referenced by xTimer is already active when it is called, then the timer
- * // is deleted. If the timer referenced by xTimer is not active when it is
- * // called, then the period of the timer is set to 500ms and the timer is
- * // started.
- * void vAFunction( TimerHandle_t xTimer )
- * {
- * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
- * {
- * // xTimer is already active - delete it.
- * xTimerDelete( xTimer );
- * }
- * else
- * {
- * // xTimer is not active, change its period to 500ms. This will also
- * // cause the timer to start. Block for a maximum of 100 ticks if the
- * // change period command cannot immediately be sent to the timer
- * // command queue.
- * if( xTimerChangePeriod( xTimer, 500 / portTICK_PERIOD_MS, 100 ) == pdPASS )
- * {
- * // The command was successfully sent.
- * }
- * else
- * {
- * // The command could not be sent, even after waiting for 100 ticks
- * // to pass. Take appropriate action here.
- * }
- * }
- * }
- * @endverbatim
- */
-#define xTimerChangePeriod( xTimer, xNewPeriod, xTicksToWait ) \
- xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xTicksToWait ) )
-
-/**
- * BaseType_t xTimerDelete( TimerHandle_t xTimer, TickType_t xTicksToWait );
- *
- * Timer functionality is provided by a timer service/daemon task. Many of the
- * public FreeRTOS timer API functions send commands to the timer service task
- * through a queue called the timer command queue. The timer command queue is
- * private to the kernel itself and is not directly accessible to application
- * code. The length of the timer command queue is set by the
- * configTIMER_QUEUE_LENGTH configuration constant.
- *
- * xTimerDelete() deletes a timer that was previously created using the
- * xTimerCreate() API function.
- *
- * The configUSE_TIMERS configuration constant must be set to 1 for
- * xTimerDelete() to be available.
- *
- * @param xTimer The handle of the timer being deleted.
- *
- * @param xTicksToWait Specifies the time, in ticks, that the calling task should
- * be held in the Blocked state to wait for the delete command to be
- * successfully sent to the timer command queue, should the queue already be
- * full when xTimerDelete() was called. xTicksToWait is ignored if xTimerDelete()
- * is called before the scheduler is started.
- *
- * @return pdFAIL will be returned if the delete command could not be sent to
- * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
- * be returned if the command was successfully sent to the timer command queue.
- * When the command is actually processed will depend on the priority of the
- * timer service/daemon task relative to other tasks in the system. The timer
- * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
- * configuration constant.
- *
- * Example usage:
- *
- * See the xTimerChangePeriod() API function example usage scenario.
- */
-#define xTimerDelete( xTimer, xTicksToWait ) \
- xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) )
-
-/**
- * BaseType_t xTimerReset( TimerHandle_t xTimer, TickType_t xTicksToWait );
- *
- * Timer functionality is provided by a timer service/daemon task. Many of the
- * public FreeRTOS timer API functions send commands to the timer service task
- * through a queue called the timer command queue. The timer command queue is
- * private to the kernel itself and is not directly accessible to application
- * code. The length of the timer command queue is set by the
- * configTIMER_QUEUE_LENGTH configuration constant.
- *
- * xTimerReset() re-starts a timer that was previously created using the
- * xTimerCreate() API function. If the timer had already been started and was
- * already in the active state, then xTimerReset() will cause the timer to
- * re-evaluate its expiry time so that it is relative to when xTimerReset() was
- * called. If the timer was in the dormant state then xTimerReset() has
- * equivalent functionality to the xTimerStart() API function.
- *
- * Resetting a timer ensures the timer is in the active state. If the timer
- * is not stopped, deleted, or reset in the mean time, the callback function
- * associated with the timer will get called 'n' ticks after xTimerReset() was
- * called, where 'n' is the timers defined period.
- *
- * It is valid to call xTimerReset() before the scheduler has been started, but
- * when this is done the timer will not actually start until the scheduler is
- * started, and the timers expiry time will be relative to when the scheduler is
- * started, not relative to when xTimerReset() was called.
- *
- * The configUSE_TIMERS configuration constant must be set to 1 for xTimerReset()
- * to be available.
- *
- * @param xTimer The handle of the timer being reset/started/restarted.
- *
- * @param xTicksToWait Specifies the time, in ticks, that the calling task should
- * be held in the Blocked state to wait for the reset command to be successfully
- * sent to the timer command queue, should the queue already be full when
- * xTimerReset() was called. xTicksToWait is ignored if xTimerReset() is called
- * before the scheduler is started.
- *
- * @return pdFAIL will be returned if the reset command could not be sent to
- * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
- * be returned if the command was successfully sent to the timer command queue.
- * When the command is actually processed will depend on the priority of the
- * timer service/daemon task relative to other tasks in the system, although the
- * timers expiry time is relative to when xTimerStart() is actually called. The
- * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
- * configuration constant.
- *
- * Example usage:
- * @verbatim
- * // When a key is pressed, an LCD back-light is switched on. If 5 seconds pass
- * // without a key being pressed, then the LCD back-light is switched off. In
- * // this case, the timer is a one-shot timer.
- *
- * TimerHandle_t xBacklightTimer = NULL;
- *
- * // The callback function assigned to the one-shot timer. In this case the
- * // parameter is not used.
- * void vBacklightTimerCallback( TimerHandle_t pxTimer )
- * {
- * // The timer expired, therefore 5 seconds must have passed since a key
- * // was pressed. Switch off the LCD back-light.
- * vSetBacklightState( BACKLIGHT_OFF );
- * }
- *
- * // The key press event handler.
- * void vKeyPressEventHandler( char cKey )
- * {
- * // Ensure the LCD back-light is on, then reset the timer that is
- * // responsible for turning the back-light off after 5 seconds of
- * // key inactivity. Wait 10 ticks for the command to be successfully sent
- * // if it cannot be sent immediately.
- * vSetBacklightState( BACKLIGHT_ON );
- * if( xTimerReset( xBacklightTimer, 100 ) != pdPASS )
- * {
- * // The reset command was not executed successfully. Take appropriate
- * // action here.
- * }
- *
- * // Perform the rest of the key processing here.
- * }
- *
- * void main( void )
- * {
- * int32_t x;
- *
- * // Create then start the one-shot timer that is responsible for turning
- * // the back-light off if no keys are pressed within a 5 second period.
- * xBacklightTimer = xTimerCreate( "BacklightTimer", // Just a text name, not used by the kernel.
- * ( 5000 / portTICK_PERIOD_MS), // The timer period in ticks.
- * pdFALSE, // The timer is a one-shot timer.
- * 0, // The id is not used by the callback so can take any value.
- * vBacklightTimerCallback // The callback function that switches the LCD back-light off.
- * );
- *
- * if( xBacklightTimer == NULL )
- * {
- * // The timer was not created.
- * }
- * else
- * {
- * // Start the timer. No block time is specified, and even if one was
- * // it would be ignored because the scheduler has not yet been
- * // started.
- * if( xTimerStart( xBacklightTimer, 0 ) != pdPASS )
- * {
- * // The timer could not be set into the Active state.
- * }
- * }
- *
- * // ...
- * // Create tasks here.
- * // ...
- *
- * // Starting the scheduler will start the timer running as it has already
- * // been set into the active state.
- * vTaskStartScheduler();
- *
- * // Should not reach here.
- * for( ;; );
- * }
- * @endverbatim
- */
-#define xTimerReset( xTimer, xTicksToWait ) \
- xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
-
-/**
- * BaseType_t xTimerStartFromISR( TimerHandle_t xTimer,
- * BaseType_t *pxHigherPriorityTaskWoken );
- *
- * A version of xTimerStart() that can be called from an interrupt service
- * routine.
- *
- * @param xTimer The handle of the timer being started/restarted.
- *
- * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
- * of its time in the Blocked state, waiting for messages to arrive on the timer
- * command queue. Calling xTimerStartFromISR() writes a message to the timer
- * command queue, so has the potential to transition the timer service/daemon
- * task out of the Blocked state. If calling xTimerStartFromISR() causes the
- * timer service/daemon task to leave the Blocked state, and the timer service/
- * daemon task has a priority equal to or greater than the currently executing
- * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
- * get set to pdTRUE internally within the xTimerStartFromISR() function. If
- * xTimerStartFromISR() sets this value to pdTRUE then a context switch should
- * be performed before the interrupt exits.
- *
- * @return pdFAIL will be returned if the start command could not be sent to
- * the timer command queue. pdPASS will be returned if the command was
- * successfully sent to the timer command queue. When the command is actually
- * processed will depend on the priority of the timer service/daemon task
- * relative to other tasks in the system, although the timers expiry time is
- * relative to when xTimerStartFromISR() is actually called. The timer
- * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
- * configuration constant.
- *
- * Example usage:
- * @verbatim
- * // This scenario assumes xBacklightTimer has already been created. When a
- * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
- * // without a key being pressed, then the LCD back-light is switched off. In
- * // this case, the timer is a one-shot timer, and unlike the example given for
- * // the xTimerReset() function, the key press event handler is an interrupt
- * // service routine.
- *
- * // The callback function assigned to the one-shot timer. In this case the
- * // parameter is not used.
- * void vBacklightTimerCallback( TimerHandle_t pxTimer )
- * {
- * // The timer expired, therefore 5 seconds must have passed since a key
- * // was pressed. Switch off the LCD back-light.
- * vSetBacklightState( BACKLIGHT_OFF );
- * }
- *
- * // The key press interrupt service routine.
- * void vKeyPressEventInterruptHandler( void )
- * {
- * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
- *
- * // Ensure the LCD back-light is on, then restart the timer that is
- * // responsible for turning the back-light off after 5 seconds of
- * // key inactivity. This is an interrupt service routine so can only
- * // call FreeRTOS API functions that end in "FromISR".
- * vSetBacklightState( BACKLIGHT_ON );
- *
- * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
- * // as both cause the timer to re-calculate its expiry time.
- * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
- * // declared (in this function).
- * if( xTimerStartFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
- * {
- * // The start command was not executed successfully. Take appropriate
- * // action here.
- * }
- *
- * // Perform the rest of the key processing here.
- *
- * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
- * // should be performed. The syntax required to perform a context switch
- * // from inside an ISR varies from port to port, and from compiler to
- * // compiler. Inspect the demos for the port you are using to find the
- * // actual syntax required.
- * if( xHigherPriorityTaskWoken != pdFALSE )
- * {
- * // Call the interrupt safe yield function here (actual function
- * // depends on the FreeRTOS port being used).
- * }
- * }
- * @endverbatim
- */
-#define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) \
- xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
-
-/**
- * BaseType_t xTimerStopFromISR( TimerHandle_t xTimer,
- * BaseType_t *pxHigherPriorityTaskWoken );
- *
- * A version of xTimerStop() that can be called from an interrupt service
- * routine.
- *
- * @param xTimer The handle of the timer being stopped.
- *
- * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
- * of its time in the Blocked state, waiting for messages to arrive on the timer
- * command queue. Calling xTimerStopFromISR() writes a message to the timer
- * command queue, so has the potential to transition the timer service/daemon
- * task out of the Blocked state. If calling xTimerStopFromISR() causes the
- * timer service/daemon task to leave the Blocked state, and the timer service/
- * daemon task has a priority equal to or greater than the currently executing
- * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
- * get set to pdTRUE internally within the xTimerStopFromISR() function. If
- * xTimerStopFromISR() sets this value to pdTRUE then a context switch should
- * be performed before the interrupt exits.
- *
- * @return pdFAIL will be returned if the stop command could not be sent to
- * the timer command queue. pdPASS will be returned if the command was
- * successfully sent to the timer command queue. When the command is actually
- * processed will depend on the priority of the timer service/daemon task
- * relative to other tasks in the system. The timer service/daemon task
- * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
- *
- * Example usage:
- * @verbatim
- * // This scenario assumes xTimer has already been created and started. When
- * // an interrupt occurs, the timer should be simply stopped.
- *
- * // The interrupt service routine that stops the timer.
- * void vAnExampleInterruptServiceRoutine( void )
- * {
- * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
- *
- * // The interrupt has occurred - simply stop the timer.
- * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
- * // (within this function). As this is an interrupt service routine, only
- * // FreeRTOS API functions that end in "FromISR" can be used.
- * if( xTimerStopFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
- * {
- * // The stop command was not executed successfully. Take appropriate
- * // action here.
- * }
- *
- * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
- * // should be performed. The syntax required to perform a context switch
- * // from inside an ISR varies from port to port, and from compiler to
- * // compiler. Inspect the demos for the port you are using to find the
- * // actual syntax required.
- * if( xHigherPriorityTaskWoken != pdFALSE )
- * {
- * // Call the interrupt safe yield function here (actual function
- * // depends on the FreeRTOS port being used).
- * }
- * }
- * @endverbatim
- */
-#define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) \
- xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP_FROM_ISR, 0, ( pxHigherPriorityTaskWoken ), 0U )
-
-/**
- * BaseType_t xTimerChangePeriodFromISR( TimerHandle_t xTimer,
- * TickType_t xNewPeriod,
- * BaseType_t *pxHigherPriorityTaskWoken );
- *
- * A version of xTimerChangePeriod() that can be called from an interrupt
- * service routine.
- *
- * @param xTimer The handle of the timer that is having its period changed.
- *
- * @param xNewPeriod The new period for xTimer. Timer periods are specified in
- * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
- * that has been specified in milliseconds. For example, if the timer must
- * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
- * if the timer must expire after 500ms, then xNewPeriod can be set to
- * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
- * or equal to 1000.
- *
- * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
- * of its time in the Blocked state, waiting for messages to arrive on the timer
- * command queue. Calling xTimerChangePeriodFromISR() writes a message to the
- * timer command queue, so has the potential to transition the timer service/
- * daemon task out of the Blocked state. If calling xTimerChangePeriodFromISR()
- * causes the timer service/daemon task to leave the Blocked state, and the
- * timer service/daemon task has a priority equal to or greater than the
- * currently executing task (the task that was interrupted), then
- * *pxHigherPriorityTaskWoken will get set to pdTRUE internally within the
- * xTimerChangePeriodFromISR() function. If xTimerChangePeriodFromISR() sets
- * this value to pdTRUE then a context switch should be performed before the
- * interrupt exits.
- *
- * @return pdFAIL will be returned if the command to change the timers period
- * could not be sent to the timer command queue. pdPASS will be returned if the
- * command was successfully sent to the timer command queue. When the command
- * is actually processed will depend on the priority of the timer service/daemon
- * task relative to other tasks in the system. The timer service/daemon task
- * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
- *
- * Example usage:
- * @verbatim
- * // This scenario assumes xTimer has already been created and started. When
- * // an interrupt occurs, the period of xTimer should be changed to 500ms.
- *
- * // The interrupt service routine that changes the period of xTimer.
- * void vAnExampleInterruptServiceRoutine( void )
- * {
- * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
- *
- * // The interrupt has occurred - change the period of xTimer to 500ms.
- * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
- * // (within this function). As this is an interrupt service routine, only
- * // FreeRTOS API functions that end in "FromISR" can be used.
- * if( xTimerChangePeriodFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
- * {
- * // The command to change the timers period was not executed
- * // successfully. Take appropriate action here.
- * }
- *
- * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
- * // should be performed. The syntax required to perform a context switch
- * // from inside an ISR varies from port to port, and from compiler to
- * // compiler. Inspect the demos for the port you are using to find the
- * // actual syntax required.
- * if( xHigherPriorityTaskWoken != pdFALSE )
- * {
- * // Call the interrupt safe yield function here (actual function
- * // depends on the FreeRTOS port being used).
- * }
- * }
- * @endverbatim
- */
-#define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) \
- xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U )
-
-/**
- * BaseType_t xTimerResetFromISR( TimerHandle_t xTimer,
- * BaseType_t *pxHigherPriorityTaskWoken );
- *
- * A version of xTimerReset() that can be called from an interrupt service
- * routine.
- *
- * @param xTimer The handle of the timer that is to be started, reset, or
- * restarted.
- *
- * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
- * of its time in the Blocked state, waiting for messages to arrive on the timer
- * command queue. Calling xTimerResetFromISR() writes a message to the timer
- * command queue, so has the potential to transition the timer service/daemon
- * task out of the Blocked state. If calling xTimerResetFromISR() causes the
- * timer service/daemon task to leave the Blocked state, and the timer service/
- * daemon task has a priority equal to or greater than the currently executing
- * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
- * get set to pdTRUE internally within the xTimerResetFromISR() function. If
- * xTimerResetFromISR() sets this value to pdTRUE then a context switch should
- * be performed before the interrupt exits.
- *
- * @return pdFAIL will be returned if the reset command could not be sent to
- * the timer command queue. pdPASS will be returned if the command was
- * successfully sent to the timer command queue. When the command is actually
- * processed will depend on the priority of the timer service/daemon task
- * relative to other tasks in the system, although the timers expiry time is
- * relative to when xTimerResetFromISR() is actually called. The timer service/daemon
- * task priority is set by the configTIMER_TASK_PRIORITY configuration constant.
- *
- * Example usage:
- * @verbatim
- * // This scenario assumes xBacklightTimer has already been created. When a
- * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
- * // without a key being pressed, then the LCD back-light is switched off. In
- * // this case, the timer is a one-shot timer, and unlike the example given for
- * // the xTimerReset() function, the key press event handler is an interrupt
- * // service routine.
- *
- * // The callback function assigned to the one-shot timer. In this case the
- * // parameter is not used.
- * void vBacklightTimerCallback( TimerHandle_t pxTimer )
- * {
- * // The timer expired, therefore 5 seconds must have passed since a key
- * // was pressed. Switch off the LCD back-light.
- * vSetBacklightState( BACKLIGHT_OFF );
- * }
- *
- * // The key press interrupt service routine.
- * void vKeyPressEventInterruptHandler( void )
- * {
- * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
- *
- * // Ensure the LCD back-light is on, then reset the timer that is
- * // responsible for turning the back-light off after 5 seconds of
- * // key inactivity. This is an interrupt service routine so can only
- * // call FreeRTOS API functions that end in "FromISR".
- * vSetBacklightState( BACKLIGHT_ON );
- *
- * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
- * // as both cause the timer to re-calculate its expiry time.
- * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
- * // declared (in this function).
- * if( xTimerResetFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
- * {
- * // The reset command was not executed successfully. Take appropriate
- * // action here.
- * }
- *
- * // Perform the rest of the key processing here.
- *
- * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
- * // should be performed. The syntax required to perform a context switch
- * // from inside an ISR varies from port to port, and from compiler to
- * // compiler. Inspect the demos for the port you are using to find the
- * // actual syntax required.
- * if( xHigherPriorityTaskWoken != pdFALSE )
- * {
- * // Call the interrupt safe yield function here (actual function
- * // depends on the FreeRTOS port being used).
- * }
- * }
- * @endverbatim
- */
-#define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) \
- xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
-
-
-/**
- * BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend,
- * void *pvParameter1,
- * uint32_t ulParameter2,
- * BaseType_t *pxHigherPriorityTaskWoken );
- *
- *
- * Used from application interrupt service routines to defer the execution of a
- * function to the RTOS daemon task (the timer service task, hence this function
- * is implemented in timers.c and is prefixed with 'Timer').
- *
- * Ideally an interrupt service routine (ISR) is kept as short as possible, but
- * sometimes an ISR either has a lot of processing to do, or needs to perform
- * processing that is not deterministic. In these cases
- * xTimerPendFunctionCallFromISR() can be used to defer processing of a function
- * to the RTOS daemon task.
- *
- * A mechanism is provided that allows the interrupt to return directly to the
- * task that will subsequently execute the pended callback function. This
- * allows the callback function to execute contiguously in time with the
- * interrupt - just as if the callback had executed in the interrupt itself.
- *
- * @param xFunctionToPend The function to execute from the timer service/
- * daemon task. The function must conform to the PendedFunction_t
- * prototype.
- *
- * @param pvParameter1 The value of the callback function's first parameter.
- * The parameter has a void * type to allow it to be used to pass any type.
- * For example, unsigned longs can be cast to a void *, or the void * can be
- * used to point to a structure.
- *
- * @param ulParameter2 The value of the callback function's second parameter.
- *
- * @param pxHigherPriorityTaskWoken As mentioned above, calling this function
- * will result in a message being sent to the timer daemon task. If the
- * priority of the timer daemon task (which is set using
- * configTIMER_TASK_PRIORITY in FreeRTOSConfig.h) is higher than the priority of
- * the currently running task (the task the interrupt interrupted) then
- * *pxHigherPriorityTaskWoken will be set to pdTRUE within
- * xTimerPendFunctionCallFromISR(), indicating that a context switch should be
- * requested before the interrupt exits. For that reason
- * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
- * example code below.
- *
- * @return pdPASS is returned if the message was successfully sent to the
- * timer daemon task, otherwise pdFALSE is returned.
- *
- * Example usage:
- * @verbatim
- *
- * // The callback function that will execute in the context of the daemon task.
- * // Note callback functions must all use this same prototype.
- * void vProcessInterface( void *pvParameter1, uint32_t ulParameter2 )
- * {
- * BaseType_t xInterfaceToService;
- *
- * // The interface that requires servicing is passed in the second
- * // parameter. The first parameter is not used in this case.
- * xInterfaceToService = ( BaseType_t ) ulParameter2;
- *
- * // ...Perform the processing here...
- * }
- *
- * // An ISR that receives data packets from multiple interfaces
- * void vAnISR( void )
- * {
- * BaseType_t xInterfaceToService, xHigherPriorityTaskWoken;
- *
- * // Query the hardware to determine which interface needs processing.
- * xInterfaceToService = prvCheckInterfaces();
- *
- * // The actual processing is to be deferred to a task. Request the
- * // vProcessInterface() callback function is executed, passing in the
- * // number of the interface that needs processing. The interface to
- * // service is passed in the second parameter. The first parameter is
- * // not used in this case.
- * xHigherPriorityTaskWoken = pdFALSE;
- * xTimerPendFunctionCallFromISR( vProcessInterface, NULL, ( uint32_t ) xInterfaceToService, &xHigherPriorityTaskWoken );
- *
- * // If xHigherPriorityTaskWoken is now set to pdTRUE then a context
- * // switch should be requested. The macro used is port specific and will
- * // be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to
- * // the documentation page for the port being used.
- * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
- *
- * }
- * @endverbatim
- */
-BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend,
- void * pvParameter1,
- uint32_t ulParameter2,
- BaseType_t * pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;
-
-/**
- * BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
- * void *pvParameter1,
- * uint32_t ulParameter2,
- * TickType_t xTicksToWait );
- *
- *
- * Used to defer the execution of a function to the RTOS daemon task (the timer
- * service task, hence this function is implemented in timers.c and is prefixed
- * with 'Timer').
- *
- * @param xFunctionToPend The function to execute from the timer service/
- * daemon task. The function must conform to the PendedFunction_t
- * prototype.
- *
- * @param pvParameter1 The value of the callback function's first parameter.
- * The parameter has a void * type to allow it to be used to pass any type.
- * For example, unsigned longs can be cast to a void *, or the void * can be
- * used to point to a structure.
- *
- * @param ulParameter2 The value of the callback function's second parameter.
- *
- * @param xTicksToWait Calling this function will result in a message being
- * sent to the timer daemon task on a queue. xTicksToWait is the amount of
- * time the calling task should remain in the Blocked state (so not using any
- * processing time) for space to become available on the timer queue if the
- * queue is found to be full.
- *
- * @return pdPASS is returned if the message was successfully sent to the
- * timer daemon task, otherwise pdFALSE is returned.
- *
- */
-BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
- void * pvParameter1,
- uint32_t ulParameter2,
- TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
-
-/**
- * const char * const pcTimerGetName( TimerHandle_t xTimer );
- *
- * Returns the name that was assigned to a timer when the timer was created.
- *
- * @param xTimer The handle of the timer being queried.
- *
- * @return The name assigned to the timer specified by the xTimer parameter.
- */
-const char * pcTimerGetName( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
-
-/**
- * void vTimerSetReloadMode( TimerHandle_t xTimer, const UBaseType_t uxAutoReload );
- *
- * Updates a timer to be either an auto-reload timer, in which case the timer
- * automatically resets itself each time it expires, or a one-shot timer, in
- * which case the timer will only expire once unless it is manually restarted.
- *
- * @param xTimer The handle of the timer being updated.
- *
- * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
- * expire repeatedly with a frequency set by the timer's period (see the
- * xTimerPeriodInTicks parameter of the xTimerCreate() API function). If
- * uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
- * enter the dormant state after it expires.
- */
-void vTimerSetReloadMode( TimerHandle_t xTimer,
- const UBaseType_t uxAutoReload ) PRIVILEGED_FUNCTION;
-
-/**
- * UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer );
- *
- * Queries a timer to determine if it is an auto-reload timer, in which case the timer
- * automatically resets itself each time it expires, or a one-shot timer, in
- * which case the timer will only expire once unless it is manually restarted.
- *
- * @param xTimer The handle of the timer being queried.
- *
- * @return If the timer is an auto-reload timer then pdTRUE is returned, otherwise
- * pdFALSE is returned.
- */
-UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
-
-/**
- * TickType_t xTimerGetPeriod( TimerHandle_t xTimer );
- *
- * Returns the period of a timer.
- *
- * @param xTimer The handle of the timer being queried.
- *
- * @return The period of the timer in ticks.
- */
-TickType_t xTimerGetPeriod( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
-
-/**
- * TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer );
- *
- * Returns the time in ticks at which the timer will expire. If this is less
- * than the current tick count then the expiry time has overflowed from the
- * current time.
- *
- * @param xTimer The handle of the timer being queried.
- *
- * @return If the timer is running then the time in ticks at which the timer
- * will next expire is returned. If the timer is not running then the return
- * value is undefined.
- */
-TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
-
-/*
- * Functions beyond this part are not part of the public API and are intended
- * for use by the kernel only.
- */
-BaseType_t xTimerCreateTimerTask( void ) PRIVILEGED_FUNCTION;
-BaseType_t xTimerGenericCommand( TimerHandle_t xTimer,
- const BaseType_t xCommandID,
- const TickType_t xOptionalValue,
- BaseType_t * const pxHigherPriorityTaskWoken,
- const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
-
-#if ( configUSE_TRACE_FACILITY == 1 )
- void vTimerSetTimerNumber( TimerHandle_t xTimer,
- UBaseType_t uxTimerNumber ) PRIVILEGED_FUNCTION;
- UBaseType_t uxTimerGetTimerNumber( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
-#endif
-
-#if ( configSUPPORT_STATIC_ALLOCATION == 1 )
-
- /**
- * task.h
- * void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer, StackType_t ** ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
- *
- * This function is used to provide a statically allocated block of memory to FreeRTOS to hold the Timer Task 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
- *
- * @param ppxTimerTaskTCBBuffer A handle to a statically allocated TCB buffer
- * @param ppxTimerTaskStackBuffer A handle to a statically allocated Stack buffer for thie idle task
- * @param pulTimerTaskStackSize A pointer to the number of elements that will fit in the allocated stack buffer
- */
- void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
- StackType_t ** ppxTimerTaskStackBuffer,
- uint32_t * pulTimerTaskStackSize );
-
-#endif
+typedef void (* PendedFunction_t)( void *, uint32_t );
/* *INDENT-OFF* */
#ifdef __cplusplus
diff --git a/examples/chapter11_07/src/os/FreeRTOS/Source/timers.c b/examples/chapter11_07/src/os/FreeRTOS/Source/timers.c
deleted file mode 100644
index c57101ebb..000000000
--- a/examples/chapter11_07/src/os/FreeRTOS/Source/timers.c
+++ /dev/null
@@ -1,1144 +0,0 @@
-/*
- * FreeRTOS Kernel V10.4.1
- * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. 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.
- *
- * https://www.FreeRTOS.org
- * https://github.com/FreeRTOS
- *
- */
-
-/* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
- * all the API functions to use the MPU wrappers. That should only be done when
- * task.h is included from an application file. */
-#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
-
-#include
-#include
-#include
-#include
-
-/* Standard includes. */
-#include
-
-#if ( INCLUDE_xTimerPendFunctionCall == 1 ) && ( configUSE_TIMERS == 0 )
- #error configUSE_TIMERS must be set to 1 to make the xTimerPendFunctionCall() function available.
-#endif
-
-/* Lint e9021, e961 and e750 are suppressed as a MISRA exception justified
- * because the MPU ports require MPU_WRAPPERS_INCLUDED_FROM_API_FILE to be defined
- * for the header files above, but not in this file, in order to generate the
- * correct privileged Vs unprivileged linkage and placement. */
-#undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE /*lint !e9021 !e961 !e750. */
-
-
-/* This entire source file will be skipped if the application is not configured
- * to include software timer functionality. This #if is closed at the very bottom
- * of this file. If you want to include software timer functionality then ensure
- * configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
-#if ( configUSE_TIMERS == 1 )
-
-/* Misc definitions. */
- #define tmrNO_DELAY ( TickType_t ) 0U
-
-/* The name assigned to the timer service task. This can be overridden by
- * defining trmTIMER_SERVICE_TASK_NAME in FreeRTOSConfig.h. */
- #ifndef configTIMER_SERVICE_TASK_NAME
- #define configTIMER_SERVICE_TASK_NAME "Tmr Svc"
- #endif
-
-/* Bit definitions used in the ucStatus member of a timer structure. */
- #define tmrSTATUS_IS_ACTIVE ( ( uint8_t ) 0x01 )
- #define tmrSTATUS_IS_STATICALLY_ALLOCATED ( ( uint8_t ) 0x02 )
- #define tmrSTATUS_IS_AUTORELOAD ( ( uint8_t ) 0x04 )
-
-/* The definition of the timers themselves. */
- typedef struct tmrTimerControl /* The old naming convention is used to prevent breaking kernel aware debuggers. */
- {
- const char * pcTimerName; /*<< Text name. This is not used by the kernel, it is included simply to make debugging easier. */ /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
- ListItem_t xTimerListItem; /*<< Standard linked list item as used by all kernel features for event management. */
- TickType_t xTimerPeriodInTicks; /*<< How quickly and often the timer expires. */
- void * pvTimerID; /*<< An ID to identify the timer. This allows the timer to be identified when the same callback is used for multiple timers. */
- TimerCallbackFunction_t pxCallbackFunction; /*<< The function that will be called when the timer expires. */
- #if ( configUSE_TRACE_FACILITY == 1 )
- UBaseType_t uxTimerNumber; /*<< An ID assigned by trace tools such as FreeRTOS+Trace */
- #endif
- uint8_t ucStatus; /*<< Holds bits to say if the timer was statically allocated or not, and if it is active or not. */
- } xTIMER;
-
-/* The old xTIMER name is maintained above then typedefed to the new Timer_t
- * name below to enable the use of older kernel aware debuggers. */
- typedef xTIMER Timer_t;
-
-/* The definition of messages that can be sent and received on the timer queue.
- * Two types of message can be queued - messages that manipulate a software timer,
- * and messages that request the execution of a non-timer related callback. The
- * two message types are defined in two separate structures, xTimerParametersType
- * and xCallbackParametersType respectively. */
- typedef struct tmrTimerParameters
- {
- TickType_t xMessageValue; /*<< An optional value used by a subset of commands, for example, when changing the period of a timer. */
- Timer_t * pxTimer; /*<< The timer to which the command will be applied. */
- } TimerParameter_t;
-
-
- typedef struct tmrCallbackParameters
- {
- PendedFunction_t pxCallbackFunction; /* << The callback function to execute. */
- void * pvParameter1; /* << The value that will be used as the callback functions first parameter. */
- uint32_t ulParameter2; /* << The value that will be used as the callback functions second parameter. */
- } CallbackParameters_t;
-
-/* The structure that contains the two message types, along with an identifier
- * that is used to determine which message type is valid. */
- typedef struct tmrTimerQueueMessage
- {
- BaseType_t xMessageID; /*<< The command being sent to the timer service task. */
- union
- {
- TimerParameter_t xTimerParameters;
-
- /* Don't include xCallbackParameters if it is not going to be used as
- * it makes the structure (and therefore the timer queue) larger. */
- #if ( INCLUDE_xTimerPendFunctionCall == 1 )
- CallbackParameters_t xCallbackParameters;
- #endif /* INCLUDE_xTimerPendFunctionCall */
- } u;
- } DaemonTaskMessage_t;
-
-/*lint -save -e956 A manual analysis and inspection has been used to determine
- * which static variables must be declared volatile. */
-
-/* The list in which active timers are stored. Timers are referenced in expire
- * time order, with the nearest expiry time at the front of the list. Only the
- * timer service task is allowed to access these lists.
- * xActiveTimerList1 and xActiveTimerList2 could be at function scope but that
- * breaks some kernel aware debuggers, and debuggers that reply on removing the
- * static qualifier. */
- PRIVILEGED_DATA static List_t xActiveTimerList1;
- PRIVILEGED_DATA static List_t xActiveTimerList2;
- PRIVILEGED_DATA static List_t * pxCurrentTimerList;
- PRIVILEGED_DATA static List_t * pxOverflowTimerList;
-
-/* A queue that is used to send commands to the timer service task. */
- PRIVILEGED_DATA static QueueHandle_t xTimerQueue = NULL;
- PRIVILEGED_DATA static TaskHandle_t xTimerTaskHandle = NULL;
-
-/*lint -restore */
-
-/*-----------------------------------------------------------*/
-
-/*
- * Initialise the infrastructure used by the timer service task if it has not
- * been initialised already.
- */
- static void prvCheckForValidListAndQueue( void ) PRIVILEGED_FUNCTION;
-
-/*
- * The timer service task (daemon). Timer functionality is controlled by this
- * task. Other tasks communicate with the timer service task using the
- * xTimerQueue queue.
- */
- static portTASK_FUNCTION_PROTO( prvTimerTask, pvParameters ) PRIVILEGED_FUNCTION;
-
-/*
- * Called by the timer service task to interpret and process a command it
- * received on the timer queue.
- */
- static void prvProcessReceivedCommands( void ) PRIVILEGED_FUNCTION;
-
-/*
- * Insert the timer into either xActiveTimerList1, or xActiveTimerList2,
- * depending on if the expire time causes a timer counter overflow.
- */
- static BaseType_t prvInsertTimerInActiveList( Timer_t * const pxTimer,
- const TickType_t xNextExpiryTime,
- const TickType_t xTimeNow,
- const TickType_t xCommandTime ) PRIVILEGED_FUNCTION;
-
-/*
- * An active timer has reached its expire time. Reload the timer if it is an
- * auto-reload timer, then call its callback.
- */
- static void prvProcessExpiredTimer( const TickType_t xNextExpireTime,
- const TickType_t xTimeNow ) PRIVILEGED_FUNCTION;
-
-/*
- * The tick count has overflowed. Switch the timer lists after ensuring the
- * current timer list does not still reference some timers.
- */
- static void prvSwitchTimerLists( void ) PRIVILEGED_FUNCTION;
-
-/*
- * Obtain the current tick count, setting *pxTimerListsWereSwitched to pdTRUE
- * if a tick count overflow occurred since prvSampleTimeNow() was last called.
- */
- static TickType_t prvSampleTimeNow( BaseType_t * const pxTimerListsWereSwitched ) PRIVILEGED_FUNCTION;
-
-/*
- * If the timer list contains any active timers then return the expire time of
- * the timer that will expire first and set *pxListWasEmpty to false. If the
- * timer list does not contain any timers then return 0 and set *pxListWasEmpty
- * to pdTRUE.
- */
- static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty ) PRIVILEGED_FUNCTION;
-
-/*
- * If a timer has expired, process it. Otherwise, block the timer service task
- * until either a timer does expire or a command is received.
- */
- static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime,
- BaseType_t xListWasEmpty ) PRIVILEGED_FUNCTION;
-
-/*
- * Called after a Timer_t structure has been allocated either statically or
- * dynamically to fill in the structure's members.
- */
- static void prvInitialiseNewTimer( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
- const TickType_t xTimerPeriodInTicks,
- const UBaseType_t uxAutoReload,
- void * const pvTimerID,
- TimerCallbackFunction_t pxCallbackFunction,
- Timer_t * pxNewTimer ) PRIVILEGED_FUNCTION;
-/*-----------------------------------------------------------*/
-
- BaseType_t xTimerCreateTimerTask( void )
- {
- BaseType_t xReturn = pdFAIL;
-
- /* This function is called when the scheduler is started if
- * configUSE_TIMERS is set to 1. Check that the infrastructure used by the
- * timer service task has been created/initialised. If timers have already
- * been created then the initialisation will already have been performed. */
- prvCheckForValidListAndQueue();
-
- if( xTimerQueue != NULL )
- {
- #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
- {
- StaticTask_t * pxTimerTaskTCBBuffer = NULL;
- StackType_t * pxTimerTaskStackBuffer = NULL;
- uint32_t ulTimerTaskStackSize;
-
- vApplicationGetTimerTaskMemory( &pxTimerTaskTCBBuffer, &pxTimerTaskStackBuffer, &ulTimerTaskStackSize );
- xTimerTaskHandle = xTaskCreateStatic( prvTimerTask,
- configTIMER_SERVICE_TASK_NAME,
- ulTimerTaskStackSize,
- NULL,
- ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
- pxTimerTaskStackBuffer,
- pxTimerTaskTCBBuffer );
-
- if( xTimerTaskHandle != NULL )
- {
- xReturn = pdPASS;
- }
- }
- #else /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
- {
- xReturn = xTaskCreate( prvTimerTask,
- configTIMER_SERVICE_TASK_NAME,
- configTIMER_TASK_STACK_DEPTH,
- NULL,
- ( ( UBaseType_t ) configTIMER_TASK_PRIORITY ) | portPRIVILEGE_BIT,
- &xTimerTaskHandle );
- }
- #endif /* configSUPPORT_STATIC_ALLOCATION */
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
-
- configASSERT( xReturn );
- return xReturn;
- }
-/*-----------------------------------------------------------*/
-
- #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
-
- TimerHandle_t xTimerCreate( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
- const TickType_t xTimerPeriodInTicks,
- const UBaseType_t uxAutoReload,
- void * const pvTimerID,
- TimerCallbackFunction_t pxCallbackFunction )
- {
- Timer_t * pxNewTimer;
-
- pxNewTimer = ( Timer_t * ) pvPortMalloc( sizeof( Timer_t ) ); /*lint !e9087 !e9079 All values returned by pvPortMalloc() have at least the alignment required by the MCU's stack, and the first member of Timer_t is always a pointer to the timer's mame. */
-
- if( pxNewTimer != NULL )
- {
- /* Status is thus far zero as the timer is not created statically
- * and has not been started. The auto-reload bit may get set in
- * prvInitialiseNewTimer. */
- pxNewTimer->ucStatus = 0x00;
- prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
- }
-
- return pxNewTimer;
- }
-
- #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
-/*-----------------------------------------------------------*/
-
- #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
-
- TimerHandle_t xTimerCreateStatic( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
- const TickType_t xTimerPeriodInTicks,
- const UBaseType_t uxAutoReload,
- void * const pvTimerID,
- TimerCallbackFunction_t pxCallbackFunction,
- StaticTimer_t * pxTimerBuffer )
- {
- Timer_t * pxNewTimer;
-
- #if ( configASSERT_DEFINED == 1 )
- {
- /* Sanity check that the size of the structure used to declare a
- * variable of type StaticTimer_t equals the size of the real timer
- * structure. */
- volatile size_t xSize = sizeof( StaticTimer_t );
- configASSERT( xSize == sizeof( Timer_t ) );
- ( void ) xSize; /* Keeps lint quiet when configASSERT() is not defined. */
- }
- #endif /* configASSERT_DEFINED */
-
- /* A pointer to a StaticTimer_t structure MUST be provided, use it. */
- configASSERT( pxTimerBuffer );
- pxNewTimer = ( Timer_t * ) pxTimerBuffer; /*lint !e740 !e9087 StaticTimer_t is a pointer to a Timer_t, so guaranteed to be aligned and sized correctly (checked by an assert()), so this is safe. */
-
- if( pxNewTimer != NULL )
- {
- /* Timers can be created statically or dynamically so note this
- * timer was created statically in case it is later deleted. The
- * auto-reload bit may get set in prvInitialiseNewTimer(). */
- pxNewTimer->ucStatus = tmrSTATUS_IS_STATICALLY_ALLOCATED;
-
- prvInitialiseNewTimer( pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction, pxNewTimer );
- }
-
- return pxNewTimer;
- }
-
- #endif /* configSUPPORT_STATIC_ALLOCATION */
-/*-----------------------------------------------------------*/
-
- static void prvInitialiseNewTimer( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
- const TickType_t xTimerPeriodInTicks,
- const UBaseType_t uxAutoReload,
- void * const pvTimerID,
- TimerCallbackFunction_t pxCallbackFunction,
- Timer_t * pxNewTimer )
- {
- /* 0 is not a valid value for xTimerPeriodInTicks. */
- configASSERT( ( xTimerPeriodInTicks > 0 ) );
-
- if( pxNewTimer != NULL )
- {
- /* Ensure the infrastructure used by the timer service task has been
- * created/initialised. */
- prvCheckForValidListAndQueue();
-
- /* Initialise the timer structure members using the function
- * parameters. */
- pxNewTimer->pcTimerName = pcTimerName;
- pxNewTimer->xTimerPeriodInTicks = xTimerPeriodInTicks;
- pxNewTimer->pvTimerID = pvTimerID;
- pxNewTimer->pxCallbackFunction = pxCallbackFunction;
- vListInitialiseItem( &( pxNewTimer->xTimerListItem ) );
-
- if( uxAutoReload != pdFALSE )
- {
- pxNewTimer->ucStatus |= tmrSTATUS_IS_AUTORELOAD;
- }
-
- traceTIMER_CREATE( pxNewTimer );
- }
- }
-/*-----------------------------------------------------------*/
-
- BaseType_t xTimerGenericCommand( TimerHandle_t xTimer,
- const BaseType_t xCommandID,
- const TickType_t xOptionalValue,
- BaseType_t * const pxHigherPriorityTaskWoken,
- const TickType_t xTicksToWait )
- {
- BaseType_t xReturn = pdFAIL;
- DaemonTaskMessage_t xMessage;
-
- configASSERT( xTimer );
-
- /* Send a message to the timer service task to perform a particular action
- * on a particular timer definition. */
- if( xTimerQueue != NULL )
- {
- /* Send a command to the timer service task to start the xTimer timer. */
- xMessage.xMessageID = xCommandID;
- xMessage.u.xTimerParameters.xMessageValue = xOptionalValue;
- xMessage.u.xTimerParameters.pxTimer = xTimer;
-
- if( xCommandID < tmrFIRST_FROM_ISR_COMMAND )
- {
- if( xTaskGetSchedulerState() == taskSCHEDULER_RUNNING )
- {
- xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait );
- }
- else
- {
- xReturn = xQueueSendToBack( xTimerQueue, &xMessage, tmrNO_DELAY );
- }
- }
- else
- {
- xReturn = xQueueSendToBackFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );
- }
-
- traceTIMER_COMMAND_SEND( xTimer, xCommandID, xOptionalValue, xReturn );
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
-
- return xReturn;
- }
-/*-----------------------------------------------------------*/
-
- TaskHandle_t xTimerGetTimerDaemonTaskHandle( void )
- {
- /* If xTimerGetTimerDaemonTaskHandle() is called before the scheduler has been
- * started, then xTimerTaskHandle will be NULL. */
- configASSERT( ( xTimerTaskHandle != NULL ) );
- return xTimerTaskHandle;
- }
-/*-----------------------------------------------------------*/
-
- TickType_t xTimerGetPeriod( TimerHandle_t xTimer )
- {
- Timer_t * pxTimer = xTimer;
-
- configASSERT( xTimer );
- return pxTimer->xTimerPeriodInTicks;
- }
-/*-----------------------------------------------------------*/
-
- void vTimerSetReloadMode( TimerHandle_t xTimer,
- const UBaseType_t uxAutoReload )
- {
- Timer_t * pxTimer = xTimer;
-
- configASSERT( xTimer );
- taskENTER_CRITICAL();
- {
- if( uxAutoReload != pdFALSE )
- {
- pxTimer->ucStatus |= tmrSTATUS_IS_AUTORELOAD;
- }
- else
- {
- pxTimer->ucStatus &= ~tmrSTATUS_IS_AUTORELOAD;
- }
- }
- taskEXIT_CRITICAL();
- }
-/*-----------------------------------------------------------*/
-
- UBaseType_t uxTimerGetReloadMode( TimerHandle_t xTimer )
- {
- Timer_t * pxTimer = xTimer;
- UBaseType_t uxReturn;
-
- configASSERT( xTimer );
- taskENTER_CRITICAL();
- {
- if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) == 0 )
- {
- /* Not an auto-reload timer. */
- uxReturn = ( UBaseType_t ) pdFALSE;
- }
- else
- {
- /* Is an auto-reload timer. */
- uxReturn = ( UBaseType_t ) pdTRUE;
- }
- }
- taskEXIT_CRITICAL();
-
- return uxReturn;
- }
-/*-----------------------------------------------------------*/
-
- TickType_t xTimerGetExpiryTime( TimerHandle_t xTimer )
- {
- Timer_t * pxTimer = xTimer;
- TickType_t xReturn;
-
- configASSERT( xTimer );
- xReturn = listGET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ) );
- return xReturn;
- }
-/*-----------------------------------------------------------*/
-
- const char * pcTimerGetName( TimerHandle_t xTimer ) /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
- {
- Timer_t * pxTimer = xTimer;
-
- configASSERT( xTimer );
- return pxTimer->pcTimerName;
- }
-/*-----------------------------------------------------------*/
-
- static void prvProcessExpiredTimer( const TickType_t xNextExpireTime,
- const TickType_t xTimeNow )
- {
- BaseType_t xResult;
- Timer_t * const pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList ); /*lint !e9087 !e9079 void * is used as this macro is used with tasks and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */
-
- /* Remove the timer from the list of active timers. A check has already
- * been performed to ensure the list is not empty. */
-
- ( void ) uxListRemove( &( pxTimer->xTimerListItem ) );
- traceTIMER_EXPIRED( pxTimer );
-
- /* If the timer is an auto-reload timer then calculate the next
- * expiry time and re-insert the timer in the list of active timers. */
- if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )
- {
- /* The timer is inserted into a list using a time relative to anything
- * other than the current time. It will therefore be inserted into the
- * correct list relative to the time this task thinks it is now. */
- if( prvInsertTimerInActiveList( pxTimer, ( xNextExpireTime + pxTimer->xTimerPeriodInTicks ), xTimeNow, xNextExpireTime ) != pdFALSE )
- {
- /* The timer expired before it was added to the active timer
- * list. Reload it now. */
- xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY );
- configASSERT( xResult );
- ( void ) xResult;
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- }
- else
- {
- pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;
- mtCOVERAGE_TEST_MARKER();
- }
-
- /* Call the timer callback. */
- pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
- }
-/*-----------------------------------------------------------*/
-
- static portTASK_FUNCTION( prvTimerTask, pvParameters )
- {
- TickType_t xNextExpireTime;
- BaseType_t xListWasEmpty;
-
- /* Just to avoid compiler warnings. */
- ( void ) pvParameters;
-
- #if ( configUSE_DAEMON_TASK_STARTUP_HOOK == 1 )
- {
- extern void vApplicationDaemonTaskStartupHook( void );
-
- /* Allow the application writer to execute some code in the context of
- * this task at the point the task starts executing. This is useful if the
- * application includes initialisation code that would benefit from
- * executing after the scheduler has been started. */
- vApplicationDaemonTaskStartupHook();
- }
- #endif /* configUSE_DAEMON_TASK_STARTUP_HOOK */
-
- for( ; ; )
- {
- /* Query the timers list to see if it contains any timers, and if so,
- * obtain the time at which the next timer will expire. */
- xNextExpireTime = prvGetNextExpireTime( &xListWasEmpty );
-
- /* If a timer has expired, process it. Otherwise, block this task
- * until either a timer does expire, or a command is received. */
- prvProcessTimerOrBlockTask( xNextExpireTime, xListWasEmpty );
-
- /* Empty the command queue. */
- prvProcessReceivedCommands();
- }
- }
-/*-----------------------------------------------------------*/
-
- static void prvProcessTimerOrBlockTask( const TickType_t xNextExpireTime,
- BaseType_t xListWasEmpty )
- {
- TickType_t xTimeNow;
- BaseType_t xTimerListsWereSwitched;
-
- vTaskSuspendAll();
- {
- /* Obtain the time now to make an assessment as to whether the timer
- * has expired or not. If obtaining the time causes the lists to switch
- * then don't process this timer as any timers that remained in the list
- * when the lists were switched will have been processed within the
- * prvSampleTimeNow() function. */
- xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
-
- if( xTimerListsWereSwitched == pdFALSE )
- {
- /* The tick count has not overflowed, has the timer expired? */
- if( ( xListWasEmpty == pdFALSE ) && ( xNextExpireTime <= xTimeNow ) )
- {
- ( void ) xTaskResumeAll();
- prvProcessExpiredTimer( xNextExpireTime, xTimeNow );
- }
- else
- {
- /* The tick count has not overflowed, and the next expire
- * time has not been reached yet. This task should therefore
- * block to wait for the next expire time or a command to be
- * received - whichever comes first. The following line cannot
- * be reached unless xNextExpireTime > xTimeNow, except in the
- * case when the current timer list is empty. */
- if( xListWasEmpty != pdFALSE )
- {
- /* The current timer list is empty - is the overflow list
- * also empty? */
- xListWasEmpty = listLIST_IS_EMPTY( pxOverflowTimerList );
- }
-
- vQueueWaitForMessageRestricted( xTimerQueue, ( xNextExpireTime - xTimeNow ), xListWasEmpty );
-
- if( xTaskResumeAll() == pdFALSE )
- {
- /* Yield to wait for either a command to arrive, or the
- * block time to expire. If a command arrived between the
- * critical section being exited and this yield then the yield
- * will not cause the task to block. */
- portYIELD_WITHIN_API();
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- }
- }
- else
- {
- ( void ) xTaskResumeAll();
- }
- }
- }
-/*-----------------------------------------------------------*/
-
- static TickType_t prvGetNextExpireTime( BaseType_t * const pxListWasEmpty )
- {
- TickType_t xNextExpireTime;
-
- /* Timers are listed in expiry time order, with the head of the list
- * referencing the task that will expire first. Obtain the time at which
- * the timer with the nearest expiry time will expire. If there are no
- * active timers then just set the next expire time to 0. That will cause
- * this task to unblock when the tick count overflows, at which point the
- * timer lists will be switched and the next expiry time can be
- * re-assessed. */
- *pxListWasEmpty = listLIST_IS_EMPTY( pxCurrentTimerList );
-
- if( *pxListWasEmpty == pdFALSE )
- {
- xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );
- }
- else
- {
- /* Ensure the task unblocks when the tick count rolls over. */
- xNextExpireTime = ( TickType_t ) 0U;
- }
-
- return xNextExpireTime;
- }
-/*-----------------------------------------------------------*/
-
- static TickType_t prvSampleTimeNow( BaseType_t * const pxTimerListsWereSwitched )
- {
- TickType_t xTimeNow;
- PRIVILEGED_DATA static TickType_t xLastTime = ( TickType_t ) 0U; /*lint !e956 Variable is only accessible to one task. */
-
- xTimeNow = xTaskGetTickCount();
-
- if( xTimeNow < xLastTime )
- {
- prvSwitchTimerLists();
- *pxTimerListsWereSwitched = pdTRUE;
- }
- else
- {
- *pxTimerListsWereSwitched = pdFALSE;
- }
-
- xLastTime = xTimeNow;
-
- return xTimeNow;
- }
-/*-----------------------------------------------------------*/
-
- static BaseType_t prvInsertTimerInActiveList( Timer_t * const pxTimer,
- const TickType_t xNextExpiryTime,
- const TickType_t xTimeNow,
- const TickType_t xCommandTime )
- {
- BaseType_t xProcessTimerNow = pdFALSE;
-
- listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xNextExpiryTime );
- listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );
-
- if( xNextExpiryTime <= xTimeNow )
- {
- /* Has the expiry time elapsed between the command to start/reset a
- * timer was issued, and the time the command was processed? */
- if( ( ( TickType_t ) ( xTimeNow - xCommandTime ) ) >= pxTimer->xTimerPeriodInTicks ) /*lint !e961 MISRA exception as the casts are only redundant for some ports. */
- {
- /* The time between a command being issued and the command being
- * processed actually exceeds the timers period. */
- xProcessTimerNow = pdTRUE;
- }
- else
- {
- vListInsert( pxOverflowTimerList, &( pxTimer->xTimerListItem ) );
- }
- }
- else
- {
- if( ( xTimeNow < xCommandTime ) && ( xNextExpiryTime >= xCommandTime ) )
- {
- /* If, since the command was issued, the tick count has overflowed
- * but the expiry time has not, then the timer must have already passed
- * its expiry time and should be processed immediately. */
- xProcessTimerNow = pdTRUE;
- }
- else
- {
- vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );
- }
- }
-
- return xProcessTimerNow;
- }
-/*-----------------------------------------------------------*/
-
- static void prvProcessReceivedCommands( void )
- {
- DaemonTaskMessage_t xMessage;
- Timer_t * pxTimer;
- BaseType_t xTimerListsWereSwitched, xResult;
- TickType_t xTimeNow;
-
- while( xQueueReceive( xTimerQueue, &xMessage, tmrNO_DELAY ) != pdFAIL ) /*lint !e603 xMessage does not have to be initialised as it is passed out, not in, and it is not used unless xQueueReceive() returns pdTRUE. */
- {
- #if ( INCLUDE_xTimerPendFunctionCall == 1 )
- {
- /* Negative commands are pended function calls rather than timer
- * commands. */
- if( xMessage.xMessageID < ( BaseType_t ) 0 )
- {
- const CallbackParameters_t * const pxCallback = &( xMessage.u.xCallbackParameters );
-
- /* The timer uses the xCallbackParameters member to request a
- * callback be executed. Check the callback is not NULL. */
- configASSERT( pxCallback );
-
- /* Call the function. */
- pxCallback->pxCallbackFunction( pxCallback->pvParameter1, pxCallback->ulParameter2 );
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- }
- #endif /* INCLUDE_xTimerPendFunctionCall */
-
- /* Commands that are positive are timer commands rather than pended
- * function calls. */
- if( xMessage.xMessageID >= ( BaseType_t ) 0 )
- {
- /* The messages uses the xTimerParameters member to work on a
- * software timer. */
- pxTimer = xMessage.u.xTimerParameters.pxTimer;
-
- if( listIS_CONTAINED_WITHIN( NULL, &( pxTimer->xTimerListItem ) ) == pdFALSE ) /*lint !e961. The cast is only redundant when NULL is passed into the macro. */
- {
- /* The timer is in a list, remove it. */
- ( void ) uxListRemove( &( pxTimer->xTimerListItem ) );
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
-
- traceTIMER_COMMAND_RECEIVED( pxTimer, xMessage.xMessageID, xMessage.u.xTimerParameters.xMessageValue );
-
- /* In this case the xTimerListsWereSwitched parameter is not used, but
- * it must be present in the function call. prvSampleTimeNow() must be
- * called after the message is received from xTimerQueue so there is no
- * possibility of a higher priority task adding a message to the message
- * queue with a time that is ahead of the timer daemon task (because it
- * pre-empted the timer daemon task after the xTimeNow value was set). */
- xTimeNow = prvSampleTimeNow( &xTimerListsWereSwitched );
-
- switch( xMessage.xMessageID )
- {
- case tmrCOMMAND_START:
- case tmrCOMMAND_START_FROM_ISR:
- case tmrCOMMAND_RESET:
- case tmrCOMMAND_RESET_FROM_ISR:
- case tmrCOMMAND_START_DONT_TRACE:
- /* Start or restart a timer. */
- pxTimer->ucStatus |= tmrSTATUS_IS_ACTIVE;
-
- if( prvInsertTimerInActiveList( pxTimer, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, xTimeNow, xMessage.u.xTimerParameters.xMessageValue ) != pdFALSE )
- {
- /* The timer expired before it was added to the active
- * timer list. Process it now. */
- pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
- traceTIMER_EXPIRED( pxTimer );
-
- if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )
- {
- xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xMessage.u.xTimerParameters.xMessageValue + pxTimer->xTimerPeriodInTicks, NULL, tmrNO_DELAY );
- configASSERT( xResult );
- ( void ) xResult;
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
-
- break;
-
- case tmrCOMMAND_STOP:
- case tmrCOMMAND_STOP_FROM_ISR:
- /* The timer has already been removed from the active list. */
- pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;
- break;
-
- case tmrCOMMAND_CHANGE_PERIOD:
- case tmrCOMMAND_CHANGE_PERIOD_FROM_ISR:
- pxTimer->ucStatus |= tmrSTATUS_IS_ACTIVE;
- pxTimer->xTimerPeriodInTicks = xMessage.u.xTimerParameters.xMessageValue;
- configASSERT( ( pxTimer->xTimerPeriodInTicks > 0 ) );
-
- /* The new period does not really have a reference, and can
- * be longer or shorter than the old one. The command time is
- * therefore set to the current time, and as the period cannot
- * be zero the next expiry time can only be in the future,
- * meaning (unlike for the xTimerStart() case above) there is
- * no fail case that needs to be handled here. */
- ( void ) prvInsertTimerInActiveList( pxTimer, ( xTimeNow + pxTimer->xTimerPeriodInTicks ), xTimeNow, xTimeNow );
- break;
-
- case tmrCOMMAND_DELETE:
- #if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )
- {
- /* The timer has already been removed from the active list,
- * just free up the memory if the memory was dynamically
- * allocated. */
- if( ( pxTimer->ucStatus & tmrSTATUS_IS_STATICALLY_ALLOCATED ) == ( uint8_t ) 0 )
- {
- vPortFree( pxTimer );
- }
- else
- {
- pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;
- }
- }
- #else /* if ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) */
- {
- /* If dynamic allocation is not enabled, the memory
- * could not have been dynamically allocated. So there is
- * no need to free the memory - just mark the timer as
- * "not active". */
- pxTimer->ucStatus &= ~tmrSTATUS_IS_ACTIVE;
- }
- #endif /* configSUPPORT_DYNAMIC_ALLOCATION */
- break;
-
- default:
- /* Don't expect to get here. */
- break;
- }
- }
- }
- }
-/*-----------------------------------------------------------*/
-
- static void prvSwitchTimerLists( void )
- {
- TickType_t xNextExpireTime, xReloadTime;
- List_t * pxTemp;
- Timer_t * pxTimer;
- BaseType_t xResult;
-
- /* The tick count has overflowed. The timer lists must be switched.
- * If there are any timers still referenced from the current timer list
- * then they must have expired and should be processed before the lists
- * are switched. */
- while( listLIST_IS_EMPTY( pxCurrentTimerList ) == pdFALSE )
- {
- xNextExpireTime = listGET_ITEM_VALUE_OF_HEAD_ENTRY( pxCurrentTimerList );
-
- /* Remove the timer from the list. */
- pxTimer = ( Timer_t * ) listGET_OWNER_OF_HEAD_ENTRY( pxCurrentTimerList ); /*lint !e9087 !e9079 void * is used as this macro is used with tasks and co-routines too. Alignment is known to be fine as the type of the pointer stored and retrieved is the same. */
- ( void ) uxListRemove( &( pxTimer->xTimerListItem ) );
- traceTIMER_EXPIRED( pxTimer );
-
- /* Execute its callback, then send a command to restart the timer if
- * it is an auto-reload timer. It cannot be restarted here as the lists
- * have not yet been switched. */
- pxTimer->pxCallbackFunction( ( TimerHandle_t ) pxTimer );
-
- if( ( pxTimer->ucStatus & tmrSTATUS_IS_AUTORELOAD ) != 0 )
- {
- /* Calculate the reload value, and if the reload value results in
- * the timer going into the same timer list then it has already expired
- * and the timer should be re-inserted into the current list so it is
- * processed again within this loop. Otherwise a command should be sent
- * to restart the timer to ensure it is only inserted into a list after
- * the lists have been swapped. */
- xReloadTime = ( xNextExpireTime + pxTimer->xTimerPeriodInTicks );
-
- if( xReloadTime > xNextExpireTime )
- {
- listSET_LIST_ITEM_VALUE( &( pxTimer->xTimerListItem ), xReloadTime );
- listSET_LIST_ITEM_OWNER( &( pxTimer->xTimerListItem ), pxTimer );
- vListInsert( pxCurrentTimerList, &( pxTimer->xTimerListItem ) );
- }
- else
- {
- xResult = xTimerGenericCommand( pxTimer, tmrCOMMAND_START_DONT_TRACE, xNextExpireTime, NULL, tmrNO_DELAY );
- configASSERT( xResult );
- ( void ) xResult;
- }
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- }
-
- pxTemp = pxCurrentTimerList;
- pxCurrentTimerList = pxOverflowTimerList;
- pxOverflowTimerList = pxTemp;
- }
-/*-----------------------------------------------------------*/
-
- static void prvCheckForValidListAndQueue( void )
- {
- /* Check that the list from which active timers are referenced, and the
- * queue used to communicate with the timer service, have been
- * initialised. */
- taskENTER_CRITICAL();
- {
- if( xTimerQueue == NULL )
- {
- vListInitialise( &xActiveTimerList1 );
- vListInitialise( &xActiveTimerList2 );
- pxCurrentTimerList = &xActiveTimerList1;
- pxOverflowTimerList = &xActiveTimerList2;
-
- #if ( configSUPPORT_STATIC_ALLOCATION == 1 )
- {
- /* The timer queue is allocated statically in case
- * configSUPPORT_DYNAMIC_ALLOCATION is 0. */
- PRIVILEGED_DATA static StaticQueue_t xStaticTimerQueue; /*lint !e956 Ok to declare in this manner to prevent additional conditional compilation guards in other locations. */
- PRIVILEGED_DATA static uint8_t ucStaticTimerQueueStorage[ ( size_t ) configTIMER_QUEUE_LENGTH * sizeof( DaemonTaskMessage_t ) ]; /*lint !e956 Ok to declare in this manner to prevent additional conditional compilation guards in other locations. */
-
- xTimerQueue = xQueueCreateStatic( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, ( UBaseType_t ) sizeof( DaemonTaskMessage_t ), &( ucStaticTimerQueueStorage[ 0 ] ), &xStaticTimerQueue );
- }
- #else
- {
- xTimerQueue = xQueueCreate( ( UBaseType_t ) configTIMER_QUEUE_LENGTH, sizeof( DaemonTaskMessage_t ) );
- }
- #endif /* if ( configSUPPORT_STATIC_ALLOCATION == 1 ) */
-
- #if ( configQUEUE_REGISTRY_SIZE > 0 )
- {
- if( xTimerQueue != NULL )
- {
- vQueueAddToRegistry( xTimerQueue, "TmrQ" );
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- }
- #endif /* configQUEUE_REGISTRY_SIZE */
- }
- else
- {
- mtCOVERAGE_TEST_MARKER();
- }
- }
- taskEXIT_CRITICAL();
- }
-/*-----------------------------------------------------------*/
-
- BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer )
- {
- BaseType_t xReturn;
- Timer_t * pxTimer = xTimer;
-
- configASSERT( xTimer );
-
- /* Is the timer in the list of active timers? */
- taskENTER_CRITICAL();
- {
- if( ( pxTimer->ucStatus & tmrSTATUS_IS_ACTIVE ) == 0 )
- {
- xReturn = pdFALSE;
- }
- else
- {
- xReturn = pdTRUE;
- }
- }
- taskEXIT_CRITICAL();
-
- return xReturn;
- } /*lint !e818 Can't be pointer to const due to the typedef. */
-/*-----------------------------------------------------------*/
-
- void * pvTimerGetTimerID( const TimerHandle_t xTimer )
- {
- Timer_t * const pxTimer = xTimer;
- void * pvReturn;
-
- configASSERT( xTimer );
-
- taskENTER_CRITICAL();
- {
- pvReturn = pxTimer->pvTimerID;
- }
- taskEXIT_CRITICAL();
-
- return pvReturn;
- }
-/*-----------------------------------------------------------*/
-
- void vTimerSetTimerID( TimerHandle_t xTimer,
- void * pvNewID )
- {
- Timer_t * const pxTimer = xTimer;
-
- configASSERT( xTimer );
-
- taskENTER_CRITICAL();
- {
- pxTimer->pvTimerID = pvNewID;
- }
- taskEXIT_CRITICAL();
- }
-/*-----------------------------------------------------------*/
-
- #if ( INCLUDE_xTimerPendFunctionCall == 1 )
-
- BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend,
- void * pvParameter1,
- uint32_t ulParameter2,
- BaseType_t * pxHigherPriorityTaskWoken )
- {
- DaemonTaskMessage_t xMessage;
- BaseType_t xReturn;
-
- /* Complete the message with the function parameters and post it to the
- * daemon task. */
- xMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR;
- xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend;
- xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1;
- xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2;
-
- xReturn = xQueueSendFromISR( xTimerQueue, &xMessage, pxHigherPriorityTaskWoken );
-
- tracePEND_FUNC_CALL_FROM_ISR( xFunctionToPend, pvParameter1, ulParameter2, xReturn );
-
- return xReturn;
- }
-
- #endif /* INCLUDE_xTimerPendFunctionCall */
-/*-----------------------------------------------------------*/
-
- #if ( INCLUDE_xTimerPendFunctionCall == 1 )
-
- BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
- void * pvParameter1,
- uint32_t ulParameter2,
- TickType_t xTicksToWait )
- {
- DaemonTaskMessage_t xMessage;
- BaseType_t xReturn;
-
- /* This function can only be called after a timer has been created or
- * after the scheduler has been started because, until then, the timer
- * queue does not exist. */
- configASSERT( xTimerQueue );
-
- /* Complete the message with the function parameters and post it to the
- * daemon task. */
- xMessage.xMessageID = tmrCOMMAND_EXECUTE_CALLBACK;
- xMessage.u.xCallbackParameters.pxCallbackFunction = xFunctionToPend;
- xMessage.u.xCallbackParameters.pvParameter1 = pvParameter1;
- xMessage.u.xCallbackParameters.ulParameter2 = ulParameter2;
-
- xReturn = xQueueSendToBack( xTimerQueue, &xMessage, xTicksToWait );
-
- tracePEND_FUNC_CALL( xFunctionToPend, pvParameter1, ulParameter2, xReturn );
-
- return xReturn;
- }
-
- #endif /* INCLUDE_xTimerPendFunctionCall */
-/*-----------------------------------------------------------*/
-
- #if ( configUSE_TRACE_FACILITY == 1 )
-
- UBaseType_t uxTimerGetTimerNumber( TimerHandle_t xTimer )
- {
- return ( ( Timer_t * ) xTimer )->uxTimerNumber;
- }
-
- #endif /* configUSE_TRACE_FACILITY */
-/*-----------------------------------------------------------*/
-
- #if ( configUSE_TRACE_FACILITY == 1 )
-
- void vTimerSetTimerNumber( TimerHandle_t xTimer,
- UBaseType_t uxTimerNumber )
- {
- ( ( Timer_t * ) xTimer )->uxTimerNumber = uxTimerNumber;
- }
-
- #endif /* configUSE_TRACE_FACILITY */
-/*-----------------------------------------------------------*/
-
-/* This entire source file will be skipped if the application is not configured
- * to include software timer functionality. If you want to include software timer
- * functionality then ensure configUSE_TIMERS is set to 1 in FreeRTOSConfig.h. */
-#endif /* configUSE_TIMERS == 1 */
diff --git a/examples/chapter11_07/target/app/make/app_files.gmk b/examples/chapter11_07/target/app/make/app_files.gmk
index 53211e4ab..9a9a238cd 100644
--- a/examples/chapter11_07/target/app/make/app_files.gmk
+++ b/examples/chapter11_07/target/app/make/app_files.gmk
@@ -1,5 +1,5 @@
#
-# Copyright Christopher Kormanyos 2007 - 2024.
+# Copyright Christopher Kormanyos 2007 - 2025.
# Distributed under the Boost Software License,
# Version 1.0. (See accompanying file LICENSE_1_0.txt
# or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -23,5 +23,4 @@ FILES_CPP = $(PATH_APP)/app/led/app_led \
$(PATH_APP)/os/FreeRTOS/Source/list \
$(PATH_APP)/os/FreeRTOS/Source/queue \
$(PATH_APP)/os/FreeRTOS/Source/tasks \
- $(PATH_APP)/os/FreeRTOS/Source/timers \
$(PATH_APP)/sys/start/sys_start
diff --git a/examples/chapter16_08/src/mcal/avr/mcal_reg.h b/examples/chapter16_08/src/mcal/avr/mcal_reg.h
index ddce03e7c..d2ef64bf8 100644
--- a/examples/chapter16_08/src/mcal/avr/mcal_reg.h
+++ b/examples/chapter16_08/src/mcal/avr/mcal_reg.h
@@ -1,12 +1,12 @@
///////////////////////////////////////////////////////////////////////////////
-// Copyright Christopher Kormanyos 2007 - 2022.
+// Copyright Christopher Kormanyos 2007 - 2025.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//
-#ifndef MCAL_REG_2010_04_10_H_
- #define MCAL_REG_2010_04_10_H_
+#ifndef MCAL_REG_2010_04_10_H
+ #define MCAL_REG_2010_04_10_H
#include
@@ -17,76 +17,76 @@
constexpr std::uint8_t sfr_offset = 0x20U;
// Bit-position values.
- constexpr std::uint8_t bval0 = 1U;
- constexpr std::uint8_t bval1 = 1U << 1U;
- constexpr std::uint8_t bval2 = 1U << 2U;
- constexpr std::uint8_t bval3 = 1U << 3U;
- constexpr std::uint8_t bval4 = 1U << 4U;
- constexpr std::uint8_t bval5 = 1U << 5U;
- constexpr std::uint8_t bval6 = 1U << 6U;
- constexpr std::uint8_t bval7 = 1U << 7U;
+ constexpr std::uint8_t bval0 { 1U };
+ constexpr std::uint8_t bval1 { 1U << 1U };
+ constexpr std::uint8_t bval2 { 1U << 2U };
+ constexpr std::uint8_t bval3 { 1U << 3U };
+ constexpr std::uint8_t bval4 { 1U << 4U };
+ constexpr std::uint8_t bval5 { 1U << 5U };
+ constexpr std::uint8_t bval6 { 1U << 6U };
+ constexpr std::uint8_t bval7 { 1U << 7U };
// System registers.
- constexpr std::uint8_t mcusr = 0x14U + sfr_offset;
- constexpr std::uint8_t prr = 0x64U;
+ constexpr std::uint8_t mcusr { 0x14U + sfr_offset };
+ constexpr std::uint8_t prr { 0x64U };
// Port registers.
- constexpr std::uint8_t pinb = 0x03U + sfr_offset;
- constexpr std::uint8_t ddrb = 0x04U + sfr_offset;
- constexpr std::uint8_t portb = 0x05U + sfr_offset;
- constexpr std::uint8_t pinc = 0x06U + sfr_offset;
- constexpr std::uint8_t ddrc = 0x07U + sfr_offset;
- constexpr std::uint8_t portc = 0x08U + sfr_offset;
- constexpr std::uint8_t pind = 0x09U + sfr_offset;
- constexpr std::uint8_t ddrd = 0x0AU + sfr_offset;
- constexpr std::uint8_t portd = 0x0BU + sfr_offset;
- constexpr std::uint8_t pine = 0x0CU + sfr_offset;
- constexpr std::uint8_t ddre = 0x0DU + sfr_offset;
- constexpr std::uint8_t porte = 0x0EU + sfr_offset;
+ constexpr std::uint8_t pinb { 0x03U + sfr_offset };
+ constexpr std::uint8_t ddrb { 0x04U + sfr_offset };
+ constexpr std::uint8_t portb { 0x05U + sfr_offset };
+ constexpr std::uint8_t pinc { 0x06U + sfr_offset };
+ constexpr std::uint8_t ddrc { 0x07U + sfr_offset };
+ constexpr std::uint8_t portc { 0x08U + sfr_offset };
+ constexpr std::uint8_t pind { 0x09U + sfr_offset };
+ constexpr std::uint8_t ddrd { 0x0AU + sfr_offset };
+ constexpr std::uint8_t portd { 0x0BU + sfr_offset };
+ constexpr std::uint8_t pine { 0x0CU + sfr_offset };
+ constexpr std::uint8_t ddre { 0x0DU + sfr_offset };
+ constexpr std::uint8_t porte { 0x0EU + sfr_offset };
// Timer registers
- constexpr std::uint8_t tifr0 = 0x15U + sfr_offset;
- constexpr std::uint8_t tccr0a = 0x24U + sfr_offset;
- constexpr std::uint8_t tccr0b = 0x25U + sfr_offset;
- constexpr std::uint8_t tcnt0 = 0x26U + sfr_offset;
- constexpr std::uint8_t ocr0a = 0x27U + sfr_offset;
- constexpr std::uint8_t timsk0 = 0x6EU;
+ constexpr std::uint8_t tifr0 { 0x15U + sfr_offset };
+ constexpr std::uint8_t tccr0a { 0x24U + sfr_offset };
+ constexpr std::uint8_t tccr0b { 0x25U + sfr_offset };
+ constexpr std::uint8_t tcnt0 { 0x26U + sfr_offset };
+ constexpr std::uint8_t ocr0a { 0x27U + sfr_offset };
+ constexpr std::uint8_t timsk0 { 0x6EU };
- constexpr std::uint8_t tifr1 = 0x16U + sfr_offset;
- constexpr std::uint8_t tccr1a = 0x80U;
- constexpr std::uint8_t tccr1b = 0x81U;
- constexpr std::uint8_t tcnt1l = 0x84U;
- constexpr std::uint8_t tcnt1h = 0x85U;
- constexpr std::uint8_t icr1 = 0x86U; // 16-bit register
- constexpr std::uint8_t ocr1a = 0x88U; // 16-bit register
- constexpr std::uint8_t ocr1b = 0x8AU; // 16-bit register
- constexpr std::uint8_t timsk1 = 0x6FU;
+ constexpr std::uint8_t tifr1 { 0x16U + sfr_offset };
+ constexpr std::uint8_t tccr1a { 0x80U };
+ constexpr std::uint8_t tccr1b { 0x81U };
+ constexpr std::uint8_t tcnt1l { 0x84U };
+ constexpr std::uint8_t tcnt1h { 0x85U };
+ constexpr std::uint8_t icr1 { 0x86U }; // 16-bit register
+ constexpr std::uint8_t ocr1a { 0x88U }; // 16-bit register
+ constexpr std::uint8_t ocr1b { 0x8AU }; // 16-bit register
+ constexpr std::uint8_t timsk1 { 0x6FU };
- constexpr std::uint8_t tifr2 = 0x17U + sfr_offset;
- constexpr std::uint8_t tccr2a = 0xB0U;
- constexpr std::uint8_t tccr2b = 0xB1U;
- constexpr std::uint8_t tcnt2 = 0xB2U;
- constexpr std::uint8_t ocr2a = 0xB3U;
- constexpr std::uint8_t timsk2 = 0x70U;
+ constexpr std::uint8_t tifr2 { 0x17U + sfr_offset };
+ constexpr std::uint8_t tccr2a { 0xB0U };
+ constexpr std::uint8_t tccr2b { 0xB1U };
+ constexpr std::uint8_t tcnt2 { 0xB2U };
+ constexpr std::uint8_t ocr2a { 0xB3U };
+ constexpr std::uint8_t timsk2 { 0x70U };
// SPI(TM) registers.
- constexpr std::uint8_t spcr = 0x2CU + sfr_offset;
- constexpr std::uint8_t spsr = 0x2DU + sfr_offset;
- constexpr std::uint8_t spdr = 0x2EU + sfr_offset;
+ constexpr std::uint8_t spcr { 0x2CU + sfr_offset };
+ constexpr std::uint8_t spsr { 0x2DU + sfr_offset };
+ constexpr std::uint8_t spdr { 0x2EU + sfr_offset };
// Watchdog registers
- constexpr std::uint8_t wdtcsr = 0x60U;
+ constexpr std::uint8_t wdtcsr { 0x60U };
// Eeprom registers
- constexpr std::uint8_t eecr = 0x1FU + sfr_offset;
- constexpr std::uint8_t eedr = 0x20U + sfr_offset;
- constexpr std::uint8_t eear = 0x21U + sfr_offset;
- constexpr std::uint8_t eearl = 0x21U + sfr_offset;
- constexpr std::uint8_t eearh = 0x22U + sfr_offset;
+ constexpr std::uint8_t eecr { 0x1FU + sfr_offset };
+ constexpr std::uint8_t eedr { 0x20U + sfr_offset };
+ constexpr std::uint8_t eear { 0x21U + sfr_offset };
+ constexpr std::uint8_t eearl { 0x21U + sfr_offset };
+ constexpr std::uint8_t eearh { 0x22U + sfr_offset };
}
}
#include
#include
-#endif // MCAL_REG_2010_04_10_H_
+#endif // MCAL_REG_2010_04_10_H
diff --git a/examples/chapter16_08/src/mcal/win32/mcal_math_independent_test_system.cpp b/examples/chapter16_08/src/mcal/win32/mcal_math_independent_test_system.cpp
index 696fe18ba..8e983ddcf 100644
--- a/examples/chapter16_08/src/mcal/win32/mcal_math_independent_test_system.cpp
+++ b/examples/chapter16_08/src/mcal/win32/mcal_math_independent_test_system.cpp
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////
-// Copyright Christopher Kormanyos 2019 - 2024.
+// Copyright Christopher Kormanyos 2019 - 2025.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
diff --git a/examples/chapter16_08/src/mcal/win32/mcal_wdg.h b/examples/chapter16_08/src/mcal/win32/mcal_wdg.h
index e79d6714d..b84715a2e 100644
--- a/examples/chapter16_08/src/mcal/win32/mcal_wdg.h
+++ b/examples/chapter16_08/src/mcal/win32/mcal_wdg.h
@@ -1,12 +1,12 @@
///////////////////////////////////////////////////////////////////////////////
-// Copyright Christopher Kormanyos 2007 - 2013.
+// Copyright Christopher Kormanyos 2007 - 2025.
// Distributed under the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
//
-#ifndef MCAL_WDG_2010_04_10_H_
- #define MCAL_WDG_2010_04_10_H_
+#ifndef MCAL_WDG_2010_04_10_H
+ #define MCAL_WDG_2010_04_10_H
namespace sys { namespace idle { void task_func(); } }
@@ -27,4 +27,4 @@
}
}
-#endif // MCAL_WDG_2010_04_10_H_
+#endif // MCAL_WDG_2010_04_10_H
diff --git a/examples/chapter16_08/target/micros/avr/startup/crt0.cpp b/examples/chapter16_08/target/micros/avr/startup/crt0.cpp
index 5e8f21cdf..e9bc0bae5 100644
--- a/examples/chapter16_08/target/micros/avr/startup/crt0.cpp
+++ b/examples/chapter16_08/target/micros/avr/startup/crt0.cpp
@@ -20,7 +20,7 @@ namespace crt
extern "C" void __my_startup() __attribute__((section(".startup"), used, noinline));
-int main(void) __attribute__((used, noinline));
+extern "C" int main(void) __attribute__((used, noinline));
void __my_startup()
{