X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=FreeRTOS%2FDemo%2FWIN32-MingW%2Fmain_full.c;h=718c1e1b0a86edcc052fc646f43a7855cdecd2ce;hb=61a5601b461eea61201ee14fc20615ddecf8c259;hp=b8e06d184646cf1d7a8840e9b402f93356e9570d;hpb=cd1ad55ff8962389a69bcdcf56f129a017cd6bac;p=freertos diff --git a/FreeRTOS/Demo/WIN32-MingW/main_full.c b/FreeRTOS/Demo/WIN32-MingW/main_full.c index b8e06d184..718c1e1b0 100644 --- a/FreeRTOS/Demo/WIN32-MingW/main_full.c +++ b/FreeRTOS/Demo/WIN32-MingW/main_full.c @@ -1,6 +1,6 @@ /* - * FreeRTOS Kernel V10.0.1 - * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * FreeRTOS Kernel V10.2.1 + * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in @@ -46,7 +46,7 @@ * in main.c. This file implements the comprehensive test and demo version. * * NOTE 3: This file only contains the source code that is specific to the - * basic demo. Generic functions, such FreeRTOS hook functions, are defined in + * full demo. Generic functions, such FreeRTOS hook functions, are defined in * main.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 auto-reload mode. + */ +static void prvDemonstrateChangingTimerReloadMode( void *pvParameters ); +static void prvReloadModeTestTimerCallback( TimerHandle_t xTimer ); + /*-----------------------------------------------------------*/ /* The variable into which error messages are latched. */ @@ -201,7 +208,7 @@ int main_full( void ) vStartDynamicPriorityTasks(); vStartQueueSetTasks(); vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY ); - xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); + xTaskCreate( prvDemoQueueSpaceFunctions, NULL, configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); /* Name is null for code coverage. */ vStartEventGroupTasks(); vStartInterruptSemaphoreTasks(); vStartQueueSetPollingTask(); @@ -210,11 +217,12 @@ 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(); + vStartMessageBufferTasks( configMINIMAL_STACK_SIZE ); vStartStreamBufferTasks(); vStartStreamBufferInterruptDemo(); - vStartMessageBufferAMPTasks(); + vStartMessageBufferAMPTasks( configMINIMAL_STACK_SIZE ); #if( configSUPPORT_STATIC_ALLOCATION == 1 ) { @@ -252,6 +260,7 @@ static void prvCheckTask( void *pvParameters ) { TickType_t xNextWakeTime; const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL ); +HeapStats_t xHeapStats; /* Just to remove compiler warning. */ ( void ) pvParameters; @@ -377,10 +386,19 @@ const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL ); /* This is the only task that uses stdout so its ok to call printf() directly. */ - printf( "%s - tick count %u - free heap %u - min free heap %u\r\n", pcStatusMessage, - xTaskGetTickCount(), - xPortGetFreeHeapSize(), - xPortGetMinimumEverFreeHeapSize() ); + vPortGetHeapStats( &xHeapStats ); + + configASSERT( xHeapStats.xAvailableHeapSpaceInBytes == xPortGetFreeHeapSize() ); + configASSERT( xHeapStats.xMinimumEverFreeBytesRemaining == xPortGetMinimumEverFreeHeapSize() ); + + printf( "%s - tick count %u - free heap %u - min free heap %u - largest free block %u - number of free blocks %u\r\n", + pcStatusMessage, + xTaskGetTickCount(), + xHeapStats.xAvailableHeapSpaceInBytes, + xHeapStats.xMinimumEverFreeBytesRemaining, + xHeapStats.xSizeOfLargestFreeBlockInBytes, + xHeapStats.xNumberOfFreeBlocks ); + fflush( stdout ); } } @@ -609,6 +627,8 @@ static portBASE_TYPE xPerformedOneShotTests = pdFALSE; TaskHandle_t xTestTask; TaskStatus_t xTaskInfo; extern StackType_t uxTimerTaskStack[]; +static TickType_t xLastIdleExecutionTime = 0; +TickType_t xIdleExecutionTime; /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and xTaskGetIdleTaskHandle() functions. Also try using the function that sets @@ -707,6 +727,13 @@ extern StackType_t uxTimerTaskStack[]; } } } + + xIdleExecutionTime = xTaskGetIdleRunTimeCounter(); + if( xIdleExecutionTime == xLastIdleExecutionTime ) + { + pcStatusMessage = "Error: Total amount of Idle task execution time did not change"; + } + xLastIdleExecutionTime = xIdleExecutionTime; } /*-----------------------------------------------------------*/ @@ -815,5 +842,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 auto-reload 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 ); +}