]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Common/Minimal/AltQTest.c
Update version numbers in preparation for V8.2.0 release candidate 1.
[freertos] / FreeRTOS / Demo / Common / Minimal / AltQTest.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 /* \r
98  * This file implements the same demo and test as GenQTest.c, but uses the \r
99  * light weight API in place of the fully featured API.\r
100  *\r
101  * See the comments at the top of GenQTest.c for a description.\r
102  */\r
103 \r
104 \r
105 #include <stdlib.h>\r
106 \r
107 /* Scheduler include files. */\r
108 #include "FreeRTOS.h"\r
109 #include "task.h"\r
110 #include "queue.h"\r
111 #include "semphr.h"\r
112 \r
113 /* Demo program include files. */\r
114 #include "AltQTest.h"\r
115 \r
116 #define genqQUEUE_LENGTH                ( 5 )\r
117 #define genqNO_BLOCK                    ( 0 )\r
118 \r
119 #define genqMUTEX_LOW_PRIORITY          ( tskIDLE_PRIORITY )\r
120 #define genqMUTEX_TEST_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
121 #define genqMUTEX_MEDIUM_PRIORITY       ( tskIDLE_PRIORITY + 2 )\r
122 #define genqMUTEX_HIGH_PRIORITY         ( tskIDLE_PRIORITY + 3 )\r
123 \r
124 /*-----------------------------------------------------------*/\r
125 \r
126 /*\r
127  * Tests the behaviour of the xQueueAltSendToFront() and xQueueAltSendToBack()\r
128  * macros by using both to fill a queue, then reading from the queue to\r
129  * check the resultant queue order is as expected.  Queue data is also\r
130  * peeked.\r
131  */\r
132 static void prvSendFrontAndBackTest( void *pvParameters );\r
133 \r
134 /*\r
135  * The following three tasks are used to demonstrate the mutex behaviour.\r
136  * Each task is given a different priority to demonstrate the priority\r
137  * inheritance mechanism.\r
138  *\r
139  * The low priority task obtains a mutex.  After this a high priority task\r
140  * attempts to obtain the same mutex, causing its priority to be inherited\r
141  * by the low priority task.  The task with the inherited high priority then\r
142  * resumes a medium priority task to ensure it is not blocked by the medium\r
143  * priority task while it holds the inherited high priority.  Once the mutex\r
144  * is returned the task with the inherited priority returns to its original\r
145  * low priority, and is therefore immediately preempted by first the high\r
146  * priority task and then the medium prioroity task before it can continue.\r
147  */\r
148 static void prvLowPriorityMutexTask( void *pvParameters );\r
149 static void prvMediumPriorityMutexTask( void *pvParameters );\r
150 static void prvHighPriorityMutexTask( void *pvParameters );\r
151 \r
152 /*-----------------------------------------------------------*/\r
153 \r
154 /* Flag that will be latched to pdTRUE should any unexpected behaviour be\r
155 detected in any of the tasks. */\r
156 static BaseType_t xErrorDetected = pdFALSE;\r
157 \r
158 /* Counters that are incremented on each cycle of a test.  This is used to\r
159 detect a stalled task - a test that is no longer running. */\r
160 static volatile uint32_t ulLoopCounter = 0;\r
161 static volatile uint32_t ulLoopCounter2 = 0;\r
162 \r
163 /* The variable that is guarded by the mutex in the mutex demo tasks. */\r
164 static volatile uint32_t ulGuardedVariable = 0;\r
165 \r
166 /* Handles used in the mutext test to suspend and resume the high and medium\r
167 priority mutex test tasks. */\r
168 static TaskHandle_t xHighPriorityMutexTask, xMediumPriorityMutexTask;\r
169 \r
170 /*-----------------------------------------------------------*/\r
171 \r
172 void vStartAltGenericQueueTasks( UBaseType_t uxPriority )\r
173 {\r
174 QueueHandle_t xQueue;\r
175 SemaphoreHandle_t xMutex;\r
176 \r
177         /* Create the queue that we are going to use for the\r
178         prvSendFrontAndBackTest demo. */\r
179         xQueue = xQueueCreate( genqQUEUE_LENGTH, sizeof( uint32_t ) );\r
180 \r
181         /* vQueueAddToRegistry() adds the queue to the queue registry, if one is\r
182         in use.  The queue registry is provided as a means for kernel aware \r
183         debuggers to locate queues and has no purpose if a kernel aware debugger\r
184         is not being used.  The call to vQueueAddToRegistry() will be removed\r
185         by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is \r
186         defined to be less than 1. */\r
187         vQueueAddToRegistry( xQueue, "Alt_Gen_Test_Queue" );\r
188 \r
189         /* Create the demo task and pass it the queue just created.  We are\r
190         passing the queue handle by value so it does not matter that it is\r
191         declared on the stack here. */\r
192         xTaskCreate( prvSendFrontAndBackTest, "FGenQ", configMINIMAL_STACK_SIZE, ( void * ) xQueue, uxPriority, NULL );\r
193 \r
194         /* Create the mutex used by the prvMutexTest task. */\r
195         xMutex = xSemaphoreCreateMutex();\r
196 \r
197         /* vQueueAddToRegistry() adds the mutex to the registry, if one is\r
198         in use.  The registry is provided as a means for kernel aware \r
199         debuggers to locate mutex and has no purpose if a kernel aware debugger\r
200         is not being used.  The call to vQueueAddToRegistry() will be removed\r
201         by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is \r
202         defined to be less than 1. */\r
203         vQueueAddToRegistry( ( QueueHandle_t ) xMutex, "Alt_Q_Mutex" );\r
204 \r
205         /* Create the mutex demo tasks and pass it the mutex just created.  We are\r
206         passing the mutex handle by value so it does not matter that it is declared\r
207         on the stack here. */\r
208         xTaskCreate( prvLowPriorityMutexTask, "FMuLow", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_LOW_PRIORITY, NULL );\r
209         xTaskCreate( prvMediumPriorityMutexTask, "FMuMed", configMINIMAL_STACK_SIZE, NULL, genqMUTEX_MEDIUM_PRIORITY, &xMediumPriorityMutexTask );\r
210         xTaskCreate( prvHighPriorityMutexTask, "FMuHigh", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_HIGH_PRIORITY, &xHighPriorityMutexTask );\r
211 }\r
212 /*-----------------------------------------------------------*/\r
213 \r
214 static void prvSendFrontAndBackTest( void *pvParameters )\r
215 {\r
216 uint32_t ulData, ulData2;\r
217 QueueHandle_t xQueue;\r
218 \r
219         #ifdef USE_STDIO\r
220         void vPrintDisplayMessage( const char * const * ppcMessageToSend );\r
221         \r
222                 const char * const pcTaskStartMsg = "Alt queue SendToFront/SendToBack/Peek test started.\r\n";\r
223 \r
224                 /* Queue a message for printing to say the task has started. */\r
225                 vPrintDisplayMessage( &pcTaskStartMsg );\r
226         #endif\r
227 \r
228         xQueue = ( QueueHandle_t ) pvParameters;\r
229 \r
230         for( ;; )\r
231         {\r
232                 /* The queue is empty, so sending an item to the back of the queue\r
233                 should have the same efect as sending it to the front of the queue.\r
234 \r
235                 First send to the front and check everything is as expected. */\r
236                 xQueueAltSendToFront( xQueue, ( void * ) &ulLoopCounter, genqNO_BLOCK );\r
237 \r
238                 if( uxQueueMessagesWaiting( xQueue ) != 1 )\r
239                 {\r
240                         xErrorDetected = pdTRUE;\r
241                 }\r
242 \r
243                 if( xQueueAltReceive( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )\r
244                 {\r
245                         xErrorDetected = pdTRUE;\r
246                 }\r
247 \r
248                 /* The data we sent to the queue should equal the data we just received\r
249                 from the queue. */\r
250                 if( ulLoopCounter != ulData )\r
251                 {\r
252                         xErrorDetected = pdTRUE;\r
253                 }\r
254 \r
255                 /* Then do the same, sending the data to the back, checking everything\r
256                 is as expected. */\r
257                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
258                 {\r
259                         xErrorDetected = pdTRUE;\r
260                 }\r
261 \r
262                 xQueueAltSendToBack( xQueue, ( void * ) &ulLoopCounter, genqNO_BLOCK );\r
263 \r
264                 if( uxQueueMessagesWaiting( xQueue ) != 1 )\r
265                 {\r
266                         xErrorDetected = pdTRUE;\r
267                 }\r
268 \r
269                 if( xQueueAltReceive( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )\r
270                 {\r
271                         xErrorDetected = pdTRUE;\r
272                 }\r
273 \r
274                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
275                 {\r
276                         xErrorDetected = pdTRUE;\r
277                 }\r
278 \r
279                 /* The data we sent to the queue should equal the data we just received\r
280                 from the queue. */\r
281                 if( ulLoopCounter != ulData )\r
282                 {\r
283                         xErrorDetected = pdTRUE;\r
284                 }\r
285 \r
286                 #if configUSE_PREEMPTION == 0\r
287                         taskYIELD();\r
288                 #endif\r
289 \r
290 \r
291 \r
292                 /* Place 2, 3, 4 into the queue, adding items to the back of the queue. */\r
293                 for( ulData = 2; ulData < 5; ulData++ )\r
294                 {\r
295                         xQueueAltSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK );\r
296                 }\r
297 \r
298                 /* Now the order in the queue should be 2, 3, 4, with 2 being the first\r
299                 thing to be read out.  Now add 1 then 0 to the front of the queue. */\r
300                 if( uxQueueMessagesWaiting( xQueue ) != 3 )\r
301                 {\r
302                         xErrorDetected = pdTRUE;\r
303                 }\r
304                 ulData = 1;\r
305                 xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK );\r
306                 ulData = 0;\r
307                 xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK );\r
308 \r
309                 /* Now the queue should be full, and when we read the data out we\r
310                 should receive 0, 1, 2, 3, 4. */\r
311                 if( uxQueueMessagesWaiting( xQueue ) != 5 )\r
312                 {\r
313                         xErrorDetected = pdTRUE;\r
314                 }\r
315 \r
316                 if( xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
317                 {\r
318                         xErrorDetected = pdTRUE;\r
319                 }\r
320 \r
321                 if( xQueueAltSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
322                 {\r
323                         xErrorDetected = pdTRUE;\r
324                 }\r
325 \r
326                 #if configUSE_PREEMPTION == 0\r
327                         taskYIELD();\r
328                 #endif\r
329 \r
330                 /* Check the data we read out is in the expected order. */\r
331                 for( ulData = 0; ulData < genqQUEUE_LENGTH; ulData++ )\r
332                 {\r
333                         /* Try peeking the data first. */\r
334                         if( xQueueAltPeek( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )\r
335                         {\r
336                                 xErrorDetected = pdTRUE;\r
337                         }\r
338 \r
339                         if( ulData != ulData2 )\r
340                         {\r
341                                 xErrorDetected = pdTRUE;\r
342                         }\r
343                         \r
344 \r
345                         /* Now try receiving the data for real.  The value should be the\r
346                         same.  Clobber the value first so we know we really received it. */\r
347                         ulData2 = ~ulData2;\r
348                         if( xQueueAltReceive( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )\r
349                         {\r
350                                 xErrorDetected = pdTRUE;\r
351                         }\r
352 \r
353                         if( ulData != ulData2 )\r
354                         {\r
355                                 xErrorDetected = pdTRUE;\r
356                         }\r
357                 }\r
358 \r
359                 /* The queue should now be empty again. */\r
360                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
361                 {\r
362                         xErrorDetected = pdTRUE;\r
363                 }\r
364 \r
365                 #if configUSE_PREEMPTION == 0\r
366                         taskYIELD();\r
367                 #endif\r
368 \r
369 \r
370                 /* Our queue is empty once more, add 10, 11 to the back. */\r
371                 ulData = 10;\r
372                 if( xQueueAltSendToBack( xQueue, &ulData, genqNO_BLOCK ) != pdPASS )\r
373                 {\r
374                         xErrorDetected = pdTRUE;\r
375                 }\r
376                 ulData = 11;\r
377                 if( xQueueAltSendToBack( xQueue, &ulData, genqNO_BLOCK ) != pdPASS )\r
378                 {\r
379                         xErrorDetected = pdTRUE;\r
380                 }\r
381 \r
382                 if( uxQueueMessagesWaiting( xQueue ) != 2 )\r
383                 {\r
384                         xErrorDetected = pdTRUE;\r
385                 }\r
386 \r
387                 /* Now we should have 10, 11 in the queue.  Add 7, 8, 9 to the\r
388                 front. */\r
389                 for( ulData = 9; ulData >= 7; ulData-- )\r
390                 {\r
391                         if( xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )\r
392                         {\r
393                                 xErrorDetected = pdTRUE;\r
394                         }\r
395                 }\r
396 \r
397                 /* Now check that the queue is full, and that receiving data provides\r
398                 the expected sequence of 7, 8, 9, 10, 11. */\r
399                 if( uxQueueMessagesWaiting( xQueue ) != 5 )\r
400                 {\r
401                         xErrorDetected = pdTRUE;\r
402                 }\r
403 \r
404                 if( xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
405                 {\r
406                         xErrorDetected = pdTRUE;\r
407                 }\r
408 \r
409                 if( xQueueAltSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )\r
410                 {\r
411                         xErrorDetected = pdTRUE;\r
412                 }\r
413 \r
414                 #if configUSE_PREEMPTION == 0\r
415                         taskYIELD();\r
416                 #endif\r
417 \r
418                 /* Check the data we read out is in the expected order. */\r
419                 for( ulData = 7; ulData < ( 7 + genqQUEUE_LENGTH ); ulData++ )\r
420                 {\r
421                         if( xQueueAltReceive( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )\r
422                         {\r
423                                 xErrorDetected = pdTRUE;\r
424                         }\r
425 \r
426                         if( ulData != ulData2 )\r
427                         {\r
428                                 xErrorDetected = pdTRUE;\r
429                         }\r
430                 }\r
431 \r
432                 if( uxQueueMessagesWaiting( xQueue ) != 0 )\r
433                 {\r
434                         xErrorDetected = pdTRUE;\r
435                 }\r
436 \r
437                 ulLoopCounter++;\r
438         }\r
439 }\r
440 /*-----------------------------------------------------------*/\r
441 \r
442 static void prvLowPriorityMutexTask( void *pvParameters )\r
443 {\r
444 SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters;\r
445 \r
446         #ifdef USE_STDIO\r
447         void vPrintDisplayMessage( const char * const * ppcMessageToSend );\r
448         \r
449                 const char * const pcTaskStartMsg = "Fast mutex with priority inheritance test started.\r\n";\r
450 \r
451                 /* Queue a message for printing to say the task has started. */\r
452                 vPrintDisplayMessage( &pcTaskStartMsg );\r
453         #endif\r
454 \r
455         ( void ) pvParameters;\r
456 \r
457 \r
458         for( ;; )\r
459         {\r
460                 /* Take the mutex.  It should be available now. */\r
461                 if( xSemaphoreAltTake( xMutex, genqNO_BLOCK ) != pdPASS )\r
462                 {\r
463                         xErrorDetected = pdTRUE;\r
464                 }\r
465 \r
466                 /* Set our guarded variable to a known start value. */\r
467                 ulGuardedVariable = 0;\r
468 \r
469                 /* Our priority should be as per that assigned when the task was\r
470                 created. */\r
471                 if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )\r
472                 {\r
473                         xErrorDetected = pdTRUE;\r
474                 }\r
475 \r
476                 /* Now unsuspend the high priority task.  This will attempt to take the\r
477                 mutex, and block when it finds it cannot obtain it. */\r
478                 vTaskResume( xHighPriorityMutexTask );\r
479 \r
480                 /* We should now have inherited the prioritoy of the high priority task,\r
481                 as by now it will have attempted to get the mutex. */\r
482                 if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )\r
483                 {\r
484                         xErrorDetected = pdTRUE;\r
485                 }\r
486 \r
487                 /* We can attempt to set our priority to the test priority - between the\r
488                 idle priority and the medium/high test priorities, but our actual\r
489                 prioroity should remain at the high priority. */\r
490                 vTaskPrioritySet( NULL, genqMUTEX_TEST_PRIORITY );\r
491                 if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )\r
492                 {\r
493                         xErrorDetected = pdTRUE;\r
494                 }\r
495 \r
496                 /* Now unsuspend the medium priority task.  This should not run as our\r
497                 inherited priority is above that of the medium priority task. */\r
498                 vTaskResume( xMediumPriorityMutexTask );\r
499 \r
500                 /* If the did run then it will have incremented our guarded variable. */\r
501                 if( ulGuardedVariable != 0 )\r
502                 {\r
503                         xErrorDetected = pdTRUE;\r
504                 }\r
505 \r
506                 /* When we give back the semaphore our priority should be disinherited\r
507                 back to the priority to which we attempted to set ourselves.  This means\r
508                 that when the high priority task next blocks, the medium priority task\r
509                 should execute and increment the guarded variable.   When we next run\r
510                 both the high and medium priority tasks will have been suspended again. */\r
511                 if( xSemaphoreAltGive( xMutex ) != pdPASS )\r
512                 {\r
513                         xErrorDetected = pdTRUE;\r
514                 }\r
515 \r
516                 /* Check that the guarded variable did indeed increment... */\r
517                 if( ulGuardedVariable != 1 )\r
518                 {\r
519                         xErrorDetected = pdTRUE;\r
520                 }\r
521 \r
522                 /* ... and that our priority has been disinherited to\r
523                 genqMUTEX_TEST_PRIORITY. */\r
524                 if( uxTaskPriorityGet( NULL ) != genqMUTEX_TEST_PRIORITY )\r
525                 {\r
526                         xErrorDetected = pdTRUE;\r
527                 }\r
528 \r
529                 /* Set our priority back to our original priority ready for the next\r
530                 loop around this test. */\r
531                 vTaskPrioritySet( NULL, genqMUTEX_LOW_PRIORITY );\r
532 \r
533                 /* Just to show we are still running. */\r
534                 ulLoopCounter2++;\r
535 \r
536                 #if configUSE_PREEMPTION == 0\r
537                         taskYIELD();\r
538                 #endif          \r
539         }\r
540 }\r
541 /*-----------------------------------------------------------*/\r
542 \r
543 static void prvMediumPriorityMutexTask( void *pvParameters )\r
544 {\r
545         ( void ) pvParameters;\r
546 \r
547         for( ;; )\r
548         {\r
549                 /* The medium priority task starts by suspending itself.  The low\r
550                 priority task will unsuspend this task when required. */\r
551                 vTaskSuspend( NULL );\r
552 \r
553                 /* When this task unsuspends all it does is increment the guarded\r
554                 variable, this is so the low priority task knows that it has\r
555                 executed. */\r
556                 ulGuardedVariable++;\r
557         }\r
558 }\r
559 /*-----------------------------------------------------------*/\r
560 \r
561 static void prvHighPriorityMutexTask( void *pvParameters )\r
562 {\r
563 SemaphoreHandle_t xMutex = ( SemaphoreHandle_t ) pvParameters;\r
564 \r
565         ( void ) pvParameters;\r
566 \r
567         for( ;; )\r
568         {\r
569                 /* The high priority task starts by suspending itself.  The low\r
570                 priority task will unsuspend this task when required. */\r
571                 vTaskSuspend( NULL );\r
572 \r
573                 /* When this task unsuspends all it does is attempt to obtain\r
574                 the mutex.  It should find the mutex is not available so a\r
575                 block time is specified. */\r
576                 if( xSemaphoreAltTake( xMutex, portMAX_DELAY ) != pdPASS )\r
577                 {\r
578                         xErrorDetected = pdTRUE;\r
579                 }\r
580 \r
581                 /* When we eventually obtain the mutex we just give it back then\r
582                 return to suspend ready for the next test. */\r
583                 if( xSemaphoreAltGive( xMutex ) != pdPASS )\r
584                 {\r
585                         xErrorDetected = pdTRUE;\r
586                 }               \r
587         }\r
588 }\r
589 /*-----------------------------------------------------------*/\r
590 \r
591 /* This is called to check that all the created tasks are still running. */\r
592 BaseType_t xAreAltGenericQueueTasksStillRunning( void )\r
593 {\r
594 static uint32_t ulLastLoopCounter = 0, ulLastLoopCounter2 = 0;\r
595 \r
596         /* If the demo task is still running then we expect the loopcounters to\r
597         have incremented since this function was last called. */\r
598         if( ulLastLoopCounter == ulLoopCounter )\r
599         {\r
600                 xErrorDetected = pdTRUE;\r
601         }\r
602 \r
603         if( ulLastLoopCounter2 == ulLoopCounter2 )\r
604         {\r
605                 xErrorDetected = pdTRUE;\r
606         }\r
607 \r
608         ulLastLoopCounter = ulLoopCounter;\r
609         ulLastLoopCounter2 = ulLoopCounter2;    \r
610 \r
611         /* Errors detected in the task itself will have latched xErrorDetected\r
612         to true. */\r
613 \r
614         return !xErrorDetected;\r
615 }\r
616 \r
617 \r