00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 #include <stdlib.h>
00064
00065
00066 #include "FreeRTOS.h"
00067 #include "task.h"
00068 #include "queue.h"
00069 #include "semphr.h"
00070
00071
00072 #include "AltQTest.h"
00073
00074 #define genqQUEUE_LENGTH ( 5 )
00075 #define genqNO_BLOCK ( 0 )
00076
00077 #define genqMUTEX_LOW_PRIORITY ( tskIDLE_PRIORITY )
00078 #define genqMUTEX_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
00079 #define genqMUTEX_MEDIUM_PRIORITY ( tskIDLE_PRIORITY + 2 )
00080 #define genqMUTEX_HIGH_PRIORITY ( tskIDLE_PRIORITY + 3 )
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 static void prvSendFrontAndBackTest( void *pvParameters );
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 static void prvLowPriorityMutexTask( void *pvParameters );
00107 static void prvMediumPriorityMutexTask( void *pvParameters );
00108 static void prvHighPriorityMutexTask( void *pvParameters );
00109
00110
00111
00112
00113
00114 static portBASE_TYPE xErrorDetected = pdFALSE;
00115
00116
00117
00118 static volatile unsigned portLONG ulLoopCounter = 0;
00119 static volatile unsigned portLONG ulLoopCounter2 = 0;
00120
00121
00122 static volatile unsigned portLONG ulGuardedVariable = 0;
00123
00124
00125
00126 static xTaskHandle xHighPriorityMutexTask, xMediumPriorityMutexTask;
00127
00128
00129
00130 void vStartAltGenericQueueTasks( unsigned portBASE_TYPE uxPriority )
00131 {
00132 xQueueHandle xQueue;
00133 xSemaphoreHandle xMutex;
00134
00135
00136
00137 xQueue = xQueueCreate( genqQUEUE_LENGTH, sizeof( unsigned portLONG ) );
00138
00139
00140
00141
00142
00143
00144
00145 vQueueAddToRegistry( xQueue, ( signed portCHAR * ) "Alt_Gen_Test_Queue" );
00146
00147
00148
00149
00150 xTaskCreate( prvSendFrontAndBackTest, ( signed portCHAR * ) "FGenQ", configMINIMAL_STACK_SIZE, ( void * ) xQueue, uxPriority, NULL );
00151
00152
00153 xMutex = xSemaphoreCreateMutex();
00154
00155
00156
00157
00158
00159
00160
00161 vQueueAddToRegistry( ( xQueueHandle ) xMutex, ( signed portCHAR * ) "Alt_Q_Mutex" );
00162
00163
00164
00165
00166 xTaskCreate( prvLowPriorityMutexTask, ( signed portCHAR * ) "FMuLow", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_LOW_PRIORITY, NULL );
00167 xTaskCreate( prvMediumPriorityMutexTask, ( signed portCHAR * ) "FMuMed", configMINIMAL_STACK_SIZE, NULL, genqMUTEX_MEDIUM_PRIORITY, &xMediumPriorityMutexTask );
00168 xTaskCreate( prvHighPriorityMutexTask, ( signed portCHAR * ) "FMuHigh", configMINIMAL_STACK_SIZE, ( void * ) xMutex, genqMUTEX_HIGH_PRIORITY, &xHighPriorityMutexTask );
00169 }
00170
00171
00172 static void prvSendFrontAndBackTest( void *pvParameters )
00173 {
00174 unsigned portLONG ulData, ulData2;
00175 xQueueHandle xQueue;
00176
00177 #ifdef USE_STDIO
00178 void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );
00179
00180 const portCHAR * const pcTaskStartMsg = "Alt queue SendToFront/SendToBack/Peek test started.\r\n";
00181
00182
00183 vPrintDisplayMessage( &pcTaskStartMsg );
00184 #endif
00185
00186 xQueue = ( xQueueHandle ) pvParameters;
00187
00188 for( ;; )
00189 {
00190
00191
00192
00193
00194 xQueueAltSendToFront( xQueue, ( void * ) &ulLoopCounter, genqNO_BLOCK );
00195
00196 if( uxQueueMessagesWaiting( xQueue ) != 1 )
00197 {
00198 xErrorDetected = pdTRUE;
00199 }
00200
00201 if( xQueueAltReceive( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )
00202 {
00203 xErrorDetected = pdTRUE;
00204 }
00205
00206
00207
00208 if( ulLoopCounter != ulData )
00209 {
00210 xErrorDetected = pdTRUE;
00211 }
00212
00213
00214
00215 if( uxQueueMessagesWaiting( xQueue ) != 0 )
00216 {
00217 xErrorDetected = pdTRUE;
00218 }
00219
00220 xQueueAltSendToBack( xQueue, ( void * ) &ulLoopCounter, genqNO_BLOCK );
00221
00222 if( uxQueueMessagesWaiting( xQueue ) != 1 )
00223 {
00224 xErrorDetected = pdTRUE;
00225 }
00226
00227 if( xQueueAltReceive( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )
00228 {
00229 xErrorDetected = pdTRUE;
00230 }
00231
00232 if( uxQueueMessagesWaiting( xQueue ) != 0 )
00233 {
00234 xErrorDetected = pdTRUE;
00235 }
00236
00237
00238
00239 if( ulLoopCounter != ulData )
00240 {
00241 xErrorDetected = pdTRUE;
00242 }
00243
00244 #if configUSE_PREEMPTION == 0
00245 taskYIELD();
00246 #endif
00247
00248
00249
00250
00251 for( ulData = 2; ulData < 5; ulData++ )
00252 {
00253 xQueueAltSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK );
00254 }
00255
00256
00257
00258 if( uxQueueMessagesWaiting( xQueue ) != 3 )
00259 {
00260 xErrorDetected = pdTRUE;
00261 }
00262 ulData = 1;
00263 xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK );
00264 ulData = 0;
00265 xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK );
00266
00267
00268
00269 if( uxQueueMessagesWaiting( xQueue ) != 5 )
00270 {
00271 xErrorDetected = pdTRUE;
00272 }
00273
00274 if( xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )
00275 {
00276 xErrorDetected = pdTRUE;
00277 }
00278
00279 if( xQueueAltSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )
00280 {
00281 xErrorDetected = pdTRUE;
00282 }
00283
00284 #if configUSE_PREEMPTION == 0
00285 taskYIELD();
00286 #endif
00287
00288
00289 for( ulData = 0; ulData < genqQUEUE_LENGTH; ulData++ )
00290 {
00291
00292 if( xQueueAltPeek( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )
00293 {
00294 xErrorDetected = pdTRUE;
00295 }
00296
00297 if( ulData != ulData2 )
00298 {
00299 xErrorDetected = pdTRUE;
00300 }
00301
00302
00303
00304
00305 ulData2 = ~ulData2;
00306 if( xQueueAltReceive( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )
00307 {
00308 xErrorDetected = pdTRUE;
00309 }
00310
00311 if( ulData != ulData2 )
00312 {
00313 xErrorDetected = pdTRUE;
00314 }
00315 }
00316
00317
00318 if( uxQueueMessagesWaiting( xQueue ) != 0 )
00319 {
00320 xErrorDetected = pdTRUE;
00321 }
00322
00323 #if configUSE_PREEMPTION == 0
00324 taskYIELD();
00325 #endif
00326
00327
00328
00329 ulData = 10;
00330 if( xQueueAltSendToBack( xQueue, &ulData, genqNO_BLOCK ) != pdPASS )
00331 {
00332 xErrorDetected = pdTRUE;
00333 }
00334 ulData = 11;
00335 if( xQueueAltSendToBack( xQueue, &ulData, genqNO_BLOCK ) != pdPASS )
00336 {
00337 xErrorDetected = pdTRUE;
00338 }
00339
00340 if( uxQueueMessagesWaiting( xQueue ) != 2 )
00341 {
00342 xErrorDetected = pdTRUE;
00343 }
00344
00345
00346
00347 for( ulData = 9; ulData >= 7; ulData-- )
00348 {
00349 if( xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != pdPASS )
00350 {
00351 xErrorDetected = pdTRUE;
00352 }
00353 }
00354
00355
00356
00357 if( uxQueueMessagesWaiting( xQueue ) != 5 )
00358 {
00359 xErrorDetected = pdTRUE;
00360 }
00361
00362 if( xQueueAltSendToFront( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )
00363 {
00364 xErrorDetected = pdTRUE;
00365 }
00366
00367 if( xQueueAltSendToBack( xQueue, ( void * ) &ulData, genqNO_BLOCK ) != errQUEUE_FULL )
00368 {
00369 xErrorDetected = pdTRUE;
00370 }
00371
00372 #if configUSE_PREEMPTION == 0
00373 taskYIELD();
00374 #endif
00375
00376
00377 for( ulData = 7; ulData < ( 7 + genqQUEUE_LENGTH ); ulData++ )
00378 {
00379 if( xQueueAltReceive( xQueue, &ulData2, genqNO_BLOCK ) != pdPASS )
00380 {
00381 xErrorDetected = pdTRUE;
00382 }
00383
00384 if( ulData != ulData2 )
00385 {
00386 xErrorDetected = pdTRUE;
00387 }
00388 }
00389
00390 if( uxQueueMessagesWaiting( xQueue ) != 0 )
00391 {
00392 xErrorDetected = pdTRUE;
00393 }
00394
00395 ulLoopCounter++;
00396 }
00397 }
00398
00399
00400 static void prvLowPriorityMutexTask( void *pvParameters )
00401 {
00402 xSemaphoreHandle xMutex = ( xSemaphoreHandle ) pvParameters;
00403
00404 #ifdef USE_STDIO
00405 void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );
00406
00407 const portCHAR * const pcTaskStartMsg = "Fast mutex with priority inheritance test started.\r\n";
00408
00409
00410 vPrintDisplayMessage( &pcTaskStartMsg );
00411 #endif
00412
00413 ( void ) pvParameters;
00414
00415
00416 for( ;; )
00417 {
00418
00419 if( xSemaphoreAltTake( xMutex, genqNO_BLOCK ) != pdPASS )
00420 {
00421 xErrorDetected = pdTRUE;
00422 }
00423
00424
00425 ulGuardedVariable = 0;
00426
00427
00428
00429 if( uxTaskPriorityGet( NULL ) != genqMUTEX_LOW_PRIORITY )
00430 {
00431 xErrorDetected = pdTRUE;
00432 }
00433
00434
00435
00436 vTaskResume( xHighPriorityMutexTask );
00437
00438
00439
00440 if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
00441 {
00442 xErrorDetected = pdTRUE;
00443 }
00444
00445
00446
00447
00448 vTaskPrioritySet( NULL, genqMUTEX_TEST_PRIORITY );
00449 if( uxTaskPriorityGet( NULL ) != genqMUTEX_HIGH_PRIORITY )
00450 {
00451 xErrorDetected = pdTRUE;
00452 }
00453
00454
00455
00456 vTaskResume( xMediumPriorityMutexTask );
00457
00458
00459 if( ulGuardedVariable != 0 )
00460 {
00461 xErrorDetected = pdTRUE;
00462 }
00463
00464
00465
00466
00467
00468
00469 if( xSemaphoreAltGive( xMutex ) != pdPASS )
00470 {
00471 xErrorDetected = pdTRUE;
00472 }
00473
00474
00475 if( ulGuardedVariable != 1 )
00476 {
00477 xErrorDetected = pdTRUE;
00478 }
00479
00480
00481
00482 if( uxTaskPriorityGet( NULL ) != genqMUTEX_TEST_PRIORITY )
00483 {
00484 xErrorDetected = pdTRUE;
00485 }
00486
00487
00488
00489 vTaskPrioritySet( NULL, genqMUTEX_LOW_PRIORITY );
00490
00491
00492 ulLoopCounter2++;
00493
00494 #if configUSE_PREEMPTION == 0
00495 taskYIELD();
00496 #endif
00497 }
00498 }
00499
00500
00501 static void prvMediumPriorityMutexTask( void *pvParameters )
00502 {
00503 ( void ) pvParameters;
00504
00505 for( ;; )
00506 {
00507
00508
00509 vTaskSuspend( NULL );
00510
00511
00512
00513
00514 ulGuardedVariable++;
00515 }
00516 }
00517
00518
00519 static void prvHighPriorityMutexTask( void *pvParameters )
00520 {
00521 xSemaphoreHandle xMutex = ( xSemaphoreHandle ) pvParameters;
00522
00523 ( void ) pvParameters;
00524
00525 for( ;; )
00526 {
00527
00528
00529 vTaskSuspend( NULL );
00530
00531
00532
00533
00534 if( xSemaphoreAltTake( xMutex, portMAX_DELAY ) != pdPASS )
00535 {
00536 xErrorDetected = pdTRUE;
00537 }
00538
00539
00540
00541 if( xSemaphoreAltGive( xMutex ) != pdPASS )
00542 {
00543 xErrorDetected = pdTRUE;
00544 }
00545 }
00546 }
00547
00548
00549
00550 portBASE_TYPE xAreAltGenericQueueTasksStillRunning( void )
00551 {
00552 static unsigned portLONG ulLastLoopCounter = 0, ulLastLoopCounter2 = 0;
00553
00554
00555
00556 if( ulLastLoopCounter == ulLoopCounter )
00557 {
00558 xErrorDetected = pdTRUE;
00559 }
00560
00561 if( ulLastLoopCounter2 == ulLoopCounter2 )
00562 {
00563 xErrorDetected = pdTRUE;
00564 }
00565
00566 ulLastLoopCounter = ulLoopCounter;
00567 ulLastLoopCounter2 = ulLoopCounter2;
00568
00569
00570
00571
00572 return !xErrorDetected;
00573 }
00574
00575