]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Common/Minimal/IntSemTest.c
Update version numbers in preparation for V8.2.0 release candidate 1.
[freertos] / FreeRTOS / Demo / Common / Minimal / IntSemTest.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  * Demonstrates and tests mutexes being used from an interrupt.\r
99  */\r
100 \r
101 \r
102 #include <stdlib.h>\r
103 \r
104 /* Scheduler include files. */\r
105 #include "FreeRTOS.h"\r
106 #include "task.h"\r
107 #include "semphr.h"\r
108 \r
109 /* Demo program include files. */\r
110 #include "IntSemTest.h"\r
111 \r
112 /*-----------------------------------------------------------*/\r
113 \r
114 /* The priorities of the test tasks. */\r
115 #define intsemMASTER_PRIORITY           ( tskIDLE_PRIORITY )\r
116 #define intsemSLAVE_PRIORITY            ( tskIDLE_PRIORITY + 1 )\r
117 \r
118 /* The rate at which the tick hook will give the mutex. */\r
119 #define intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ( 100 )\r
120 \r
121 /* A block time of 0 means 'don't block'. */\r
122 #define intsemNO_BLOCK                          0\r
123 \r
124 /* The maximum count value for the counting semaphore given from an\r
125 interrupt. */\r
126 #define intsemMAX_COUNT                         3\r
127 \r
128 /*-----------------------------------------------------------*/\r
129 \r
130 /*\r
131  * The master is a task that receives a mutex that is given from an interrupt -\r
132  * although generally mutexes should not be used given in interrupts (and\r
133  * definitely never taken in an interrupt) there are some circumstances when it\r
134  * may be desirable.\r
135  *\r
136  * The slave task is just used by the master task to force priority inheritance\r
137  * on a mutex that is shared between the master and the slave - which is a\r
138  * separate mutex to that given by the interrupt.\r
139  */\r
140 static void vInterruptMutexSlaveTask( void *pvParameters );\r
141 static void vInterruptMutexMasterTask( void *pvParameters );\r
142 \r
143 /*\r
144  * A test whereby the master takes the shared and interrupt mutexes in that\r
145  * order, then gives them back in the same order, ensuring the priority\r
146  * inheritance is behaving as expected at each step.\r
147  */\r
148 static void prvTakeAndGiveInTheSameOrder( void );\r
149 \r
150 /*\r
151  * A test whereby the master takes the shared and interrupt mutexes in that\r
152  * order, then gives them back in the opposite order to which they were taken,\r
153  * ensuring the priority inheritance is behaving as expected at each step.\r
154  */\r
155 static void prvTakeAndGiveInTheOppositeOrder( void );\r
156 \r
157 /*\r
158  * A simple task that interacts with an interrupt using a counting semaphore,\r
159  * primarily for code coverage purposes.\r
160  */\r
161 static void vInterruptCountingSemaphoreTask( void *pvParameters );\r
162 \r
163 /*-----------------------------------------------------------*/\r
164 \r
165 /* Flag that will be latched to pdTRUE should any unexpected behaviour be\r
166 detected in any of the tasks. */\r
167 static volatile BaseType_t xErrorDetected = pdFALSE;\r
168 \r
169 /* Counters that are incremented on each cycle of a test.  This is used to\r
170 detect a stalled task - a test that is no longer running. */\r
171 static volatile uint32_t ulMasterLoops = 0, ulCountingSemaphoreLoops = 0;\r
172 \r
173 /* Handles of the test tasks that must be accessed from other test tasks. */\r
174 static TaskHandle_t xSlaveHandle;\r
175 \r
176 /* A mutex which is given from an interrupt - although generally mutexes should\r
177 not be used given in interrupts (and definitely never taken in an interrupt)\r
178 there are some circumstances when it may be desirable. */\r
179 static SemaphoreHandle_t xISRMutex = NULL;\r
180 \r
181 /* A counting semaphore which is given from an interrupt. */\r
182 static SemaphoreHandle_t xISRCountingSemaphore = NULL;\r
183 \r
184 /* A mutex which is shared between the master and slave tasks - the master\r
185 does both sharing of this mutex with the slave and receiving a mutex from the\r
186 interrupt. */\r
187 static SemaphoreHandle_t xMasterSlaveMutex = NULL;\r
188 \r
189 /* Flag that allows the master task to control when the interrupt gives or does\r
190 not give the mutex.  There is no mutual exclusion on this variable, but this is\r
191 only test code and it should be fine in the 32=bit test environment. */\r
192 static BaseType_t xOkToGiveMutex = pdFALSE, xOkToGiveCountingSemaphore = pdFALSE;\r
193 \r
194 /* Used to coordinate timing between tasks and the interrupt. */\r
195 const TickType_t xInterruptGivePeriod = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );\r
196 \r
197 /*-----------------------------------------------------------*/\r
198 \r
199 void vStartInterruptSemaphoreTasks( void )\r
200 {\r
201         /* Create the semaphores that are given from an interrupt. */\r
202         xISRMutex = xSemaphoreCreateMutex();\r
203         configASSERT( xISRMutex );\r
204         xISRCountingSemaphore = xSemaphoreCreateCounting( intsemMAX_COUNT, 0 );\r
205         configASSERT( xISRCountingSemaphore );\r
206 \r
207         /* Create the mutex that is shared between the master and slave tasks (the\r
208         master receives a mutex from an interrupt and shares a mutex with the\r
209         slave. */\r
210         xMasterSlaveMutex = xSemaphoreCreateMutex();\r
211         configASSERT( xMasterSlaveMutex );\r
212 \r
213         /* Create the tasks that share mutexes between then and with interrupts. */\r
214         xTaskCreate( vInterruptMutexSlaveTask, "IntMuS", configMINIMAL_STACK_SIZE, NULL, intsemSLAVE_PRIORITY, &xSlaveHandle );\r
215         xTaskCreate( vInterruptMutexMasterTask, "IntMuM", configMINIMAL_STACK_SIZE, NULL, intsemMASTER_PRIORITY, NULL );\r
216 \r
217         /* Create the task that blocks on the counting semaphore. */\r
218         xTaskCreate( vInterruptCountingSemaphoreTask, "IntCnt", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
219 }\r
220 /*-----------------------------------------------------------*/\r
221 \r
222 static void vInterruptMutexMasterTask( void *pvParameters )\r
223 {\r
224         /* Just to avoid compiler warnings. */\r
225         ( void ) pvParameters;\r
226 \r
227         for( ;; )\r
228         {\r
229                 prvTakeAndGiveInTheSameOrder();\r
230 \r
231                 /* Ensure not to starve out other tests. */\r
232                 ulMasterLoops++;\r
233                 vTaskDelay( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );\r
234 \r
235                 prvTakeAndGiveInTheOppositeOrder();\r
236 \r
237                 /* Ensure not to starve out other tests. */\r
238                 ulMasterLoops++;\r
239                 vTaskDelay( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );\r
240         }\r
241 }\r
242 /*-----------------------------------------------------------*/\r
243 \r
244 static void prvTakeAndGiveInTheSameOrder( void )\r
245 {\r
246         /* Ensure the slave is suspended, and that this task is running at the\r
247         lower priority as expected as the start conditions. */\r
248         #if( INCLUDE_eTaskGetState == 1 )\r
249         {\r
250                 configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );\r
251         }\r
252         #endif /* INCLUDE_eTaskGetState */\r
253 \r
254         if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )\r
255         {\r
256                 xErrorDetected = pdTRUE;\r
257         }\r
258 \r
259         /* Take the semaphore that is shared with the slave. */\r
260         if( xSemaphoreTake( xMasterSlaveMutex, intsemNO_BLOCK ) != pdPASS )\r
261         {\r
262                 xErrorDetected = pdTRUE;\r
263         }\r
264 \r
265         /* This task now has the mutex.  Unsuspend the slave so it too\r
266         attempts to take the mutex. */\r
267         vTaskResume( xSlaveHandle );\r
268 \r
269         /* The slave has the higher priority so should now have executed and\r
270         blocked on the semaphore. */\r
271         #if( INCLUDE_eTaskGetState == 1 )\r
272         {\r
273                 configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );\r
274         }\r
275         #endif /* INCLUDE_eTaskGetState */\r
276 \r
277         /* This task should now have inherited the priority of the slave\r
278         task. */\r
279         if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
280         {\r
281                 xErrorDetected = pdTRUE;\r
282         }\r
283 \r
284         /* Now wait a little longer than the time between ISR gives to also\r
285         obtain the ISR mutex. */\r
286         xOkToGiveMutex = pdTRUE;\r
287         if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )\r
288         {\r
289                 xErrorDetected = pdTRUE;\r
290         }\r
291         xOkToGiveMutex = pdFALSE;\r
292 \r
293         /* Attempting to take again immediately should fail as the mutex is\r
294         already held. */\r
295         if( xSemaphoreTake( xISRMutex, intsemNO_BLOCK ) != pdFAIL )\r
296         {\r
297                 xErrorDetected = pdTRUE;\r
298         }\r
299 \r
300         /* Should still be at the priority of the slave task. */\r
301         if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
302         {\r
303                 xErrorDetected = pdTRUE;\r
304         }\r
305 \r
306         /* Give back the ISR semaphore to ensure the priority is not\r
307         disinherited as the shared mutex (which the higher priority task is\r
308         attempting to obtain) is still held. */\r
309         if( xSemaphoreGive( xISRMutex ) != pdPASS )\r
310         {\r
311                 xErrorDetected = pdTRUE;\r
312         }\r
313 \r
314         if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
315         {\r
316                 xErrorDetected = pdTRUE;\r
317         }\r
318 \r
319         /* Finally give back the shared mutex.  This time the higher priority\r
320         task should run before this task runs again - so this task should have\r
321         disinherited the priority and the higher priority task should be in the\r
322         suspended state again. */\r
323         if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )\r
324         {\r
325                 xErrorDetected = pdTRUE;\r
326         }\r
327 \r
328         if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )\r
329         {\r
330                 xErrorDetected = pdTRUE;\r
331         }\r
332 \r
333         #if( INCLUDE_eTaskGetState == 1 )\r
334         {\r
335                 configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );\r
336         }\r
337         #endif /* INCLUDE_eTaskGetState */\r
338 \r
339         /* Reset the mutex ready for the next round. */\r
340         xQueueReset( xISRMutex );\r
341 }\r
342 /*-----------------------------------------------------------*/\r
343 \r
344 static void prvTakeAndGiveInTheOppositeOrder( void )\r
345 {\r
346         /* Ensure the slave is suspended, and that this task is running at the\r
347         lower priority as expected as the start conditions. */\r
348         #if( INCLUDE_eTaskGetState == 1 )\r
349         {\r
350                 configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );\r
351         }\r
352         #endif /* INCLUDE_eTaskGetState */\r
353 \r
354         if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )\r
355         {\r
356                 xErrorDetected = pdTRUE;\r
357         }\r
358 \r
359         /* Take the semaphore that is shared with the slave. */\r
360         if( xSemaphoreTake( xMasterSlaveMutex, intsemNO_BLOCK ) != pdPASS )\r
361         {\r
362                 xErrorDetected = pdTRUE;\r
363         }\r
364 \r
365         /* This task now has the mutex.  Unsuspend the slave so it too\r
366         attempts to take the mutex. */\r
367         vTaskResume( xSlaveHandle );\r
368 \r
369         /* The slave has the higher priority so should now have executed and\r
370         blocked on the semaphore. */\r
371         #if( INCLUDE_eTaskGetState == 1 )\r
372         {\r
373                 configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );\r
374         }\r
375         #endif /* INCLUDE_eTaskGetState */\r
376 \r
377         /* This task should now have inherited the priority of the slave\r
378         task. */\r
379         if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
380         {\r
381                 xErrorDetected = pdTRUE;\r
382         }\r
383 \r
384         /* Now wait a little longer than the time between ISR gives to also\r
385         obtain the ISR mutex. */\r
386         xOkToGiveMutex = pdTRUE;\r
387         if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )\r
388         {\r
389                 xErrorDetected = pdTRUE;\r
390         }\r
391         xOkToGiveMutex = pdFALSE;\r
392 \r
393         /* Attempting to take again immediately should fail as the mutex is\r
394         already held. */\r
395         if( xSemaphoreTake( xISRMutex, intsemNO_BLOCK ) != pdFAIL )\r
396         {\r
397                 xErrorDetected = pdTRUE;\r
398         }\r
399 \r
400         /* Should still be at the priority of the slave task. */\r
401         if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
402         {\r
403                 xErrorDetected = pdTRUE;\r
404         }\r
405 \r
406         /* Give back the shared semaphore to ensure the priority is not disinherited\r
407         as the ISR mutex is still held.  The higher priority slave task should run\r
408         before this task runs again. */\r
409         if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )\r
410         {\r
411                 xErrorDetected = pdTRUE;\r
412         }\r
413 \r
414         /* Should still be at the priority of the slave task as this task still\r
415         holds one semaphore (this is a simplification in the priority inheritance\r
416         mechanism. */\r
417         if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
418         {\r
419                 xErrorDetected = pdTRUE;\r
420         }\r
421 \r
422         /* Give back the ISR semaphore, which should result in the priority being\r
423         disinherited as it was the last mutex held. */\r
424         if( xSemaphoreGive( xISRMutex ) != pdPASS )\r
425         {\r
426                 xErrorDetected = pdTRUE;\r
427         }\r
428 \r
429         if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )\r
430         {\r
431                 xErrorDetected = pdTRUE;\r
432         }\r
433 \r
434         /* Reset the mutex ready for the next round. */\r
435         xQueueReset( xISRMutex );\r
436 }\r
437 /*-----------------------------------------------------------*/\r
438 \r
439 static void vInterruptMutexSlaveTask( void *pvParameters )\r
440 {\r
441         /* Just to avoid compiler warnings. */\r
442         ( void ) pvParameters;\r
443 \r
444         for( ;; )\r
445         {\r
446                 /* This task starts by suspending itself so when it executes can be\r
447                 controlled by the master task. */\r
448                 vTaskSuspend( NULL );\r
449 \r
450                 /* This task will execute when the master task already holds the mutex.\r
451                 Attempting to take the mutex will place this task in the Blocked\r
452                 state. */\r
453                 if( xSemaphoreTake( xMasterSlaveMutex, portMAX_DELAY ) != pdPASS )\r
454                 {\r
455                         xErrorDetected = pdTRUE;\r
456                 }\r
457 \r
458                 if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )\r
459                 {\r
460                         xErrorDetected = pdTRUE;\r
461                 }\r
462         }\r
463 }\r
464 /*-----------------------------------------------------------*/\r
465 \r
466 static void vInterruptCountingSemaphoreTask( void *pvParameters )\r
467 {\r
468 BaseType_t xCount;\r
469 const TickType_t xDelay = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ) * ( intsemMAX_COUNT + 1 );\r
470 \r
471         ( void ) pvParameters;\r
472 \r
473         for( ;; )\r
474         {\r
475                 /* Expect to start with the counting semaphore empty. */\r
476                 if( uxQueueMessagesWaiting( ( QueueHandle_t ) xISRCountingSemaphore ) != 0 )\r
477                 {\r
478                         xErrorDetected = pdTRUE;\r
479                 }\r
480 \r
481                 /* Wait until it is expected that the interrupt will have filled the\r
482                 counting semaphore. */\r
483                 xOkToGiveCountingSemaphore = pdTRUE;\r
484                 vTaskDelay( xDelay );\r
485                 xOkToGiveCountingSemaphore = pdFALSE;\r
486 \r
487                 /* Now it is expected that the counting semaphore is full. */\r
488                 if( uxQueueMessagesWaiting( ( QueueHandle_t ) xISRCountingSemaphore ) != intsemMAX_COUNT )\r
489                 {\r
490                         xErrorDetected = pdTRUE;\r
491                 }\r
492 \r
493                 if( uxQueueSpacesAvailable( ( QueueHandle_t ) xISRCountingSemaphore ) != 0 )\r
494                 {\r
495                         xErrorDetected = pdTRUE;\r
496                 }\r
497 \r
498                 ulCountingSemaphoreLoops++;\r
499 \r
500                 /* Expect to be able to take the counting semaphore intsemMAX_COUNT\r
501                 times.  A block time of 0 is used as the semaphore should already be\r
502                 there. */\r
503                 xCount = 0;\r
504                 while( xSemaphoreTake( xISRCountingSemaphore, 0 ) == pdPASS )\r
505                 {\r
506                         xCount++;\r
507                 }\r
508 \r
509                 if( xCount != intsemMAX_COUNT )\r
510                 {\r
511                         xErrorDetected = pdTRUE;\r
512                 }\r
513 \r
514                 /* Now raise the priority of this task so it runs immediately that the\r
515                 semaphore is given from the interrupt. */\r
516                 vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );\r
517 \r
518                 /* Block to wait for the semaphore to be given from the interrupt. */\r
519                 xOkToGiveCountingSemaphore = pdTRUE;\r
520                 xSemaphoreTake( xISRCountingSemaphore, portMAX_DELAY );\r
521                 xSemaphoreTake( xISRCountingSemaphore, portMAX_DELAY );\r
522                 xOkToGiveCountingSemaphore = pdFALSE;\r
523 \r
524                 /* Reset the priority so as not to disturbe other tests too much. */\r
525                 vTaskPrioritySet( NULL, tskIDLE_PRIORITY );\r
526 \r
527                 ulCountingSemaphoreLoops++;\r
528         }\r
529 }\r
530 /*-----------------------------------------------------------*/\r
531 \r
532 void vInterruptSemaphorePeriodicTest( void )\r
533 {\r
534 static TickType_t xLastGiveTime = 0;\r
535 BaseType_t xHigherPriorityTaskWoken = pdFALSE;\r
536 TickType_t xTimeNow;\r
537 \r
538         /* No mutual exclusion on xOkToGiveMutex, but this is only test code (and\r
539         only executed on a 32-bit architecture) so ignore that in this case. */\r
540         xTimeNow = xTaskGetTickCountFromISR();\r
541         if( ( xTimeNow - xLastGiveTime ) >= pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ) )\r
542         {\r
543                 configASSERT( xISRMutex );\r
544                 if( xOkToGiveMutex != pdFALSE )\r
545                 {\r
546                         /* Null is used as the second parameter in this give, and non-NULL\r
547                         in the other gives for code coverage reasons. */\r
548                         xSemaphoreGiveFromISR( xISRMutex, NULL );\r
549 \r
550                         /* Second give attempt should fail. */\r
551                         configASSERT( xSemaphoreGiveFromISR( xISRMutex, &xHigherPriorityTaskWoken ) == pdFAIL );\r
552                 }\r
553 \r
554                 if( xOkToGiveCountingSemaphore != pdFALSE )\r
555                 {\r
556                         xSemaphoreGiveFromISR( xISRCountingSemaphore, &xHigherPriorityTaskWoken );\r
557                 }\r
558                 xLastGiveTime = xTimeNow;\r
559         }\r
560 \r
561         /* Remove compiler warnings about the value being set but not used. */\r
562         ( void ) xHigherPriorityTaskWoken;\r
563 }\r
564 /*-----------------------------------------------------------*/\r
565 \r
566 /* This is called to check that all the created tasks are still running. */\r
567 BaseType_t xAreInterruptSemaphoreTasksStillRunning( void )\r
568 {\r
569 static uint32_t ulLastMasterLoopCounter = 0, ulLastCountingSemaphoreLoops = 0;\r
570 \r
571         /* If the demo tasks are running then it is expected that the loop counters\r
572         will have changed since this function was last called. */\r
573         if( ulLastMasterLoopCounter == ulMasterLoops )\r
574         {\r
575                 xErrorDetected = pdTRUE;\r
576         }\r
577 \r
578         ulLastMasterLoopCounter = ulMasterLoops;\r
579 \r
580         if( ulLastCountingSemaphoreLoops == ulCountingSemaphoreLoops )\r
581         {\r
582                 xErrorDetected = pdTRUE;\r
583         }\r
584 \r
585         ulLastCountingSemaphoreLoops = ulCountingSemaphoreLoops++;\r
586 \r
587         /* Errors detected in the task itself will have latched xErrorDetected\r
588         to true. */\r
589 \r
590         return ( BaseType_t ) !xErrorDetected;\r
591 }\r
592 \r
593 \r