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
31 * Creates eight tasks, each of which flash an LED at a different rate. The first
\r
32 * LED flashes every 125ms, the second every 250ms, the third every 375ms, etc.
\r
34 * The LED flash tasks provide instant visual feedback. They show that the scheduler
\r
35 * is still operational.
\r
37 * The PC port uses the standard parallel port for outputs, the Flashlite 186 port
\r
40 * \page flashC flash.c
\r
41 * \ingroup DemoFiles
\r
48 + Delay periods are now specified using variables and constants of
\r
49 TickType_t rather than unsigned long.
\r
53 + The stack size now uses configMINIMAL_STACK_SIZE.
\r
54 + String constants made file scope to decrease stack depth on 8051 port.
\r
59 /* Scheduler include files. */
\r
60 #include "FreeRTOS.h"
\r
63 /* Demo program include files. */
\r
64 #include "partest.h"
\r
68 #define ledSTACK_SIZE configMINIMAL_STACK_SIZE
\r
70 /* Structure used to pass parameters to the LED tasks. */
\r
71 typedef struct LED_PARAMETERS
\r
73 unsigned portBASE_TYPE uxLED; /*< The output the task should use. */
\r
74 TickType_t xFlashRate; /*< The rate at which the LED should flash. */
\r
77 /* The task that is created eight times - each time with a different xLEDParaemtes
\r
78 structure passed in as the parameter. */
\r
79 static void vLEDFlashTask( void *pvParameters );
\r
81 /* String to print if USE_STDIO is defined. */
\r
82 const char * const pcTaskStartMsg = "LED flash task started.\r\n";
\r
84 /*-----------------------------------------------------------*/
\r
86 void vStartLEDFlashTasks( unsigned portBASE_TYPE uxPriority )
\r
88 unsigned portBASE_TYPE uxLEDTask;
\r
89 xLEDParameters *pxLEDParameters;
\r
90 const unsigned portBASE_TYPE uxNumOfLEDs = 8;
\r
91 const TickType_t xFlashRate = 125;
\r
93 /* Create the eight tasks. */
\r
94 for( uxLEDTask = 0; uxLEDTask < uxNumOfLEDs; ++uxLEDTask )
\r
96 /* Create and complete the structure used to pass parameters to the next
\r
98 pxLEDParameters = ( xLEDParameters * ) pvPortMalloc( sizeof( xLEDParameters ) );
\r
99 pxLEDParameters->uxLED = uxLEDTask;
\r
100 pxLEDParameters->xFlashRate = ( xFlashRate + ( xFlashRate * ( TickType_t ) uxLEDTask ) );
\r
101 pxLEDParameters->xFlashRate /= portTICK_PERIOD_MS;
\r
103 /* Spawn the task. */
\r
104 xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, ( void * ) pxLEDParameters, uxPriority, ( TaskHandle_t * ) NULL );
\r
107 /*-----------------------------------------------------------*/
\r
109 static void vLEDFlashTask( void *pvParameters )
\r
111 xLEDParameters *pxParameters;
\r
113 /* Queue a message for printing to say the task has started. */
\r
114 vPrintDisplayMessage( &pcTaskStartMsg );
\r
116 pxParameters = ( xLEDParameters * ) pvParameters;
\r
120 /* Delay for half the flash period then turn the LED on. */
\r
121 vTaskDelay( pxParameters->xFlashRate / ( TickType_t ) 2 );
\r
122 vParTestToggleLED( pxParameters->uxLED );
\r
124 /* Delay for half the flash period then turn the LED off. */
\r
125 vTaskDelay( pxParameters->xFlashRate / ( TickType_t ) 2 );
\r
126 vParTestToggleLED( pxParameters->uxLED );
\r