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