3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
29 * Repeatedly toggles one or more LEDs using software timers - one timer per
33 /* Scheduler include files. */
37 /* Demo program include files. */
39 #include "flash_timer.h"
41 /* The toggle rates are all a multple of ledFLASH_RATE_BASE. */
42 #define ledFLASH_RATE_BASE ( ( ( TickType_t ) 333 ) / portTICK_PERIOD_MS )
44 /* A block time of zero simple means "don't block". */
45 #define ledDONT_BLOCK ( ( TickType_t ) 0 )
47 /*-----------------------------------------------------------*/
50 * The callback function used by each LED flashing timer. All the timers use
51 * this function, and the timer ID is used within the function to determine
52 * which timer has actually expired.
54 static void prvLEDTimerCallback( TimerHandle_t xTimer );
56 /*-----------------------------------------------------------*/
58 void vStartLEDFlashTimers( UBaseType_t uxNumberOfLEDs )
60 UBaseType_t uxLEDTimer;
63 /* Create and start the requested number of timers. */
64 for( uxLEDTimer = 0; uxLEDTimer < uxNumberOfLEDs; ++uxLEDTimer )
66 /* Create the timer. */
67 xTimer = xTimerCreate( "Flasher", /* A text name, purely to help debugging. */
68 ledFLASH_RATE_BASE * ( uxLEDTimer + 1 ), /* The timer period, which is a multiple of ledFLASH_RATE_BASE. */
69 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
70 ( void * ) uxLEDTimer, /* The ID is used to identify the timer within the timer callback function, as each timer uses the same callback. */
71 prvLEDTimerCallback /* Each timer uses the same callback. */
74 /* If the timer was created successfully, attempt to start it. If the
75 * scheduler has not yet been started then the timer command queue must
76 * be long enough to hold each command sent to it until such time that the
77 * scheduler is started. The timer command queue length is set by
78 * configTIMER_QUEUE_LENGTH in FreeRTOSConfig.h. */
81 xTimerStart( xTimer, ledDONT_BLOCK );
85 /*-----------------------------------------------------------*/
87 static void prvLEDTimerCallback( TimerHandle_t xTimer )
91 /* The timer ID is used to identify the timer that has actually expired as
92 * each timer uses the same callback. The ID is then also used as the number
93 * of the LED that is to be toggled. */
94 xTimerID = ( BaseType_t ) pvTimerGetTimerID( xTimer );
95 vParTestToggleLED( xTimerID );