2 * FreeRTOS Kernel V10.2.0
\r
3 * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
29 * This version of flash .c is for use on systems that have limited stack space
\r
30 * and no display facilities. The complete version can be found in the
\r
31 * Demo/Common/Full directory.
\r
33 * Three tasks are created, each of which flash an LED at a different rate. The first
\r
34 * LED flashes every 200ms, the second every 400ms, the third every 600ms.
\r
36 * The LED flash tasks provide instant visual feedback. They show that the scheduler
\r
37 * is still operational.
\r
44 /* Scheduler include files. */
\r
45 #include "FreeRTOS.h"
\r
48 /* Demo program include files. */
\r
49 #include "partest.h"
\r
52 #define ledSTACK_SIZE configMINIMAL_STACK_SIZE
\r
53 #define ledNUMBER_OF_LEDS ( 3 )
\r
54 #define ledFLASH_RATE_BASE ( ( TickType_t ) 333 )
\r
56 /* Variable used by the created tasks to calculate the LED number to use, and
\r
57 the rate at which they should flash the LED. */
\r
58 static volatile UBaseType_t uxFlashTaskNumber = 0;
\r
60 /* The task that is created three times. */
\r
61 static portTASK_FUNCTION_PROTO( vLEDFlashTask, pvParameters );
\r
63 /*-----------------------------------------------------------*/
\r
65 void vStartLEDFlashTasks( UBaseType_t uxPriority )
\r
67 BaseType_t xLEDTask;
\r
69 /* Create the three tasks. */
\r
70 for( xLEDTask = 0; xLEDTask < ledNUMBER_OF_LEDS; ++xLEDTask )
\r
72 /* Spawn the task. */
\r
73 xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
\r
76 /*-----------------------------------------------------------*/
\r
78 static portTASK_FUNCTION( vLEDFlashTask, pvParameters )
\r
80 TickType_t xFlashRate, xLastFlashTime;
\r
83 /* The parameters are not used. */
\r
84 ( void ) pvParameters;
\r
86 /* Calculate the LED and flash rate. */
\r
87 portENTER_CRITICAL();
\r
89 /* See which of the eight LED's we should use. */
\r
90 uxLED = uxFlashTaskNumber;
\r
92 /* Update so the next task uses the next LED. */
\r
93 uxFlashTaskNumber++;
\r
95 portEXIT_CRITICAL();
\r
97 xFlashRate = ledFLASH_RATE_BASE + ( ledFLASH_RATE_BASE * ( TickType_t ) uxLED );
\r
98 xFlashRate /= portTICK_PERIOD_MS;
\r
100 /* We will turn the LED on and off again in the delay period, so each
\r
101 delay is only half the total period. */
\r
102 xFlashRate /= ( TickType_t ) 2;
\r
104 /* We need to initialise xLastFlashTime prior to the first call to
\r
105 vTaskDelayUntil(). */
\r
106 xLastFlashTime = xTaskGetTickCount();
\r
110 /* Delay for half the flash period then turn the LED on. */
\r
111 vTaskDelayUntil( &xLastFlashTime, xFlashRate );
\r
112 vParTestToggleLED( uxLED );
\r
114 /* Delay for half the flash period then turn the LED off. */
\r
115 vTaskDelayUntil( &xLastFlashTime, xFlashRate );
\r
116 vParTestToggleLED( uxLED );
\r
118 } /*lint !e715 !e818 !e830 Function definition must be standard for task creation. */
\r