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