+/*-----------------------------------------------------------*/\r
+\r
+static void prvSaveTraceFile( void )\r
+{\r
+FILE* pxOutputFile;\r
+\r
+ fopen_s( &pxOutputFile, "Trace.dump", "wb");\r
+\r
+ if( pxOutputFile != NULL )\r
+ {\r
+ fwrite( RecorderDataPtr, sizeof( RecorderDataType ), 1, pxOutputFile );\r
+ fclose( pxOutputFile );\r
+ printf( "\r\nTrace output saved to Trace.dump\r\n" );\r
+ }\r
+ else\r
+ {\r
+ printf( "\r\nFailed to create trace dump file\r\n" );\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvDemonstrateTaskStateAndHandleGetFunctions( void )\r
+{\r
+xTaskHandle xIdleTaskHandle, xTimerTaskHandle;\r
+const unsigned char ucConstTaskNumber = 0x55U;\r
+signed char *pcTaskName;\r
+static portBASE_TYPE xPerformedOneShotTests = pdFALSE;\r
+xTaskHandle xTestTask;\r
+\r
+ /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and \r
+ xTaskGetIdleTaskHandle() functions. Also try using the function that sets\r
+ the task number. */\r
+ xIdleTaskHandle = xTaskGetIdleTaskHandle();\r
+ xTimerTaskHandle = xTimerGetTimerDaemonTaskHandle();\r
+ vTaskSetTaskNumber( xIdleTaskHandle, ( unsigned long ) ucConstTaskNumber );\r
+ configASSERT( uxTaskGetTaskNumber( xIdleTaskHandle ) == ucConstTaskNumber );\r
+\r
+ /* This is the idle hook, so the current task handle should equal the \r
+ returned idle task handle. */\r
+ if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle )\r
+ {\r
+ pcStatusMessage = "Error: Returned idle task handle was incorrect";\r
+ }\r
+\r
+ /* Check the timer task handle was returned correctly. */\r
+ pcTaskName = pcTaskGetTaskName( xTimerTaskHandle );\r
+ if( strcmp( pcTaskName, "Tmr Svc" ) != 0 )\r
+ {\r
+ pcStatusMessage = "Error: Returned timer task handle was incorrect";\r
+ }\r
+\r
+ /* This task is running, make sure it's state is returned as running. */\r
+ if( eTaskStateGet( xIdleTaskHandle ) != eRunning )\r
+ {\r
+ pcStatusMessage = "Error: Returned idle task state was incorrect";\r
+ }\r
+\r
+ /* If this task is running, then the timer task must be blocked. */\r
+ if( eTaskStateGet( xTimerTaskHandle ) != eBlocked )\r
+ {\r
+ pcStatusMessage = "Error: Returned timer task state was incorrect";\r
+ }\r
+\r
+ /* Other tests that should only be performed once follow. The test task\r
+ is not created on each iteration because to do so would cause the death\r
+ task to report an error (too many tasks running). */\r
+ if( xPerformedOneShotTests == pdFALSE )\r
+ {\r
+ /* Don't run this part of the test again. */\r
+ xPerformedOneShotTests = pdTRUE;\r
+\r
+ /* Create a test task to use to test other eTaskStateGet() return values. */\r
+ if( xTaskCreate( prvTestTask, "Test", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, &xTestTask ) == pdPASS )\r
+ {\r
+ /* If this task is running, the test task must be in the ready state. */\r
+ if( eTaskStateGet( xTestTask ) != eReady )\r
+ {\r
+ pcStatusMessage = "Error: Returned test task state was incorrect 1";\r
+ }\r
+\r
+ /* Now suspend the test task and check its state is reported correctly. */\r
+ vTaskSuspend( xTestTask );\r
+ if( eTaskStateGet( xTestTask ) != eSuspended )\r
+ {\r
+ pcStatusMessage = "Error: Returned test task state was incorrect 2";\r
+ }\r
+\r
+ /* Now delete the task and check its state is reported correctly. */\r
+ vTaskDelete( xTestTask );\r
+ if( eTaskStateGet( xTestTask ) != eDeleted )\r
+ {\r
+ pcStatusMessage = "Error: Returned test task state was incorrect 3";\r
+ }\r
+ }\r
+ }\r
+}\r