static void prvPendedFunctionCall( void *pvParameter1, uint32_t ulParameter2 )\r
{\r
uint32_t *pulCounter = ( uint32_t * ) pvParameter1;\r
- \r
+\r
/* Increment the paramater to show the pended function has executed. */\r
( *pulCounter )++;\r
}\r
static void prvTestTimerCallback( TimerHandle_t xTimer )\r
{\r
uint32_t ulTimerID;\r
- \r
+\r
/* Increment the timer's ID to show the callback has executed. */\r
ulTimerID = ( uint32_t ) pvTimerGetTimerID( xTimer );\r
ulTimerID++;\r
{\r
TimerHandle_t xTimer;\r
const char * const pcTimerName = "TestTimer";\r
-const TickType_t x10ms = pdMS_TO_TICKS( 3 );\r
+const TickType_t x3ms = pdMS_TO_TICKS( 3 );\r
uint32_t ulValueForTesting = 0;\r
- \r
- xTimer = xTimerCreate( pcTimerName, \r
- x10ms,\r
+\r
+ xTimer = xTimerCreate( pcTimerName,\r
+ x3ms,\r
pdFALSE, /* Created as a one shot timer. */\r
0,\r
prvTestTimerCallback );\r
- configASSERT( xTimer ); \r
+ configASSERT( xTimer );\r
configASSERT( xTimerIsTimerActive( xTimer ) == pdFALSE );\r
configASSERT( xTimerGetTimerDaemonTaskHandle() != NULL );\r
configASSERT( strcmp( pcTimerName, pcTimerGetName( xTimer ) ) == 0 );\r
- configASSERT( xTimerGetPeriod( xTimer ) == x10ms );\r
- configASSERT( xTimerGetExpiryTime( xTimer ) == 0 ); /* The timer has been created only. */\r
- \r
+ configASSERT( xTimerGetPeriod( xTimer ) == x3ms );\r
+\r
/* Pend a function then wait for it to execute. All it does is increment\r
its parameter. */\r
xTimerPendFunctionCall( prvPendedFunctionCall, &ulValueForTesting, 0, 0 );\r
- vTaskDelay( x10ms );\r
+ vTaskDelay( x3ms );\r
configASSERT( ulValueForTesting == 1 );\r
- \r
+\r
/* Timer was created as a one shot timer. Its callback just increments the\r
timer's ID - so set the ID to 0, let the timer run for a number of timeout\r
periods, then check the timer has only executed once. */\r
vTimerSetTimerID( xTimer, ( void * ) 0 );\r
xTimerStart( xTimer, 0 );\r
- vTaskDelay( 3UL * x10ms );\r
+ vTaskDelay( 3UL * x3ms );\r
configASSERT( ( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) ) == 1UL );\r
- \r
+\r
/* Now change the timer to be an autoreload timer and check it executes\r
the expected number of times. */\r
vTimerSetReloadMode( xTimer, pdTRUE );\r
xTimerStart( xTimer, 0 );\r
- vTaskDelay( 3UL * x10ms );\r
+ vTaskDelay( 3UL * x3ms );\r
configASSERT( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) > 3UL );\r
configASSERT( xTimerStop( xTimer, 0 ) != pdFAIL );\r
- \r
+\r
/* Clean up at the end. */\r
xTimerDelete( xTimer, portMAX_DELAY );\r
}\r
static void prvPermanentlyBlockingSemaphoreTask( void *pvParameters );\r
static void prvPermanentlyBlockingNotificationTask( void *pvParameters );\r
\r
+/*\r
+ * The test function and callback function used when exercising the timer AP\r
+ * function that changes the timer's autoreload mode.\r
+ */\r
+static void prvDemonstrateChangingTimerReloadMode( void *pvParameters );\r
+static void prvReloadModeTestTimerCallback( TimerHandle_t xTimer );\r
+\r
/*-----------------------------------------------------------*/\r
\r
/* The variable into which error messages are latched. */\r
xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
xTaskCreate( prvPermanentlyBlockingSemaphoreTask, "BlockSem", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
xTaskCreate( prvPermanentlyBlockingNotificationTask, "BlockNoti", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
+ xTaskCreate( prvDemonstrateChangingTimerReloadMode, "TimerMode", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );\r
\r
vStartMessageBufferTasks( configMINIMAL_STACK_SIZE );\r
vStartStreamBufferTasks();\r
configASSERT( pvParameters != NULL );\r
vTaskDelete( NULL );\r
}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvReloadModeTestTimerCallback( TimerHandle_t xTimer )\r
+{\r
+uint32_t ulTimerID;\r
+\r
+ /* Increment the timer's ID to show the callback has executed. */\r
+ ulTimerID = ( uint32_t ) pvTimerGetTimerID( xTimer );\r
+ ulTimerID++;\r
+ vTimerSetTimerID( xTimer, ( void * ) ulTimerID );\r
+}\r
+/*-----------------------------------------------------------*/\r
\r
+static void prvDemonstrateChangingTimerReloadMode( void *pvParameters )\r
+{\r
+TimerHandle_t xTimer;\r
+const char * const pcTimerName = "TestTimer";\r
+const TickType_t x100ms = pdMS_TO_TICKS( 100UL );\r
\r
+ /* Avoid compiler warnings about unused parameter. */\r
+ ( void ) pvParameters;\r
+\r
+ xTimer = xTimerCreate( pcTimerName,\r
+ x100ms,\r
+ pdFALSE, /* Created as a one shot timer. */\r
+ 0,\r
+ prvReloadModeTestTimerCallback );\r
+ configASSERT( xTimer );\r
+ configASSERT( xTimerIsTimerActive( xTimer ) == pdFALSE );\r
+ configASSERT( xTimerGetTimerDaemonTaskHandle() != NULL );\r
+ configASSERT( strcmp( pcTimerName, pcTimerGetName( xTimer ) ) == 0 );\r
+ configASSERT( xTimerGetPeriod( xTimer ) == x100ms );\r
+\r
+ /* Timer was created as a one shot timer. Its callback just increments the\r
+ timer's ID - so set the ID to 0, let the timer run for a number of timeout\r
+ periods, then check the timer has only executed once. */\r
+ vTimerSetTimerID( xTimer, ( void * ) 0 );\r
+ xTimerStart( xTimer, portMAX_DELAY );\r
+ vTaskDelay( 3UL * x100ms );\r
+ configASSERT( ( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) ) == 1UL );\r
+\r
+ /* Now change the timer to be an autoreload timer and check it executes\r
+ the expected number of times. */\r
+ vTimerSetReloadMode( xTimer, pdTRUE );\r
+ vTimerSetTimerID( xTimer, ( void * ) 0 );\r
+ xTimerStart( xTimer, 0 );\r
+ vTaskDelay( ( 3UL * x100ms ) + ( x100ms / 2UL ) ); /* Three full periods. */\r
+ configASSERT( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) == 3UL );\r
+ configASSERT( xTimerStop( xTimer, 0 ) != pdFAIL );\r
+\r
+ /* Now change the timer back to be a one shot timer and check it only\r
+ executes once. */\r
+ vTimerSetReloadMode( xTimer, pdFALSE );\r
+ vTimerSetTimerID( xTimer, ( void * ) 0 );\r
+ xTimerStart( xTimer, 0 );\r
+ vTaskDelay( 3UL * x100ms );\r
+ configASSERT( xTimerStop( xTimer, 0 ) != pdFAIL );\r
+ configASSERT( ( uint32_t ) ( pvTimerGetTimerID( xTimer ) ) == 1UL );\r
+\r
+ /* Clean up at the end. */\r
+ xTimerDelete( xTimer, portMAX_DELAY );\r
+ vTaskDelete( NULL );\r
+}\r