]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Common/Full/flash.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / Common / Full / flash.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\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
14  *\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
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 \r
29 /**\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
32  *\r
33  * The LED flash tasks provide instant visual feedback.  They show that the scheduler \r
34  * is still operational.\r
35  *\r
36  * The PC port uses the standard parallel port for outputs, the Flashlite 186 port \r
37  * uses IO port F.\r
38  *\r
39  * \page flashC flash.c\r
40  * \ingroup DemoFiles\r
41  * <HR>\r
42  */\r
43 \r
44 /*\r
45 Changes from V2.0.0\r
46 \r
47         + Delay periods are now specified using variables and constants of\r
48           TickType_t rather than unsigned long.\r
49 \r
50 Changes from V2.1.1\r
51 \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
54 */\r
55 \r
56 #include <stdlib.h>\r
57 \r
58 /* Scheduler include files. */\r
59 #include "FreeRTOS.h"\r
60 #include "task.h"\r
61 \r
62 /* Demo program include files. */\r
63 #include "partest.h"\r
64 #include "flash.h"\r
65 #include "print.h"\r
66 \r
67 #define ledSTACK_SIZE           configMINIMAL_STACK_SIZE\r
68 \r
69 /* Structure used to pass parameters to the LED tasks. */\r
70 typedef struct LED_PARAMETERS\r
71 {\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
74 } xLEDParameters;\r
75 \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
79 \r
80 /* String to print if USE_STDIO is defined. */\r
81 const char * const pcTaskStartMsg = "LED flash task started.\r\n";\r
82 \r
83 /*-----------------------------------------------------------*/\r
84 \r
85 void vStartLEDFlashTasks( unsigned portBASE_TYPE uxPriority )\r
86 {\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
91 \r
92         /* Create the eight tasks. */\r
93         for( uxLEDTask = 0; uxLEDTask < uxNumOfLEDs; ++uxLEDTask )\r
94         {\r
95                 /* Create and complete the structure used to pass parameters to the next \r
96                 created task. */\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
101 \r
102                 /* Spawn the task. */\r
103                 xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, ( void * ) pxLEDParameters, uxPriority, ( TaskHandle_t * ) NULL );\r
104         }\r
105 }\r
106 /*-----------------------------------------------------------*/\r
107 \r
108 static void vLEDFlashTask( void *pvParameters )\r
109 {\r
110 xLEDParameters *pxParameters;\r
111 \r
112         /* Queue a message for printing to say the task has started. */\r
113         vPrintDisplayMessage( &pcTaskStartMsg );\r
114 \r
115         pxParameters = ( xLEDParameters * ) pvParameters;\r
116 \r
117         for(;;)\r
118         {\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
122 \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
126         }\r
127 }\r
128 \r