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