]> git.sur5r.net Git - freertos/commitdiff
Implement functionality that allows the memory required to create a queue or semaphor...
authorrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Tue, 19 Jan 2016 13:41:28 +0000 (13:41 +0000)
committerrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Tue, 19 Jan 2016 13:41:28 +0000 (13:41 +0000)
Update the standard demo task that tests statically allocated tasks to also test statically allocated queues.

git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2405 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/main.c
FreeRTOS/Demo/CORTEX_M7_SAME70_Xplained_AtmelStudio/ReadMe_Instructions.url [new file with mode: 0644]
FreeRTOS/Demo/CORTEX_M7_SAME70_Xplained_AtmelStudio/src/Full_Demo/IntQueueTimer.c
FreeRTOS/Demo/Common/Minimal/StaticAllocation.c
FreeRTOS/Demo/Common/Minimal/countsem.c
FreeRTOS/Source/include/FreeRTOS.h
FreeRTOS/Source/include/queue.h
FreeRTOS/Source/include/semphr.h
FreeRTOS/Source/include/task.h
FreeRTOS/Source/queue.c

index 2b4b2bf640c824abd001e1c8f7363dacda724b90..2e68aed5451c8d2b81534750b969a378a4429589 100644 (file)
@@ -374,15 +374,15 @@ volatile size_t x;
 \r
        /* Extremely crude standard library implementations in lieu of having a C\r
        library. */\r
-    for( x = 0; x < xBytes; x++ )\r
-    {\r
-        if( pucMem1[ x ] != pucMem2[ x ] )\r
-        {\r
-            break;\r
-        }\r
-    }\r
-\r
-    return xBytes - x;\r
+       for( x = 0; x < xBytes; x++ )\r
+       {\r
+               if( pucMem1[ x ] != pucMem2[ x ] )\r
+               {\r
+                       break;\r
+               }\r
+       }\r
+\r
+       return xBytes - x;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -405,7 +405,7 @@ const uint32_t ulMaxDivisor = 0xff, ulDivisorShift = 0x08;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vApplicationGetIdleTaskMemory( DummyTCB_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint16_t *pusIdleTaskStackSize )\r
+void vApplicationGetIdleTaskMemory( StaticTCB_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint16_t *pusIdleTaskStackSize )\r
 {\r
        /* configUSE_STATIC_ALLOCATION is set to 1, so the application has the\r
        opportunity to supply the buffers that will be used by the Idle task as its\r
@@ -417,7 +417,7 @@ void vApplicationGetIdleTaskMemory( DummyTCB_t **ppxIdleTaskTCBBuffer, StackType
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-void vApplicationGetTimerTaskMemory( DummyTCB_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint16_t *pusTimerTaskStackSize )\r
+void vApplicationGetTimerTaskMemory( StaticTCB_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint16_t *pusTimerTaskStackSize )\r
 {\r
        /* configUSE_STATIC_ALLOCATION is set to 1, so the application has the\r
        opportunity to supply the buffers that will be used by the Timer/RTOS daemon\r
diff --git a/FreeRTOS/Demo/CORTEX_M7_SAME70_Xplained_AtmelStudio/ReadMe_Instructions.url b/FreeRTOS/Demo/CORTEX_M7_SAME70_Xplained_AtmelStudio/ReadMe_Instructions.url
new file mode 100644 (file)
index 0000000..ef60a9c
--- /dev/null
@@ -0,0 +1,5 @@
+[{000214A0-0000-0000-C000-000000000046}]\r
+Prop3=19,2\r
+[InternetShortcut]\r
+URL=http://www.freertos.org/Atmel_SAMV7_Cortex-M7_RTOS_Demo.html\r
+IDList=\r
index 123b350c97d14a8b7ef0bd49cebbe6639c3e669a..ebdb8e69a50df606ebfd85f72f9e8211b00defa6 100644 (file)
  * In this case, there was difficulty generating interrupts from TC1, so only\r
  * TC0 is used.  Nested interrupts are instead generated by manually pending the\r
  * TC1 interrupt from inside the TC0 interrupt handler.  This means TC1 must be\r
- * assigned an interrupt priority above TC0.\r
+ * assigned an interrupt priority above TC0.  [Note this arrangement does not\r
+ * really fulfil the purpose of the test as the nesting always occurs at the\r
+ * same point in the code, whereas the test is designed to test nesting\r
+ * occurring within the queue API functions]\r
  */\r
 \r
 /* Scheduler includes. */\r
@@ -119,9 +122,9 @@ uint32_t ulDivider, ulTCCLKS;
        NVIC_ClearPendingIRQ( TC1_IRQn );\r
        NVIC_SetPriority( TC0_IRQn, tmrLOWER_PRIORITY );\r
        NVIC_SetPriority( TC1_IRQn, tmrHIGHER_PRIORITY );\r
-       NVIC_EnableIRQ( TC0_IRQn );     \r
-       NVIC_EnableIRQ( TC1_IRQn );     \r
-       \r
+       NVIC_EnableIRQ( TC0_IRQn );\r
+       NVIC_EnableIRQ( TC1_IRQn );\r
+\r
        /* Start the timer last of all. */\r
        tc_start( TC0, 0 );\r
 }\r
@@ -144,7 +147,7 @@ static uint32_t ulISRCount = 0;
                        /* Pend an interrupt that will nest with this interrupt. */\r
                        NVIC_SetPendingIRQ( TC1_IRQn );\r
                }\r
-               \r
+\r
                /* Call the IntQ test function for this channel. */\r
                portYIELD_FROM_ISR( xFirstTimerHandler() );\r
        }\r
index 776751ec59583671aaa059ea858eb96ac69df24c..33dd56c573e2a9bf001229bb8167a9269a9082d7 100644 (file)
 \r
 /*\r
  * Demonstrates how to create FreeRTOS objects using pre-allocated memory,\r
- * rather than the normal dynamically allocated memory.  Currently only tasks\r
- * are being allocated statically.\r
+ * rather than the normal dynamically allocated memory.\r
  *\r
  * Two buffers are required by a task - one that is used by the task as its\r
  * stack, and one that holds the task's control block (TCB).\r
- * prvStaticallyAllocatedTaskCreator() creates and deletes tasks with all\r
+ * prvStaticallyAllocatedCreator() creates and deletes tasks with all\r
  * possible combinations of statically allocated and dynamically allocated\r
  * stacks and TCBs.\r
  */\r
@@ -83,6 +82,8 @@
 /* Scheduler include files. */\r
 #include "FreeRTOS.h"\r
 #include "task.h"\r
+#include "queue.h"\r
+#include "semphr.h"\r
 \r
 /* Demo program include files. */\r
 #include "StaticAllocation.h"\r
 /* Exclude the entire file if configSUPPORT_STATIC_ALLOCATION is 0. */\r
 #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
 \r
-#define staticTASK_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
+/* The priority at which the task that performs the tests is created. */\r
+#define staticTASK_PRIORITY                                    ( tskIDLE_PRIORITY + 2 )\r
+\r
+/* The length of the queue, in items, not bytes, used in the queue static\r
+allocation tests. */\r
+#define staticQUEUE_LENGTH_IN_ITEMS                    ( 5 )\r
+\r
+/* A block time of 0 simply means "don't block". */\r
+#define staticDONT_BLOCK                                       ( ( TickType_t ) 0 )\r
+\r
+/* Binary semaphores have a maximum count of 1. */\r
+#define staticBINARY_SEMAPHORE_MAX_COUNT       ( 1 )\r
+\r
+\r
+/*-----------------------------------------------------------*/\r
 \r
 /*\r
- * A task that is created multiple times, using both statically and dynamically\r
- * allocated stack and TCB.\r
+ * A task that is created and deleted multiple times, using both statically and\r
+ * dynamically allocated stack and TCB.\r
  */\r
 static void prvStaticallyAllocatedTask( void *pvParameters );\r
 \r
 /*\r
- * The task that creates and deletes the prvStaticallyAllocatedTask() task,\r
- * using various priorities, and sometimes with statically and sometimes\r
- * dynamically allocated stack and TCB.\r
+ * The task that repeatedly creates and deletes statically allocated tasks, and\r
+ * other RTOS objects.\r
  */\r
-static void prvStaticallyAllocatedTaskCreator( void *pvParameters );\r
+static void prvStaticallyAllocatedCreator( void *pvParameters );\r
 \r
 /*\r
  * Utility function to create pseudo random numbers.\r
  */\r
 static UBaseType_t prvRand( void );\r
 \r
+/*\r
+ * A function that demonstrates and tests the xTaskCreateStatic() API function\r
+ * by creating and then deleting tasks with both dynamically and statically\r
+ * allocated TCBs and stacks.\r
+ */\r
+static void prvCreateAndDeleteStaticallyAllocatedTasks( void );\r
+\r
+/*\r
+ * A function that demonstrates and tests the xQueueCreateStatic() API function\r
+ * by creating and then deleting queues with both dynamically and statically\r
+ * allocated queue structures and queue storage areas.\r
+ */\r
+static void prvCreateAndDeleteStaticallyAllocatedQueues( void );\r
+\r
+/*\r
+ * A function that demonstrates and tests the xSemaphoreCreateBinaryStatic() API\r
+ * macro by creating and then deleting binary semaphores with both dynamically\r
+ * and statically allocated semaphore structures.\r
+ */\r
+static void prvCreateAndDeleteStaticallyAllocatedBinarySemaphores( void );\r
+\r
 /*\r
  * The task that creates and deletes other tasks has to delay occasionally to\r
  * ensure lower priority tasks are not starved of processing time.  A pseudo\r
@@ -118,21 +153,32 @@ static UBaseType_t prvRand( void );
  */\r
 static TickType_t prvGetNextDelayTime( void );\r
 \r
+/*\r
+ * Checks the basic operation of a queue after it has been created.\r
+ */\r
+static void prvCheckQueueFunction( QueueHandle_t xQueue );\r
+\r
+/*\r
+ * Checks the basic operation of a binary semaphore after it has been created.\r
+ */\r
+static void prvCheckSemaphoreFunction( SemaphoreHandle_t xSemaphore, UBaseType_t uxMaxCount );\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
-/* DummyTCB_t is a publicly accessible structure that has the same size and\r
+/* StaticTCB_t is a publicly accessible structure that has the same size and\r
 alignment requirements as the real TCB structure.  It is provided as a mechanism\r
 for applications to know the size of the TCB (which is dependent on the\r
 architecture and configuration file settings) without breaking the strict data\r
-hiding policy by exposing the real TCB.  This DummyTCB_t variable is passed into\r
-the xTaskCreateStatic() function, and will hold the task's TCB. */\r
-static DummyTCB_t xTCBBuffer;\r
-\r
-/* This is the stack that will be used by the task.  The alignment requirements\r
-for the stack depend on the architecture, and the method of forcing an alignment\r
-is dependent on the compiler, but any bad alignment is corrected inside the\r
-FreeRTOS code. */\r
-static StackType_t uxStackBuffer[ configMINIMAL_STACK_SIZE ];\r
+hiding policy by exposing the real TCB.  This StaticTCB_t variable is passed\r
+into the xTaskCreateStatic() function that creates the\r
+prvStaticallyAllocatedCreator() task, and will hold the TCB of the created\r
+tasks. */\r
+static StaticTCB_t xCreatorTaskTCBBuffer;\r
+\r
+/* This is the stack that will be used by the prvStaticallyAllocatedCreator()\r
+task, which is itself created using statically allocated buffers (so without any\r
+dynamic memory allocation). */\r
+static StackType_t uxCreatorTaskStackBuffer[ configMINIMAL_STACK_SIZE ];\r
 \r
 /* Used by the pseudo random number generating function. */\r
 static uint32_t ulNextRand = 0;\r
@@ -141,6 +187,9 @@ static uint32_t ulNextRand = 0;
 stalled. */\r
 static volatile UBaseType_t uxCycleCounter = 0;\r
 \r
+/* A variable that gets set to pdTRUE if an error is detected. */\r
+static BaseType_t xErrorOccurred = pdFALSE;\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 void vStartStaticallyAllocatedTasks( void  )\r
@@ -148,106 +197,437 @@ void vStartStaticallyAllocatedTasks( void  )
        /* Create a single task, which then repeatedly creates and deletes the\r
        task implemented by prvStaticallyAllocatedTask() at various different\r
        priorities, and both with and without statically allocated TCB and stack. */\r
-       xTaskCreate( prvStaticallyAllocatedTaskCreator, "StatCreate", configMINIMAL_STACK_SIZE, NULL, staticTASK_PRIORITY, NULL );\r
+       xTaskCreateStatic( prvStaticallyAllocatedCreator,       /* The function that implements the task being created. */\r
+                                          "StatCreate",                                                /* Text name for the task - not used by the RTOS, its just to assist debugging. */\r
+                                          configMINIMAL_STACK_SIZE,                    /* Size of the buffer passed in as the stack - in words, not bytes! */\r
+                                          NULL,                                                                /* Parameter passed into the task - not used in this case. */\r
+                                          staticTASK_PRIORITY,                                 /* Priority of the task. */\r
+                                          NULL,                                                                /* Handle of the task being created, not used in this case. */\r
+                                          &( uxCreatorTaskStackBuffer[ 0 ] ),  /* The buffer to use as the task's stack. */\r
+                                          &xCreatorTaskTCBBuffer );                    /* The variable that will hold the task's TCB. */\r
 \r
        /* Pseudo seed the random number generator. */\r
        ulNextRand = ( uint32_t ) prvRand;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-static void prvStaticallyAllocatedTaskCreator( void *pvParameters )\r
+static void prvStaticallyAllocatedCreator( void *pvParameters )\r
 {\r
-TaskHandle_t xCreatedTask;\r
-BaseType_t xReturned;\r
-\r
        /* Avoid compiler warnings. */\r
        ( void ) pvParameters;\r
 \r
        for( ;; )\r
        {\r
-               /* Create the task.  xTaskCreateStatic() has two more parameters than\r
-               the usual xTaskCreate() function.  The first new parameter is a pointer to\r
-               the pre-allocated stack.  The second new parameter is a pointer to the\r
-               DummyTCB_t structure that will hold the task's TCB.  If either pointer is\r
-               passed as NULL then the respective object will be allocated dynamically as\r
-               if xTaskCreate() had been called. */\r
-               xReturned = xTaskCreateStatic(\r
-                                                       prvStaticallyAllocatedTask, /* Function that implements the task. */\r
-                                                       "Static",                                       /* Human readable name for the task. */\r
-                                                       configMINIMAL_STACK_SIZE,       /* Task's stack size, in words (not bytes!). */\r
-                                                       NULL,                                           /* Parameter to pass into the task. */\r
-                                                       tskIDLE_PRIORITY,                       /* The priority of the task. */\r
-                                                       &xCreatedTask,                          /* Handle of the task being created. */\r
-                                                       &( uxStackBuffer[ 0 ] ),        /* The buffer to use as the task's stack. */\r
-                                                       &xTCBBuffer );                          /* The variable that will hold that task's TCB. */\r
-\r
-               /* Check the task was created correctly, then delete the task. */\r
-               configASSERT( xReturned == pdPASS );\r
-               ( void ) xReturned; /* In case configASSERT() is not defined. */\r
-               vTaskDelete( xCreatedTask );\r
-\r
-               /* Ensure lower priority tasks get CPU time. */\r
-               vTaskDelay( prvGetNextDelayTime() );\r
-\r
-               /* Create and delete the task a few times again - testing both static and\r
-               dynamic allocation for the stack and TCB. */\r
-               xReturned = xTaskCreateStatic(\r
-                                                       prvStaticallyAllocatedTask, /* Function that implements the task. */\r
-                                                       "Static",                                       /* Human readable name for the task. */\r
-                                                       configMINIMAL_STACK_SIZE,       /* Task's stack size, in words (not bytes!). */\r
-                                                       NULL,                                           /* Parameter to pass into the task. */\r
-                                                       staticTASK_PRIORITY + 1,        /* The priority of the task. */\r
-                                                       &xCreatedTask,                          /* Handle of the task being created. */\r
-                                                       NULL,                                           /* This time, dynamically allocate the stack. */\r
-                                                       &xTCBBuffer );                          /* The variable that will hold that task's TCB. */\r
-\r
-               configASSERT( xReturned == pdPASS );\r
-               ( void ) xReturned; /* In case configASSERT() is not defined. */\r
-               vTaskDelete( xCreatedTask );\r
-\r
-               /* Just to show the check task that this task is still executing. */\r
-               uxCycleCounter++;\r
-\r
-               /* Ensure lower priority tasks get CPU time. */\r
-               vTaskDelay( prvGetNextDelayTime() );\r
-\r
-               xReturned = xTaskCreateStatic(\r
-                                                       prvStaticallyAllocatedTask, /* Function that implements the task. */\r
-                                                       "Static",                                       /* Human readable name for the task. */\r
-                                                       configMINIMAL_STACK_SIZE,       /* Task's stack size, in words (not bytes!). */\r
-                                                       NULL,                                           /* Parameter to pass into the task. */\r
-                                                       staticTASK_PRIORITY - 1,        /* The priority of the task. */\r
-                                                       &xCreatedTask,                          /* Handle of the task being created. */\r
-                                                       &( uxStackBuffer[ 0 ] ),        /* The buffer to use as the task's stack. */\r
-                                                       NULL );                                         /* This time dynamically allocate the TCB. */\r
-\r
-               configASSERT( xReturned == pdPASS );\r
-               ( void ) xReturned; /* In case configASSERT() is not defined. */\r
-               vTaskDelete( xCreatedTask );\r
-\r
-               /* Ensure lower priority tasks get CPU time. */\r
-               vTaskDelay( prvGetNextDelayTime() );\r
-\r
-               xReturned = xTaskCreateStatic(\r
-                                                       prvStaticallyAllocatedTask, /* Function that implements the task. */\r
-                                                       "Static",                                       /* Human readable name for the task. */\r
-                                                       configMINIMAL_STACK_SIZE,       /* Task's stack size, in words (not bytes!). */\r
-                                                       NULL,                                           /* Parameter to pass into the task. */\r
-                                                       staticTASK_PRIORITY,            /* The priority of the task. */\r
-                                                       &xCreatedTask,                          /* Handle of the task being created. */\r
-                                                       NULL,                                           /* This time dynamically allocate the stack and TCB. */\r
-                                                       NULL );                                         /* This time dynamically allocate the stack and TCB. */\r
-\r
-               configASSERT( xReturned == pdPASS );\r
-               ( void ) xReturned; /* In case configASSERT() is not defined. */\r
-               vTaskDelete( xCreatedTask );\r
-\r
-               /* Ensure lower priority tasks get CPU time. */\r
-               vTaskDelay( prvGetNextDelayTime() );\r
-\r
-               /* Just to show the check task that this task is still executing. */\r
-               uxCycleCounter++;\r
+               prvCreateAndDeleteStaticallyAllocatedTasks();\r
+               prvCreateAndDeleteStaticallyAllocatedQueues();\r
+               prvCreateAndDeleteStaticallyAllocatedBinarySemaphores();\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvCheckSemaphoreFunction( SemaphoreHandle_t xSemaphore, UBaseType_t uxMaxCount )\r
+{\r
+BaseType_t xReturned;\r
+UBaseType_t x;\r
+const TickType_t xShortBlockTime = pdMS_TO_TICKS( 10 );\r
+TickType_t xTickCount;\r
+\r
+       /* The binary semaphore should start 'empty', so a call to xSemaphoreTake()\r
+       should fail. */\r
+       xTickCount = xTaskGetTickCount();\r
+       xReturned = xSemaphoreTake( xSemaphore, xShortBlockTime );\r
+\r
+       if( ( xTaskGetTickCount() - xTickCount) < xShortBlockTime )\r
+       {\r
+               /* Did not block on the semaphore as long as expected. */\r
+               xErrorOccurred = pdTRUE;\r
+       }\r
+\r
+       if( xReturned != pdFAIL )\r
+       {\r
+               xErrorOccurred = pdTRUE;\r
+       }\r
+\r
+       /* Should be possible to 'give' the semaphore up to a maximum of uxMaxCount\r
+       times. */\r
+       for( x = 0; x < uxMaxCount; x++ )\r
+       {\r
+               xReturned = xSemaphoreGive( xSemaphore );\r
+\r
+               if( xReturned == pdFAIL )\r
+               {\r
+                       xErrorOccurred = pdTRUE;\r
+               }\r
        }\r
+\r
+       /* Giving the semaphore again should fail, as it is 'full'. */\r
+       xReturned = xSemaphoreGive( xSemaphore );\r
+\r
+       if( xReturned != pdFAIL )\r
+       {\r
+               xErrorOccurred = pdTRUE;\r
+       }\r
+\r
+       configASSERT( uxSemaphoreGetCount( xSemaphore ) == uxMaxCount );\r
+\r
+       /* Should now be possible to 'take' the semaphore up to a maximum of\r
+       uxMaxCount times without blocking. */\r
+       for( x = 0; x < uxMaxCount; x++ )\r
+       {\r
+               xReturned = xSemaphoreTake( xSemaphore, staticDONT_BLOCK );\r
+\r
+               if( xReturned == pdFAIL )\r
+               {\r
+                       xErrorOccurred = pdTRUE;\r
+               }\r
+       }\r
+\r
+       /* Back to the starting condition, where the semaphore should not be\r
+       available. */\r
+       xTickCount = xTaskGetTickCount();\r
+       xReturned = xSemaphoreTake( xSemaphore, xShortBlockTime );\r
+\r
+       if( ( xTaskGetTickCount() - xTickCount) < xShortBlockTime )\r
+       {\r
+               /* Did not block on the semaphore as long as expected. */\r
+               xErrorOccurred = pdTRUE;\r
+       }\r
+\r
+       if( xReturned != pdFAIL )\r
+       {\r
+               xErrorOccurred = pdTRUE;\r
+       }\r
+\r
+       configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvCheckQueueFunction( QueueHandle_t xQueue )\r
+{\r
+uint64_t ull, ullRead;\r
+BaseType_t xReturned, xLoop;\r
+\r
+       /* This test is done twice to ensure the queue storage area wraps. */\r
+       for( xLoop = 0; xLoop < 2; xLoop++ )\r
+       {\r
+               /* A very basic test that the queue can be written to and read from as\r
+               expected.  First the queue should be empty. */\r
+               xReturned = xQueueReceive( xQueue, &ull, staticDONT_BLOCK );\r
+               if( xReturned != errQUEUE_EMPTY )\r
+               {\r
+                       xErrorOccurred = pdTRUE;\r
+               }\r
+\r
+               /* Now it should be possible to write to the queue staticQUEUE_LENGTH_IN_ITEMS\r
+               times. */\r
+               for( ull = 0; ull < staticQUEUE_LENGTH_IN_ITEMS; ull++ )\r
+               {\r
+                       xReturned = xQueueSend( xQueue, &ull, staticDONT_BLOCK );\r
+                       if( xReturned != pdPASS )\r
+                       {\r
+                               xErrorOccurred = pdTRUE;\r
+                       }\r
+               }\r
+\r
+               /* Should not now be possible to write to the queue again. */\r
+               xReturned = xQueueSend( xQueue, &ull, staticDONT_BLOCK );\r
+               if( xReturned != errQUEUE_FULL )\r
+               {\r
+                       xErrorOccurred = pdTRUE;\r
+               }\r
+\r
+               /* Now read back from the queue to ensure the data read back matches that\r
+               written. */\r
+               for( ull = 0; ull < staticQUEUE_LENGTH_IN_ITEMS; ull++ )\r
+               {\r
+                       xReturned = xQueueReceive( xQueue, &ullRead, staticDONT_BLOCK );\r
+\r
+                       if( xReturned != pdPASS )\r
+                       {\r
+                               xErrorOccurred = pdTRUE;\r
+                       }\r
+\r
+                       if( ullRead != ull )\r
+                       {\r
+                               xErrorOccurred = pdTRUE;\r
+                       }\r
+               }\r
+\r
+               /* The queue should be empty again. */\r
+               xReturned = xQueueReceive( xQueue, &ull, staticDONT_BLOCK );\r
+               if( xReturned != errQUEUE_EMPTY )\r
+               {\r
+                       xErrorOccurred = pdTRUE;\r
+               }\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvCreateAndDeleteStaticallyAllocatedQueues( void )\r
+{\r
+QueueHandle_t xQueue;\r
+\r
+/* StaticQueue_t is a publicly accessible structure that has the same size and\r
+alignment requirements as the real queue structure.  It is provided as a\r
+mechanism for applications to know the size of the queue (which is dependent on\r
+the architecture and configuration file settings) without breaking the strict\r
+data hiding policy by exposing the real queue internals.  This StaticQueue_t\r
+variable is passed into the xQueueCreateStatic() function calls within this\r
+function. */\r
+static StaticQueue_t xStaticQueue;\r
+\r
+/* The queue storage area must be large enough to hold the maximum number of\r
+items it is possible for the queue to hold at any one time, which equals the\r
+queue length (in items, not bytes) multiplied by the size of each item.  In this\r
+case the queue will hold staticQUEUE_LENGTH_IN_ITEMS 64-bit items.  See\r
+http://www.freertos.org/Embedded-RTOS-Queues.html */\r
+static uint8_t ucQueueStorageArea[ staticQUEUE_LENGTH_IN_ITEMS * sizeof( uint64_t ) ];\r
+\r
+       /* Create the queue.  xQueueCreateStatic() has two more parameters than the\r
+       usual xQueueCreate() function.  The first new paraemter is a pointer to the\r
+       pre-allocated queue storage area.  The second new parameter is a pointer to\r
+       the StaticQueue_t structure that will hold the queue state information in\r
+       an anonymous way.  If either pointer is passed as NULL then the respective\r
+       data will be allocated dynamically as if xQueueCreate() had been called. */\r
+       xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */\r
+                                                                sizeof( uint64_t ), /* The size of each item. */\r
+                                                                ucQueueStorageArea, /* The buffer used to hold items within the queue. */\r
+                                                                &xStaticQueue );        /* The static queue structure that will hold the state of the queue. */\r
+\r
+       /* The queue handle should equal the static queue structure passed into the\r
+       xQueueCreateStatic() function. */\r
+       configASSERT( xQueue == ( QueueHandle_t ) &xStaticQueue );\r
+\r
+       /* Ensure the queue passes a few sanity checks as a valid queue. */\r
+       prvCheckQueueFunction( xQueue );\r
+\r
+       /* Delete the queue again so the buffers can be reused. */\r
+       vQueueDelete( xQueue );\r
+\r
+\r
+       /* The queue created above had a statically allocated queue storage area and\r
+       queue structure.  Repeat the above with three more times - with different\r
+       combinations of static and dynamic allocation. */\r
+\r
+       xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */\r
+                                                                sizeof( uint64_t ), /* The size of each item. */\r
+                                                                NULL,                           /* Allocate the buffer used to hold items within the queue dynamically. */\r
+                                                                &xStaticQueue );        /* The static queue structure that will hold the state of the queue. */\r
+\r
+       configASSERT( xQueue == ( QueueHandle_t ) &xStaticQueue );\r
+       prvCheckQueueFunction( xQueue );\r
+       vQueueDelete( xQueue );\r
+\r
+       /* Ensure lower priority tasks get CPU time. */\r
+       vTaskDelay( prvGetNextDelayTime() );\r
+\r
+       /* Just to show the check task that this task is still executing. */\r
+       uxCycleCounter++;\r
+\r
+       xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */\r
+                                                                sizeof( uint64_t ), /* The size of each item. */\r
+                                                                ucQueueStorageArea, /* The buffer used to hold items within the queue. */\r
+                                                                NULL );                         /* The queue structure is allocated dynamically. */\r
+\r
+       prvCheckQueueFunction( xQueue );\r
+       vQueueDelete( xQueue );\r
+\r
+       xQueue = xQueueCreateStatic( staticQUEUE_LENGTH_IN_ITEMS, /* The maximum number of items the queue can hold. */\r
+                                                                sizeof( uint64_t ), /* The size of each item. */\r
+                                                                NULL,                           /* Allocate the buffer used to hold items within the queue dynamically. */\r
+                                                                NULL );                         /* The queue structure is allocated dynamically. */\r
+\r
+       prvCheckQueueFunction( xQueue );\r
+       vQueueDelete( xQueue );\r
+\r
+       /* Ensure lower priority tasks get CPU time. */\r
+       vTaskDelay( prvGetNextDelayTime() );\r
+\r
+       /* Just to show the check task that this task is still executing. */\r
+       uxCycleCounter++;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvCreateAndDeleteStaticallyAllocatedBinarySemaphores( void )\r
+{\r
+SemaphoreHandle_t xSemaphore;\r
+\r
+/* StaticSemaphore_t is a publicly accessible structure that has the same size\r
+and alignment requirements as the real semaphore structure.  It is provided as a\r
+mechanism for applications to know the size of the semaphore (which is dependent\r
+on the architecture and configuration file settings) without breaking the strict\r
+data hiding policy by exposing the real semaphore internals.  This\r
+StaticSemaphore_t variable is passed into the xSemaphoreCreateBinary() function\r
+calls within this function.  NOTE: In most usage scenarios now it is faster and\r
+more memory efficient to use a direct to task notification instead of a binary\r
+semaphore.  http://www.freertos.org/RTOS-task-notifications.html */\r
+static StaticSemaphore_t xSemaphoreBuffer; /* Static so it doesn't use too much stack space. */\r
+\r
+       /* Create the semaphore.  xSemaphoreCreateBinaryStatic() has one more\r
+       parameter than the usual xSemaphoreCreateBinary() function.  The paraemter\r
+       is a pointer to the pre-allocated StaticSemaphore_t structure, which will\r
+       hold information on the semaphore in an anonymous way.  If the pointer is\r
+       passed as NULL then the structure will be allocated dynamically, just as\r
+       when xSemaphoreCreateBinary() is called. */\r
+       xSemaphore = xSemaphoreCreateBinaryStatic( &xSemaphoreBuffer );\r
+\r
+       /* The semaphore handle should equal the static semaphore structure passed\r
+       into the xSemaphoreCreateBinaryStatic() function. */\r
+       configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer );\r
+\r
+       /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */\r
+       prvCheckSemaphoreFunction( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );\r
+\r
+       /* Delete the semaphore again so the buffers can be reused. */\r
+       vSemaphoreDelete( xSemaphore );\r
+\r
+\r
+       /* The semaphore created above had a statically allocated semaphore\r
+       structure.  Repeat the above using NULL as the xSemaphoreCreateBinaryStatic()\r
+       parameter so the queue structure is instead allocated dynamically. */\r
+       xSemaphore = xSemaphoreCreateBinaryStatic( NULL );\r
+\r
+       /* Ensure the semaphore passes a few sanity checks as a valid semaphore. */\r
+       prvCheckSemaphoreFunction( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );\r
+\r
+       /* Delete the semaphore again so the buffers can be reused. */\r
+       vSemaphoreDelete( xSemaphore );\r
+\r
+\r
+\r
+       /* There isn't a static version of the old and deprecated\r
+       vSemaphoreCreateBinary() macro (because its deprecated!), but check it is\r
+       still functioning correctly when configSUPPORT_STATIC_ALLOCATION is set to\r
+       1. */\r
+       vSemaphoreCreateBinary( xSemaphore );\r
+\r
+       /* The macro starts with the binary semaphore available, but the test\r
+       function expects it to be unavailable. */\r
+       if( xSemaphoreTake( xSemaphore, staticDONT_BLOCK ) == pdFAIL )\r
+       {\r
+               xErrorOccurred = pdTRUE;\r
+       }\r
+\r
+       prvCheckSemaphoreFunction( xSemaphore, staticBINARY_SEMAPHORE_MAX_COUNT );\r
+       vSemaphoreDelete( xSemaphore );\r
+\r
+       /* Ensure lower priority tasks get CPU time. */\r
+       vTaskDelay( prvGetNextDelayTime() );\r
+\r
+       /* Just to show the check task that this task is still executing. */\r
+       uxCycleCounter++;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvCreateAndDeleteStaticallyAllocatedTasks( void )\r
+{\r
+TaskHandle_t xCreatedTask;\r
+BaseType_t xReturned;\r
+\r
+/* The variable that will hold the TCB of tasks created by this function.  See\r
+the comments above the declaration of the xCreatorTaskTCBBuffer variable for\r
+more information. */\r
+static StaticTCB_t xTCBBuffer; /* Static so it does not use too much stack space. */\r
+\r
+/* This buffer that will be used as the stack of tasks created by this function.\r
+See the comments above the declaration of the uxCreatorTaskStackBuffer[] array\r
+above for more information. */\r
+static StackType_t uxStackBuffer[ configMINIMAL_STACK_SIZE ];\r
+\r
+       /* Create the task.  xTaskCreateStatic() has two more parameters than\r
+       the usual xTaskCreate() function.  The first new parameter is a pointer to\r
+       the pre-allocated stack.  The second new parameter is a pointer to the\r
+       StaticTCB_t structure that will hold the task's TCB.  If either pointer is\r
+       passed as NULL then the respective object will be allocated dynamically as\r
+       if xTaskCreate() had been called. */\r
+       xReturned = xTaskCreateStatic(\r
+                                               prvStaticallyAllocatedTask, /* Function that implements the task. */\r
+                                               "Static",                                       /* Human readable name for the task. */\r
+                                               configMINIMAL_STACK_SIZE,       /* Task's stack size, in words (not bytes!). */\r
+                                               NULL,                                           /* Parameter to pass into the task. */\r
+                                               tskIDLE_PRIORITY,                       /* The priority of the task. */\r
+                                               &xCreatedTask,                          /* Handle of the task being created. */\r
+                                               &( uxStackBuffer[ 0 ] ),        /* The buffer to use as the task's stack. */\r
+                                               &xTCBBuffer );                          /* The variable that will hold that task's TCB. */\r
+\r
+       /* Check the task was created correctly, then delete the task. */\r
+       configASSERT( xReturned == pdPASS );\r
+       if( xReturned != pdPASS )\r
+       {\r
+               xErrorOccurred = pdTRUE;\r
+       }\r
+       vTaskDelete( xCreatedTask );\r
+\r
+       /* Ensure lower priority tasks get CPU time. */\r
+       vTaskDelay( prvGetNextDelayTime() );\r
+\r
+       /* Create and delete the task a few times again - testing both static and\r
+       dynamic allocation for the stack and TCB. */\r
+       xReturned = xTaskCreateStatic(\r
+                                               prvStaticallyAllocatedTask, /* Function that implements the task. */\r
+                                               "Static",                                       /* Human readable name for the task. */\r
+                                               configMINIMAL_STACK_SIZE,       /* Task's stack size, in words (not bytes!). */\r
+                                               NULL,                                           /* Parameter to pass into the task. */\r
+                                               staticTASK_PRIORITY + 1,        /* The priority of the task. */\r
+                                               &xCreatedTask,                          /* Handle of the task being created. */\r
+                                               NULL,                                           /* This time, dynamically allocate the stack. */\r
+                                               &xTCBBuffer );                          /* The variable that will hold that task's TCB. */\r
+\r
+       configASSERT( xReturned == pdPASS );\r
+       if( xReturned != pdPASS )\r
+       {\r
+               xErrorOccurred = pdTRUE;\r
+       }\r
+       vTaskDelete( xCreatedTask );\r
+\r
+       /* Just to show the check task that this task is still executing. */\r
+       uxCycleCounter++;\r
+\r
+       /* Ensure lower priority tasks get CPU time. */\r
+       vTaskDelay( prvGetNextDelayTime() );\r
+\r
+       xReturned = xTaskCreateStatic(\r
+                                               prvStaticallyAllocatedTask, /* Function that implements the task. */\r
+                                               "Static",                                       /* Human readable name for the task. */\r
+                                               configMINIMAL_STACK_SIZE,       /* Task's stack size, in words (not bytes!). */\r
+                                               NULL,                                           /* Parameter to pass into the task. */\r
+                                               staticTASK_PRIORITY - 1,        /* The priority of the task. */\r
+                                               &xCreatedTask,                          /* Handle of the task being created. */\r
+                                               &( uxStackBuffer[ 0 ] ),        /* The buffer to use as the task's stack. */\r
+                                               NULL );                                         /* This time dynamically allocate the TCB. */\r
+\r
+       configASSERT( xReturned == pdPASS );\r
+       if( xReturned != pdPASS )\r
+       {\r
+               xErrorOccurred = pdTRUE;\r
+       }\r
+       vTaskDelete( xCreatedTask );\r
+\r
+       /* Ensure lower priority tasks get CPU time. */\r
+       vTaskDelay( prvGetNextDelayTime() );\r
+\r
+       xReturned = xTaskCreateStatic(\r
+                                               prvStaticallyAllocatedTask, /* Function that implements the task. */\r
+                                               "Static",                                       /* Human readable name for the task. */\r
+                                               configMINIMAL_STACK_SIZE,       /* Task's stack size, in words (not bytes!). */\r
+                                               NULL,                                           /* Parameter to pass into the task. */\r
+                                               staticTASK_PRIORITY,            /* The priority of the task. */\r
+                                               &xCreatedTask,                          /* Handle of the task being created. */\r
+                                               NULL,                                           /* This time dynamically allocate the stack and TCB. */\r
+                                               NULL );                                         /* This time dynamically allocate the stack and TCB. */\r
+\r
+       configASSERT( xReturned == pdPASS );\r
+       if( xReturned != pdPASS )\r
+       {\r
+               xErrorOccurred = pdTRUE;\r
+       }\r
+       vTaskDelete( xCreatedTask );\r
+\r
+       /* Ensure lower priority tasks get CPU time. */\r
+       vTaskDelay( prvGetNextDelayTime() );\r
+\r
+       /* Just to show the check task that this task is still executing. */\r
+       uxCycleCounter++;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -299,13 +679,21 @@ static UBaseType_t uxLastCycleCounter = 0;
 BaseType_t xReturn;\r
 \r
        if( uxCycleCounter == uxLastCycleCounter )\r
+       {\r
+               xErrorOccurred = pdTRUE;\r
+       }\r
+       else\r
+       {\r
+               uxLastCycleCounter = uxCycleCounter;\r
+       }\r
+\r
+       if( xErrorOccurred != pdFALSE )\r
        {\r
                xReturn = pdFAIL;\r
        }\r
        else\r
        {\r
                xReturn = pdPASS;\r
-               uxLastCycleCounter = uxCycleCounter;\r
        }\r
 \r
        return xReturn;\r
index bf6f2bbb803ffd133993f527e24335a53b82de22..3389e4a84e193c6e7e353b3c11f41e3d43595d00 100644 (file)
@@ -193,7 +193,7 @@ UBaseType_t ux;
        /* We should be able to 'take' the semaphore countMAX_COUNT_VALUE times. */\r
        for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ )\r
        {\r
-               configASSERT( xSemaphoreGetCount( xSemaphore ) == ( countMAX_COUNT_VALUE - ux ) );\r
+               configASSERT( uxSemaphoreGetCount( xSemaphore ) == ( countMAX_COUNT_VALUE - ux ) );\r
 \r
                if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) != pdPASS )\r
                {\r
@@ -210,7 +210,7 @@ UBaseType_t ux;
 \r
        /* If the semaphore count is zero then we should not be able to 'take'\r
        the semaphore. */\r
-       configASSERT( xSemaphoreGetCount( xSemaphore ) == 0 );\r
+       configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 );\r
        if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS )\r
        {\r
                xErrorDetected = pdTRUE;\r
@@ -232,7 +232,7 @@ UBaseType_t ux;
        /* We should be able to 'give' the semaphore countMAX_COUNT_VALUE times. */\r
        for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ )\r
        {\r
-               configASSERT( xSemaphoreGetCount( xSemaphore ) == ux );\r
+               configASSERT( uxSemaphoreGetCount( xSemaphore ) == ux );\r
 \r
                if( xSemaphoreGive( xSemaphore ) != pdPASS )\r
                {\r
index 0e23edcdfa02e51b943eade15f12eb41f6622981..cb75a6fb356f000ca4dc23b181ea4f0880d6a5a7 100644 (file)
@@ -922,7 +922,7 @@ typedef struct xSTATIC_TCB
                eDummy                  eDummy19;\r
        #endif\r
        #if ( configSUPPORT_STATIC_ALLOCATION == 1 )\r
-               UBaseType_t             uxDummy20;\r
+               uint8_t                 uxDummy20;\r
        #endif\r
 \r
 } StaticTCB_t;\r
@@ -964,6 +964,8 @@ typedef struct xSTATIC_QUEUE
 \r
 } StaticQueue_t;\r
 \r
+typedef StaticQueue_t StaticSemaphore_t;\r
+\r
 \r
 #ifdef __cplusplus\r
 }\r
index dfaa647fe5e04ec1e4a6d647c1bf4fc642650314..a63481b34c23b60051b26f77c4867d541bc9cca3 100644 (file)
@@ -170,7 +170,11 @@ typedef void * QueueSetMemberHandle_t;
  * \defgroup xQueueCreate xQueueCreate\r
  * \ingroup QueueManagement\r
  */\r
-#define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( uxQueueLength, uxItemSize, queueQUEUE_TYPE_BASE )\r
+#define xQueueCreate( uxQueueLength, uxItemSize ) xQueueGenericCreate( uxQueueLength, uxItemSize, NULL, NULL, queueQUEUE_TYPE_BASE )\r
+\r
+#if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+       #define xQueueCreateStatic( uxQueueLength, uxItemSize, pucQueueStorage, pxStaticQueue ) xQueueGenericCreate( uxQueueLength, uxItemSize, pucQueueStorage, pxStaticQueue, queueQUEUE_TYPE_BASE )\r
+#endif\r
 \r
 /**\r
  * queue. h\r
@@ -1554,7 +1558,7 @@ BaseType_t xQueueGiveMutexRecursive( QueueHandle_t pxMutex ) PRIVILEGED_FUNCTION
  * Generic version of the queue creation function, which is in turn called by\r
  * any queue, semaphore or mutex creation function or macro.\r
  */\r
-QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;\r
+QueueHandle_t xQueueGenericCreate( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue, const uint8_t ucQueueType ) PRIVILEGED_FUNCTION;\r
 \r
 /*\r
  * Queue sets provide a mechanism to allow a task to block (pend) on a read\r
index 4a1e72969caeaebdec0d42c97937271d76c10057..a2ae50ec4713c770ea8db4b59063ffedc3a62eff 100644 (file)
@@ -87,6 +87,10 @@ typedef QueueHandle_t SemaphoreHandle_t;
  * semphr. h\r
  * <pre>vSemaphoreCreateBinary( SemaphoreHandle_t xSemaphore )</pre>\r
  *\r
+ * In many usage scenarios it is faster and more memory efficient to use a\r
+ * direct to task notification in place of a binary semaphore!\r
+ * http://www.freertos.org/RTOS-task-notifications.html\r
+ *\r
  * This old vSemaphoreCreateBinary() macro is now deprecated in favour of the\r
  * xSemaphoreCreateBinary() function.  Note that binary semaphores created using\r
  * the vSemaphoreCreateBinary() macro are created in a state such that the\r
@@ -128,19 +132,23 @@ typedef QueueHandle_t SemaphoreHandle_t;
  * \defgroup vSemaphoreCreateBinary vSemaphoreCreateBinary\r
  * \ingroup Semaphores\r
  */\r
-#define vSemaphoreCreateBinary( xSemaphore )                                                                                                                                                                                   \\r
-       {                                                                                                                                                                                                                                                                       \\r
-               ( xSemaphore ) = xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE );    \\r
-               if( ( xSemaphore ) != NULL )                                                                                                                                                                                                    \\r
-               {                                                                                                                                                                                                                                                               \\r
-                       ( void ) xSemaphoreGive( ( xSemaphore ) );                                                                                                                                                                      \\r
-               }                                                                                                                                                                                                                                                               \\r
+#define vSemaphoreCreateBinary( xSemaphore )                                                                                                                                                                                                           \\r
+       {                                                                                                                                                                                                                                                                                               \\r
+               ( xSemaphore ) = xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, NULL, queueQUEUE_TYPE_BINARY_SEMAPHORE );        \\r
+               if( ( xSemaphore ) != NULL )                                                                                                                                                                                                                            \\r
+               {                                                                                                                                                                                                                                                                                       \\r
+                       ( void ) xSemaphoreGive( ( xSemaphore ) );                                                                                                                                                                                              \\r
+               }                                                                                                                                                                                                                                                                                       \\r
        }\r
 \r
 /**\r
  * semphr. h\r
  * <pre>SemaphoreHandle_t xSemaphoreCreateBinary( void )</pre>\r
  *\r
+ * In many usage scenarios it is faster and more memory efficient to use a\r
+ * direct to task notification in place of a binary semaphore!\r
+ * http://www.freertos.org/RTOS-task-notifications.html\r
+ *\r
  * The old vSemaphoreCreateBinary() macro is now deprecated in favour of this\r
  * xSemaphoreCreateBinary() function.  Note that binary semaphores created using\r
  * the vSemaphoreCreateBinary() macro are created in a state such that the\r
@@ -182,7 +190,8 @@ typedef QueueHandle_t SemaphoreHandle_t;
  * \defgroup vSemaphoreCreateBinary vSemaphoreCreateBinary\r
  * \ingroup Semaphores\r
  */\r
-#define xSemaphoreCreateBinary() xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE )\r
+#define xSemaphoreCreateBinary() xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, NULL, queueQUEUE_TYPE_BINARY_SEMAPHORE )\r
+#define xSemaphoreCreateBinaryStatic( pxStaticQueue ) xQueueGenericCreate( ( UBaseType_t ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, NULL, pxStaticQueue, queueQUEUE_TYPE_BINARY_SEMAPHORE )\r
 \r
 /**\r
  * semphr. h\r
@@ -849,7 +858,7 @@ typedef QueueHandle_t SemaphoreHandle_t;
  * semaphore is not available.\r
  *\r
  */\r
-#define xSemaphoreGetCount( xSemaphore ) uxQueueMessagesWaiting( ( QueueHandle_t ) ( xSemaphore ) )\r
+#define uxSemaphoreGetCount( xSemaphore ) uxQueueMessagesWaiting( ( QueueHandle_t ) ( xSemaphore ) )\r
 \r
 #endif /* SEMAPHORE_H */\r
 \r
index 1108d34212811f20ef8c7bb9415ece7572a2fc33..a4d423b27851998d0b4226aba2fb59c211ab3120 100644 (file)
@@ -128,12 +128,6 @@ typedef enum
        eSetValueWithoutOverwrite       /* Set the task's notification value if the previous value has been read by the task. */\r
 } eNotifyAction;\r
 \r
-/* For data hiding purposes. */\r
-typedef enum\r
-{\r
-       eNothing = 0\r
-} eDummy;\r
-\r
 /*\r
  * Used internally only.\r
  */\r
@@ -197,58 +191,6 @@ typedef enum
        eNotified\r
 } eNotifyValue;\r
 \r
-/*\r
- * FreeRTOS implements a strict data hiding policy, so the real task control\r
- * block (TCB) structure is not accessible to the application code.  However, if\r
- * the application writer wants to statically allocate a TCB then the size of\r
- * the TCB needs to be know.  The dummy TCB structure below is used for this\r
- * purpose.  Its size will allows match the size of the real TCB, no matter what\r
- * the FreeRTOSConfig.h settings.\r
- */\r
-typedef struct xDUMMY_TCB\r
-{\r
-       void                            *pxDummy1;\r
-       #if ( portUSING_MPU_WRAPPERS == 1 )\r
-               xMPU_SETTINGS   xDummy2;\r
-       #endif\r
-       ListItem_t                      xDummy3[ 2 ];\r
-       UBaseType_t                     uxDummy5;\r
-       void                            *pxDummy6;\r
-       uint8_t                         ucDummy7[ configMAX_TASK_NAME_LEN ];\r
-       #if ( portSTACK_GROWTH > 0 )\r
-               void                    *pxDummy8;\r
-       #endif\r
-       #if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
-               UBaseType_t             uxDummy9;\r
-       #endif\r
-       #if ( configUSE_TRACE_FACILITY == 1 )\r
-               UBaseType_t             uxDummy10[ 2 ];\r
-       #endif\r
-       #if ( configUSE_MUTEXES == 1 )\r
-               UBaseType_t             uxDummy12[ 2 ];\r
-       #endif\r
-       #if ( configUSE_APPLICATION_TASK_TAG == 1 )\r
-               void                    *pxDummy14;\r
-       #endif\r
-       #if( configNUM_THREAD_LOCAL_STORAGE_POINTERS > 0 )\r
-               void                    pvDummy15[ configNUM_THREAD_LOCAL_STORAGE_POINTERS ];\r
-       #endif\r
-       #if ( configGENERATE_RUN_TIME_STATS == 1 )\r
-               uint32_t                ulDummy16;\r
-       #endif\r
-       #if ( configUSE_NEWLIB_REENTRANT == 1 )\r
-               struct  _reent  xDummy17;\r
-       #endif\r
-       #if ( configUSE_TASK_NOTIFICATIONS == 1 )\r
-               uint32_t                ulDummy18;\r
-               eDummy                  eDummy19;\r
-       #endif\r
-       #if ( configSUPPORT_STATIC_ALLOCATION == 1 )\r
-               UBaseType_t             uxDummy20;\r
-       #endif\r
-\r
-} DummyTCB_t;\r
-\r
 /**\r
  * Defines the priority used by the idle task.  This must not be modified.\r
  *\r
@@ -420,14 +362,14 @@ is used in assert() statements. */
                                                          UBaseType_t uxPriority,\r
                                                          TaskHandle_t *pvCreatedTask,\r
                                                          StackType_t *pxStackBuffer,\r
-                                                         DummyTCB_t *pxTCBBuffer\r
+                                                         StaticTCB_t *pxTCBBuffer\r
                                                  );</pre>\r
  *\r
  * Create a new task and add it to the list of tasks that are ready to run.\r
- * If a task is created using xTaskCreate() then the stack and task control \r
+ * If a task is created using xTaskCreate() then the stack and task control\r
  * block (TCB) used by the task are allocated dynamically.  If a task is created\r
  * using xTaskCreateStatic() then the application writer can optionally provide\r
- * the buffers that will hold the task stack and TCB respectively.  \r
+ * the buffers that will hold the task stack and TCB respectively.\r
  * xTaskCreateStatic() therefore allows tasks to be created without any dynamic\r
  * memory allocation.\r
  *\r
@@ -435,7 +377,7 @@ is used in assert() statements. */
  * must be implemented to never return (i.e. continuous loop).\r
  *\r
  * @param pcName A descriptive name for the task.  This is mainly used to\r
- * facilitate debugging.  The maximum length of the string is defined by \r
+ * facilitate debugging.  The maximum length of the string is defined by\r
  * configMAX_TASK_NAME_LEN in FreeRTOSConfig.h.\r
  *\r
  * @param usStackDepth The size of the task stack specified as the number of\r
@@ -453,14 +395,14 @@ is used in assert() statements. */
  *\r
  * @param pxStackBuffer If pxStackBuffer is NULL then the stack used by the\r
  * task will be allocated dynamically, just as if the task was created using\r
- * xTaskCreate().  if pxStackBuffer is not NULL then it must point to a \r
+ * xTaskCreate().  if pxStackBuffer is not NULL then it must point to a\r
  * StackType_t array that has at least usStackDepth indexes - the array will\r
  * then be used as the task's stack.\r
  *\r
  * @param pxTCBBuffer If pxTCBBuffer is NULL then the TCB (which is the\r
  * structures used internally within FreeRTOS to hold information on the task)\r
  * will be allocated dynamically, just as when xTaskCreate() is used.  If\r
- * pxTCBBuffer is not NULL then it must point to a variable of type DummyTCB_T,\r
+ * pxTCBBuffer is not NULL then it must point to a variable of type StaticTCB_t,\r
  * which will then be used as the TCB of the task being created.\r
  *\r
  * @return pdPASS if the task was successfully created and added to a ready\r
@@ -476,11 +418,11 @@ is used in assert() statements. */
  #define STACK_SIZE 200\r
 \r
  // Structure that will hold the TCB of the task being created.\r
DummyTCB_t xTCB;\r
StaticTCB_t xTCB;\r
 \r
  // Buffer that the task being created will use as its stack.\r
  StackType_t xStack[ STACK_SIZE ];\r
-   \r
+\r
  // Task to be created.\r
  void vTaskCode( void * pvParameters )\r
  {\r
@@ -500,7 +442,7 @@ is used in assert() statements. */
         xTaskCreate( vTaskCode,          // As per xTaskCreate() parameter.\r
                                  "NAME",             // As per xTaskCreate() parameter.\r
                                  STACK_SIZE,         // As per xTaskCreate() parameter.\r
-                                 &ucParameterToPass, // As per xTaskCreate() parameter. \r
+                                 &ucParameterToPass, // As per xTaskCreate() parameter.\r
                                  tskIDLE_PRIORITY,   // As per xTaskCreate() parameter.\r
                                  &xHandle,           // As per xTaskCreate() parameter.\r
                                  xStack,             // Pointer to the buffer that the task being created will use as its stack.\r
@@ -2153,7 +2095,7 @@ BaseType_t xTaskPriorityDisinherit( TaskHandle_t const pxMutexHolder ) PRIVILEGE
  * Generic version of the task creation function which is in turn called by the\r
  * xTaskCreate() and xTaskCreateRestricted() macros.\r
  */\r
-BaseType_t xTaskGenericCreate( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask, StackType_t * const puxStackBuffer, DummyTCB_t * const pxTCBBuffer, const MemoryRegion_t * const xRegions ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
+BaseType_t xTaskGenericCreate( TaskFunction_t pxTaskCode, const char * const pcName, const uint16_t usStackDepth, void * const pvParameters, UBaseType_t uxPriority, TaskHandle_t * const pxCreatedTask, StackType_t * const puxStackBuffer, StaticTCB_t * const pxTCBBuffer, const MemoryRegion_t * const xRegions ) PRIVILEGED_FUNCTION; /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
 \r
 /*\r
  * Get the uxTCBNumber assigned to the task referenced by the xTask parameter.\r
index 17a860d98866934c636a50b775936abaf45a0e50..fc6224d230de896b10bdcc5c7114a712354296e9 100644 (file)
@@ -239,6 +239,17 @@ static BaseType_t prvCopyDataToQueue( Queue_t * const pxQueue, const void *pvIte
  */\r
 static void prvCopyDataFromQueue( Queue_t * const pxQueue, void * const pvBuffer ) PRIVILEGED_FUNCTION;\r
 \r
+/*\r
+ * A queue requires two blocks of memory; a structure to hold the queue state\r
+ * and a storage area to hold the items in the queue.  The memory is assigned\r
+ * by prvAllocateQueueMemory().  If ppucQueueStorage is NULL then the queue\r
+ * storage will allocated dynamically, otherwise the buffer passed in\r
+ * ppucQueueStorage will be used.  If pxStaticQueue is NULL then the queue\r
+ * structure will be allocated dynamically, otherwise the buffer pointed to by\r
+ * pxStaticQueue will be used.\r
+ */\r
+static Queue_t *prvAllocateQueueMemory( const UBaseType_t uxQueueLength, const UBaseType_t uxItemSize, uint8_t **ppucQueueStorage, StaticQueue_t *pxStaticQueue );\r
+\r
 #if ( configUSE_QUEUE_SETS == 1 )\r
        /*\r
         * Checks to see if a queue is a member of a queue set, and if so, notifies\r
@@ -331,8 +342,8 @@ size_t xQueueSizeInBytes;
        #if( ( configASSERT_DEFINED == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) )\r
        {\r
                /* Sanity check that the size of the structure used to declare a\r
-               variable of type DummyQueue_t or DummySemaphore_t equals the size of the\r
-               real queue and semaphore structures. */\r
+               variable of type StaticQueue_t or StaticSemaphore_t equals the size of \r
+               the real queue and semaphore structures. */\r
                volatile size_t xSize = sizeof( StaticQueue_t );\r
                configASSERT( xSize == sizeof( Queue_t ) );\r
        }\r
@@ -345,9 +356,9 @@ size_t xQueueSizeInBytes;
        }\r
        else\r
        {\r
-               /* The queue is one byte longer than asked for to make wrap checking\r
-               easier/faster. */\r
-               xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ) + ( size_t ) 1; /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
+               /* Allocate enough space to hold the maximum number of items that can be\r
+               in the queue at any time. */\r
+               xQueueSizeInBytes = ( size_t ) ( uxQueueLength * uxItemSize ); /*lint !e961 MISRA exception as the casts are only redundant for some ports. */\r
        }\r
 \r
        #if( configSUPPORT_STATIC_ALLOCATION == 0 )\r
@@ -361,7 +372,7 @@ size_t xQueueSizeInBytes;
                        storage area. */\r
                        *ppucQueueStorage = ( ( uint8_t * ) pxNewQueue ) + sizeof( Queue_t );\r
                }\r
-               \r
+\r
                /* The pxStaticQueue parameter is not used.  Remove compiler warnings. */\r
                ( void ) pxStaticQueue;\r
        }\r
@@ -399,8 +410,17 @@ size_t xQueueSizeInBytes;
                                        {\r
                                                vPortFree( ( void * ) pxNewQueue );\r
                                        }\r
+                                       else\r
+                                       {\r
+                                               mtCOVERAGE_TEST_MARKER();\r
+                                       }\r
+\r
                                        pxNewQueue = NULL;\r
                                }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
                        }\r
                        else\r
                        {\r
@@ -1860,6 +1880,10 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        freed. */\r
                        vPortFree( pxQueue->pcHead );\r
                }\r
+               else\r
+               {\r
+                       mtCOVERAGE_TEST_MARKER();\r
+               }\r
 \r
                if( ( pxQueue->ucStaticAllocationFlags & queueSTATICALLY_ALLOCATED_QUEUE_STRUCT ) == 0 )\r
                {\r
@@ -1867,6 +1891,10 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        free. */\r
                        vPortFree( pxQueue );\r
                }\r
+               else\r
+               {\r
+                       mtCOVERAGE_TEST_MARKER();\r
+               }\r
        }\r
        #endif\r
 }\r