2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 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. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
30 * This version of flash .c is for use on systems that have limited stack space
\r
31 * and no display facilities. The complete version can be found in the
\r
32 * Demo/Common/Full directory.
\r
34 * Three tasks are created, each of which flash an LED at a different rate. The first
\r
35 * LED flashes every 200ms, the second every 400ms, the third every 600ms.
\r
37 * The LED flash tasks provide instant visual feedback. They show that the scheduler
\r
38 * is still operational.
\r
45 /* Scheduler include files. */
\r
46 #include "FreeRTOS.h"
\r
49 /* Demo program include files. */
\r
50 #include "partest.h"
\r
53 #define ledSTACK_SIZE configMINIMAL_STACK_SIZE
\r
54 #define ledNUMBER_OF_LEDS ( 3 )
\r
55 #define ledFLASH_RATE_BASE ( ( TickType_t ) 333 )
\r
57 /* Variable used by the created tasks to calculate the LED number to use, and
\r
58 the rate at which they should flash the LED. */
\r
59 static volatile UBaseType_t uxFlashTaskNumber = 0;
\r
61 /* The task that is created three times. */
\r
62 static portTASK_FUNCTION_PROTO( vLEDFlashTask, pvParameters );
\r
64 /*-----------------------------------------------------------*/
\r
66 void vStartLEDFlashTasks( UBaseType_t uxPriority )
\r
68 BaseType_t xLEDTask;
\r
70 /* Create the three tasks. */
\r
71 for( xLEDTask = 0; xLEDTask < ledNUMBER_OF_LEDS; ++xLEDTask )
\r
73 /* Spawn the task. */
\r
74 xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );
\r
77 /*-----------------------------------------------------------*/
\r
79 static portTASK_FUNCTION( vLEDFlashTask, pvParameters )
\r
81 TickType_t xFlashRate, xLastFlashTime;
\r
84 /* The parameters are not used. */
\r
85 ( void ) pvParameters;
\r
87 /* Calculate the LED and flash rate. */
\r
88 portENTER_CRITICAL();
\r
90 /* See which of the eight LED's we should use. */
\r
91 uxLED = uxFlashTaskNumber;
\r
93 /* Update so the next task uses the next LED. */
\r
94 uxFlashTaskNumber++;
\r
96 portEXIT_CRITICAL();
\r
98 xFlashRate = ledFLASH_RATE_BASE + ( ledFLASH_RATE_BASE * ( TickType_t ) uxLED );
\r
99 xFlashRate /= portTICK_PERIOD_MS;
\r
101 /* We will turn the LED on and off again in the delay period, so each
\r
102 delay is only half the total period. */
\r
103 xFlashRate /= ( TickType_t ) 2;
\r
105 /* We need to initialise xLastFlashTime prior to the first call to
\r
106 vTaskDelayUntil(). */
\r
107 xLastFlashTime = xTaskGetTickCount();
\r
111 /* Delay for half the flash period then turn the LED on. */
\r
112 vTaskDelayUntil( &xLastFlashTime, xFlashRate );
\r
113 vParTestToggleLED( uxLED );
\r
115 /* Delay for half the flash period then turn the LED off. */
\r
116 vTaskDelayUntil( &xLastFlashTime, xFlashRate );
\r
117 vParTestToggleLED( uxLED );
\r
119 } /*lint !e715 !e818 !e830 Function definition must be standard for task creation. */
\r