]> git.sur5r.net Git - freertos/blob - Demo/MB91460_Softune/SRC/crflash_modified.c
Prepare for V5.3.1 release.
[freertos] / Demo / MB91460_Softune / SRC / crflash_modified.c
1 /*\r
2         FreeRTOS.org V5.3.1 - Copyright (C) 2003-2009 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify it\r
7         under the terms of the GNU General Public License (version 2) as published\r
8         by the Free Software Foundation and modified by the FreeRTOS exception.\r
9         **NOTE** The exception to the GPL is included to allow you to distribute a\r
10         combined work that includes FreeRTOS.org without being obliged to provide\r
11         the source code for any proprietary components.  Alternative commercial\r
12         license and support terms are also available upon request.  See the \r
13         licensing section of http://www.FreeRTOS.org for full details.\r
14 \r
15         FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
16         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
17         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
18         more details.\r
19 \r
20         You should have received a copy of the GNU General Public License along\r
21         with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59\r
22         Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
23 \r
24 \r
25         ***************************************************************************\r
26         *                                                                         *\r
27         * Get the FreeRTOS eBook!  See http://www.FreeRTOS.org/Documentation      *\r
28         *                                                                         *\r
29         * This is a concise, step by step, 'hands on' guide that describes both   *\r
30         * general multitasking concepts and FreeRTOS specifics. It presents and   *\r
31         * explains numerous examples that are written using the FreeRTOS API.     *\r
32         * Full source code for all the examples is provided in an accompanying    *\r
33         * .zip file.                                                              *\r
34         *                                                                         *\r
35         ***************************************************************************\r
36 \r
37         1 tab == 4 spaces!\r
38 \r
39         Please ensure to read the configuration and relevant port sections of the\r
40         online documentation.\r
41 \r
42         http://www.FreeRTOS.org - Documentation, latest information, license and\r
43         contact details.\r
44 \r
45         http://www.SafeRTOS.com - A version that is certified for use in safety\r
46         critical systems.\r
47 \r
48         http://www.OpenRTOS.com - Commercial support, development, porting,\r
49         licensing and training services.\r
50 */\r
51 \r
52 /*\r
53  * This demo application file demonstrates the use of queues to pass data\r
54  * between co-routines.\r
55  *\r
56  * N represents the number of 'fixed delay' co-routines that are created and\r
57  * is set during initialisation.\r
58  *\r
59  * N 'fixed delay' co-routines are created that just block for a fixed\r
60  * period then post the number of an LED onto a queue.  Each such co-routine\r
61  * uses a different block period.  A single 'flash' co-routine is also created\r
62  * that blocks on the same queue, waiting for the number of the next LED it\r
63  * should flash.  Upon receiving a number it simply toggle the instructed LED\r
64  * then blocks on the queue once more.  In this manner each LED from LED 0 to\r
65  * LED N-1 is caused to flash at a different rate.\r
66  *\r
67  * The 'fixed delay' co-routines are created with co-routine priority 0.  The\r
68  * flash co-routine is created with co-routine priority 1.  This means that\r
69  * the queue should never contain more than a single item.  This is because\r
70  * posting to the queue will unblock the 'flash' co-routine, and as this has\r
71  * a priority greater than the tasks posting to the queue it is guaranteed to\r
72  * have emptied the queue and blocked once again before the queue can contain\r
73  * any more date.  An error is indicated if an attempt to post data to the\r
74  * queue fails - indicating that the queue is already full.\r
75  *\r
76  */\r
77 \r
78 /* Scheduler includes. */\r
79 #include "FreeRTOS.h"\r
80 #include "croutine.h"\r
81 #include "queue.h"\r
82 \r
83 /* Demo application includes. */\r
84 #include "partest.h"\r
85 #include "crflash.h"\r
86 \r
87 /* The queue should only need to be of length 1.  See the description at the\r
88 top of the file. */\r
89 #define crfQUEUE_LENGTH         1\r
90 \r
91 #define crfFIXED_DELAY_PRIORITY         0\r
92 #define crfFLASH_PRIORITY                       1\r
93 \r
94 /* Only one flash co-routine is created so the index is not significant. */\r
95 #define crfFLASH_INDEX                          0\r
96 \r
97 /* Don't allow more than crfMAX_FLASH_TASKS 'fixed delay' co-routines to be\r
98 created. */\r
99 #define crfMAX_FLASH_TASKS                      8\r
100 \r
101 /* We don't want to block when posting to the queue. */\r
102 #define crfPOSTING_BLOCK_TIME           0\r
103 \r
104 /* Added by MPi, this define is added in order to make the vParTestToggleLED()\r
105 work. This basically differentiates the PDR09 from PDR00. 7-seg display LEDs connected \r
106 to PDR09 (SEG1) are used by the prvFlashCoRoutine() and PDR00 (SEG2) are used by tasks. */ \r
107 #define PDR00_Offset    8\r
108 \r
109 /*\r
110  * The 'fixed delay' co-routine as described at the top of the file.\r
111  */\r
112 static void prvFixedDelayCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex );\r
113 \r
114 /*\r
115  * The 'flash' co-routine as described at the top of the file.\r
116  */\r
117 static void prvFlashCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex );\r
118 \r
119 /* The queue used to pass data between the 'fixed delay' co-routines and the\r
120 'flash' co-routine. */\r
121 static xQueueHandle xFlashQueue;\r
122 \r
123 /* This will be set to pdFALSE if we detect an error. */\r
124 static unsigned portBASE_TYPE uxCoRoutineFlashStatus = pdPASS;\r
125 \r
126 /*-----------------------------------------------------------*/\r
127 \r
128 /*\r
129  * See the header file for details.\r
130  */\r
131 void vStartFlashCoRoutines( unsigned portBASE_TYPE uxNumberToCreate )\r
132 {\r
133 unsigned portBASE_TYPE uxIndex;\r
134 \r
135         if( uxNumberToCreate > crfMAX_FLASH_TASKS )\r
136         {\r
137                 uxNumberToCreate = crfMAX_FLASH_TASKS;\r
138         }\r
139 \r
140         /* Create the queue used to pass data between the co-routines. */\r
141         xFlashQueue = xQueueCreate( crfQUEUE_LENGTH, sizeof( unsigned portBASE_TYPE ) );\r
142 \r
143         if( xFlashQueue )\r
144         {\r
145                 /* Create uxNumberToCreate 'fixed delay' co-routines. */\r
146                 for( uxIndex = 0; uxIndex < uxNumberToCreate; uxIndex++ )\r
147                 {\r
148                         xCoRoutineCreate( prvFixedDelayCoRoutine, crfFIXED_DELAY_PRIORITY, uxIndex );\r
149                 }\r
150 \r
151                 /* Create the 'flash' co-routine. */\r
152                 xCoRoutineCreate( prvFlashCoRoutine, crfFLASH_PRIORITY, crfFLASH_INDEX );\r
153         }\r
154 }\r
155 /*-----------------------------------------------------------*/\r
156 \r
157 static void prvFixedDelayCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )\r
158 {\r
159 /* Even though this is a co-routine the xResult variable does not need to be\r
160 static as we do not need it to maintain its state between blocks. */\r
161 signed portBASE_TYPE xResult;\r
162 /* The uxIndex parameter of the co-routine function is used as an index into\r
163 the xFlashRates array to obtain the delay period to use. */\r
164 static const portTickType xFlashRates[ crfMAX_FLASH_TASKS ] = { 150 / portTICK_RATE_MS,\r
165                                                                                                                                 200 / portTICK_RATE_MS,\r
166                                                                                                                                 250 / portTICK_RATE_MS,\r
167                                                                                                                                 300 / portTICK_RATE_MS,\r
168                                                                                                                                 350 / portTICK_RATE_MS,\r
169                                                                                                                                 400 / portTICK_RATE_MS,\r
170                                                                                                                                 450 / portTICK_RATE_MS,\r
171                                                                                                                                 500  / portTICK_RATE_MS };\r
172 \r
173         /* Co-routines MUST start with a call to crSTART. */\r
174         crSTART( xHandle );\r
175 \r
176         for( ;; )\r
177         {\r
178                 /* Post our uxIndex value onto the queue.  This is used as the LED to\r
179                 flash. */\r
180                 crQUEUE_SEND( xHandle, xFlashQueue, ( void * ) &uxIndex, crfPOSTING_BLOCK_TIME, &xResult );\r
181 \r
182                 if( xResult != pdPASS )\r
183                 {\r
184                         /* For the reasons stated at the top of the file we should always\r
185                         find that we can post to the queue.  If we could not then an error\r
186                         has occurred. */\r
187                         uxCoRoutineFlashStatus = pdFAIL;\r
188                 }\r
189 \r
190                 crDELAY( xHandle, xFlashRates[ uxIndex ] );\r
191         }\r
192 \r
193         /* Co-routines MUST end with a call to crEND. */\r
194         crEND();\r
195 }\r
196 /*-----------------------------------------------------------*/\r
197 \r
198 static void prvFlashCoRoutine( xCoRoutineHandle xHandle, unsigned portBASE_TYPE uxIndex )\r
199 {\r
200 /* Even though this is a co-routine the variable do not need to be\r
201 static as we do not need it to maintain their state between blocks. */\r
202 signed portBASE_TYPE xResult;\r
203 unsigned portBASE_TYPE uxLEDToFlash;\r
204 \r
205         /* Co-routines MUST start with a call to crSTART. */\r
206         crSTART( xHandle );\r
207         ( void ) uxIndex;\r
208         \r
209         for( ;; )\r
210         {\r
211                 /* Block to wait for the number of the LED to flash. */\r
212                 crQUEUE_RECEIVE( xHandle, xFlashQueue, &uxLEDToFlash, portMAX_DELAY, &xResult );                \r
213 \r
214                 if( xResult != pdPASS )\r
215                 {\r
216                         /* We would not expect to wake unless we received something. */\r
217                         uxCoRoutineFlashStatus = pdFAIL;\r
218                 }\r
219                 else\r
220                 {\r
221                         /* We received the number of an LED to flash - flash it! */\r
222                         /* Added by MPi, PDR00_Offset is added in order to make the \r
223                         vParTestToggleLED() work. */ \r
224                         vParTestToggleLED( uxLEDToFlash +  PDR00_Offset );\r
225                 }\r
226         }\r
227 \r
228         /* Co-routines MUST end with a call to crEND. */\r
229         crEND();\r
230 }\r
231 /*-----------------------------------------------------------*/\r
232 \r
233 portBASE_TYPE xAreFlashCoRoutinesStillRunning( void )\r
234 {\r
235         /* Return pdPASS or pdFAIL depending on whether an error has been detected\r
236         or not. */\r
237         return uxCoRoutineFlashStatus;\r
238 }\r
239 \r