/*\r
- FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.\r
+ FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.\r
+ All rights reserved\r
\r
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
\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 distribute\r
- >>! a combined work that includes FreeRTOS without being obliged to provide\r
- >>! the source code for proprietary components outside of the FreeRTOS\r
- >>! kernel.\r
+ >>! NOTE: The modification to the GPL is included to allow you to !<<\r
+ >>! distribute a combined work that includes FreeRTOS without being !<<\r
+ >>! obliged to provide the source code for proprietary components !<<\r
+ >>! outside of the FreeRTOS 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
* 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
+ * Windows will not be running the FreeRTOS simulator threads continuously, so\r
+ * the timing information in the FreeRTOS+Trace logs have no meaningful units.\r
+ * See the documentation page for the Windows simulator for an explanation of\r
+ * 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
+ * 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
+ * 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
+ * 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
\r
/* Kernel includes. */\r
#include <FreeRTOS.h>\r
-#include "task.h"\r
-#include "queue.h"\r
-#include "timers.h"\r
-#include "semphr.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 "dynamic.h"\r
#include "QueueSet.h"\r
#include "QueueOverwrite.h"\r
+#include "EventGroupsDemo.h"\r
+#include "IntSemTest.h"\r
+#include "TaskNotify.h"\r
\r
/* Priorities at which the tasks are created. */\r
-#define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )\r
+#define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )\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
/* 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
+/* 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
static void prvDemonstrateTaskStateAndHandleGetFunctions( void );\r
\r
+/*\r
+ * Called from the idle task hook function to demonstrate the use of\r
+ * xTimerPendFunctionCall() as xTimerPendFunctionCall() is not demonstrated by\r
+ * any of the standard demo tasks.\r
+ */\r
+static void prvDemonstratePendingFunctionCall( void );\r
+\r
+/*\r
+ * The function that is pended by prvDemonstratePendingFunctionCall().\r
+ */\r
+static void prvPendedFunction( void *pvParameter1, uint32_t ulParameter2 );\r
+\r
+/*\r
+ * A task to demonstrate the use of the xQueueSpacesAvailable() function.\r
+ */\r
+static void prvDemoQueueSpaceFunctions( void *pvParameters );\r
+\r
/*-----------------------------------------------------------*/\r
\r
/* The variable into which error messages are latched. */\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 SemaphoreHandle_t 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
+ xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
\r
/* Create the standard demo tasks. */\r
+ vStartTaskNotifyTask();\r
vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
vStartPolledQueueTasks( mainQUEUE_POLL_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
+ xTaskCreate( prvDemoQueueSpaceFunctions, "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
+ vStartEventGroupTasks();\r
+ vStartInterruptSemaphoreTasks();\r
+\r
+ #if( configUSE_PREEMPTION != 0 )\r
+ {\r
+ /* Don't expect these tasks to pass when preemption is not used. */\r
+ vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
+ }\r
+ #endif\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
+ 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
/* Start the scheduler itself. */\r
vTaskStartScheduler();\r
\r
- /* Should never get here unless there was not enough heap space to create \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
static void prvCheckTask( void *pvParameters )\r
{\r
-portTickType xNextWakeTime;\r
-const portTickType xCycleFrequency = 1000 / portTICK_RATE_MS;\r
+TickType_t xNextWakeTime;\r
+const TickType_t xCycleFrequency = 2500 / portTICK_PERIOD_MS;\r
\r
/* Just to remove compiler warning. */\r
( void ) pvParameters;\r
vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );\r
\r
/* Check the standard demo tasks are running without error. */\r
- if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )\r
+ #if( configUSE_PREEMPTION != 0 )\r
+ {\r
+ /* These tasks are only created when preemption is used. */\r
+ if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )\r
+ {\r
+ pcStatusMessage = "Error: TimerDemo";\r
+ }\r
+ }\r
+ #endif\r
+\r
+ if( xAreTaskNotificationTasksStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "Error: Notification";\r
+ }\r
+\r
+ if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )\r
+ {\r
+ pcStatusMessage = "Error: IntSem";\r
+ }\r
+ else if( xAreEventGroupTasksStillRunning() != pdTRUE )\r
{\r
- pcStatusMessage = "Error: TimerDemo";\r
+ pcStatusMessage = "Error: EventGroup";\r
}\r
else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
{\r
pcStatusMessage = "Error: IntMath";\r
- } \r
+ }\r
else if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
- { \r
+ {\r
pcStatusMessage = "Error: GenQueue";\r
}\r
else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
}\r
else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )\r
{\r
- pcStatusMessage = "Error: Dynamic\r\n";\r
+ pcStatusMessage = "Error: Dynamic";\r
}\r
else if( xAreQueueSetTasksStillRunning() != pdPASS )\r
{\r
- pcStatusMessage = "Error: Queue set\r\n";\r
+ pcStatusMessage = "Error: Queue set";\r
}\r
else if( xIsQueueOverwriteTaskStillRunning() != pdPASS )\r
{\r
- pcStatusMessage = "Error: Queue overwrite\r\n";\r
+ pcStatusMessage = "Error: Queue overwrite";\r
}\r
\r
- /* This is the only task that uses stdout so its ok to call printf() \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
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
the standard demo tasks. */\r
prvDemonstrateTaskStateAndHandleGetFunctions();\r
\r
+ /* Demonstrate the use of xTimerPendFunctionCall(), which is not\r
+ demonstrated by any of the standard demo tasks. */\r
+ prvDemonstratePendingFunctionCall();\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
+ 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
+ /* Exercise heap_5 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
/* Called by vApplicationTickHook(), which is defined in main.c. */\r
void vFullDemoTickHookFunction( void )\r
{\r
+TaskHandle_t xTimerTask;\r
+\r
/* Call the periodic timer test, which tests the timer API functions that\r
can be called from an ISR. */\r
- vTimerPeriodicISRTests();\r
+ #if( configUSE_PREEMPTION != 0 )\r
+ {\r
+ /* Only created when preemption is used. */\r
+ vTimerPeriodicISRTests();\r
+ }\r
+ #endif\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
+ /* 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
+ /* Exercise event groups from interrupts. */\r
+ vPeriodicEventGroupsProcessing();\r
+\r
+ /* Exercise giving mutexes from an interrupt. */\r
+ vInterruptSemaphorePeriodicTest();\r
+\r
+ /* Exercise using task notifications from an interrupt. */\r
+ xNotifyTaskFromISR();\r
+\r
+ /* For code coverage purposes. */\r
+ xTimerTask = xTimerGetTimerDaemonTaskHandle();\r
+ configASSERT( uxTaskPriorityGetFromISR( xTimerTask ) == configTIMER_TASK_PRIORITY );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvPendedFunction( void *pvParameter1, uint32_t ulParameter2 )\r
+{\r
+static uint32_t ulLastParameter1 = 1000UL, ulLastParameter2 = 0UL;\r
+uint32_t ulParameter1;\r
+\r
+ ulParameter1 = ( uint32_t ) pvParameter1;\r
+\r
+ /* Ensure the parameters are as expected. */\r
+ configASSERT( ulParameter1 == ( ulLastParameter1 + 1 ) );\r
+ configASSERT( ulParameter2 == ( ulLastParameter2 + 1 ) );\r
+\r
+ /* Remember the parameters for the next time the function is called. */\r
+ ulLastParameter1 = ulParameter1;\r
+ ulLastParameter2 = ulParameter2;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvDemonstratePendingFunctionCall( void )\r
+{\r
+static uint32_t ulParameter1 = 1000UL, ulParameter2 = 0UL;\r
+const TickType_t xDontBlock = 0; /* This is called from the idle task so must *not* attempt to block. */\r
+\r
+ /* prvPendedFunction() just expects the parameters to be incremented by one\r
+ each time it is called. */\r
+ ulParameter1++;\r
+ ulParameter2++;\r
+\r
+ /* Pend the function call, sending the parameters. */\r
+ xTimerPendFunctionCall( prvPendedFunction, ( void * ) ulParameter1, ulParameter2, xDontBlock );\r
}\r
/*-----------------------------------------------------------*/\r
\r
static void prvDemonstrateTaskStateAndHandleGetFunctions( void )\r
{\r
-xTaskHandle xIdleTaskHandle, xTimerTaskHandle;\r
-const unsigned char ucConstTaskNumber = 0x55U;\r
-signed char *pcTaskName;\r
+TaskHandle_t xIdleTaskHandle, xTimerTaskHandle;\r
+char *pcTaskName;\r
static portBASE_TYPE xPerformedOneShotTests = pdFALSE;\r
-xTaskHandle xTestTask;\r
+TaskHandle_t xTestTask;\r
\r
- /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and \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
+ /* This is the idle hook, so the current task handle should equal the\r
returned idle task handle. */\r
if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle )\r
{\r
}\r
/*-----------------------------------------------------------*/\r
\r
+static void prvDemoQueueSpaceFunctions( void *pvParameters )\r
+{\r
+QueueHandle_t xQueue = NULL;\r
+const unsigned portBASE_TYPE uxQueueLength = 10;\r
+unsigned portBASE_TYPE uxReturn, x;\r
+\r
+ /* Remove compiler warnings. */\r
+ ( void ) pvParameters;\r
+\r
+ /* Create the queue that will be used. Nothing is actually going to be\r
+ sent or received so the queue item size is set to 0. */\r
+ xQueue = xQueueCreate( uxQueueLength, 0 );\r
+ configASSERT( xQueue );\r
+\r
+ for( ;; )\r
+ {\r
+ for( x = 0; x < uxQueueLength; x++ )\r
+ {\r
+ /* Ask how many messages are available... */\r
+ uxReturn = uxQueueMessagesWaiting( xQueue );\r
+\r
+ /* Check the number of messages being reported as being available\r
+ is as expected, and force an assert if not. */\r
+ if( uxReturn != x )\r
+ {\r
+ /* xQueue cannot be NULL so this is deliberately causing an\r
+ assert to be triggered as there is an error. */\r
+ configASSERT( xQueue == NULL );\r
+ }\r
+\r
+ /* Ask how many spaces remain in the queue... */\r
+ uxReturn = uxQueueSpacesAvailable( xQueue );\r
+\r
+ /* Check the number of spaces being reported as being available\r
+ is as expected, and force an assert if not. */\r
+ if( uxReturn != ( uxQueueLength - x ) )\r
+ {\r
+ /* xQueue cannot be NULL so this is deliberately causing an\r
+ assert to be triggered as there is an error. */\r
+ configASSERT( xQueue == NULL );\r
+ }\r
+\r
+ /* Fill one more space in the queue. */\r
+ xQueueSendToBack( xQueue, NULL, 0 );\r
+ }\r
+\r
+ /* Perform the same check while the queue is full. */\r
+ uxReturn = uxQueueMessagesWaiting( xQueue );\r
+ if( uxReturn != uxQueueLength )\r
+ {\r
+ configASSERT( xQueue == NULL );\r
+ }\r
+\r
+ uxReturn = uxQueueSpacesAvailable( xQueue );\r
+\r
+ if( uxReturn != 0 )\r
+ {\r
+ configASSERT( xQueue == NULL );\r
+ }\r
+\r
+ /* The queue is full, start again. */\r
+ xQueueReset( xQueue );\r
+\r
+ #if( configUSE_PREEMPTION == 0 )\r
+ taskYIELD();\r
+ #endif\r
+ }\r
+}\r
+\r
\r