From: rtel Date: Mon, 17 Dec 2018 23:19:23 +0000 (+0000) Subject: Add vTimerSetReloadMode() calls to the code coverage tests. X-Git-Tag: V10.2.0~34 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6eded2ed37dd23ec1c97baa9a9cbf56a713a587c;p=freertos Add vTimerSetReloadMode() calls to the code coverage tests. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2608 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- diff --git a/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/main.c b/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/main.c index 82b51a1b5..a1e4ac6d5 100644 --- a/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/main.c +++ b/FreeRTOS/Demo/CORTEX_MPU_Simulator_Keil_GCC/main.c @@ -783,7 +783,7 @@ static void prvTaskToDelete( void *pvParameters ) static void prvPendedFunctionCall( void *pvParameter1, uint32_t ulParameter2 ) { uint32_t *pulCounter = ( uint32_t * ) pvParameter1; - + /* Increment the paramater to show the pended function has executed. */ ( *pulCounter )++; } @@ -792,7 +792,7 @@ uint32_t *pulCounter = ( uint32_t * ) pvParameter1; static void prvTestTimerCallback( TimerHandle_t xTimer ) { uint32_t ulTimerID; - + /* Increment the timer's ID to show the callback has executed. */ ulTimerID = ( uint32_t ) pvTimerGetTimerID( xTimer ); ulTimerID++; @@ -804,43 +804,42 @@ static void prvExerciseTimerAPI( void ) { TimerHandle_t xTimer; const char * const pcTimerName = "TestTimer"; -const TickType_t x10ms = pdMS_TO_TICKS( 3 ); +const TickType_t x3ms = pdMS_TO_TICKS( 3 ); uint32_t ulValueForTesting = 0; - - xTimer = xTimerCreate( pcTimerName, - x10ms, + + xTimer = xTimerCreate( pcTimerName, + x3ms, pdFALSE, /* Created as a one shot timer. */ 0, prvTestTimerCallback ); - configASSERT( xTimer ); + configASSERT( xTimer ); configASSERT( xTimerIsTimerActive( xTimer ) == pdFALSE ); configASSERT( xTimerGetTimerDaemonTaskHandle() != NULL ); configASSERT( strcmp( pcTimerName, pcTimerGetName( xTimer ) ) == 0 ); - configASSERT( xTimerGetPeriod( xTimer ) == x10ms ); - configASSERT( xTimerGetExpiryTime( xTimer ) == 0 ); /* The timer has been created only. */ - + configASSERT( xTimerGetPeriod( xTimer ) == x3ms ); + /* Pend a function then wait for it to execute. All it does is increment its parameter. */ xTimerPendFunctionCall( prvPendedFunctionCall, &ulValueForTesting, 0, 0 ); - vTaskDelay( x10ms ); + vTaskDelay( x3ms ); configASSERT( ulValueForTesting == 1 ); - + /* Timer was created as a one shot timer. Its callback just increments the timer's ID - so set the ID to 0, let the timer run for a number of timeout periods, then check the timer has only executed once. */ vTimerSetTimerID( xTimer, ( void * ) 0 ); xTimerStart( xTimer, 0 ); - vTaskDelay( 3UL * x10ms ); + vTaskDelay( 3UL * x3ms ); configASSERT( ( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) ) == 1UL ); - + /* Now change the timer to be an autoreload timer and check it executes the expected number of times. */ vTimerSetReloadMode( xTimer, pdTRUE ); xTimerStart( xTimer, 0 ); - vTaskDelay( 3UL * x10ms ); + vTaskDelay( 3UL * x3ms ); configASSERT( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) > 3UL ); configASSERT( xTimerStop( xTimer, 0 ) != pdFAIL ); - + /* Clean up at the end. */ xTimerDelete( xTimer, portMAX_DELAY ); } diff --git a/FreeRTOS/Demo/WIN32-MingW/main_full.c b/FreeRTOS/Demo/WIN32-MingW/main_full.c index b6f59aafc..3b27f908e 100644 --- a/FreeRTOS/Demo/WIN32-MingW/main_full.c +++ b/FreeRTOS/Demo/WIN32-MingW/main_full.c @@ -171,6 +171,13 @@ static void prvDemoQueueSpaceFunctions( void *pvParameters ); static void prvPermanentlyBlockingSemaphoreTask( void *pvParameters ); static void prvPermanentlyBlockingNotificationTask( void *pvParameters ); +/* + * The test function and callback function used when exercising the timer AP + * function that changes the timer's autoreload mode. + */ +static void prvDemonstrateChangingTimerReloadMode( void *pvParameters ); +static void prvReloadModeTestTimerCallback( TimerHandle_t xTimer ); + /*-----------------------------------------------------------*/ /* The variable into which error messages are latched. */ @@ -210,6 +217,7 @@ int main_full( void ) xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); xTaskCreate( prvPermanentlyBlockingSemaphoreTask, "BlockSem", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); xTaskCreate( prvPermanentlyBlockingNotificationTask, "BlockNoti", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); + xTaskCreate( prvDemonstrateChangingTimerReloadMode, "TimerMode", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL ); vStartMessageBufferTasks( configMINIMAL_STACK_SIZE ); vStartStreamBufferTasks(); @@ -815,5 +823,66 @@ static void prvPermanentlyBlockingNotificationTask( void *pvParameters ) configASSERT( pvParameters != NULL ); vTaskDelete( NULL ); } +/*-----------------------------------------------------------*/ + +static void prvReloadModeTestTimerCallback( TimerHandle_t xTimer ) +{ +uint32_t ulTimerID; + + /* Increment the timer's ID to show the callback has executed. */ + ulTimerID = ( uint32_t ) pvTimerGetTimerID( xTimer ); + ulTimerID++; + vTimerSetTimerID( xTimer, ( void * ) ulTimerID ); +} +/*-----------------------------------------------------------*/ +static void prvDemonstrateChangingTimerReloadMode( void *pvParameters ) +{ +TimerHandle_t xTimer; +const char * const pcTimerName = "TestTimer"; +const TickType_t x100ms = pdMS_TO_TICKS( 100UL ); + /* Avoid compiler warnings about unused parameter. */ + ( void ) pvParameters; + + xTimer = xTimerCreate( pcTimerName, + x100ms, + pdFALSE, /* Created as a one shot timer. */ + 0, + prvReloadModeTestTimerCallback ); + configASSERT( xTimer ); + configASSERT( xTimerIsTimerActive( xTimer ) == pdFALSE ); + configASSERT( xTimerGetTimerDaemonTaskHandle() != NULL ); + configASSERT( strcmp( pcTimerName, pcTimerGetName( xTimer ) ) == 0 ); + configASSERT( xTimerGetPeriod( xTimer ) == x100ms ); + + /* Timer was created as a one shot timer. Its callback just increments the + timer's ID - so set the ID to 0, let the timer run for a number of timeout + periods, then check the timer has only executed once. */ + vTimerSetTimerID( xTimer, ( void * ) 0 ); + xTimerStart( xTimer, portMAX_DELAY ); + vTaskDelay( 3UL * x100ms ); + configASSERT( ( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) ) == 1UL ); + + /* Now change the timer to be an autoreload timer and check it executes + the expected number of times. */ + vTimerSetReloadMode( xTimer, pdTRUE ); + vTimerSetTimerID( xTimer, ( void * ) 0 ); + xTimerStart( xTimer, 0 ); + vTaskDelay( ( 3UL * x100ms ) + ( x100ms / 2UL ) ); /* Three full periods. */ + configASSERT( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) == 3UL ); + configASSERT( xTimerStop( xTimer, 0 ) != pdFAIL ); + + /* Now change the timer back to be a one shot timer and check it only + executes once. */ + vTimerSetReloadMode( xTimer, pdFALSE ); + vTimerSetTimerID( xTimer, ( void * ) 0 ); + xTimerStart( xTimer, 0 ); + vTaskDelay( 3UL * x100ms ); + configASSERT( xTimerStop( xTimer, 0 ) != pdFAIL ); + configASSERT( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) == 1UL ); + + /* Clean up at the end. */ + xTimerDelete( xTimer, portMAX_DELAY ); + vTaskDelete( NULL ); +}