]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MB91460_Softune/SRC/crflash_modified.c
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS / Demo / MB91460_Softune / SRC / crflash_modified.c
1 /*\r
2     FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd. \r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS kernel.                                   !<<\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 /*\r
67  * This demo application file demonstrates the use of queues to pass data\r
68  * between co-routines.\r
69  *\r
70  * N represents the number of 'fixed delay' co-routines that are created and\r
71  * is set during initialisation.\r
72  *\r
73  * N 'fixed delay' co-routines are created that just block for a fixed\r
74  * period then post the number of an LED onto a queue.  Each such co-routine\r
75  * uses a different block period.  A single 'flash' co-routine is also created\r
76  * that blocks on the same queue, waiting for the number of the next LED it\r
77  * should flash.  Upon receiving a number it simply toggle the instructed LED\r
78  * then blocks on the queue once more.  In this manner each LED from LED 0 to\r
79  * LED N-1 is caused to flash at a different rate.\r
80  *\r
81  * The 'fixed delay' co-routines are created with co-routine priority 0.  The\r
82  * flash co-routine is created with co-routine priority 1.  This means that\r
83  * the queue should never contain more than a single item.  This is because\r
84  * posting to the queue will unblock the 'flash' co-routine, and as this has\r
85  * a priority greater than the tasks posting to the queue it is guaranteed to\r
86  * have emptied the queue and blocked once again before the queue can contain\r
87  * any more date.  An error is indicated if an attempt to post data to the\r
88  * queue fails - indicating that the queue is already full.\r
89  *\r
90  */\r
91 \r
92 /* Scheduler includes. */\r
93 #include "FreeRTOS.h"\r
94 #include "croutine.h"\r
95 #include "queue.h"\r
96 \r
97 /* Demo application includes. */\r
98 #include "partest.h"\r
99 #include "crflash.h"\r
100 \r
101 /* The queue should only need to be of length 1.  See the description at the\r
102 top of the file. */\r
103 #define crfQUEUE_LENGTH         1\r
104 \r
105 #define crfFIXED_DELAY_PRIORITY         0\r
106 #define crfFLASH_PRIORITY                       1\r
107 \r
108 /* Only one flash co-routine is created so the index is not significant. */\r
109 #define crfFLASH_INDEX                          0\r
110 \r
111 /* Don't allow more than crfMAX_FLASH_TASKS 'fixed delay' co-routines to be\r
112 created. */\r
113 #define crfMAX_FLASH_TASKS                      8\r
114 \r
115 /* We don't want to block when posting to the queue. */\r
116 #define crfPOSTING_BLOCK_TIME           0\r
117 \r
118 /* Added by MPi, this define is added in order to make the vParTestToggleLED()\r
119 work. This basically differentiates the PDR09 from PDR00. 7-seg display LEDs connected \r
120 to PDR09 (SEG1) are used by the prvFlashCoRoutine() and PDR00 (SEG2) are used by tasks. */ \r
121 #define PDR00_Offset    8\r
122 \r
123 /*\r
124  * The 'fixed delay' co-routine as described at the top of the file.\r
125  */\r
126 static void prvFixedDelayCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex );\r
127 \r
128 /*\r
129  * The 'flash' co-routine as described at the top of the file.\r
130  */\r
131 static void prvFlashCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex );\r
132 \r
133 /* The queue used to pass data between the 'fixed delay' co-routines and the\r
134 'flash' co-routine. */\r
135 static QueueHandle_t xFlashQueue;\r
136 \r
137 /* This will be set to pdFALSE if we detect an error. */\r
138 static unsigned portBASE_TYPE uxCoRoutineFlashStatus = pdPASS;\r
139 \r
140 /*-----------------------------------------------------------*/\r
141 \r
142 /*\r
143  * See the header file for details.\r
144  */\r
145 void vStartFlashCoRoutines( unsigned portBASE_TYPE uxNumberToCreate )\r
146 {\r
147 unsigned portBASE_TYPE uxIndex;\r
148 \r
149         if( uxNumberToCreate > crfMAX_FLASH_TASKS )\r
150         {\r
151                 uxNumberToCreate = crfMAX_FLASH_TASKS;\r
152         }\r
153 \r
154         /* Create the queue used to pass data between the co-routines. */\r
155         xFlashQueue = xQueueCreate( crfQUEUE_LENGTH, sizeof( unsigned portBASE_TYPE ) );\r
156 \r
157         if( xFlashQueue )\r
158         {\r
159                 /* Create uxNumberToCreate 'fixed delay' co-routines. */\r
160                 for( uxIndex = 0; uxIndex < uxNumberToCreate; uxIndex++ )\r
161                 {\r
162                         xCoRoutineCreate( prvFixedDelayCoRoutine, crfFIXED_DELAY_PRIORITY, uxIndex );\r
163                 }\r
164 \r
165                 /* Create the 'flash' co-routine. */\r
166                 xCoRoutineCreate( prvFlashCoRoutine, crfFLASH_PRIORITY, crfFLASH_INDEX );\r
167         }\r
168 }\r
169 /*-----------------------------------------------------------*/\r
170 \r
171 static void prvFixedDelayCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex )\r
172 {\r
173 /* Even though this is a co-routine the xResult variable does not need to be\r
174 static as we do not need it to maintain its state between blocks. */\r
175 signed portBASE_TYPE xResult;\r
176 /* The uxIndex parameter of the co-routine function is used as an index into\r
177 the xFlashRates array to obtain the delay period to use. */\r
178 static const TickType_t xFlashRates[ crfMAX_FLASH_TASKS ] = { 150 / portTICK_PERIOD_MS,\r
179                                                                                                                                 200 / portTICK_PERIOD_MS,\r
180                                                                                                                                 250 / portTICK_PERIOD_MS,\r
181                                                                                                                                 300 / portTICK_PERIOD_MS,\r
182                                                                                                                                 350 / portTICK_PERIOD_MS,\r
183                                                                                                                                 400 / portTICK_PERIOD_MS,\r
184                                                                                                                                 450 / portTICK_PERIOD_MS,\r
185                                                                                                                                 500  / portTICK_PERIOD_MS };\r
186 \r
187         /* Co-routines MUST start with a call to crSTART. */\r
188         crSTART( xHandle );\r
189 \r
190         for( ;; )\r
191         {\r
192                 /* Post our uxIndex value onto the queue.  This is used as the LED to\r
193                 flash. */\r
194                 crQUEUE_SEND( xHandle, xFlashQueue, ( void * ) &uxIndex, crfPOSTING_BLOCK_TIME, &xResult );\r
195 \r
196                 if( xResult != pdPASS )\r
197                 {\r
198                         /* For the reasons stated at the top of the file we should always\r
199                         find that we can post to the queue.  If we could not then an error\r
200                         has occurred. */\r
201                         uxCoRoutineFlashStatus = pdFAIL;\r
202                 }\r
203 \r
204                 crDELAY( xHandle, xFlashRates[ uxIndex ] );\r
205         }\r
206 \r
207         /* Co-routines MUST end with a call to crEND. */\r
208         crEND();\r
209 }\r
210 /*-----------------------------------------------------------*/\r
211 \r
212 static void prvFlashCoRoutine( CoRoutineHandle_t xHandle, unsigned portBASE_TYPE uxIndex )\r
213 {\r
214 /* Even though this is a co-routine the variable do not need to be\r
215 static as we do not need it to maintain their state between blocks. */\r
216 signed portBASE_TYPE xResult;\r
217 unsigned portBASE_TYPE uxLEDToFlash;\r
218 \r
219         /* Co-routines MUST start with a call to crSTART. */\r
220         crSTART( xHandle );\r
221         ( void ) uxIndex;\r
222         \r
223         for( ;; )\r
224         {\r
225                 /* Block to wait for the number of the LED to flash. */\r
226                 crQUEUE_RECEIVE( xHandle, xFlashQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );                \r
227 \r
228                 if( xResult != pdPASS )\r
229                 {\r
230                         /* We would not expect to wake unless we received something. */\r
231                         uxCoRoutineFlashStatus = pdFAIL;\r
232                 }\r
233                 else\r
234                 {\r
235                         /* We received the number of an LED to flash - flash it! */\r
236                         /* Added by MPi, PDR00_Offset is added in order to make the \r
237                         vParTestToggleLED() work. */ \r
238                         vParTestToggleLED( uxLEDToFlash +  PDR00_Offset );\r
239                 }\r
240         }\r
241 \r
242         /* Co-routines MUST end with a call to crEND. */\r
243         crEND();\r
244 }\r
245 /*-----------------------------------------------------------*/\r
246 \r
247 portBASE_TYPE xAreFlashCoRoutinesStillRunning( void )\r
248 {\r
249         /* Return pdPASS or pdFAIL depending on whether an error has been detected\r
250         or not. */\r
251         return uxCoRoutineFlashStatus;\r
252 }\r
253 \r