#define INCLUDE_eTaskGetState 1\r
#define INCLUDE_xSemaphoreGetMutexHolder 1\r
\r
-extern void vAssertCalled( void );\r
-#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled()\r
+/* Standard assert semantics. */\r
+extern void vAssertCalled( unsigned long ulLine, const char * const pcFileName );\r
+#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __LINE__, __FILE__ )\r
\r
/* configUSE_PORT_OPTIMISED_TASK_SELECTION is only available in the MSVC \r
version of the Win32 simulator projects. It will be ignored in the GCC\r
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
</ClCompile>\r
+ <ClCompile Include="main_blinky.c" />\r
+ <ClCompile Include="main_full.c" />\r
<ClCompile Include="Run-time-stats-utils.c" />\r
</ItemGroup>\r
<ItemGroup>\r
<ClCompile Include="..\Common\Minimal\QueueOverwrite.c">\r
<Filter>Demo App Source\Common Demo Tasks</Filter>\r
</ClCompile>\r
+ <ClCompile Include="main_full.c">\r
+ <Filter>Demo App Source</Filter>\r
+ </ClCompile>\r
+ <ClCompile Include="main_blinky.c">\r
+ <Filter>Demo App Source</Filter>\r
+ </ClCompile>\r
</ItemGroup>\r
<ItemGroup>\r
<ClInclude Include="FreeRTOSConfig.h">\r
mission critical applications that require provable dependability.\r
*/\r
\r
-/*\r
+/******************************************************************************\r
+ * This project provides two demo applications. A simple blinky style project,\r
+ * and a more comprehensive test and demo application. The\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two. \r
+ * The simply blinky demo is implemented and described in main_blinky.c. The \r
+ * more comprehensive test and demo application is implemented and described in \r
+ * main_full.c.\r
+ *\r
+ * This file implements the code that is not demo specific, including the\r
+ * hardware setup and FreeRTOS hook functions.\r
+ *\r
*******************************************************************************\r
* -NOTE- The Win32 port is a simulation (or is that emulation?) only! Do not\r
* expect to get real time behaviour from the Win32 port or this demo\r
* - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT -\r
*******************************************************************************\r
*\r
- * main() creates all the demo application tasks, then starts the scheduler. \r
- * The web documentation provides more details of the standard demo application \r
- * tasks, which provide no particular functionality but do provide a good \r
- * example of how to use the FreeRTOS API.\r
- *\r
- * In addition to the standard demo tasks, the following tasks and tests are\r
- * defined and/or created within this file:\r
- *\r
- * "Check" task - This only executes every five seconds but has a high priority\r
- * to ensure it gets processor time. Its main function is to check that all the\r
- * standard demo tasks are still operational. While no errors have been\r
- * discovered the check task will print out "OK" and the current simulated tick\r
- * time. If an error is discovered in the execution of a task then the check\r
- * task will print out an appropriate error message.\r
- *\r
*/\r
\r
-\r
/* Standard includes. */\r
#include <stdio.h>\r
#include <stdlib.h>\r
#include <conio.h>\r
\r
-/* Kernel includes. */\r
-#include <FreeRTOS.h>\r
+/* FreeRTOS kernel includes. */\r
+#include "FreeRTOS.h"\r
#include "task.h"\r
-#include "queue.h"\r
-#include "timers.h"\r
-#include "semphr.h"\r
-\r
-/* Standard demo includes. */\r
-#include "BlockQ.h"\r
-#include "integer.h"\r
-#include "semtest.h"\r
-#include "PollQ.h"\r
-#include "GenQTest.h"\r
-#include "QPeek.h"\r
-#include "recmutex.h"\r
-#include "flop.h"\r
-#include "TimerDemo.h"\r
-#include "countsem.h"\r
-#include "death.h"\r
-#include "dynamic.h"\r
-#include "QueueSet.h"\r
-#include "QueueOverwrite.h"\r
-\r
-/* Priorities at which the tasks are created. */\r
-#define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )\r
-#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
-#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
-#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
-#define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )\r
-#define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
-#define mainuIP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
-#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
-#define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
-#define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
-#define mainQUEUE_OVERWRITE_PRIORITY ( tskIDLE_PRIORITY )\r
-\r
-#define mainTIMER_TEST_PERIOD ( 50 )\r
-\r
-/* Task function prototypes. */\r
-static void prvCheckTask( void *pvParameters );\r
-\r
-/* A task that is created from the idle task to test the functionality of \r
-eTaskStateGet(). */\r
-static void prvTestTask( void *pvParameters );\r
+\r
+/* This project provides two demo applications. A simple blinky style project,\r
+and a more comprehensive test and demo application. The\r
+mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is used to select between the two. \r
+The simply blinky demo is implemented and described in main_blinky.c. The more \r
+comprehensive test and demo application is implemented and described in \r
+main_full.c. */\r
+#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1\r
\r
/*\r
- * Writes trace data to a disk file when the trace recording is stopped.\r
- * This function will simply overwrite any trace files that already exist.\r
+ * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
+ * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
*/\r
-static void prvSaveTraceFile( void );\r
+extern void main_blinky( void );\r
+extern void main_full( void );\r
+\r
+/* Some of the RTOS hook (callback) functions only need special processing when\r
+the full demo is being used. The simply blinky demo has no special requirements,\r
+so these functions are called from the hook functions defined in this file, but\r
+are defined in main_full.c. */\r
+void vFullDemoTickHookFunction( void );\r
+void vFullDemoIdleFunction( void );\r
+\r
+/* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
+within this file. */\r
+void vApplicationMallocFailedHook( void );\r
+void vApplicationIdleHook( void );\r
+void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName );\r
+void vApplicationTickHook( void );\r
\r
/*\r
- * Called from the idle task hook function to demonstrate a few utility\r
- * functions that are not demonstrated by any of the standard demo tasks.\r
+ * Writes trace data to a disk file when the trace recording is stopped.\r
+ * This function will simply overwrite any trace files that already exist.\r
*/\r
-static void prvDemonstrateTaskStateAndHandleGetFunctions( void );\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-/* The variable into which error messages are latched. */\r
-static char *pcStatusMessage = "OK";\r
-\r
-/* This semaphore is created purely to test using the vSemaphoreDelete() and\r
-semaphore tracing API functions. It has no other purpose. */\r
-static xSemaphoreHandle xMutexToDelete = NULL;\r
+static void prvSaveTraceFile( void );\r
\r
/* The user trace event posted to the trace recording on each tick interrupt.\r
Note tick events will not appear in the trace recording with regular period\r
because this project runs in a Windows simulator, and does not therefore\r
exhibit deterministic behaviour. */\r
traceLabel xTickTraceUserEvent;\r
+static portBASE_TYPE xTraceRunning = pdTRUE;\r
\r
/*-----------------------------------------------------------*/\r
\r
vTraceInitTraceData();\r
xTickTraceUserEvent = xTraceOpenLabel( "tick" );\r
\r
- /* Start the check task as described at the top of this file. */\r
- xTaskCreate( prvCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
-\r
- /* Create the standard demo tasks. */\r
- vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
- vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
- vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
- vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
- vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
- vStartQueuePeekTasks();\r
- vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
- vStartRecursiveMutexTasks();\r
- vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
- vStartCountingSemaphoreTasks();\r
- vStartDynamicPriorityTasks();\r
- vStartQueueSetTasks();\r
- vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY );\r
-\r
- /* The suicide tasks must be created last as they need to know how many\r
- tasks were running prior to their creation. This then allows them to \r
- ascertain whether or not the correct/expected number of tasks are running at \r
- any given time. */\r
- vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
-\r
- /* Create the semaphore that will be deleted in the idle task hook. This\r
- is done purely to test the use of vSemaphoreDelete(). */\r
- xMutexToDelete = xSemaphoreCreateMutex();\r
-\r
/* Start the trace recording - the recording is written to a file if\r
configASSERT() is called. */\r
printf( "\r\nTrace started. Hit a key to dump trace file to disk.\r\n" );\r
uiTraceStart();\r
\r
- /* Start the scheduler itself. */\r
- vTaskStartScheduler();\r
-\r
- /* Should never get here unless there was not enough heap space to create \r
- the idle and other system tasks. */\r
- return 0;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvCheckTask( void *pvParameters )\r
-{\r
-portTickType xNextWakeTime;\r
-const portTickType xCycleFrequency = 1000 / portTICK_RATE_MS;\r
-\r
- /* Just to remove compiler warning. */\r
- ( void ) pvParameters;\r
-\r
- /* Initialise xNextWakeTime - this only needs to be done once. */\r
- xNextWakeTime = xTaskGetTickCount();\r
-\r
- for( ;; )\r
+ /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
+ of this file. */\r
+ #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r
{\r
- /* Place this task in the blocked state until it is time to run again. */\r
- vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );\r
-\r
- /* Check the standard demo tasks are running without error. */\r
- if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )\r
- {\r
- pcStatusMessage = "Error: TimerDemo";\r
- }\r
- else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "Error: IntMath";\r
- } \r
- else if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
- { \r
- pcStatusMessage = "Error: GenQueue";\r
- }\r
- else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "Error: QueuePeek";\r
- }\r
- else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "Error: BlockQueue";\r
- }\r
- else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "Error: SemTest";\r
- }\r
- else if( xArePollingQueuesStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "Error: PollQueue";\r
- }\r
- else if( xAreMathsTaskStillRunning() != pdPASS )\r
- {\r
- pcStatusMessage = "Error: Flop";\r
- }\r
- else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "Error: RecMutex";\r
- }\r
- else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "Error: CountSem";\r
- }\r
- else if( xIsCreateTaskStillRunning() != pdTRUE )\r
- {\r
- pcStatusMessage = "Error: Death";\r
- }\r
- else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )\r
- {\r
- pcStatusMessage = "Error: Dynamic\r\n";\r
- }\r
- else if( xAreQueueSetTasksStillRunning() != pdPASS )\r
- {\r
- pcStatusMessage = "Error: Queue set\r\n";\r
- }\r
- else if( xIsQueueOverwriteTaskStillRunning() != pdPASS )\r
- {\r
- pcStatusMessage = "Error: Queue overwrite\r\n";\r
- }\r
-\r
- /* This is the only task that uses stdout so its ok to call printf() \r
- directly. */\r
- printf( "%s - %d\r\n", pcStatusMessage, xTaskGetTickCount() );\r
+ main_blinky();\r
}\r
+ #else\r
+ {\r
+ main_full();\r
+ }\r
+ #endif\r
+\r
+ return 0;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static void prvTestTask( void *pvParameters )\r
+void vApplicationMallocFailedHook( void )\r
{\r
-const unsigned long ulMSToSleep = 5;\r
-\r
- /* Just to remove compiler warnings. */\r
- ( void ) pvParameters;\r
-\r
- /* This task is just used to test the eTaskStateGet() function. It\r
- does not have anything to do. */\r
- for( ;; )\r
- {\r
- /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are\r
- tasks waiting to be terminated by the idle task. */\r
- Sleep( ulMSToSleep );\r
- }\r
+ /* vApplicationMallocFailedHook() will only be called if\r
+ configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook\r
+ function that will get called if a call to pvPortMalloc() fails.\r
+ pvPortMalloc() is called internally by the kernel whenever a task, queue,\r
+ timer or semaphore is created. It is also called by various parts of the\r
+ demo application. If heap_1.c or heap_2.c are used, then the size of the\r
+ heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in\r
+ FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used\r
+ to query the size of free heap space that remains (although it does not\r
+ provide information on how the remaining heap might be fragmented). */\r
+ vAssertCalled( __LINE__, __FILE__ );\r
}\r
/*-----------------------------------------------------------*/\r
\r
void vApplicationIdleHook( void )\r
{\r
-const unsigned long ulMSToSleep = 15;\r
-const unsigned char ucConstQueueNumber = 0xaaU;\r
-void *pvAllocated;\r
-static portBASE_TYPE xTraceRunning = pdTRUE;\r
-\r
-/* These three functions are only meant for use by trace code, and not for\r
-direct use from application code, hence their prototypes are not in queue.h. */\r
-extern void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber );\r
-extern unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue );\r
-extern unsigned char ucQueueGetQueueType( xQueueHandle pxQueue );\r
-extern void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle );\r
-extern unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask );\r
-\r
- /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are\r
- tasks waiting to be terminated by the idle task. */\r
- Sleep( ulMSToSleep );\r
-\r
- /* Demonstrate a few utility functions that are not demonstrated by any of\r
- the standard demo tasks. */\r
- prvDemonstrateTaskStateAndHandleGetFunctions();\r
-\r
- /* If xMutexToDelete has not already been deleted, then delete it now.\r
- This is done purely to demonstrate the use of, and test, the \r
- vSemaphoreDelete() macro. Care must be taken not to delete a semaphore\r
- that has tasks blocked on it. */\r
- if( xMutexToDelete != NULL )\r
- {\r
- /* Before deleting the semaphore, test the function used to set its\r
- number. This would normally only be done from trace software, rather\r
- than application code. */\r
- vQueueSetQueueNumber( xMutexToDelete, ucConstQueueNumber );\r
-\r
- /* Before deleting the semaphore, test the functions used to get its\r
- type and number. Again, these would normally only be done from trace\r
- software, rather than application code. */\r
- configASSERT( ucQueueGetQueueNumber( xMutexToDelete ) == ucConstQueueNumber );\r
- configASSERT( ucQueueGetQueueType( xMutexToDelete ) == queueQUEUE_TYPE_MUTEX );\r
- vSemaphoreDelete( xMutexToDelete );\r
- xMutexToDelete = NULL;\r
- }\r
-\r
- /* Exercise heap_4 a bit. The malloc failed hook will trap failed \r
- allocations so there is no need to test here. */\r
- pvAllocated = pvPortMalloc( ( rand() % 100 ) + 1 );\r
- vPortFree( pvAllocated );\r
-\r
+ /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set\r
+ to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle\r
+ task. It is essential that code added to this hook function never attempts\r
+ to block in any way (for example, call xQueueReceive() with a block time\r
+ specified, or call vTaskDelay()). If the application makes use of the\r
+ vTaskDelete() API function (as this demo application does) then it is also\r
+ important that vApplicationIdleHook() is permitted to return to its calling\r
+ function, because it is the responsibility of the idle task to clean up\r
+ memory allocated by the kernel to any task that has since been deleted. */\r
+\r
+ /* The trace can be stopped with any key press. */\r
if( _kbhit() != pdFALSE )\r
{\r
if( xTraceRunning == pdTRUE )\r
{\r
+ vTraceStop();\r
prvSaveTraceFile();\r
xTraceRunning = pdFALSE;\r
}\r
}\r
-}\r
-/*-----------------------------------------------------------*/\r
\r
-void vApplicationMallocFailedHook( void )\r
-{\r
- vAssertCalled();\r
+ #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1 )\r
+ {\r
+ /* Call the idle task processing used by the full demo. The simple\r
+ blinky demo does not use the idle task hook. */\r
+ vFullDemoIdleFunction();\r
+ }\r
+ #endif\r
}\r
/*-----------------------------------------------------------*/\r
\r
-void vApplicationStackOverflowHook( void )\r
+void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )\r
{\r
- /* Can be implemented if required, but not required in this \r
- environment and running this demo. */\r
+ ( void ) pcTaskName;\r
+ ( void ) pxTask;\r
+\r
+ /* Run time stack overflow checking is performed if\r
+ configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook\r
+ function is called if a stack overflow is detected. */\r
+ vAssertCalled( __LINE__, __FILE__ );\r
}\r
/*-----------------------------------------------------------*/\r
\r
void vApplicationTickHook( void )\r
{\r
- /* Call the periodic timer test, which tests the timer API functions that\r
- can be called from an ISR. */\r
- vTimerPeriodicISRTests();\r
-\r
- /* Call the periodic queue overwrite from ISR demo. */\r
- vQueueOverwritePeriodicISRDemo();\r
+ /* This function will be called by each tick interrupt if\r
+ configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be\r
+ added here, but the tick hook is called from an interrupt context, so\r
+ code must not attempt to block, and only the interrupt safe FreeRTOS API\r
+ functions can be used (those that end in FromISR()). */\r
\r
- /* Write to a queue that is in use as part of the queue set demo to \r
- demonstrate using queue sets from an ISR. */\r
- vQueueSetAccessQueueSetFromISR();\r
+ #if ( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1 )\r
+ {\r
+ vFullDemoTickHookFunction();\r
+ }\r
+ #endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */\r
\r
/* Write a user event to the trace log. \r
Note tick events will not appear in the trace recording with regular period\r
because this project runs in a Windows simulator, and does not therefore\r
- exhibit deterministic behaviour. */\r
+ exhibit deterministic behaviour. Windows will run the simulator in \r
+ bursts. */\r
vTraceUserEvent( xTickTraceUserEvent );\r
}\r
/*-----------------------------------------------------------*/\r
\r
-void vAssertCalled( void )\r
+void vAssertCalled( unsigned long ulLine, const char * const pcFileName )\r
{\r
+ /* Parameters are not used. */\r
+ ( void ) ulLine;\r
+ ( void ) pcFileName;\r
+\r
taskDISABLE_INTERRUPTS();\r
\r
/* Stop the trace recording. */\r
- vTraceStop();\r
- prvSaveTraceFile();\r
+ if( xTraceRunning == pdTRUE )\r
+ {\r
+ vTraceStop();\r
+ prvSaveTraceFile();\r
+ }\r
\r
for( ;; );\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
-\r
--- /dev/null
+/*\r
+ FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.\r
+\r
+ FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT\r
+ http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * FreeRTOS tutorial books are available in pdf and paperback. *\r
+ * Complete, revised, and edited pdf reference manuals are also *\r
+ * available. *\r
+ * *\r
+ * Purchasing FreeRTOS documentation will not only help you, by *\r
+ * ensuring you get running as quickly as possible and with an *\r
+ * in-depth knowledge of how to use FreeRTOS, it will also help *\r
+ * the FreeRTOS project to continue with its mission of providing *\r
+ * professional grade, cross platform, de facto standard solutions *\r
+ * for microcontrollers - completely free of charge! *\r
+ * *\r
+ * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
+ * *\r
+ * Thank you for using FreeRTOS, and thank you for your support! *\r
+ * *\r
+ ***************************************************************************\r
+\r
+\r
+ This file is part of the FreeRTOS distribution.\r
+\r
+ FreeRTOS is free software; you can redistribute it and/or modify it under\r
+ the terms of the GNU General Public License (version 2) as published by the\r
+ Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
+\r
+ >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to\r
+ distribute a combined work that includes FreeRTOS without being obliged to\r
+ provide the source code for proprietary components outside of the FreeRTOS\r
+ kernel.\r
+\r
+ FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\r
+ details. You should have received a copy of the GNU General Public License\r
+ and the FreeRTOS license exception along with FreeRTOS; if not it can be\r
+ viewed here: http://www.freertos.org/a00114.html and also obtained by\r
+ writing to Real Time Engineers Ltd., contact details for whom are available\r
+ on the FreeRTOS WEB site.\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * Having a problem? Start by reading the FAQ "My application does *\r
+ * not run, what could be wrong?" *\r
+ * *\r
+ * http://www.FreeRTOS.org/FAQHelp.html *\r
+ * *\r
+ ***************************************************************************\r
+\r
+\r
+ http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
+ license and Real Time Engineers Ltd. contact details.\r
+\r
+ http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
+ including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
+ fully thread aware and reentrant UDP/IP stack.\r
+\r
+ http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
+ Integrity Systems, who sell the code with commercial support,\r
+ indemnification and middleware, under the OpenRTOS brand.\r
+\r
+ http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
+ engineered and independently SIL3 certified version for use in safety and\r
+ mission critical applications that require provable dependability.\r
+*/\r
+\r
+/******************************************************************************\r
+ * NOTE 1: The Win32 port is a simulation (or is that emulation?) only! Do not\r
+ * expect to get real time behaviour from the Win32 port or this demo\r
+ * application. It is provided as a convenient development and demonstration\r
+ * test bed only. This was tested using Windows XP on a dual core laptop.\r
+ *\r
+ * In this example, one simulated millisecond will take approximately 40ms to\r
+ * execute, and Windows will not be running the FreeRTOS simulator threads\r
+ * continuously, so the timing information in the FreeRTOS+Trace logs have no\r
+ * meaningful units. See the documentation page for the Windows simulator for\r
+ * an explanation of the slow timing:\r
+ * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html\r
+ * - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT -\r
+ *\r
+ * NOTE 2: This project provides two demo applications. A simple blinky style\r
+ * project, and a more comprehensive test and demo application. The\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select \r
+ * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY \r
+ * in main.c. This file implements the simply blinky style version.\r
+ *\r
+ * NOTE 3: This file only contains the source code that is specific to the\r
+ * basic demo. Generic functions, such FreeRTOS hook functions, are defined \r
+ * in main.c.\r
+ ******************************************************************************\r
+ *\r
+ * main_blinky() creates one queue, and two tasks. It then starts the\r
+ * scheduler.\r
+ *\r
+ * The Queue Send Task:\r
+ * The queue send task is implemented by the prvQueueSendTask() function in\r
+ * this file. prvQueueSendTask() sits in a loop that causes it to repeatedly\r
+ * block for 200 (simulated as far as the scheduler is concerned, but in\r
+ * reality much longer - see notes above) milliseconds, before sending the \r
+ * value 100 to the queue that was created within main_blinky(). Once the \r
+ * value is sent, the task loops back around to block for another 200 \r
+ * (simulated) milliseconds.\r
+ *\r
+ * The Queue Receive Task:\r
+ * The queue receive task is implemented by the prvQueueReceiveTask() function\r
+ * in this file. prvQueueReceiveTask() sits in a loop where it repeatedly\r
+ * blocks on attempts to read data from the queue that was created within\r
+ * main_blinky(). When data is received, the task checks the value of the\r
+ * data, and if the value equals the expected 100, outputs a message. The \r
+ * 'block time' parameter passed to the queue receive function specifies that \r
+ * the task should be held in the Blocked state indefinitely to wait for data \r
+ * to be available on the queue. The queue receive task will only leave the\r
+ * Blocked state when the queue send task writes to the queue. As the queue\r
+ * send task writes to the queue every 200 (simulated - see notes above) \r
+ * milliseconds, the queue receive task leaves the Blocked state every 200 \r
+ * milliseconds, and therefore outputs a message every 200 milliseconds.\r
+ */\r
+\r
+/* Standard includes. */\r
+#include <stdio.h>\r
+\r
+/* Kernel includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "semphr.h"\r
+\r
+/* Priorities at which the tasks are created. */\r
+#define mainQUEUE_RECEIVE_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
+#define mainQUEUE_SEND_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
+\r
+/* The rate at which data is sent to the queue. The 200ms value is converted\r
+to ticks using the portTICK_RATE_MS constant. */\r
+#define mainQUEUE_SEND_FREQUENCY_MS ( 200 / portTICK_RATE_MS )\r
+\r
+/* The number of items the queue can hold. This is 1 as the receive task\r
+will remove items as they are added, meaning the send task should always find\r
+the queue empty. */\r
+#define mainQUEUE_LENGTH ( 1 )\r
+\r
+/* Values passed to the two tasks just to check the task parameter\r
+functionality. */\r
+#define mainQUEUE_SEND_PARAMETER ( 0x1111UL )\r
+#define mainQUEUE_RECEIVE_PARAMETER ( 0x22UL )\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * The tasks as described in the comments at the top of this file.\r
+ */\r
+static void prvQueueReceiveTask( void *pvParameters );\r
+static void prvQueueSendTask( void *pvParameters );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The queue used by both tasks. */\r
+static xQueueHandle xQueue = NULL;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void main_blinky( void )\r
+{\r
+ /* Create the queue. */\r
+ xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
+\r
+ if( xQueue != NULL )\r
+ {\r
+ /* Start the two tasks as described in the comments at the top of this\r
+ file. */\r
+ xTaskCreate( prvQueueReceiveTask, /* The function that implements the task. */\r
+ ( signed char * ) "Rx", /* The text name assigned to the task - for debug only as it is not used by the kernel. */\r
+ configMINIMAL_STACK_SIZE, /* The size of the stack to allocate to the task. */\r
+ ( void * ) mainQUEUE_RECEIVE_PARAMETER, /* The parameter passed to the task - just to check the functionality. */\r
+ mainQUEUE_RECEIVE_TASK_PRIORITY, /* The priority assigned to the task. */\r
+ NULL ); /* The task handle is not required, so NULL is passed. */\r
+\r
+ xTaskCreate( prvQueueSendTask, ( signed char * ) "TX", configMINIMAL_STACK_SIZE, ( void * ) mainQUEUE_SEND_PARAMETER, mainQUEUE_SEND_TASK_PRIORITY, NULL );\r
+\r
+ /* Start the tasks and timer running. */\r
+ vTaskStartScheduler();\r
+ }\r
+\r
+ /* If all is well, the scheduler will now be running, and the following\r
+ line will never be reached. If the following line does execute, then\r
+ there was insufficient FreeRTOS heap memory available for the idle and/or\r
+ timer tasks to be created. See the memory management section on the\r
+ FreeRTOS web site for more details. */\r
+ for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvQueueSendTask( void *pvParameters )\r
+{\r
+portTickType xNextWakeTime;\r
+const unsigned long ulValueToSend = 100UL;\r
+\r
+ /* Check the task parameter is as expected. */\r
+ configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_SEND_PARAMETER );\r
+\r
+ /* Initialise xNextWakeTime - this only needs to be done once. */\r
+ xNextWakeTime = xTaskGetTickCount();\r
+\r
+ for( ;; )\r
+ {\r
+ /* Place this task in the blocked state until it is time to run again.\r
+ The block time is specified in ticks, the constant used converts ticks\r
+ to ms. While in the Blocked state this task will not consume any CPU\r
+ time. */\r
+ vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
+\r
+ /* Send to the queue - causing the queue receive task to unblock and\r
+ toggle the LED. 0 is used as the block time so the sending operation\r
+ will not block - it shouldn't need to block as the queue should always\r
+ be empty at this point in the code. */\r
+ xQueueSend( xQueue, &ulValueToSend, 0U );\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvQueueReceiveTask( void *pvParameters )\r
+{\r
+unsigned long ulReceivedValue;\r
+\r
+ /* Check the task parameter is as expected. */\r
+ configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_RECEIVE_PARAMETER );\r
+\r
+ for( ;; )\r
+ {\r
+ /* Wait until something arrives in the queue - this task will block\r
+ indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
+ FreeRTOSConfig.h. */\r
+ xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
+\r
+ /* To get here something must have been received from the queue, but\r
+ is it the expected value? If it is, toggle the LED. */\r
+ if( ulReceivedValue == 100UL )\r
+ {\r
+ /* Normally calling printf() from a task is not a good idea. Here\r
+ there is lots of stack space and only one task is using console IO\r
+ so it is ok. */\r
+ printf( "Message received\r\n" );\r
+ ulReceivedValue = 0U;\r
+ }\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
--- /dev/null
+/*\r
+ FreeRTOS V7.4.2 - Copyright (C) 2013 Real Time Engineers Ltd.\r
+\r
+ FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT\r
+ http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * FreeRTOS tutorial books are available in pdf and paperback. *\r
+ * Complete, revised, and edited pdf reference manuals are also *\r
+ * available. *\r
+ * *\r
+ * Purchasing FreeRTOS documentation will not only help you, by *\r
+ * ensuring you get running as quickly as possible and with an *\r
+ * in-depth knowledge of how to use FreeRTOS, it will also help *\r
+ * the FreeRTOS project to continue with its mission of providing *\r
+ * professional grade, cross platform, de facto standard solutions *\r
+ * for microcontrollers - completely free of charge! *\r
+ * *\r
+ * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
+ * *\r
+ * Thank you for using FreeRTOS, and thank you for your support! *\r
+ * *\r
+ ***************************************************************************\r
+\r
+\r
+ This file is part of the FreeRTOS distribution.\r
+\r
+ FreeRTOS is free software; you can redistribute it and/or modify it under\r
+ the terms of the GNU General Public License (version 2) as published by the\r
+ Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
+\r
+ >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to\r
+ distribute a combined work that includes FreeRTOS without being obliged to\r
+ provide the source code for proprietary components outside of the FreeRTOS\r
+ kernel.\r
+\r
+ FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
+ FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\r
+ details. You should have received a copy of the GNU General Public License\r
+ and the FreeRTOS license exception along with FreeRTOS; if not it can be\r
+ viewed here: http://www.freertos.org/a00114.html and also obtained by\r
+ writing to Real Time Engineers Ltd., contact details for whom are available\r
+ on the FreeRTOS WEB site.\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * Having a problem? Start by reading the FAQ "My application does *\r
+ * not run, what could be wrong?" *\r
+ * *\r
+ * http://www.FreeRTOS.org/FAQHelp.html *\r
+ * *\r
+ ***************************************************************************\r
+\r
+\r
+ http://www.FreeRTOS.org - Documentation, books, training, latest versions, \r
+ license and Real Time Engineers Ltd. contact details.\r
+\r
+ http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
+ including FreeRTOS+Trace - an indispensable productivity tool, and our new\r
+ fully thread aware and reentrant UDP/IP stack.\r
+\r
+ http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High \r
+ Integrity Systems, who sell the code with commercial support, \r
+ indemnification and middleware, under the OpenRTOS brand.\r
+ \r
+ http://www.SafeRTOS.com - High Integrity Systems also provide a safety \r
+ engineered and independently SIL3 certified version for use in safety and \r
+ mission critical applications that require provable dependability.\r
+*/\r
+\r
+/*\r
+ *******************************************************************************\r
+ * NOTE 1: The Win32 port is a simulation (or is that emulation?) only! Do not\r
+ * expect to get real time behaviour from the Win32 port or this demo\r
+ * application. It is provided as a convenient development and demonstration\r
+ * test bed only. This was tested using Windows XP on a dual core laptop.\r
+ *\r
+ * In this example, one simulated millisecond will take approximately 40ms to\r
+ * execute, and Windows will not be running the FreeRTOS simulator threads\r
+ * continuously, so the timing information in the FreeRTOS+Trace logs have no\r
+ * meaningful units. See the documentation page for the Windows simulator for\r
+ * an explanation of the slow timing:\r
+ * http://www.freertos.org/FreeRTOS-Windows-Simulator-Emulator-for-Visual-Studio-and-Eclipse-MingW.html\r
+ * - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT -\r
+ *\r
+ * NOTE 2: This project provides two demo applications. A simple blinky style\r
+ * project, and a more comprehensive test and demo application. The\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select \r
+ * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY \r
+ * in main.c. This file implements the comprehensive test and demo version.\r
+ *\r
+ * NOTE 3: This file only contains the source code that is specific to the\r
+ * basic demo. Generic functions, such FreeRTOS hook functions, are defined in \r
+ * main.c.\r
+ *******************************************************************************\r
+ *\r
+ * main() creates all the demo application tasks, then starts the scheduler. \r
+ * The web documentation provides more details of the standard demo application \r
+ * tasks, which provide no particular functionality but do provide a good \r
+ * example of how to use the FreeRTOS API.\r
+ *\r
+ * In addition to the standard demo tasks, the following tasks and tests are\r
+ * defined and/or created within this file:\r
+ *\r
+ * "Check" task - This only executes every five seconds but has a high priority\r
+ * to ensure it gets processor time. Its main function is to check that all the\r
+ * standard demo tasks are still operational. While no errors have been\r
+ * discovered the check task will print out "OK" and the current simulated tick\r
+ * time. If an error is discovered in the execution of a task then the check\r
+ * task will print out an appropriate error message.\r
+ *\r
+ */\r
+\r
+\r
+/* Standard includes. */\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+\r
+/* Kernel includes. */\r
+#include <FreeRTOS.h>\r
+#include "task.h"\r
+#include "queue.h"\r
+#include "timers.h"\r
+#include "semphr.h"\r
+\r
+/* Standard demo includes. */\r
+#include "BlockQ.h"\r
+#include "integer.h"\r
+#include "semtest.h"\r
+#include "PollQ.h"\r
+#include "GenQTest.h"\r
+#include "QPeek.h"\r
+#include "recmutex.h"\r
+#include "flop.h"\r
+#include "TimerDemo.h"\r
+#include "countsem.h"\r
+#include "death.h"\r
+#include "dynamic.h"\r
+#include "QueueSet.h"\r
+#include "QueueOverwrite.h"\r
+\r
+/* Priorities at which the tasks are created. */\r
+#define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )\r
+#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
+#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
+#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
+#define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )\r
+#define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
+#define mainuIP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
+#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
+#define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
+#define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
+#define mainQUEUE_OVERWRITE_PRIORITY ( tskIDLE_PRIORITY )\r
+\r
+#define mainTIMER_TEST_PERIOD ( 50 )\r
+\r
+/* Task function prototypes. */\r
+static void prvCheckTask( void *pvParameters );\r
+\r
+/* A task that is created from the idle task to test the functionality of \r
+eTaskStateGet(). */\r
+static void prvTestTask( void *pvParameters );\r
+\r
+/*\r
+ * Called from the idle task hook function to demonstrate a few utility\r
+ * functions that are not demonstrated by any of the standard demo tasks.\r
+ */\r
+static void prvDemonstrateTaskStateAndHandleGetFunctions( void );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The variable into which error messages are latched. */\r
+static char *pcStatusMessage = "OK";\r
+\r
+/* This semaphore is created purely to test using the vSemaphoreDelete() and\r
+semaphore tracing API functions. It has no other purpose. */\r
+static xSemaphoreHandle xMutexToDelete = NULL;\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+int main_full( void )\r
+{\r
+ /* Start the check task as described at the top of this file. */\r
+ xTaskCreate( prvCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
+\r
+ /* Create the standard demo tasks. */\r
+ vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
+ vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
+ vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
+ vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
+ vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
+ vStartQueuePeekTasks();\r
+ vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
+ vStartRecursiveMutexTasks();\r
+ vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
+ vStartCountingSemaphoreTasks();\r
+ vStartDynamicPriorityTasks();\r
+ vStartQueueSetTasks();\r
+ vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY );\r
+\r
+ /* The suicide tasks must be created last as they need to know how many\r
+ tasks were running prior to their creation. This then allows them to \r
+ ascertain whether or not the correct/expected number of tasks are running at \r
+ any given time. */\r
+ vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
+\r
+ /* Create the semaphore that will be deleted in the idle task hook. This\r
+ is done purely to test the use of vSemaphoreDelete(). */\r
+ xMutexToDelete = xSemaphoreCreateMutex();\r
+\r
+ /* Start the scheduler itself. */\r
+ vTaskStartScheduler();\r
+\r
+ /* Should never get here unless there was not enough heap space to create \r
+ the idle and other system tasks. */\r
+ return 0;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvCheckTask( void *pvParameters )\r
+{\r
+portTickType xNextWakeTime;\r
+const portTickType xCycleFrequency = 1000 / portTICK_RATE_MS;\r
+\r
+ /* Just to remove compiler warning. */\r
+ ( void ) pvParameters;\r
+\r
+ /* Initialise xNextWakeTime - this only needs to be done once. */\r
+ xNextWakeTime = xTaskGetTickCount();\r
+\r
+ for( ;; )\r
+ {\r
+ /* Place this task in the blocked state until it is time to run again. */\r
+ vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );\r
+\r
+ /* Check the standard demo tasks are running without error. */\r
+ if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )\r
+ {\r
+ pcStatusMessage = "Error: TimerDemo";\r
+ }\r
+ else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "Error: IntMath";\r
+ } \r
+ else if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
+ { \r
+ pcStatusMessage = "Error: GenQueue";\r
+ }\r
+ else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "Error: QueuePeek";\r
+ }\r
+ else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "Error: BlockQueue";\r
+ }\r
+ else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "Error: SemTest";\r
+ }\r
+ else if( xArePollingQueuesStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "Error: PollQueue";\r
+ }\r
+ else if( xAreMathsTaskStillRunning() != pdPASS )\r
+ {\r
+ pcStatusMessage = "Error: Flop";\r
+ }\r
+ else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "Error: RecMutex";\r
+ }\r
+ else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "Error: CountSem";\r
+ }\r
+ else if( xIsCreateTaskStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "Error: Death";\r
+ }\r
+ else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )\r
+ {\r
+ pcStatusMessage = "Error: Dynamic\r\n";\r
+ }\r
+ else if( xAreQueueSetTasksStillRunning() != pdPASS )\r
+ {\r
+ pcStatusMessage = "Error: Queue set\r\n";\r
+ }\r
+ else if( xIsQueueOverwriteTaskStillRunning() != pdPASS )\r
+ {\r
+ pcStatusMessage = "Error: Queue overwrite\r\n";\r
+ }\r
+\r
+ /* This is the only task that uses stdout so its ok to call printf() \r
+ directly. */\r
+ printf( "%s - %d\r\n", pcStatusMessage, xTaskGetTickCount() );\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvTestTask( void *pvParameters )\r
+{\r
+const unsigned long ulMSToSleep = 5;\r
+\r
+ /* Just to remove compiler warnings. */\r
+ ( void ) pvParameters;\r
+\r
+ /* This task is just used to test the eTaskStateGet() function. It\r
+ does not have anything to do. */\r
+ for( ;; )\r
+ {\r
+ /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are\r
+ tasks waiting to be terminated by the idle task. */\r
+ Sleep( ulMSToSleep );\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+/* Called from vApplicationIdleHook(), which is defined in main.c. */\r
+void vFullDemoIdleFunction( void )\r
+{\r
+const unsigned long ulMSToSleep = 15;\r
+const unsigned char ucConstQueueNumber = 0xaaU;\r
+void *pvAllocated;\r
+\r
+/* These three functions are only meant for use by trace code, and not for\r
+direct use from application code, hence their prototypes are not in queue.h. */\r
+extern void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber );\r
+extern unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue );\r
+extern unsigned char ucQueueGetQueueType( xQueueHandle pxQueue );\r
+extern void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle );\r
+extern unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask );\r
+\r
+ /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are\r
+ tasks waiting to be terminated by the idle task. */\r
+ Sleep( ulMSToSleep );\r
+\r
+ /* Demonstrate a few utility functions that are not demonstrated by any of\r
+ the standard demo tasks. */\r
+ prvDemonstrateTaskStateAndHandleGetFunctions();\r
+\r
+ /* If xMutexToDelete has not already been deleted, then delete it now.\r
+ This is done purely to demonstrate the use of, and test, the \r
+ vSemaphoreDelete() macro. Care must be taken not to delete a semaphore\r
+ that has tasks blocked on it. */\r
+ if( xMutexToDelete != NULL )\r
+ {\r
+ /* Before deleting the semaphore, test the function used to set its\r
+ number. This would normally only be done from trace software, rather\r
+ than application code. */\r
+ vQueueSetQueueNumber( xMutexToDelete, ucConstQueueNumber );\r
+\r
+ /* Before deleting the semaphore, test the functions used to get its\r
+ type and number. Again, these would normally only be done from trace\r
+ software, rather than application code. */\r
+ configASSERT( ucQueueGetQueueNumber( xMutexToDelete ) == ucConstQueueNumber );\r
+ configASSERT( ucQueueGetQueueType( xMutexToDelete ) == queueQUEUE_TYPE_MUTEX );\r
+ vSemaphoreDelete( xMutexToDelete );\r
+ xMutexToDelete = NULL;\r
+ }\r
+\r
+ /* Exercise heap_4 a bit. The malloc failed hook will trap failed \r
+ allocations so there is no need to test here. */\r
+ pvAllocated = pvPortMalloc( ( rand() % 100 ) + 1 );\r
+ vPortFree( pvAllocated );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+/* Called by vApplicationTickHook(), which is defined in main.c. */\r
+void vFullDemoTickHookFunction( void )\r
+{\r
+ /* Call the periodic timer test, which tests the timer API functions that\r
+ can be called from an ISR. */\r
+ vTimerPeriodicISRTests();\r
+\r
+ /* Call the periodic queue overwrite from ISR demo. */\r
+ vQueueOverwritePeriodicISRDemo();\r
+\r
+ /* Write to a queue that is in use as part of the queue set demo to \r
+ demonstrate using queue sets from an ISR. */\r
+ vQueueSetAccessQueueSetFromISR();\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
+/*-----------------------------------------------------------*/\r
+\r
+\r