]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Common/Minimal/flash.c
Update version numbers ready for release.
[freertos] / FreeRTOS / Demo / Common / Minimal / flash.c
1 /*\r
2  * FreeRTOS Kernel V10.1.1\r
3  * Copyright (C) 2018 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  * 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
32  *\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
35  *\r
36  * The LED flash tasks provide instant visual feedback.  They show that the scheduler\r
37  * is still operational.\r
38  *\r
39  */\r
40 \r
41 \r
42 #include <stdlib.h>\r
43 \r
44 /* Scheduler include files. */\r
45 #include "FreeRTOS.h"\r
46 #include "task.h"\r
47 \r
48 /* Demo program include files. */\r
49 #include "partest.h"\r
50 #include "flash.h"\r
51 \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
55 \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
59 \r
60 /* The task that is created three times. */\r
61 static portTASK_FUNCTION_PROTO( vLEDFlashTask, pvParameters );\r
62 \r
63 /*-----------------------------------------------------------*/\r
64 \r
65 void vStartLEDFlashTasks( UBaseType_t uxPriority )\r
66 {\r
67 BaseType_t xLEDTask;\r
68 \r
69         /* Create the three tasks. */\r
70         for( xLEDTask = 0; xLEDTask < ledNUMBER_OF_LEDS; ++xLEDTask )\r
71         {\r
72                 /* Spawn the task. */\r
73                 xTaskCreate( vLEDFlashTask, "LEDx", ledSTACK_SIZE, NULL, uxPriority, ( TaskHandle_t * ) NULL );\r
74         }\r
75 }\r
76 /*-----------------------------------------------------------*/\r
77 \r
78 static portTASK_FUNCTION( vLEDFlashTask, pvParameters )\r
79 {\r
80 TickType_t xFlashRate, xLastFlashTime;\r
81 UBaseType_t uxLED;\r
82 \r
83         /* The parameters are not used. */\r
84         ( void ) pvParameters;\r
85 \r
86         /* Calculate the LED and flash rate. */\r
87         portENTER_CRITICAL();\r
88         {\r
89                 /* See which of the eight LED's we should use. */\r
90                 uxLED = uxFlashTaskNumber;\r
91 \r
92                 /* Update so the next task uses the next LED. */\r
93                 uxFlashTaskNumber++;\r
94         }\r
95         portEXIT_CRITICAL();\r
96 \r
97         xFlashRate = ledFLASH_RATE_BASE + ( ledFLASH_RATE_BASE * ( TickType_t ) uxLED );\r
98         xFlashRate /= portTICK_PERIOD_MS;\r
99 \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
103 \r
104         /* We need to initialise xLastFlashTime prior to the first call to\r
105         vTaskDelayUntil(). */\r
106         xLastFlashTime = xTaskGetTickCount();\r
107 \r
108         for(;;)\r
109         {\r
110                 /* Delay for half the flash period then turn the LED on. */\r
111                 vTaskDelayUntil( &xLastFlashTime, xFlashRate );\r
112                 vParTestToggleLED( uxLED );\r
113 \r
114                 /* Delay for half the flash period then turn the LED off. */\r
115                 vTaskDelayUntil( &xLastFlashTime, xFlashRate );\r
116                 vParTestToggleLED( uxLED );\r
117         }\r
118 } /*lint !e715 !e818 !e830 Function definition must be standard for task creation. */\r
119 \r