2 * FreeRTOS Kernel V10.0.1
\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.
\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
30 * Creates eight tasks, each of which flash an LED at a different rate. The first
\r
31 * LED flashes every 125ms, the second every 250ms, the third every 375ms, etc.
\r
33 * The LED flash tasks provide instant visual feedback. They show that the scheduler
\r
34 * is still operational.
\r
36 * The PC port uses the standard parallel port for outputs, the Flashlite 186 port
\r
39 * \page flashC flash.c
\r
40 * \ingroup DemoFiles
\r
47 + Delay periods are now specified using variables and constants of
\r
48 TickType_t rather than unsigned long.
\r
52 + The stack size now uses configMINIMAL_STACK_SIZE.
\r
53 + String constants made file scope to decrease stack depth on 8051 port.
\r
58 /* Scheduler include files. */
\r
59 #include "FreeRTOS.h"
\r
62 /* Demo program include files. */
\r
63 #include "partest.h"
\r
67 #define ledSTACK_SIZE configMINIMAL_STACK_SIZE
\r
69 /* Structure used to pass parameters to the LED tasks. */
\r
70 typedef struct LED_PARAMETERS
\r
72 unsigned portBASE_TYPE uxLED; /*< The output the task should use. */
\r
73 TickType_t xFlashRate; /*< The rate at which the LED should flash. */
\r
76 /* The task that is created eight times - each time with a different xLEDParaemtes
\r
77 structure passed in as the parameter. */
\r
78 static void vLEDFlashTask( void *pvParameters );
\r
80 /* String to print if USE_STDIO is defined. */
\r
81 const char * const pcTaskStartMsg = "LED flash task started.\r\n";
\r
83 /*-----------------------------------------------------------*/
\r
85 void vStartLEDFlashTasks( unsigned portBASE_TYPE uxPriority )
\r
87 unsigned portBASE_TYPE uxLEDTask;
\r
88 xLEDParameters *pxLEDParameters;
\r
89 const unsigned portBASE_TYPE uxNumOfLEDs = 8;
\r
90 const TickType_t xFlashRate = 125;
\r
92 /* Create the eight tasks. */
\r
93 for( uxLEDTask = 0; uxLEDTask < uxNumOfLEDs; ++uxLEDTask )
\r
95 /* Create and complete the structure used to pass parameters to the next
\r
97 pxLEDParameters = ( xLEDParameters * ) pvPortMalloc( sizeof( xLEDParameters ) );
\r
98 pxLEDParameters->uxLED = uxLEDTask;
\r
99 pxLEDParameters->xFlashRate = ( xFlashRate + ( xFlashRate * ( TickType_t ) uxLEDTask ) );
\r
100 pxLEDParameters->xFlashRate /= portTICK_PERIOD_MS;
\r
102 /* Spawn the task. */
\r
103 xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, ( void * ) pxLEDParameters, uxPriority, ( TaskHandle_t * ) NULL );
\r
106 /*-----------------------------------------------------------*/
\r
108 static void vLEDFlashTask( void *pvParameters )
\r
110 xLEDParameters *pxParameters;
\r
112 /* Queue a message for printing to say the task has started. */
\r
113 vPrintDisplayMessage( &pcTaskStartMsg );
\r
115 pxParameters = ( xLEDParameters * ) pvParameters;
\r
119 /* Delay for half the flash period then turn the LED on. */
\r
120 vTaskDelay( pxParameters->xFlashRate / ( TickType_t ) 2 );
\r
121 vParTestToggleLED( pxParameters->uxLED );
\r
123 /* Delay for half the flash period then turn the LED off. */
\r
124 vTaskDelay( pxParameters->xFlashRate / ( TickType_t ) 2 );
\r
125 vParTestToggleLED( pxParameters->uxLED );
\r