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