]> begriffs open source - cmsis-freertos/blob - Demo/Common/Minimal/flash_timer.c
Updated pack to FreeRTOS 10.4.6
[cmsis-freertos] / Demo / Common / Minimal / flash_timer.c
1 /*
2  * FreeRTOS V202111.00
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
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:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
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.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 /**
29  * Repeatedly toggles one or more LEDs using software timers - one timer per
30  * LED.
31  */
32
33 /* Scheduler include files. */
34 #include "FreeRTOS.h"
35 #include "timers.h"
36
37 /* Demo program include files. */
38 #include "partest.h"
39 #include "flash_timer.h"
40
41 /* The toggle rates are all a multple of ledFLASH_RATE_BASE. */
42 #define ledFLASH_RATE_BASE    ( ( ( TickType_t ) 333 ) / portTICK_PERIOD_MS )
43
44 /* A block time of zero simple means "don't block". */
45 #define ledDONT_BLOCK         ( ( TickType_t ) 0 )
46
47 /*-----------------------------------------------------------*/
48
49 /*
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.
53  */
54 static void prvLEDTimerCallback( TimerHandle_t xTimer );
55
56 /*-----------------------------------------------------------*/
57
58 void vStartLEDFlashTimers( UBaseType_t uxNumberOfLEDs )
59 {
60     UBaseType_t uxLEDTimer;
61     TimerHandle_t xTimer;
62
63     /* Create and start the requested number of timers. */
64     for( uxLEDTimer = 0; uxLEDTimer < uxNumberOfLEDs; ++uxLEDTimer )
65     {
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. */
72                                );
73
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. */
79         if( xTimer != NULL )
80         {
81             xTimerStart( xTimer, ledDONT_BLOCK );
82         }
83     }
84 }
85 /*-----------------------------------------------------------*/
86
87 static void prvLEDTimerCallback( TimerHandle_t xTimer )
88 {
89     BaseType_t xTimerID;
90
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 );
96 }