Update revision to use TI's mqtt and Freertos.

Dependencies:   mbed client server

Fork of cc3100_Test_mqtt_CM3 by David Fletcher

Committer:
dflet
Date:
Thu Sep 03 14:02:37 2015 +0000
Revision:
3:a8c249046181
SPI Mode change 1 to 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dflet 3:a8c249046181 1 /*
dflet 3:a8c249046181 2 FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.
dflet 3:a8c249046181 3 All rights reserved
dflet 3:a8c249046181 4
dflet 3:a8c249046181 5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
dflet 3:a8c249046181 6
dflet 3:a8c249046181 7 This file is part of the FreeRTOS distribution.
dflet 3:a8c249046181 8
dflet 3:a8c249046181 9 FreeRTOS is free software; you can redistribute it and/or modify it under
dflet 3:a8c249046181 10 the terms of the GNU General Public License (version 2) as published by the
dflet 3:a8c249046181 11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
dflet 3:a8c249046181 12
dflet 3:a8c249046181 13 ***************************************************************************
dflet 3:a8c249046181 14 >>! NOTE: The modification to the GPL is included to allow you to !<<
dflet 3:a8c249046181 15 >>! distribute a combined work that includes FreeRTOS without being !<<
dflet 3:a8c249046181 16 >>! obliged to provide the source code for proprietary components !<<
dflet 3:a8c249046181 17 >>! outside of the FreeRTOS kernel. !<<
dflet 3:a8c249046181 18 ***************************************************************************
dflet 3:a8c249046181 19
dflet 3:a8c249046181 20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
dflet 3:a8c249046181 21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
dflet 3:a8c249046181 22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
dflet 3:a8c249046181 23 link: http://www.freertos.org/a00114.html
dflet 3:a8c249046181 24
dflet 3:a8c249046181 25 ***************************************************************************
dflet 3:a8c249046181 26 * *
dflet 3:a8c249046181 27 * FreeRTOS provides completely free yet professionally developed, *
dflet 3:a8c249046181 28 * robust, strictly quality controlled, supported, and cross *
dflet 3:a8c249046181 29 * platform software that is more than just the market leader, it *
dflet 3:a8c249046181 30 * is the industry's de facto standard. *
dflet 3:a8c249046181 31 * *
dflet 3:a8c249046181 32 * Help yourself get started quickly while simultaneously helping *
dflet 3:a8c249046181 33 * to support the FreeRTOS project by purchasing a FreeRTOS *
dflet 3:a8c249046181 34 * tutorial book, reference manual, or both: *
dflet 3:a8c249046181 35 * http://www.FreeRTOS.org/Documentation *
dflet 3:a8c249046181 36 * *
dflet 3:a8c249046181 37 ***************************************************************************
dflet 3:a8c249046181 38
dflet 3:a8c249046181 39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
dflet 3:a8c249046181 40 the FAQ page "My application does not run, what could be wrong?". Have you
dflet 3:a8c249046181 41 defined configASSERT()?
dflet 3:a8c249046181 42
dflet 3:a8c249046181 43 http://www.FreeRTOS.org/support - In return for receiving this top quality
dflet 3:a8c249046181 44 embedded software for free we request you assist our global community by
dflet 3:a8c249046181 45 participating in the support forum.
dflet 3:a8c249046181 46
dflet 3:a8c249046181 47 http://www.FreeRTOS.org/training - Investing in training allows your team to
dflet 3:a8c249046181 48 be as productive as possible as early as possible. Now you can receive
dflet 3:a8c249046181 49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
dflet 3:a8c249046181 50 Ltd, and the world's leading authority on the world's leading RTOS.
dflet 3:a8c249046181 51
dflet 3:a8c249046181 52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
dflet 3:a8c249046181 53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
dflet 3:a8c249046181 54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
dflet 3:a8c249046181 55
dflet 3:a8c249046181 56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
dflet 3:a8c249046181 57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
dflet 3:a8c249046181 58
dflet 3:a8c249046181 59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
dflet 3:a8c249046181 60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
dflet 3:a8c249046181 61 licenses offer ticketed support, indemnification and commercial middleware.
dflet 3:a8c249046181 62
dflet 3:a8c249046181 63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
dflet 3:a8c249046181 64 engineered and independently SIL3 certified version for use in safety and
dflet 3:a8c249046181 65 mission critical applications that require provable dependability.
dflet 3:a8c249046181 66
dflet 3:a8c249046181 67 1 tab == 4 spaces!
dflet 3:a8c249046181 68 */
dflet 3:a8c249046181 69
dflet 3:a8c249046181 70
dflet 3:a8c249046181 71 #ifndef TIMERS_H
dflet 3:a8c249046181 72 #define TIMERS_H
dflet 3:a8c249046181 73
dflet 3:a8c249046181 74 #ifndef INC_FREERTOS_H
dflet 3:a8c249046181 75 #error "include FreeRTOS.h must appear in source files before include timers.h"
dflet 3:a8c249046181 76 #endif
dflet 3:a8c249046181 77
dflet 3:a8c249046181 78 /*lint -e537 This headers are only multiply included if the application code
dflet 3:a8c249046181 79 happens to also be including task.h. */
dflet 3:a8c249046181 80 #include "task.h"
dflet 3:a8c249046181 81 /*lint +e537 */
dflet 3:a8c249046181 82
dflet 3:a8c249046181 83 #ifdef __cplusplus
dflet 3:a8c249046181 84 extern "C" {
dflet 3:a8c249046181 85 #endif
dflet 3:a8c249046181 86
dflet 3:a8c249046181 87 /*-----------------------------------------------------------
dflet 3:a8c249046181 88 * MACROS AND DEFINITIONS
dflet 3:a8c249046181 89 *----------------------------------------------------------*/
dflet 3:a8c249046181 90
dflet 3:a8c249046181 91 /* IDs for commands that can be sent/received on the timer queue. These are to
dflet 3:a8c249046181 92 be used solely through the macros that make up the public software timer API,
dflet 3:a8c249046181 93 as defined below. The commands that are sent from interrupts must use the
dflet 3:a8c249046181 94 highest numbers as tmrFIRST_FROM_ISR_COMMAND is used to determine if the task
dflet 3:a8c249046181 95 or interrupt version of the queue send function should be used. */
dflet 3:a8c249046181 96 #define tmrCOMMAND_EXECUTE_CALLBACK_FROM_ISR ( ( BaseType_t ) -2 )
dflet 3:a8c249046181 97 #define tmrCOMMAND_EXECUTE_CALLBACK ( ( BaseType_t ) -1 )
dflet 3:a8c249046181 98 #define tmrCOMMAND_START_DONT_TRACE ( ( BaseType_t ) 0 )
dflet 3:a8c249046181 99 #define tmrCOMMAND_START ( ( BaseType_t ) 1 )
dflet 3:a8c249046181 100 #define tmrCOMMAND_RESET ( ( BaseType_t ) 2 )
dflet 3:a8c249046181 101 #define tmrCOMMAND_STOP ( ( BaseType_t ) 3 )
dflet 3:a8c249046181 102 #define tmrCOMMAND_CHANGE_PERIOD ( ( BaseType_t ) 4 )
dflet 3:a8c249046181 103 #define tmrCOMMAND_DELETE ( ( BaseType_t ) 5 )
dflet 3:a8c249046181 104
dflet 3:a8c249046181 105 #define tmrFIRST_FROM_ISR_COMMAND ( ( BaseType_t ) 6 )
dflet 3:a8c249046181 106 #define tmrCOMMAND_START_FROM_ISR ( ( BaseType_t ) 6 )
dflet 3:a8c249046181 107 #define tmrCOMMAND_RESET_FROM_ISR ( ( BaseType_t ) 7 )
dflet 3:a8c249046181 108 #define tmrCOMMAND_STOP_FROM_ISR ( ( BaseType_t ) 8 )
dflet 3:a8c249046181 109 #define tmrCOMMAND_CHANGE_PERIOD_FROM_ISR ( ( BaseType_t ) 9 )
dflet 3:a8c249046181 110
dflet 3:a8c249046181 111
dflet 3:a8c249046181 112 /**
dflet 3:a8c249046181 113 * Type by which software timers are referenced. For example, a call to
dflet 3:a8c249046181 114 * xTimerCreate() returns an TimerHandle_t variable that can then be used to
dflet 3:a8c249046181 115 * reference the subject timer in calls to other software timer API functions
dflet 3:a8c249046181 116 * (for example, xTimerStart(), xTimerReset(), etc.).
dflet 3:a8c249046181 117 */
dflet 3:a8c249046181 118 typedef void * TimerHandle_t;
dflet 3:a8c249046181 119
dflet 3:a8c249046181 120 /*
dflet 3:a8c249046181 121 * Defines the prototype to which timer callback functions must conform.
dflet 3:a8c249046181 122 */
dflet 3:a8c249046181 123 typedef void (*TimerCallbackFunction_t)( TimerHandle_t xTimer );
dflet 3:a8c249046181 124
dflet 3:a8c249046181 125 /*
dflet 3:a8c249046181 126 * Defines the prototype to which functions used with the
dflet 3:a8c249046181 127 * xTimerPendFunctionCallFromISR() function must conform.
dflet 3:a8c249046181 128 */
dflet 3:a8c249046181 129 typedef void (*PendedFunction_t)( void *, uint32_t );
dflet 3:a8c249046181 130
dflet 3:a8c249046181 131 /**
dflet 3:a8c249046181 132 * TimerHandle_t xTimerCreate( const char * const pcTimerName,
dflet 3:a8c249046181 133 * TickType_t xTimerPeriodInTicks,
dflet 3:a8c249046181 134 * UBaseType_t uxAutoReload,
dflet 3:a8c249046181 135 * void * pvTimerID,
dflet 3:a8c249046181 136 * TimerCallbackFunction_t pxCallbackFunction );
dflet 3:a8c249046181 137 *
dflet 3:a8c249046181 138 * Creates a new software timer instance. This allocates the storage required
dflet 3:a8c249046181 139 * by the new timer, initialises the new timers internal state, and returns a
dflet 3:a8c249046181 140 * handle by which the new timer can be referenced.
dflet 3:a8c249046181 141 *
dflet 3:a8c249046181 142 * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
dflet 3:a8c249046181 143 * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
dflet 3:a8c249046181 144 * xTimerChangePeriodFromISR() API functions can all be used to transition a
dflet 3:a8c249046181 145 * timer into the active state.
dflet 3:a8c249046181 146 *
dflet 3:a8c249046181 147 * @param pcTimerName A text name that is assigned to the timer. This is done
dflet 3:a8c249046181 148 * purely to assist debugging. The kernel itself only ever references a timer
dflet 3:a8c249046181 149 * by its handle, and never by its name.
dflet 3:a8c249046181 150 *
dflet 3:a8c249046181 151 * @param xTimerPeriodInTicks The timer period. The time is defined in tick
dflet 3:a8c249046181 152 * periods so the constant portTICK_PERIOD_MS can be used to convert a time that
dflet 3:a8c249046181 153 * has been specified in milliseconds. For example, if the timer must expire
dflet 3:a8c249046181 154 * after 100 ticks, then xTimerPeriodInTicks should be set to 100.
dflet 3:a8c249046181 155 * Alternatively, if the timer must expire after 500ms, then xPeriod can be set
dflet 3:a8c249046181 156 * to ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than or
dflet 3:a8c249046181 157 * equal to 1000.
dflet 3:a8c249046181 158 *
dflet 3:a8c249046181 159 * @param uxAutoReload If uxAutoReload is set to pdTRUE then the timer will
dflet 3:a8c249046181 160 * expire repeatedly with a frequency set by the xTimerPeriodInTicks parameter.
dflet 3:a8c249046181 161 * If uxAutoReload is set to pdFALSE then the timer will be a one-shot timer and
dflet 3:a8c249046181 162 * enter the dormant state after it expires.
dflet 3:a8c249046181 163 *
dflet 3:a8c249046181 164 * @param pvTimerID An identifier that is assigned to the timer being created.
dflet 3:a8c249046181 165 * Typically this would be used in the timer callback function to identify which
dflet 3:a8c249046181 166 * timer expired when the same callback function is assigned to more than one
dflet 3:a8c249046181 167 * timer.
dflet 3:a8c249046181 168 *
dflet 3:a8c249046181 169 * @param pxCallbackFunction The function to call when the timer expires.
dflet 3:a8c249046181 170 * Callback functions must have the prototype defined by TimerCallbackFunction_t,
dflet 3:a8c249046181 171 * which is "void vCallbackFunction( TimerHandle_t xTimer );".
dflet 3:a8c249046181 172 *
dflet 3:a8c249046181 173 * @return If the timer is successfully created then a handle to the newly
dflet 3:a8c249046181 174 * created timer is returned. If the timer cannot be created (because either
dflet 3:a8c249046181 175 * there is insufficient FreeRTOS heap remaining to allocate the timer
dflet 3:a8c249046181 176 * structures, or the timer period was set to 0) then NULL is returned.
dflet 3:a8c249046181 177 *
dflet 3:a8c249046181 178 * Example usage:
dflet 3:a8c249046181 179 * @verbatim
dflet 3:a8c249046181 180 * #define NUM_TIMERS 5
dflet 3:a8c249046181 181 *
dflet 3:a8c249046181 182 * // An array to hold handles to the created timers.
dflet 3:a8c249046181 183 * TimerHandle_t xTimers[ NUM_TIMERS ];
dflet 3:a8c249046181 184 *
dflet 3:a8c249046181 185 * // An array to hold a count of the number of times each timer expires.
dflet 3:a8c249046181 186 * int32_t lExpireCounters[ NUM_TIMERS ] = { 0 };
dflet 3:a8c249046181 187 *
dflet 3:a8c249046181 188 * // Define a callback function that will be used by multiple timer instances.
dflet 3:a8c249046181 189 * // The callback function does nothing but count the number of times the
dflet 3:a8c249046181 190 * // associated timer expires, and stop the timer once the timer has expired
dflet 3:a8c249046181 191 * // 10 times.
dflet 3:a8c249046181 192 * void vTimerCallback( TimerHandle_t pxTimer )
dflet 3:a8c249046181 193 * {
dflet 3:a8c249046181 194 * int32_t lArrayIndex;
dflet 3:a8c249046181 195 * const int32_t xMaxExpiryCountBeforeStopping = 10;
dflet 3:a8c249046181 196 *
dflet 3:a8c249046181 197 * // Optionally do something if the pxTimer parameter is NULL.
dflet 3:a8c249046181 198 * configASSERT( pxTimer );
dflet 3:a8c249046181 199 *
dflet 3:a8c249046181 200 * // Which timer expired?
dflet 3:a8c249046181 201 * lArrayIndex = ( int32_t ) pvTimerGetTimerID( pxTimer );
dflet 3:a8c249046181 202 *
dflet 3:a8c249046181 203 * // Increment the number of times that pxTimer has expired.
dflet 3:a8c249046181 204 * lExpireCounters[ lArrayIndex ] += 1;
dflet 3:a8c249046181 205 *
dflet 3:a8c249046181 206 * // If the timer has expired 10 times then stop it from running.
dflet 3:a8c249046181 207 * if( lExpireCounters[ lArrayIndex ] == xMaxExpiryCountBeforeStopping )
dflet 3:a8c249046181 208 * {
dflet 3:a8c249046181 209 * // Do not use a block time if calling a timer API function from a
dflet 3:a8c249046181 210 * // timer callback function, as doing so could cause a deadlock!
dflet 3:a8c249046181 211 * xTimerStop( pxTimer, 0 );
dflet 3:a8c249046181 212 * }
dflet 3:a8c249046181 213 * }
dflet 3:a8c249046181 214 *
dflet 3:a8c249046181 215 * void main( void )
dflet 3:a8c249046181 216 * {
dflet 3:a8c249046181 217 * int32_t x;
dflet 3:a8c249046181 218 *
dflet 3:a8c249046181 219 * // Create then start some timers. Starting the timers before the scheduler
dflet 3:a8c249046181 220 * // has been started means the timers will start running immediately that
dflet 3:a8c249046181 221 * // the scheduler starts.
dflet 3:a8c249046181 222 * for( x = 0; x < NUM_TIMERS; x++ )
dflet 3:a8c249046181 223 * {
dflet 3:a8c249046181 224 * xTimers[ x ] = xTimerCreate( "Timer", // Just a text name, not used by the kernel.
dflet 3:a8c249046181 225 * ( 100 * x ), // The timer period in ticks.
dflet 3:a8c249046181 226 * pdTRUE, // The timers will auto-reload themselves when they expire.
dflet 3:a8c249046181 227 * ( void * ) x, // Assign each timer a unique id equal to its array index.
dflet 3:a8c249046181 228 * vTimerCallback // Each timer calls the same callback when it expires.
dflet 3:a8c249046181 229 * );
dflet 3:a8c249046181 230 *
dflet 3:a8c249046181 231 * if( xTimers[ x ] == NULL )
dflet 3:a8c249046181 232 * {
dflet 3:a8c249046181 233 * // The timer was not created.
dflet 3:a8c249046181 234 * }
dflet 3:a8c249046181 235 * else
dflet 3:a8c249046181 236 * {
dflet 3:a8c249046181 237 * // Start the timer. No block time is specified, and even if one was
dflet 3:a8c249046181 238 * // it would be ignored because the scheduler has not yet been
dflet 3:a8c249046181 239 * // started.
dflet 3:a8c249046181 240 * if( xTimerStart( xTimers[ x ], 0 ) != pdPASS )
dflet 3:a8c249046181 241 * {
dflet 3:a8c249046181 242 * // The timer could not be set into the Active state.
dflet 3:a8c249046181 243 * }
dflet 3:a8c249046181 244 * }
dflet 3:a8c249046181 245 * }
dflet 3:a8c249046181 246 *
dflet 3:a8c249046181 247 * // ...
dflet 3:a8c249046181 248 * // Create tasks here.
dflet 3:a8c249046181 249 * // ...
dflet 3:a8c249046181 250 *
dflet 3:a8c249046181 251 * // Starting the scheduler will start the timers running as they have already
dflet 3:a8c249046181 252 * // been set into the active state.
dflet 3:a8c249046181 253 * xTaskStartScheduler();
dflet 3:a8c249046181 254 *
dflet 3:a8c249046181 255 * // Should not reach here.
dflet 3:a8c249046181 256 * for( ;; );
dflet 3:a8c249046181 257 * }
dflet 3:a8c249046181 258 * @endverbatim
dflet 3:a8c249046181 259 */
dflet 3:a8c249046181 260 TimerHandle_t xTimerCreate( const char * const pcTimerName, const TickType_t xTimerPeriodInTicks, const UBaseType_t uxAutoReload, void * const pvTimerID, TimerCallbackFunction_t pxCallbackFunction ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
dflet 3:a8c249046181 261
dflet 3:a8c249046181 262 /**
dflet 3:a8c249046181 263 * void *pvTimerGetTimerID( TimerHandle_t xTimer );
dflet 3:a8c249046181 264 *
dflet 3:a8c249046181 265 * Returns the ID assigned to the timer.
dflet 3:a8c249046181 266 *
dflet 3:a8c249046181 267 * IDs are assigned to timers using the pvTimerID parameter of the call to
dflet 3:a8c249046181 268 * xTimerCreated() that was used to create the timer, and by calling the
dflet 3:a8c249046181 269 * vTimerSetTimerID() API function.
dflet 3:a8c249046181 270 *
dflet 3:a8c249046181 271 * If the same callback function is assigned to multiple timers then the timer
dflet 3:a8c249046181 272 * ID can be used as time specific (timer local) storage.
dflet 3:a8c249046181 273 *
dflet 3:a8c249046181 274 * @param xTimer The timer being queried.
dflet 3:a8c249046181 275 *
dflet 3:a8c249046181 276 * @return The ID assigned to the timer being queried.
dflet 3:a8c249046181 277 *
dflet 3:a8c249046181 278 * Example usage:
dflet 3:a8c249046181 279 *
dflet 3:a8c249046181 280 * See the xTimerCreate() API function example usage scenario.
dflet 3:a8c249046181 281 */
dflet 3:a8c249046181 282 void *pvTimerGetTimerID( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
dflet 3:a8c249046181 283
dflet 3:a8c249046181 284 /**
dflet 3:a8c249046181 285 * void vTimerSetTimerID( TimerHandle_t xTimer, void *pvNewID );
dflet 3:a8c249046181 286 *
dflet 3:a8c249046181 287 * Sets the ID assigned to the timer.
dflet 3:a8c249046181 288 *
dflet 3:a8c249046181 289 * IDs are assigned to timers using the pvTimerID parameter of the call to
dflet 3:a8c249046181 290 * xTimerCreated() that was used to create the timer.
dflet 3:a8c249046181 291 *
dflet 3:a8c249046181 292 * If the same callback function is assigned to multiple timers then the timer
dflet 3:a8c249046181 293 * ID can be used as time specific (timer local) storage.
dflet 3:a8c249046181 294 *
dflet 3:a8c249046181 295 * @param xTimer The timer being updated.
dflet 3:a8c249046181 296 *
dflet 3:a8c249046181 297 * @param pvNewID The ID to assign to the timer.
dflet 3:a8c249046181 298 *
dflet 3:a8c249046181 299 * Example usage:
dflet 3:a8c249046181 300 *
dflet 3:a8c249046181 301 * See the xTimerCreate() API function example usage scenario.
dflet 3:a8c249046181 302 */
dflet 3:a8c249046181 303 void vTimerSetTimerID( const TimerHandle_t xTimer, void *pvNewID ) PRIVILEGED_FUNCTION;
dflet 3:a8c249046181 304
dflet 3:a8c249046181 305 /**
dflet 3:a8c249046181 306 * BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer );
dflet 3:a8c249046181 307 *
dflet 3:a8c249046181 308 * Queries a timer to see if it is active or dormant.
dflet 3:a8c249046181 309 *
dflet 3:a8c249046181 310 * A timer will be dormant if:
dflet 3:a8c249046181 311 * 1) It has been created but not started, or
dflet 3:a8c249046181 312 * 2) It is an expired one-shot timer that has not been restarted.
dflet 3:a8c249046181 313 *
dflet 3:a8c249046181 314 * Timers are created in the dormant state. The xTimerStart(), xTimerReset(),
dflet 3:a8c249046181 315 * xTimerStartFromISR(), xTimerResetFromISR(), xTimerChangePeriod() and
dflet 3:a8c249046181 316 * xTimerChangePeriodFromISR() API functions can all be used to transition a timer into the
dflet 3:a8c249046181 317 * active state.
dflet 3:a8c249046181 318 *
dflet 3:a8c249046181 319 * @param xTimer The timer being queried.
dflet 3:a8c249046181 320 *
dflet 3:a8c249046181 321 * @return pdFALSE will be returned if the timer is dormant. A value other than
dflet 3:a8c249046181 322 * pdFALSE will be returned if the timer is active.
dflet 3:a8c249046181 323 *
dflet 3:a8c249046181 324 * Example usage:
dflet 3:a8c249046181 325 * @verbatim
dflet 3:a8c249046181 326 * // This function assumes xTimer has already been created.
dflet 3:a8c249046181 327 * void vAFunction( TimerHandle_t xTimer )
dflet 3:a8c249046181 328 * {
dflet 3:a8c249046181 329 * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
dflet 3:a8c249046181 330 * {
dflet 3:a8c249046181 331 * // xTimer is active, do something.
dflet 3:a8c249046181 332 * }
dflet 3:a8c249046181 333 * else
dflet 3:a8c249046181 334 * {
dflet 3:a8c249046181 335 * // xTimer is not active, do something else.
dflet 3:a8c249046181 336 * }
dflet 3:a8c249046181 337 * }
dflet 3:a8c249046181 338 * @endverbatim
dflet 3:a8c249046181 339 */
dflet 3:a8c249046181 340 BaseType_t xTimerIsTimerActive( TimerHandle_t xTimer ) PRIVILEGED_FUNCTION;
dflet 3:a8c249046181 341
dflet 3:a8c249046181 342 /**
dflet 3:a8c249046181 343 * TaskHandle_t xTimerGetTimerDaemonTaskHandle( void );
dflet 3:a8c249046181 344 *
dflet 3:a8c249046181 345 * xTimerGetTimerDaemonTaskHandle() is only available if
dflet 3:a8c249046181 346 * INCLUDE_xTimerGetTimerDaemonTaskHandle is set to 1 in FreeRTOSConfig.h.
dflet 3:a8c249046181 347 *
dflet 3:a8c249046181 348 * Simply returns the handle of the timer service/daemon task. It it not valid
dflet 3:a8c249046181 349 * to call xTimerGetTimerDaemonTaskHandle() before the scheduler has been started.
dflet 3:a8c249046181 350 */
dflet 3:a8c249046181 351 TaskHandle_t xTimerGetTimerDaemonTaskHandle( void );
dflet 3:a8c249046181 352
dflet 3:a8c249046181 353 /**
dflet 3:a8c249046181 354 * BaseType_t xTimerStart( TimerHandle_t xTimer, TickType_t xTicksToWait );
dflet 3:a8c249046181 355 *
dflet 3:a8c249046181 356 * Timer functionality is provided by a timer service/daemon task. Many of the
dflet 3:a8c249046181 357 * public FreeRTOS timer API functions send commands to the timer service task
dflet 3:a8c249046181 358 * through a queue called the timer command queue. The timer command queue is
dflet 3:a8c249046181 359 * private to the kernel itself and is not directly accessible to application
dflet 3:a8c249046181 360 * code. The length of the timer command queue is set by the
dflet 3:a8c249046181 361 * configTIMER_QUEUE_LENGTH configuration constant.
dflet 3:a8c249046181 362 *
dflet 3:a8c249046181 363 * xTimerStart() starts a timer that was previously created using the
dflet 3:a8c249046181 364 * xTimerCreate() API function. If the timer had already been started and was
dflet 3:a8c249046181 365 * already in the active state, then xTimerStart() has equivalent functionality
dflet 3:a8c249046181 366 * to the xTimerReset() API function.
dflet 3:a8c249046181 367 *
dflet 3:a8c249046181 368 * Starting a timer ensures the timer is in the active state. If the timer
dflet 3:a8c249046181 369 * is not stopped, deleted, or reset in the mean time, the callback function
dflet 3:a8c249046181 370 * associated with the timer will get called 'n' ticks after xTimerStart() was
dflet 3:a8c249046181 371 * called, where 'n' is the timers defined period.
dflet 3:a8c249046181 372 *
dflet 3:a8c249046181 373 * It is valid to call xTimerStart() before the scheduler has been started, but
dflet 3:a8c249046181 374 * when this is done the timer will not actually start until the scheduler is
dflet 3:a8c249046181 375 * started, and the timers expiry time will be relative to when the scheduler is
dflet 3:a8c249046181 376 * started, not relative to when xTimerStart() was called.
dflet 3:a8c249046181 377 *
dflet 3:a8c249046181 378 * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStart()
dflet 3:a8c249046181 379 * to be available.
dflet 3:a8c249046181 380 *
dflet 3:a8c249046181 381 * @param xTimer The handle of the timer being started/restarted.
dflet 3:a8c249046181 382 *
dflet 3:a8c249046181 383 * @param xTicksToWait Specifies the time, in ticks, that the calling task should
dflet 3:a8c249046181 384 * be held in the Blocked state to wait for the start command to be successfully
dflet 3:a8c249046181 385 * sent to the timer command queue, should the queue already be full when
dflet 3:a8c249046181 386 * xTimerStart() was called. xTicksToWait is ignored if xTimerStart() is called
dflet 3:a8c249046181 387 * before the scheduler is started.
dflet 3:a8c249046181 388 *
dflet 3:a8c249046181 389 * @return pdFAIL will be returned if the start command could not be sent to
dflet 3:a8c249046181 390 * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
dflet 3:a8c249046181 391 * be returned if the command was successfully sent to the timer command queue.
dflet 3:a8c249046181 392 * When the command is actually processed will depend on the priority of the
dflet 3:a8c249046181 393 * timer service/daemon task relative to other tasks in the system, although the
dflet 3:a8c249046181 394 * timers expiry time is relative to when xTimerStart() is actually called. The
dflet 3:a8c249046181 395 * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
dflet 3:a8c249046181 396 * configuration constant.
dflet 3:a8c249046181 397 *
dflet 3:a8c249046181 398 * Example usage:
dflet 3:a8c249046181 399 *
dflet 3:a8c249046181 400 * See the xTimerCreate() API function example usage scenario.
dflet 3:a8c249046181 401 *
dflet 3:a8c249046181 402 */
dflet 3:a8c249046181 403 #define xTimerStart( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
dflet 3:a8c249046181 404
dflet 3:a8c249046181 405 /**
dflet 3:a8c249046181 406 * BaseType_t xTimerStop( TimerHandle_t xTimer, TickType_t xTicksToWait );
dflet 3:a8c249046181 407 *
dflet 3:a8c249046181 408 * Timer functionality is provided by a timer service/daemon task. Many of the
dflet 3:a8c249046181 409 * public FreeRTOS timer API functions send commands to the timer service task
dflet 3:a8c249046181 410 * through a queue called the timer command queue. The timer command queue is
dflet 3:a8c249046181 411 * private to the kernel itself and is not directly accessible to application
dflet 3:a8c249046181 412 * code. The length of the timer command queue is set by the
dflet 3:a8c249046181 413 * configTIMER_QUEUE_LENGTH configuration constant.
dflet 3:a8c249046181 414 *
dflet 3:a8c249046181 415 * xTimerStop() stops a timer that was previously started using either of the
dflet 3:a8c249046181 416 * The xTimerStart(), xTimerReset(), xTimerStartFromISR(), xTimerResetFromISR(),
dflet 3:a8c249046181 417 * xTimerChangePeriod() or xTimerChangePeriodFromISR() API functions.
dflet 3:a8c249046181 418 *
dflet 3:a8c249046181 419 * Stopping a timer ensures the timer is not in the active state.
dflet 3:a8c249046181 420 *
dflet 3:a8c249046181 421 * The configUSE_TIMERS configuration constant must be set to 1 for xTimerStop()
dflet 3:a8c249046181 422 * to be available.
dflet 3:a8c249046181 423 *
dflet 3:a8c249046181 424 * @param xTimer The handle of the timer being stopped.
dflet 3:a8c249046181 425 *
dflet 3:a8c249046181 426 * @param xTicksToWait Specifies the time, in ticks, that the calling task should
dflet 3:a8c249046181 427 * be held in the Blocked state to wait for the stop command to be successfully
dflet 3:a8c249046181 428 * sent to the timer command queue, should the queue already be full when
dflet 3:a8c249046181 429 * xTimerStop() was called. xTicksToWait is ignored if xTimerStop() is called
dflet 3:a8c249046181 430 * before the scheduler is started.
dflet 3:a8c249046181 431 *
dflet 3:a8c249046181 432 * @return pdFAIL will be returned if the stop command could not be sent to
dflet 3:a8c249046181 433 * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
dflet 3:a8c249046181 434 * be returned if the command was successfully sent to the timer command queue.
dflet 3:a8c249046181 435 * When the command is actually processed will depend on the priority of the
dflet 3:a8c249046181 436 * timer service/daemon task relative to other tasks in the system. The timer
dflet 3:a8c249046181 437 * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
dflet 3:a8c249046181 438 * configuration constant.
dflet 3:a8c249046181 439 *
dflet 3:a8c249046181 440 * Example usage:
dflet 3:a8c249046181 441 *
dflet 3:a8c249046181 442 * See the xTimerCreate() API function example usage scenario.
dflet 3:a8c249046181 443 *
dflet 3:a8c249046181 444 */
dflet 3:a8c249046181 445 #define xTimerStop( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP, 0U, NULL, ( xTicksToWait ) )
dflet 3:a8c249046181 446
dflet 3:a8c249046181 447 /**
dflet 3:a8c249046181 448 * BaseType_t xTimerChangePeriod( TimerHandle_t xTimer,
dflet 3:a8c249046181 449 * TickType_t xNewPeriod,
dflet 3:a8c249046181 450 * TickType_t xTicksToWait );
dflet 3:a8c249046181 451 *
dflet 3:a8c249046181 452 * Timer functionality is provided by a timer service/daemon task. Many of the
dflet 3:a8c249046181 453 * public FreeRTOS timer API functions send commands to the timer service task
dflet 3:a8c249046181 454 * through a queue called the timer command queue. The timer command queue is
dflet 3:a8c249046181 455 * private to the kernel itself and is not directly accessible to application
dflet 3:a8c249046181 456 * code. The length of the timer command queue is set by the
dflet 3:a8c249046181 457 * configTIMER_QUEUE_LENGTH configuration constant.
dflet 3:a8c249046181 458 *
dflet 3:a8c249046181 459 * xTimerChangePeriod() changes the period of a timer that was previously
dflet 3:a8c249046181 460 * created using the xTimerCreate() API function.
dflet 3:a8c249046181 461 *
dflet 3:a8c249046181 462 * xTimerChangePeriod() can be called to change the period of an active or
dflet 3:a8c249046181 463 * dormant state timer.
dflet 3:a8c249046181 464 *
dflet 3:a8c249046181 465 * The configUSE_TIMERS configuration constant must be set to 1 for
dflet 3:a8c249046181 466 * xTimerChangePeriod() to be available.
dflet 3:a8c249046181 467 *
dflet 3:a8c249046181 468 * @param xTimer The handle of the timer that is having its period changed.
dflet 3:a8c249046181 469 *
dflet 3:a8c249046181 470 * @param xNewPeriod The new period for xTimer. Timer periods are specified in
dflet 3:a8c249046181 471 * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
dflet 3:a8c249046181 472 * that has been specified in milliseconds. For example, if the timer must
dflet 3:a8c249046181 473 * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
dflet 3:a8c249046181 474 * if the timer must expire after 500ms, then xNewPeriod can be set to
dflet 3:a8c249046181 475 * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
dflet 3:a8c249046181 476 * or equal to 1000.
dflet 3:a8c249046181 477 *
dflet 3:a8c249046181 478 * @param xTicksToWait Specifies the time, in ticks, that the calling task should
dflet 3:a8c249046181 479 * be held in the Blocked state to wait for the change period command to be
dflet 3:a8c249046181 480 * successfully sent to the timer command queue, should the queue already be
dflet 3:a8c249046181 481 * full when xTimerChangePeriod() was called. xTicksToWait is ignored if
dflet 3:a8c249046181 482 * xTimerChangePeriod() is called before the scheduler is started.
dflet 3:a8c249046181 483 *
dflet 3:a8c249046181 484 * @return pdFAIL will be returned if the change period command could not be
dflet 3:a8c249046181 485 * sent to the timer command queue even after xTicksToWait ticks had passed.
dflet 3:a8c249046181 486 * pdPASS will be returned if the command was successfully sent to the timer
dflet 3:a8c249046181 487 * command queue. When the command is actually processed will depend on the
dflet 3:a8c249046181 488 * priority of the timer service/daemon task relative to other tasks in the
dflet 3:a8c249046181 489 * system. The timer service/daemon task priority is set by the
dflet 3:a8c249046181 490 * configTIMER_TASK_PRIORITY configuration constant.
dflet 3:a8c249046181 491 *
dflet 3:a8c249046181 492 * Example usage:
dflet 3:a8c249046181 493 * @verbatim
dflet 3:a8c249046181 494 * // This function assumes xTimer has already been created. If the timer
dflet 3:a8c249046181 495 * // referenced by xTimer is already active when it is called, then the timer
dflet 3:a8c249046181 496 * // is deleted. If the timer referenced by xTimer is not active when it is
dflet 3:a8c249046181 497 * // called, then the period of the timer is set to 500ms and the timer is
dflet 3:a8c249046181 498 * // started.
dflet 3:a8c249046181 499 * void vAFunction( TimerHandle_t xTimer )
dflet 3:a8c249046181 500 * {
dflet 3:a8c249046181 501 * if( xTimerIsTimerActive( xTimer ) != pdFALSE ) // or more simply and equivalently "if( xTimerIsTimerActive( xTimer ) )"
dflet 3:a8c249046181 502 * {
dflet 3:a8c249046181 503 * // xTimer is already active - delete it.
dflet 3:a8c249046181 504 * xTimerDelete( xTimer );
dflet 3:a8c249046181 505 * }
dflet 3:a8c249046181 506 * else
dflet 3:a8c249046181 507 * {
dflet 3:a8c249046181 508 * // xTimer is not active, change its period to 500ms. This will also
dflet 3:a8c249046181 509 * // cause the timer to start. Block for a maximum of 100 ticks if the
dflet 3:a8c249046181 510 * // change period command cannot immediately be sent to the timer
dflet 3:a8c249046181 511 * // command queue.
dflet 3:a8c249046181 512 * if( xTimerChangePeriod( xTimer, 500 / portTICK_PERIOD_MS, 100 ) == pdPASS )
dflet 3:a8c249046181 513 * {
dflet 3:a8c249046181 514 * // The command was successfully sent.
dflet 3:a8c249046181 515 * }
dflet 3:a8c249046181 516 * else
dflet 3:a8c249046181 517 * {
dflet 3:a8c249046181 518 * // The command could not be sent, even after waiting for 100 ticks
dflet 3:a8c249046181 519 * // to pass. Take appropriate action here.
dflet 3:a8c249046181 520 * }
dflet 3:a8c249046181 521 * }
dflet 3:a8c249046181 522 * }
dflet 3:a8c249046181 523 * @endverbatim
dflet 3:a8c249046181 524 */
dflet 3:a8c249046181 525 #define xTimerChangePeriod( xTimer, xNewPeriod, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD, ( xNewPeriod ), NULL, ( xTicksToWait ) )
dflet 3:a8c249046181 526
dflet 3:a8c249046181 527 /**
dflet 3:a8c249046181 528 * BaseType_t xTimerDelete( TimerHandle_t xTimer, TickType_t xTicksToWait );
dflet 3:a8c249046181 529 *
dflet 3:a8c249046181 530 * Timer functionality is provided by a timer service/daemon task. Many of the
dflet 3:a8c249046181 531 * public FreeRTOS timer API functions send commands to the timer service task
dflet 3:a8c249046181 532 * through a queue called the timer command queue. The timer command queue is
dflet 3:a8c249046181 533 * private to the kernel itself and is not directly accessible to application
dflet 3:a8c249046181 534 * code. The length of the timer command queue is set by the
dflet 3:a8c249046181 535 * configTIMER_QUEUE_LENGTH configuration constant.
dflet 3:a8c249046181 536 *
dflet 3:a8c249046181 537 * xTimerDelete() deletes a timer that was previously created using the
dflet 3:a8c249046181 538 * xTimerCreate() API function.
dflet 3:a8c249046181 539 *
dflet 3:a8c249046181 540 * The configUSE_TIMERS configuration constant must be set to 1 for
dflet 3:a8c249046181 541 * xTimerDelete() to be available.
dflet 3:a8c249046181 542 *
dflet 3:a8c249046181 543 * @param xTimer The handle of the timer being deleted.
dflet 3:a8c249046181 544 *
dflet 3:a8c249046181 545 * @param xTicksToWait Specifies the time, in ticks, that the calling task should
dflet 3:a8c249046181 546 * be held in the Blocked state to wait for the delete command to be
dflet 3:a8c249046181 547 * successfully sent to the timer command queue, should the queue already be
dflet 3:a8c249046181 548 * full when xTimerDelete() was called. xTicksToWait is ignored if xTimerDelete()
dflet 3:a8c249046181 549 * is called before the scheduler is started.
dflet 3:a8c249046181 550 *
dflet 3:a8c249046181 551 * @return pdFAIL will be returned if the delete command could not be sent to
dflet 3:a8c249046181 552 * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
dflet 3:a8c249046181 553 * be returned if the command was successfully sent to the timer command queue.
dflet 3:a8c249046181 554 * When the command is actually processed will depend on the priority of the
dflet 3:a8c249046181 555 * timer service/daemon task relative to other tasks in the system. The timer
dflet 3:a8c249046181 556 * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
dflet 3:a8c249046181 557 * configuration constant.
dflet 3:a8c249046181 558 *
dflet 3:a8c249046181 559 * Example usage:
dflet 3:a8c249046181 560 *
dflet 3:a8c249046181 561 * See the xTimerChangePeriod() API function example usage scenario.
dflet 3:a8c249046181 562 */
dflet 3:a8c249046181 563 #define xTimerDelete( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_DELETE, 0U, NULL, ( xTicksToWait ) )
dflet 3:a8c249046181 564
dflet 3:a8c249046181 565 /**
dflet 3:a8c249046181 566 * BaseType_t xTimerReset( TimerHandle_t xTimer, TickType_t xTicksToWait );
dflet 3:a8c249046181 567 *
dflet 3:a8c249046181 568 * Timer functionality is provided by a timer service/daemon task. Many of the
dflet 3:a8c249046181 569 * public FreeRTOS timer API functions send commands to the timer service task
dflet 3:a8c249046181 570 * through a queue called the timer command queue. The timer command queue is
dflet 3:a8c249046181 571 * private to the kernel itself and is not directly accessible to application
dflet 3:a8c249046181 572 * code. The length of the timer command queue is set by the
dflet 3:a8c249046181 573 * configTIMER_QUEUE_LENGTH configuration constant.
dflet 3:a8c249046181 574 *
dflet 3:a8c249046181 575 * xTimerReset() re-starts a timer that was previously created using the
dflet 3:a8c249046181 576 * xTimerCreate() API function. If the timer had already been started and was
dflet 3:a8c249046181 577 * already in the active state, then xTimerReset() will cause the timer to
dflet 3:a8c249046181 578 * re-evaluate its expiry time so that it is relative to when xTimerReset() was
dflet 3:a8c249046181 579 * called. If the timer was in the dormant state then xTimerReset() has
dflet 3:a8c249046181 580 * equivalent functionality to the xTimerStart() API function.
dflet 3:a8c249046181 581 *
dflet 3:a8c249046181 582 * Resetting a timer ensures the timer is in the active state. If the timer
dflet 3:a8c249046181 583 * is not stopped, deleted, or reset in the mean time, the callback function
dflet 3:a8c249046181 584 * associated with the timer will get called 'n' ticks after xTimerReset() was
dflet 3:a8c249046181 585 * called, where 'n' is the timers defined period.
dflet 3:a8c249046181 586 *
dflet 3:a8c249046181 587 * It is valid to call xTimerReset() before the scheduler has been started, but
dflet 3:a8c249046181 588 * when this is done the timer will not actually start until the scheduler is
dflet 3:a8c249046181 589 * started, and the timers expiry time will be relative to when the scheduler is
dflet 3:a8c249046181 590 * started, not relative to when xTimerReset() was called.
dflet 3:a8c249046181 591 *
dflet 3:a8c249046181 592 * The configUSE_TIMERS configuration constant must be set to 1 for xTimerReset()
dflet 3:a8c249046181 593 * to be available.
dflet 3:a8c249046181 594 *
dflet 3:a8c249046181 595 * @param xTimer The handle of the timer being reset/started/restarted.
dflet 3:a8c249046181 596 *
dflet 3:a8c249046181 597 * @param xTicksToWait Specifies the time, in ticks, that the calling task should
dflet 3:a8c249046181 598 * be held in the Blocked state to wait for the reset command to be successfully
dflet 3:a8c249046181 599 * sent to the timer command queue, should the queue already be full when
dflet 3:a8c249046181 600 * xTimerReset() was called. xTicksToWait is ignored if xTimerReset() is called
dflet 3:a8c249046181 601 * before the scheduler is started.
dflet 3:a8c249046181 602 *
dflet 3:a8c249046181 603 * @return pdFAIL will be returned if the reset command could not be sent to
dflet 3:a8c249046181 604 * the timer command queue even after xTicksToWait ticks had passed. pdPASS will
dflet 3:a8c249046181 605 * be returned if the command was successfully sent to the timer command queue.
dflet 3:a8c249046181 606 * When the command is actually processed will depend on the priority of the
dflet 3:a8c249046181 607 * timer service/daemon task relative to other tasks in the system, although the
dflet 3:a8c249046181 608 * timers expiry time is relative to when xTimerStart() is actually called. The
dflet 3:a8c249046181 609 * timer service/daemon task priority is set by the configTIMER_TASK_PRIORITY
dflet 3:a8c249046181 610 * configuration constant.
dflet 3:a8c249046181 611 *
dflet 3:a8c249046181 612 * Example usage:
dflet 3:a8c249046181 613 * @verbatim
dflet 3:a8c249046181 614 * // When a key is pressed, an LCD back-light is switched on. If 5 seconds pass
dflet 3:a8c249046181 615 * // without a key being pressed, then the LCD back-light is switched off. In
dflet 3:a8c249046181 616 * // this case, the timer is a one-shot timer.
dflet 3:a8c249046181 617 *
dflet 3:a8c249046181 618 * TimerHandle_t xBacklightTimer = NULL;
dflet 3:a8c249046181 619 *
dflet 3:a8c249046181 620 * // The callback function assigned to the one-shot timer. In this case the
dflet 3:a8c249046181 621 * // parameter is not used.
dflet 3:a8c249046181 622 * void vBacklightTimerCallback( TimerHandle_t pxTimer )
dflet 3:a8c249046181 623 * {
dflet 3:a8c249046181 624 * // The timer expired, therefore 5 seconds must have passed since a key
dflet 3:a8c249046181 625 * // was pressed. Switch off the LCD back-light.
dflet 3:a8c249046181 626 * vSetBacklightState( BACKLIGHT_OFF );
dflet 3:a8c249046181 627 * }
dflet 3:a8c249046181 628 *
dflet 3:a8c249046181 629 * // The key press event handler.
dflet 3:a8c249046181 630 * void vKeyPressEventHandler( char cKey )
dflet 3:a8c249046181 631 * {
dflet 3:a8c249046181 632 * // Ensure the LCD back-light is on, then reset the timer that is
dflet 3:a8c249046181 633 * // responsible for turning the back-light off after 5 seconds of
dflet 3:a8c249046181 634 * // key inactivity. Wait 10 ticks for the command to be successfully sent
dflet 3:a8c249046181 635 * // if it cannot be sent immediately.
dflet 3:a8c249046181 636 * vSetBacklightState( BACKLIGHT_ON );
dflet 3:a8c249046181 637 * if( xTimerReset( xBacklightTimer, 100 ) != pdPASS )
dflet 3:a8c249046181 638 * {
dflet 3:a8c249046181 639 * // The reset command was not executed successfully. Take appropriate
dflet 3:a8c249046181 640 * // action here.
dflet 3:a8c249046181 641 * }
dflet 3:a8c249046181 642 *
dflet 3:a8c249046181 643 * // Perform the rest of the key processing here.
dflet 3:a8c249046181 644 * }
dflet 3:a8c249046181 645 *
dflet 3:a8c249046181 646 * void main( void )
dflet 3:a8c249046181 647 * {
dflet 3:a8c249046181 648 * int32_t x;
dflet 3:a8c249046181 649 *
dflet 3:a8c249046181 650 * // Create then start the one-shot timer that is responsible for turning
dflet 3:a8c249046181 651 * // the back-light off if no keys are pressed within a 5 second period.
dflet 3:a8c249046181 652 * xBacklightTimer = xTimerCreate( "BacklightTimer", // Just a text name, not used by the kernel.
dflet 3:a8c249046181 653 * ( 5000 / portTICK_PERIOD_MS), // The timer period in ticks.
dflet 3:a8c249046181 654 * pdFALSE, // The timer is a one-shot timer.
dflet 3:a8c249046181 655 * 0, // The id is not used by the callback so can take any value.
dflet 3:a8c249046181 656 * vBacklightTimerCallback // The callback function that switches the LCD back-light off.
dflet 3:a8c249046181 657 * );
dflet 3:a8c249046181 658 *
dflet 3:a8c249046181 659 * if( xBacklightTimer == NULL )
dflet 3:a8c249046181 660 * {
dflet 3:a8c249046181 661 * // The timer was not created.
dflet 3:a8c249046181 662 * }
dflet 3:a8c249046181 663 * else
dflet 3:a8c249046181 664 * {
dflet 3:a8c249046181 665 * // Start the timer. No block time is specified, and even if one was
dflet 3:a8c249046181 666 * // it would be ignored because the scheduler has not yet been
dflet 3:a8c249046181 667 * // started.
dflet 3:a8c249046181 668 * if( xTimerStart( xBacklightTimer, 0 ) != pdPASS )
dflet 3:a8c249046181 669 * {
dflet 3:a8c249046181 670 * // The timer could not be set into the Active state.
dflet 3:a8c249046181 671 * }
dflet 3:a8c249046181 672 * }
dflet 3:a8c249046181 673 *
dflet 3:a8c249046181 674 * // ...
dflet 3:a8c249046181 675 * // Create tasks here.
dflet 3:a8c249046181 676 * // ...
dflet 3:a8c249046181 677 *
dflet 3:a8c249046181 678 * // Starting the scheduler will start the timer running as it has already
dflet 3:a8c249046181 679 * // been set into the active state.
dflet 3:a8c249046181 680 * xTaskStartScheduler();
dflet 3:a8c249046181 681 *
dflet 3:a8c249046181 682 * // Should not reach here.
dflet 3:a8c249046181 683 * for( ;; );
dflet 3:a8c249046181 684 * }
dflet 3:a8c249046181 685 * @endverbatim
dflet 3:a8c249046181 686 */
dflet 3:a8c249046181 687 #define xTimerReset( xTimer, xTicksToWait ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET, ( xTaskGetTickCount() ), NULL, ( xTicksToWait ) )
dflet 3:a8c249046181 688
dflet 3:a8c249046181 689 /**
dflet 3:a8c249046181 690 * BaseType_t xTimerStartFromISR( TimerHandle_t xTimer,
dflet 3:a8c249046181 691 * BaseType_t *pxHigherPriorityTaskWoken );
dflet 3:a8c249046181 692 *
dflet 3:a8c249046181 693 * A version of xTimerStart() that can be called from an interrupt service
dflet 3:a8c249046181 694 * routine.
dflet 3:a8c249046181 695 *
dflet 3:a8c249046181 696 * @param xTimer The handle of the timer being started/restarted.
dflet 3:a8c249046181 697 *
dflet 3:a8c249046181 698 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
dflet 3:a8c249046181 699 * of its time in the Blocked state, waiting for messages to arrive on the timer
dflet 3:a8c249046181 700 * command queue. Calling xTimerStartFromISR() writes a message to the timer
dflet 3:a8c249046181 701 * command queue, so has the potential to transition the timer service/daemon
dflet 3:a8c249046181 702 * task out of the Blocked state. If calling xTimerStartFromISR() causes the
dflet 3:a8c249046181 703 * timer service/daemon task to leave the Blocked state, and the timer service/
dflet 3:a8c249046181 704 * daemon task has a priority equal to or greater than the currently executing
dflet 3:a8c249046181 705 * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
dflet 3:a8c249046181 706 * get set to pdTRUE internally within the xTimerStartFromISR() function. If
dflet 3:a8c249046181 707 * xTimerStartFromISR() sets this value to pdTRUE then a context switch should
dflet 3:a8c249046181 708 * be performed before the interrupt exits.
dflet 3:a8c249046181 709 *
dflet 3:a8c249046181 710 * @return pdFAIL will be returned if the start command could not be sent to
dflet 3:a8c249046181 711 * the timer command queue. pdPASS will be returned if the command was
dflet 3:a8c249046181 712 * successfully sent to the timer command queue. When the command is actually
dflet 3:a8c249046181 713 * processed will depend on the priority of the timer service/daemon task
dflet 3:a8c249046181 714 * relative to other tasks in the system, although the timers expiry time is
dflet 3:a8c249046181 715 * relative to when xTimerStartFromISR() is actually called. The timer
dflet 3:a8c249046181 716 * service/daemon task priority is set by the configTIMER_TASK_PRIORITY
dflet 3:a8c249046181 717 * configuration constant.
dflet 3:a8c249046181 718 *
dflet 3:a8c249046181 719 * Example usage:
dflet 3:a8c249046181 720 * @verbatim
dflet 3:a8c249046181 721 * // This scenario assumes xBacklightTimer has already been created. When a
dflet 3:a8c249046181 722 * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
dflet 3:a8c249046181 723 * // without a key being pressed, then the LCD back-light is switched off. In
dflet 3:a8c249046181 724 * // this case, the timer is a one-shot timer, and unlike the example given for
dflet 3:a8c249046181 725 * // the xTimerReset() function, the key press event handler is an interrupt
dflet 3:a8c249046181 726 * // service routine.
dflet 3:a8c249046181 727 *
dflet 3:a8c249046181 728 * // The callback function assigned to the one-shot timer. In this case the
dflet 3:a8c249046181 729 * // parameter is not used.
dflet 3:a8c249046181 730 * void vBacklightTimerCallback( TimerHandle_t pxTimer )
dflet 3:a8c249046181 731 * {
dflet 3:a8c249046181 732 * // The timer expired, therefore 5 seconds must have passed since a key
dflet 3:a8c249046181 733 * // was pressed. Switch off the LCD back-light.
dflet 3:a8c249046181 734 * vSetBacklightState( BACKLIGHT_OFF );
dflet 3:a8c249046181 735 * }
dflet 3:a8c249046181 736 *
dflet 3:a8c249046181 737 * // The key press interrupt service routine.
dflet 3:a8c249046181 738 * void vKeyPressEventInterruptHandler( void )
dflet 3:a8c249046181 739 * {
dflet 3:a8c249046181 740 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
dflet 3:a8c249046181 741 *
dflet 3:a8c249046181 742 * // Ensure the LCD back-light is on, then restart the timer that is
dflet 3:a8c249046181 743 * // responsible for turning the back-light off after 5 seconds of
dflet 3:a8c249046181 744 * // key inactivity. This is an interrupt service routine so can only
dflet 3:a8c249046181 745 * // call FreeRTOS API functions that end in "FromISR".
dflet 3:a8c249046181 746 * vSetBacklightState( BACKLIGHT_ON );
dflet 3:a8c249046181 747 *
dflet 3:a8c249046181 748 * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
dflet 3:a8c249046181 749 * // as both cause the timer to re-calculate its expiry time.
dflet 3:a8c249046181 750 * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
dflet 3:a8c249046181 751 * // declared (in this function).
dflet 3:a8c249046181 752 * if( xTimerStartFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
dflet 3:a8c249046181 753 * {
dflet 3:a8c249046181 754 * // The start command was not executed successfully. Take appropriate
dflet 3:a8c249046181 755 * // action here.
dflet 3:a8c249046181 756 * }
dflet 3:a8c249046181 757 *
dflet 3:a8c249046181 758 * // Perform the rest of the key processing here.
dflet 3:a8c249046181 759 *
dflet 3:a8c249046181 760 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
dflet 3:a8c249046181 761 * // should be performed. The syntax required to perform a context switch
dflet 3:a8c249046181 762 * // from inside an ISR varies from port to port, and from compiler to
dflet 3:a8c249046181 763 * // compiler. Inspect the demos for the port you are using to find the
dflet 3:a8c249046181 764 * // actual syntax required.
dflet 3:a8c249046181 765 * if( xHigherPriorityTaskWoken != pdFALSE )
dflet 3:a8c249046181 766 * {
dflet 3:a8c249046181 767 * // Call the interrupt safe yield function here (actual function
dflet 3:a8c249046181 768 * // depends on the FreeRTOS port being used).
dflet 3:a8c249046181 769 * }
dflet 3:a8c249046181 770 * }
dflet 3:a8c249046181 771 * @endverbatim
dflet 3:a8c249046181 772 */
dflet 3:a8c249046181 773 #define xTimerStartFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
dflet 3:a8c249046181 774
dflet 3:a8c249046181 775 /**
dflet 3:a8c249046181 776 * BaseType_t xTimerStopFromISR( TimerHandle_t xTimer,
dflet 3:a8c249046181 777 * BaseType_t *pxHigherPriorityTaskWoken );
dflet 3:a8c249046181 778 *
dflet 3:a8c249046181 779 * A version of xTimerStop() that can be called from an interrupt service
dflet 3:a8c249046181 780 * routine.
dflet 3:a8c249046181 781 *
dflet 3:a8c249046181 782 * @param xTimer The handle of the timer being stopped.
dflet 3:a8c249046181 783 *
dflet 3:a8c249046181 784 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
dflet 3:a8c249046181 785 * of its time in the Blocked state, waiting for messages to arrive on the timer
dflet 3:a8c249046181 786 * command queue. Calling xTimerStopFromISR() writes a message to the timer
dflet 3:a8c249046181 787 * command queue, so has the potential to transition the timer service/daemon
dflet 3:a8c249046181 788 * task out of the Blocked state. If calling xTimerStopFromISR() causes the
dflet 3:a8c249046181 789 * timer service/daemon task to leave the Blocked state, and the timer service/
dflet 3:a8c249046181 790 * daemon task has a priority equal to or greater than the currently executing
dflet 3:a8c249046181 791 * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
dflet 3:a8c249046181 792 * get set to pdTRUE internally within the xTimerStopFromISR() function. If
dflet 3:a8c249046181 793 * xTimerStopFromISR() sets this value to pdTRUE then a context switch should
dflet 3:a8c249046181 794 * be performed before the interrupt exits.
dflet 3:a8c249046181 795 *
dflet 3:a8c249046181 796 * @return pdFAIL will be returned if the stop command could not be sent to
dflet 3:a8c249046181 797 * the timer command queue. pdPASS will be returned if the command was
dflet 3:a8c249046181 798 * successfully sent to the timer command queue. When the command is actually
dflet 3:a8c249046181 799 * processed will depend on the priority of the timer service/daemon task
dflet 3:a8c249046181 800 * relative to other tasks in the system. The timer service/daemon task
dflet 3:a8c249046181 801 * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
dflet 3:a8c249046181 802 *
dflet 3:a8c249046181 803 * Example usage:
dflet 3:a8c249046181 804 * @verbatim
dflet 3:a8c249046181 805 * // This scenario assumes xTimer has already been created and started. When
dflet 3:a8c249046181 806 * // an interrupt occurs, the timer should be simply stopped.
dflet 3:a8c249046181 807 *
dflet 3:a8c249046181 808 * // The interrupt service routine that stops the timer.
dflet 3:a8c249046181 809 * void vAnExampleInterruptServiceRoutine( void )
dflet 3:a8c249046181 810 * {
dflet 3:a8c249046181 811 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
dflet 3:a8c249046181 812 *
dflet 3:a8c249046181 813 * // The interrupt has occurred - simply stop the timer.
dflet 3:a8c249046181 814 * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
dflet 3:a8c249046181 815 * // (within this function). As this is an interrupt service routine, only
dflet 3:a8c249046181 816 * // FreeRTOS API functions that end in "FromISR" can be used.
dflet 3:a8c249046181 817 * if( xTimerStopFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
dflet 3:a8c249046181 818 * {
dflet 3:a8c249046181 819 * // The stop command was not executed successfully. Take appropriate
dflet 3:a8c249046181 820 * // action here.
dflet 3:a8c249046181 821 * }
dflet 3:a8c249046181 822 *
dflet 3:a8c249046181 823 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
dflet 3:a8c249046181 824 * // should be performed. The syntax required to perform a context switch
dflet 3:a8c249046181 825 * // from inside an ISR varies from port to port, and from compiler to
dflet 3:a8c249046181 826 * // compiler. Inspect the demos for the port you are using to find the
dflet 3:a8c249046181 827 * // actual syntax required.
dflet 3:a8c249046181 828 * if( xHigherPriorityTaskWoken != pdFALSE )
dflet 3:a8c249046181 829 * {
dflet 3:a8c249046181 830 * // Call the interrupt safe yield function here (actual function
dflet 3:a8c249046181 831 * // depends on the FreeRTOS port being used).
dflet 3:a8c249046181 832 * }
dflet 3:a8c249046181 833 * }
dflet 3:a8c249046181 834 * @endverbatim
dflet 3:a8c249046181 835 */
dflet 3:a8c249046181 836 #define xTimerStopFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_STOP_FROM_ISR, 0, ( pxHigherPriorityTaskWoken ), 0U )
dflet 3:a8c249046181 837
dflet 3:a8c249046181 838 /**
dflet 3:a8c249046181 839 * BaseType_t xTimerChangePeriodFromISR( TimerHandle_t xTimer,
dflet 3:a8c249046181 840 * TickType_t xNewPeriod,
dflet 3:a8c249046181 841 * BaseType_t *pxHigherPriorityTaskWoken );
dflet 3:a8c249046181 842 *
dflet 3:a8c249046181 843 * A version of xTimerChangePeriod() that can be called from an interrupt
dflet 3:a8c249046181 844 * service routine.
dflet 3:a8c249046181 845 *
dflet 3:a8c249046181 846 * @param xTimer The handle of the timer that is having its period changed.
dflet 3:a8c249046181 847 *
dflet 3:a8c249046181 848 * @param xNewPeriod The new period for xTimer. Timer periods are specified in
dflet 3:a8c249046181 849 * tick periods, so the constant portTICK_PERIOD_MS can be used to convert a time
dflet 3:a8c249046181 850 * that has been specified in milliseconds. For example, if the timer must
dflet 3:a8c249046181 851 * expire after 100 ticks, then xNewPeriod should be set to 100. Alternatively,
dflet 3:a8c249046181 852 * if the timer must expire after 500ms, then xNewPeriod can be set to
dflet 3:a8c249046181 853 * ( 500 / portTICK_PERIOD_MS ) provided configTICK_RATE_HZ is less than
dflet 3:a8c249046181 854 * or equal to 1000.
dflet 3:a8c249046181 855 *
dflet 3:a8c249046181 856 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
dflet 3:a8c249046181 857 * of its time in the Blocked state, waiting for messages to arrive on the timer
dflet 3:a8c249046181 858 * command queue. Calling xTimerChangePeriodFromISR() writes a message to the
dflet 3:a8c249046181 859 * timer command queue, so has the potential to transition the timer service/
dflet 3:a8c249046181 860 * daemon task out of the Blocked state. If calling xTimerChangePeriodFromISR()
dflet 3:a8c249046181 861 * causes the timer service/daemon task to leave the Blocked state, and the
dflet 3:a8c249046181 862 * timer service/daemon task has a priority equal to or greater than the
dflet 3:a8c249046181 863 * currently executing task (the task that was interrupted), then
dflet 3:a8c249046181 864 * *pxHigherPriorityTaskWoken will get set to pdTRUE internally within the
dflet 3:a8c249046181 865 * xTimerChangePeriodFromISR() function. If xTimerChangePeriodFromISR() sets
dflet 3:a8c249046181 866 * this value to pdTRUE then a context switch should be performed before the
dflet 3:a8c249046181 867 * interrupt exits.
dflet 3:a8c249046181 868 *
dflet 3:a8c249046181 869 * @return pdFAIL will be returned if the command to change the timers period
dflet 3:a8c249046181 870 * could not be sent to the timer command queue. pdPASS will be returned if the
dflet 3:a8c249046181 871 * command was successfully sent to the timer command queue. When the command
dflet 3:a8c249046181 872 * is actually processed will depend on the priority of the timer service/daemon
dflet 3:a8c249046181 873 * task relative to other tasks in the system. The timer service/daemon task
dflet 3:a8c249046181 874 * priority is set by the configTIMER_TASK_PRIORITY configuration constant.
dflet 3:a8c249046181 875 *
dflet 3:a8c249046181 876 * Example usage:
dflet 3:a8c249046181 877 * @verbatim
dflet 3:a8c249046181 878 * // This scenario assumes xTimer has already been created and started. When
dflet 3:a8c249046181 879 * // an interrupt occurs, the period of xTimer should be changed to 500ms.
dflet 3:a8c249046181 880 *
dflet 3:a8c249046181 881 * // The interrupt service routine that changes the period of xTimer.
dflet 3:a8c249046181 882 * void vAnExampleInterruptServiceRoutine( void )
dflet 3:a8c249046181 883 * {
dflet 3:a8c249046181 884 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
dflet 3:a8c249046181 885 *
dflet 3:a8c249046181 886 * // The interrupt has occurred - change the period of xTimer to 500ms.
dflet 3:a8c249046181 887 * // xHigherPriorityTaskWoken was set to pdFALSE where it was defined
dflet 3:a8c249046181 888 * // (within this function). As this is an interrupt service routine, only
dflet 3:a8c249046181 889 * // FreeRTOS API functions that end in "FromISR" can be used.
dflet 3:a8c249046181 890 * if( xTimerChangePeriodFromISR( xTimer, &xHigherPriorityTaskWoken ) != pdPASS )
dflet 3:a8c249046181 891 * {
dflet 3:a8c249046181 892 * // The command to change the timers period was not executed
dflet 3:a8c249046181 893 * // successfully. Take appropriate action here.
dflet 3:a8c249046181 894 * }
dflet 3:a8c249046181 895 *
dflet 3:a8c249046181 896 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
dflet 3:a8c249046181 897 * // should be performed. The syntax required to perform a context switch
dflet 3:a8c249046181 898 * // from inside an ISR varies from port to port, and from compiler to
dflet 3:a8c249046181 899 * // compiler. Inspect the demos for the port you are using to find the
dflet 3:a8c249046181 900 * // actual syntax required.
dflet 3:a8c249046181 901 * if( xHigherPriorityTaskWoken != pdFALSE )
dflet 3:a8c249046181 902 * {
dflet 3:a8c249046181 903 * // Call the interrupt safe yield function here (actual function
dflet 3:a8c249046181 904 * // depends on the FreeRTOS port being used).
dflet 3:a8c249046181 905 * }
dflet 3:a8c249046181 906 * }
dflet 3:a8c249046181 907 * @endverbatim
dflet 3:a8c249046181 908 */
dflet 3:a8c249046181 909 #define xTimerChangePeriodFromISR( xTimer, xNewPeriod, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_CHANGE_PERIOD_FROM_ISR, ( xNewPeriod ), ( pxHigherPriorityTaskWoken ), 0U )
dflet 3:a8c249046181 910
dflet 3:a8c249046181 911 /**
dflet 3:a8c249046181 912 * BaseType_t xTimerResetFromISR( TimerHandle_t xTimer,
dflet 3:a8c249046181 913 * BaseType_t *pxHigherPriorityTaskWoken );
dflet 3:a8c249046181 914 *
dflet 3:a8c249046181 915 * A version of xTimerReset() that can be called from an interrupt service
dflet 3:a8c249046181 916 * routine.
dflet 3:a8c249046181 917 *
dflet 3:a8c249046181 918 * @param xTimer The handle of the timer that is to be started, reset, or
dflet 3:a8c249046181 919 * restarted.
dflet 3:a8c249046181 920 *
dflet 3:a8c249046181 921 * @param pxHigherPriorityTaskWoken The timer service/daemon task spends most
dflet 3:a8c249046181 922 * of its time in the Blocked state, waiting for messages to arrive on the timer
dflet 3:a8c249046181 923 * command queue. Calling xTimerResetFromISR() writes a message to the timer
dflet 3:a8c249046181 924 * command queue, so has the potential to transition the timer service/daemon
dflet 3:a8c249046181 925 * task out of the Blocked state. If calling xTimerResetFromISR() causes the
dflet 3:a8c249046181 926 * timer service/daemon task to leave the Blocked state, and the timer service/
dflet 3:a8c249046181 927 * daemon task has a priority equal to or greater than the currently executing
dflet 3:a8c249046181 928 * task (the task that was interrupted), then *pxHigherPriorityTaskWoken will
dflet 3:a8c249046181 929 * get set to pdTRUE internally within the xTimerResetFromISR() function. If
dflet 3:a8c249046181 930 * xTimerResetFromISR() sets this value to pdTRUE then a context switch should
dflet 3:a8c249046181 931 * be performed before the interrupt exits.
dflet 3:a8c249046181 932 *
dflet 3:a8c249046181 933 * @return pdFAIL will be returned if the reset command could not be sent to
dflet 3:a8c249046181 934 * the timer command queue. pdPASS will be returned if the command was
dflet 3:a8c249046181 935 * successfully sent to the timer command queue. When the command is actually
dflet 3:a8c249046181 936 * processed will depend on the priority of the timer service/daemon task
dflet 3:a8c249046181 937 * relative to other tasks in the system, although the timers expiry time is
dflet 3:a8c249046181 938 * relative to when xTimerResetFromISR() is actually called. The timer service/daemon
dflet 3:a8c249046181 939 * task priority is set by the configTIMER_TASK_PRIORITY configuration constant.
dflet 3:a8c249046181 940 *
dflet 3:a8c249046181 941 * Example usage:
dflet 3:a8c249046181 942 * @verbatim
dflet 3:a8c249046181 943 * // This scenario assumes xBacklightTimer has already been created. When a
dflet 3:a8c249046181 944 * // key is pressed, an LCD back-light is switched on. If 5 seconds pass
dflet 3:a8c249046181 945 * // without a key being pressed, then the LCD back-light is switched off. In
dflet 3:a8c249046181 946 * // this case, the timer is a one-shot timer, and unlike the example given for
dflet 3:a8c249046181 947 * // the xTimerReset() function, the key press event handler is an interrupt
dflet 3:a8c249046181 948 * // service routine.
dflet 3:a8c249046181 949 *
dflet 3:a8c249046181 950 * // The callback function assigned to the one-shot timer. In this case the
dflet 3:a8c249046181 951 * // parameter is not used.
dflet 3:a8c249046181 952 * void vBacklightTimerCallback( TimerHandle_t pxTimer )
dflet 3:a8c249046181 953 * {
dflet 3:a8c249046181 954 * // The timer expired, therefore 5 seconds must have passed since a key
dflet 3:a8c249046181 955 * // was pressed. Switch off the LCD back-light.
dflet 3:a8c249046181 956 * vSetBacklightState( BACKLIGHT_OFF );
dflet 3:a8c249046181 957 * }
dflet 3:a8c249046181 958 *
dflet 3:a8c249046181 959 * // The key press interrupt service routine.
dflet 3:a8c249046181 960 * void vKeyPressEventInterruptHandler( void )
dflet 3:a8c249046181 961 * {
dflet 3:a8c249046181 962 * BaseType_t xHigherPriorityTaskWoken = pdFALSE;
dflet 3:a8c249046181 963 *
dflet 3:a8c249046181 964 * // Ensure the LCD back-light is on, then reset the timer that is
dflet 3:a8c249046181 965 * // responsible for turning the back-light off after 5 seconds of
dflet 3:a8c249046181 966 * // key inactivity. This is an interrupt service routine so can only
dflet 3:a8c249046181 967 * // call FreeRTOS API functions that end in "FromISR".
dflet 3:a8c249046181 968 * vSetBacklightState( BACKLIGHT_ON );
dflet 3:a8c249046181 969 *
dflet 3:a8c249046181 970 * // xTimerStartFromISR() or xTimerResetFromISR() could be called here
dflet 3:a8c249046181 971 * // as both cause the timer to re-calculate its expiry time.
dflet 3:a8c249046181 972 * // xHigherPriorityTaskWoken was initialised to pdFALSE when it was
dflet 3:a8c249046181 973 * // declared (in this function).
dflet 3:a8c249046181 974 * if( xTimerResetFromISR( xBacklightTimer, &xHigherPriorityTaskWoken ) != pdPASS )
dflet 3:a8c249046181 975 * {
dflet 3:a8c249046181 976 * // The reset command was not executed successfully. Take appropriate
dflet 3:a8c249046181 977 * // action here.
dflet 3:a8c249046181 978 * }
dflet 3:a8c249046181 979 *
dflet 3:a8c249046181 980 * // Perform the rest of the key processing here.
dflet 3:a8c249046181 981 *
dflet 3:a8c249046181 982 * // If xHigherPriorityTaskWoken equals pdTRUE, then a context switch
dflet 3:a8c249046181 983 * // should be performed. The syntax required to perform a context switch
dflet 3:a8c249046181 984 * // from inside an ISR varies from port to port, and from compiler to
dflet 3:a8c249046181 985 * // compiler. Inspect the demos for the port you are using to find the
dflet 3:a8c249046181 986 * // actual syntax required.
dflet 3:a8c249046181 987 * if( xHigherPriorityTaskWoken != pdFALSE )
dflet 3:a8c249046181 988 * {
dflet 3:a8c249046181 989 * // Call the interrupt safe yield function here (actual function
dflet 3:a8c249046181 990 * // depends on the FreeRTOS port being used).
dflet 3:a8c249046181 991 * }
dflet 3:a8c249046181 992 * }
dflet 3:a8c249046181 993 * @endverbatim
dflet 3:a8c249046181 994 */
dflet 3:a8c249046181 995 #define xTimerResetFromISR( xTimer, pxHigherPriorityTaskWoken ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_RESET_FROM_ISR, ( xTaskGetTickCountFromISR() ), ( pxHigherPriorityTaskWoken ), 0U )
dflet 3:a8c249046181 996
dflet 3:a8c249046181 997
dflet 3:a8c249046181 998 /**
dflet 3:a8c249046181 999 * BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend,
dflet 3:a8c249046181 1000 * void *pvParameter1,
dflet 3:a8c249046181 1001 * uint32_t ulParameter2,
dflet 3:a8c249046181 1002 * BaseType_t *pxHigherPriorityTaskWoken );
dflet 3:a8c249046181 1003 *
dflet 3:a8c249046181 1004 *
dflet 3:a8c249046181 1005 * Used from application interrupt service routines to defer the execution of a
dflet 3:a8c249046181 1006 * function to the RTOS daemon task (the timer service task, hence this function
dflet 3:a8c249046181 1007 * is implemented in timers.c and is prefixed with 'Timer').
dflet 3:a8c249046181 1008 *
dflet 3:a8c249046181 1009 * Ideally an interrupt service routine (ISR) is kept as short as possible, but
dflet 3:a8c249046181 1010 * sometimes an ISR either has a lot of processing to do, or needs to perform
dflet 3:a8c249046181 1011 * processing that is not deterministic. In these cases
dflet 3:a8c249046181 1012 * xTimerPendFunctionCallFromISR() can be used to defer processing of a function
dflet 3:a8c249046181 1013 * to the RTOS daemon task.
dflet 3:a8c249046181 1014 *
dflet 3:a8c249046181 1015 * A mechanism is provided that allows the interrupt to return directly to the
dflet 3:a8c249046181 1016 * task that will subsequently execute the pended callback function. This
dflet 3:a8c249046181 1017 * allows the callback function to execute contiguously in time with the
dflet 3:a8c249046181 1018 * interrupt - just as if the callback had executed in the interrupt itself.
dflet 3:a8c249046181 1019 *
dflet 3:a8c249046181 1020 * @param xFunctionToPend The function to execute from the timer service/
dflet 3:a8c249046181 1021 * daemon task. The function must conform to the PendedFunction_t
dflet 3:a8c249046181 1022 * prototype.
dflet 3:a8c249046181 1023 *
dflet 3:a8c249046181 1024 * @param pvParameter1 The value of the callback function's first parameter.
dflet 3:a8c249046181 1025 * The parameter has a void * type to allow it to be used to pass any type.
dflet 3:a8c249046181 1026 * For example, unsigned longs can be cast to a void *, or the void * can be
dflet 3:a8c249046181 1027 * used to point to a structure.
dflet 3:a8c249046181 1028 *
dflet 3:a8c249046181 1029 * @param ulParameter2 The value of the callback function's second parameter.
dflet 3:a8c249046181 1030 *
dflet 3:a8c249046181 1031 * @param pxHigherPriorityTaskWoken As mentioned above, calling this function
dflet 3:a8c249046181 1032 * will result in a message being sent to the timer daemon task. If the
dflet 3:a8c249046181 1033 * priority of the timer daemon task (which is set using
dflet 3:a8c249046181 1034 * configTIMER_TASK_PRIORITY in FreeRTOSConfig.h) is higher than the priority of
dflet 3:a8c249046181 1035 * the currently running task (the task the interrupt interrupted) then
dflet 3:a8c249046181 1036 * *pxHigherPriorityTaskWoken will be set to pdTRUE within
dflet 3:a8c249046181 1037 * xTimerPendFunctionCallFromISR(), indicating that a context switch should be
dflet 3:a8c249046181 1038 * requested before the interrupt exits. For that reason
dflet 3:a8c249046181 1039 * *pxHigherPriorityTaskWoken must be initialised to pdFALSE. See the
dflet 3:a8c249046181 1040 * example code below.
dflet 3:a8c249046181 1041 *
dflet 3:a8c249046181 1042 * @return pdPASS is returned if the message was successfully sent to the
dflet 3:a8c249046181 1043 * timer daemon task, otherwise pdFALSE is returned.
dflet 3:a8c249046181 1044 *
dflet 3:a8c249046181 1045 * Example usage:
dflet 3:a8c249046181 1046 * @verbatim
dflet 3:a8c249046181 1047 *
dflet 3:a8c249046181 1048 * // The callback function that will execute in the context of the daemon task.
dflet 3:a8c249046181 1049 * // Note callback functions must all use this same prototype.
dflet 3:a8c249046181 1050 * void vProcessInterface( void *pvParameter1, uint32_t ulParameter2 )
dflet 3:a8c249046181 1051 * {
dflet 3:a8c249046181 1052 * BaseType_t xInterfaceToService;
dflet 3:a8c249046181 1053 *
dflet 3:a8c249046181 1054 * // The interface that requires servicing is passed in the second
dflet 3:a8c249046181 1055 * // parameter. The first parameter is not used in this case.
dflet 3:a8c249046181 1056 * xInterfaceToService = ( BaseType_t ) ulParameter2;
dflet 3:a8c249046181 1057 *
dflet 3:a8c249046181 1058 * // ...Perform the processing here...
dflet 3:a8c249046181 1059 * }
dflet 3:a8c249046181 1060 *
dflet 3:a8c249046181 1061 * // An ISR that receives data packets from multiple interfaces
dflet 3:a8c249046181 1062 * void vAnISR( void )
dflet 3:a8c249046181 1063 * {
dflet 3:a8c249046181 1064 * BaseType_t xInterfaceToService, xHigherPriorityTaskWoken;
dflet 3:a8c249046181 1065 *
dflet 3:a8c249046181 1066 * // Query the hardware to determine which interface needs processing.
dflet 3:a8c249046181 1067 * xInterfaceToService = prvCheckInterfaces();
dflet 3:a8c249046181 1068 *
dflet 3:a8c249046181 1069 * // The actual processing is to be deferred to a task. Request the
dflet 3:a8c249046181 1070 * // vProcessInterface() callback function is executed, passing in the
dflet 3:a8c249046181 1071 * // number of the interface that needs processing. The interface to
dflet 3:a8c249046181 1072 * // service is passed in the second parameter. The first parameter is
dflet 3:a8c249046181 1073 * // not used in this case.
dflet 3:a8c249046181 1074 * xHigherPriorityTaskWoken = pdFALSE;
dflet 3:a8c249046181 1075 * xTimerPendFunctionCallFromISR( vProcessInterface, NULL, ( uint32_t ) xInterfaceToService, &xHigherPriorityTaskWoken );
dflet 3:a8c249046181 1076 *
dflet 3:a8c249046181 1077 * // If xHigherPriorityTaskWoken is now set to pdTRUE then a context
dflet 3:a8c249046181 1078 * // switch should be requested. The macro used is port specific and will
dflet 3:a8c249046181 1079 * // be either portYIELD_FROM_ISR() or portEND_SWITCHING_ISR() - refer to
dflet 3:a8c249046181 1080 * // the documentation page for the port being used.
dflet 3:a8c249046181 1081 * portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
dflet 3:a8c249046181 1082 *
dflet 3:a8c249046181 1083 * }
dflet 3:a8c249046181 1084 * @endverbatim
dflet 3:a8c249046181 1085 */
dflet 3:a8c249046181 1086 BaseType_t xTimerPendFunctionCallFromISR( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken );
dflet 3:a8c249046181 1087
dflet 3:a8c249046181 1088 /**
dflet 3:a8c249046181 1089 * BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend,
dflet 3:a8c249046181 1090 * void *pvParameter1,
dflet 3:a8c249046181 1091 * uint32_t ulParameter2,
dflet 3:a8c249046181 1092 * TickType_t xTicksToWait );
dflet 3:a8c249046181 1093 *
dflet 3:a8c249046181 1094 *
dflet 3:a8c249046181 1095 * Used to defer the execution of a function to the RTOS daemon task (the timer
dflet 3:a8c249046181 1096 * service task, hence this function is implemented in timers.c and is prefixed
dflet 3:a8c249046181 1097 * with 'Timer').
dflet 3:a8c249046181 1098 *
dflet 3:a8c249046181 1099 * @param xFunctionToPend The function to execute from the timer service/
dflet 3:a8c249046181 1100 * daemon task. The function must conform to the PendedFunction_t
dflet 3:a8c249046181 1101 * prototype.
dflet 3:a8c249046181 1102 *
dflet 3:a8c249046181 1103 * @param pvParameter1 The value of the callback function's first parameter.
dflet 3:a8c249046181 1104 * The parameter has a void * type to allow it to be used to pass any type.
dflet 3:a8c249046181 1105 * For example, unsigned longs can be cast to a void *, or the void * can be
dflet 3:a8c249046181 1106 * used to point to a structure.
dflet 3:a8c249046181 1107 *
dflet 3:a8c249046181 1108 * @param ulParameter2 The value of the callback function's second parameter.
dflet 3:a8c249046181 1109 *
dflet 3:a8c249046181 1110 * @param xTicksToWait Calling this function will result in a message being
dflet 3:a8c249046181 1111 * sent to the timer daemon task on a queue. xTicksToWait is the amount of
dflet 3:a8c249046181 1112 * time the calling task should remain in the Blocked state (so not using any
dflet 3:a8c249046181 1113 * processing time) for space to become available on the timer queue if the
dflet 3:a8c249046181 1114 * queue is found to be full.
dflet 3:a8c249046181 1115 *
dflet 3:a8c249046181 1116 * @return pdPASS is returned if the message was successfully sent to the
dflet 3:a8c249046181 1117 * timer daemon task, otherwise pdFALSE is returned.
dflet 3:a8c249046181 1118 *
dflet 3:a8c249046181 1119 */
dflet 3:a8c249046181 1120 BaseType_t xTimerPendFunctionCall( PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait );
dflet 3:a8c249046181 1121
dflet 3:a8c249046181 1122 /**
dflet 3:a8c249046181 1123 * const char * const pcTimerGetTimerName( TimerHandle_t xTimer );
dflet 3:a8c249046181 1124 *
dflet 3:a8c249046181 1125 * Returns the name that was assigned to a timer when the timer was created.
dflet 3:a8c249046181 1126 *
dflet 3:a8c249046181 1127 * @param xTimer The handle of the timer being queried.
dflet 3:a8c249046181 1128 *
dflet 3:a8c249046181 1129 * @return The name assigned to the timer specified by the xTimer parameter.
dflet 3:a8c249046181 1130 */
dflet 3:a8c249046181 1131 const char * pcTimerGetTimerName( TimerHandle_t xTimer ); /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
dflet 3:a8c249046181 1132
dflet 3:a8c249046181 1133 /*
dflet 3:a8c249046181 1134 * Functions beyond this part are not part of the public API and are intended
dflet 3:a8c249046181 1135 * for use by the kernel only.
dflet 3:a8c249046181 1136 */
dflet 3:a8c249046181 1137 BaseType_t xTimerCreateTimerTask( void ) PRIVILEGED_FUNCTION;
dflet 3:a8c249046181 1138 BaseType_t xTimerGenericCommand( TimerHandle_t xTimer, const BaseType_t xCommandID, const TickType_t xOptionalValue, BaseType_t * const pxHigherPriorityTaskWoken, const TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;
dflet 3:a8c249046181 1139
dflet 3:a8c249046181 1140 #ifdef __cplusplus
dflet 3:a8c249046181 1141 }
dflet 3:a8c249046181 1142 #endif
dflet 3:a8c249046181 1143 #endif /* TIMERS_H */
dflet 3:a8c249046181 1144
dflet 3:a8c249046181 1145
dflet 3:a8c249046181 1146
dflet 3:a8c249046181 1147