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