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 "FreeRTOS.h"
00064 #include "task.h"
00065 #include "queue.h"
00066
00067
00068 #include "AltBlock.h"
00069
00070
00071 #define bktPRIMARY_PRIORITY ( 3 )
00072 #define bktSECONDARY_PRIORITY ( 2 )
00073
00074
00075 #define bktQUEUE_LENGTH ( 5 )
00076 #define bktSHORT_WAIT ( ( ( portTickType ) 20 ) / portTICK_RATE_MS )
00077 #define bktPRIMARY_BLOCK_TIME ( 10 )
00078 #define bktALLOWABLE_MARGIN ( 12 )
00079 #define bktTIME_TO_BLOCK ( 175 )
00080 #define bktDONT_BLOCK ( ( portTickType ) 0 )
00081 #define bktRUN_INDICATOR ( ( unsigned portBASE_TYPE ) 0x55 )
00082
00083
00084 static xQueueHandle xTestQueue;
00085
00086
00087
00088 static xTaskHandle xSecondary;
00089
00090
00091 static portBASE_TYPE xPrimaryCycles = 0, xSecondaryCycles = 0;
00092 static portBASE_TYPE xErrorOccurred = pdFALSE;
00093
00094
00095
00096 static volatile unsigned portBASE_TYPE xRunIndicator;
00097
00098
00099 static void vPrimaryBlockTimeTestTask( void *pvParameters );
00100 static void vSecondaryBlockTimeTestTask( void *pvParameters );
00101
00102
00103
00104 void vCreateAltBlockTimeTasks( void )
00105 {
00106
00107 xTestQueue = xQueueCreate( bktQUEUE_LENGTH, sizeof( portBASE_TYPE ) );
00108
00109
00110
00111
00112
00113
00114
00115 vQueueAddToRegistry( xTestQueue, ( signed portCHAR * ) "AltBlockQueue" );
00116
00117
00118
00119 xTaskCreate( vPrimaryBlockTimeTestTask, ( signed portCHAR * )"FBTest1", configMINIMAL_STACK_SIZE, NULL, bktPRIMARY_PRIORITY, NULL );
00120 xTaskCreate( vSecondaryBlockTimeTestTask, ( signed portCHAR * )"FBTest2", configMINIMAL_STACK_SIZE, NULL, bktSECONDARY_PRIORITY, &xSecondary );
00121 }
00122
00123
00124 static void vPrimaryBlockTimeTestTask( void *pvParameters )
00125 {
00126 portBASE_TYPE xItem, xData;
00127 portTickType xTimeWhenBlocking;
00128 portTickType xTimeToBlock, xBlockedTime;
00129
00130 #ifdef USE_STDIO
00131 void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );
00132
00133 const portCHAR * const pcTaskStartMsg = "Alt primary block time test started.\r\n";
00134
00135
00136 vPrintDisplayMessage( &pcTaskStartMsg );
00137 #endif
00138
00139 ( void ) pvParameters;
00140
00141 for( ;; )
00142 {
00143
00144
00145
00146
00147 for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
00148 {
00149
00150
00151 xTimeToBlock = bktPRIMARY_BLOCK_TIME << xItem;
00152
00153
00154
00155 portENTER_CRITICAL();
00156 {
00157 xTimeWhenBlocking = xTaskGetTickCount();
00158
00159
00160
00161 if( xQueueAltReceive( xTestQueue, &xData, xTimeToBlock ) != errQUEUE_EMPTY )
00162 {
00163 xErrorOccurred = pdTRUE;
00164 }
00165
00166
00167 xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
00168 }
00169 portEXIT_CRITICAL();
00170
00171 if( xBlockedTime < xTimeToBlock )
00172 {
00173
00174 xErrorOccurred = pdTRUE;
00175 }
00176
00177 if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )
00178 {
00179
00180
00181
00182 xErrorOccurred = pdTRUE;
00183 }
00184 }
00185
00186
00187 #if configUSE_PREEMPTION == 0
00188 taskYIELD();
00189 #endif
00190
00191
00192
00193
00194
00195
00196
00197
00198 for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
00199 {
00200 if( xQueueAltSendToBack( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
00201 {
00202 xErrorOccurred = pdTRUE;
00203 }
00204 }
00205
00206 for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
00207 {
00208
00209
00210 xTimeToBlock = bktPRIMARY_BLOCK_TIME << xItem;
00211
00212 portENTER_CRITICAL();
00213 {
00214 xTimeWhenBlocking = xTaskGetTickCount();
00215
00216
00217
00218 if( xQueueAltSendToBack( xTestQueue, &xItem, xTimeToBlock ) != errQUEUE_FULL )
00219 {
00220 xErrorOccurred = pdTRUE;
00221 }
00222
00223
00224 xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
00225 }
00226 portEXIT_CRITICAL();
00227
00228 if( xBlockedTime < xTimeToBlock )
00229 {
00230
00231 xErrorOccurred = pdTRUE;
00232 }
00233
00234 if( xBlockedTime > ( xTimeToBlock + bktALLOWABLE_MARGIN ) )
00235 {
00236
00237
00238
00239 xErrorOccurred = pdTRUE;
00240 }
00241 }
00242
00243 #if configUSE_PREEMPTION == 0
00244 taskYIELD();
00245 #endif
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 xRunIndicator = 0;
00261 vTaskResume( xSecondary );
00262
00263
00264 while( xRunIndicator != bktRUN_INDICATOR )
00265 {
00266
00267 vTaskDelay( bktSHORT_WAIT );
00268 }
00269
00270 vTaskDelay( bktSHORT_WAIT );
00271 xRunIndicator = 0;
00272
00273 for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
00274 {
00275
00276
00277 if( xQueueAltReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
00278 {
00279 xErrorOccurred = pdTRUE;
00280 }
00281
00282
00283
00284
00285 if( xQueueAltSendToBack( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
00286 {
00287 xErrorOccurred = pdTRUE;
00288 }
00289
00290 if( xRunIndicator == bktRUN_INDICATOR )
00291 {
00292
00293 xErrorOccurred = pdTRUE;
00294 }
00295
00296
00297
00298 vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );
00299
00300
00301
00302 if( xRunIndicator == bktRUN_INDICATOR )
00303 {
00304
00305
00306 xErrorOccurred = pdTRUE;
00307 }
00308
00309
00310 vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );
00311 }
00312
00313
00314
00315 while( xRunIndicator != bktRUN_INDICATOR )
00316 {
00317 vTaskDelay( bktSHORT_WAIT );
00318 }
00319 vTaskDelay( bktSHORT_WAIT );
00320 xRunIndicator = 0;
00321
00322 #if configUSE_PREEMPTION == 0
00323 taskYIELD();
00324 #endif
00325
00326
00327
00328
00329
00330
00331
00332
00333 for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
00334 {
00335 if( xQueueAltReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
00336 {
00337 xErrorOccurred = pdTRUE;
00338 }
00339 }
00340
00341
00342
00343 vTaskResume( xSecondary );
00344
00345
00346 while( xRunIndicator != bktRUN_INDICATOR )
00347 {
00348 vTaskDelay( bktSHORT_WAIT );
00349 }
00350 vTaskDelay( bktSHORT_WAIT );
00351 xRunIndicator = 0;
00352
00353 for( xItem = 0; xItem < bktQUEUE_LENGTH; xItem++ )
00354 {
00355
00356
00357 if( xQueueAltSendToBack( xTestQueue, &xItem, bktDONT_BLOCK ) != pdPASS )
00358 {
00359 xErrorOccurred = pdTRUE;
00360 }
00361
00362
00363
00364
00365 if( xQueueAltReceive( xTestQueue, &xData, bktDONT_BLOCK ) != pdPASS )
00366 {
00367 xErrorOccurred = pdTRUE;
00368 }
00369
00370 if( xRunIndicator == bktRUN_INDICATOR )
00371 {
00372
00373 xErrorOccurred = pdTRUE;
00374 }
00375
00376
00377
00378 vTaskPrioritySet( xSecondary, bktPRIMARY_PRIORITY + 2 );
00379
00380
00381
00382 if( xRunIndicator == bktRUN_INDICATOR )
00383 {
00384
00385
00386 xErrorOccurred = pdTRUE;
00387 }
00388 vTaskPrioritySet( xSecondary, bktSECONDARY_PRIORITY );
00389 }
00390
00391
00392
00393 while( xRunIndicator != bktRUN_INDICATOR )
00394 {
00395 vTaskDelay( bktSHORT_WAIT );
00396 }
00397 vTaskDelay( bktSHORT_WAIT );
00398
00399 xPrimaryCycles++;
00400 }
00401 }
00402
00403
00404 static void vSecondaryBlockTimeTestTask( void *pvParameters )
00405 {
00406 portTickType xTimeWhenBlocking, xBlockedTime;
00407 portBASE_TYPE xData;
00408
00409 #ifdef USE_STDIO
00410 void vPrintDisplayMessage( const portCHAR * const * ppcMessageToSend );
00411
00412 const portCHAR * const pcTaskStartMsg = "Alt secondary block time test started.\r\n";
00413
00414
00415 vPrintDisplayMessage( &pcTaskStartMsg );
00416 #endif
00417
00418 ( void ) pvParameters;
00419
00420 for( ;; )
00421 {
00422
00423
00424
00425
00426 vTaskSuspend( NULL );
00427
00428
00429
00430
00431
00432
00433
00434 portENTER_CRITICAL();
00435 {
00436 xTimeWhenBlocking = xTaskGetTickCount();
00437
00438
00439
00440 xData = 0;
00441 xRunIndicator = bktRUN_INDICATOR;
00442 if( xQueueAltSendToBack( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_FULL )
00443 {
00444 xErrorOccurred = pdTRUE;
00445 }
00446
00447
00448 xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
00449 }
00450 portEXIT_CRITICAL();
00451
00452
00453 if( xBlockedTime < bktTIME_TO_BLOCK )
00454 {
00455 xErrorOccurred = pdTRUE;
00456 }
00457
00458
00459
00460
00461 if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
00462 {
00463 xErrorOccurred = pdTRUE;
00464 }
00465
00466
00467 xRunIndicator = bktRUN_INDICATOR;
00468 vTaskSuspend( NULL );
00469
00470
00471
00472
00473
00474 portENTER_CRITICAL();
00475 {
00476 xTimeWhenBlocking = xTaskGetTickCount();
00477
00478
00479
00480 xRunIndicator = bktRUN_INDICATOR;
00481 if( xQueueAltReceive( xTestQueue, &xData, bktTIME_TO_BLOCK ) != errQUEUE_EMPTY )
00482 {
00483 xErrorOccurred = pdTRUE;
00484 }
00485
00486 xBlockedTime = xTaskGetTickCount() - xTimeWhenBlocking;
00487 }
00488 portEXIT_CRITICAL();
00489
00490
00491 if( xBlockedTime < bktTIME_TO_BLOCK )
00492 {
00493 xErrorOccurred = pdTRUE;
00494 }
00495
00496
00497
00498
00499 if( xBlockedTime > ( bktTIME_TO_BLOCK + bktALLOWABLE_MARGIN ) )
00500 {
00501 xErrorOccurred = pdTRUE;
00502 }
00503
00504 xRunIndicator = bktRUN_INDICATOR;
00505
00506 xSecondaryCycles++;
00507 }
00508 }
00509
00510
00511 portBASE_TYPE xAreAltBlockTimeTestTasksStillRunning( void )
00512 {
00513 static portBASE_TYPE xLastPrimaryCycleCount = 0, xLastSecondaryCycleCount = 0;
00514 portBASE_TYPE xReturn = pdPASS;
00515
00516
00517
00518 if( xPrimaryCycles == xLastPrimaryCycleCount )
00519 {
00520 xReturn = pdFAIL;
00521 }
00522
00523 if( xSecondaryCycles == xLastSecondaryCycleCount )
00524 {
00525 xReturn = pdFAIL;
00526 }
00527
00528 if( xErrorOccurred == pdTRUE )
00529 {
00530 xReturn = pdFAIL;
00531 }
00532
00533 xLastSecondaryCycleCount = xSecondaryCycles;
00534 xLastPrimaryCycleCount = xPrimaryCycles;
00535
00536 return xReturn;
00537 }