]> git.sur5r.net Git - freertos/commitdiff
Update TaskNotify.c to test the condition where a direct to task notification is...
authorrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Fri, 25 Nov 2016 21:07:56 +0000 (21:07 +0000)
committerrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Fri, 25 Nov 2016 21:07:56 +0000 (21:07 +0000)
Introduce configSTACK_DEPTH_TYPE so the application writer change the type used to specify a stack size from uint16_t to whatever they like.  Defaults to uint16_t if not defined.
Introduce configINITIAL_TICK_COUNT to allow users to start the tick count at something other than 0.  Used for testing, but overflows can be better tested by setting configUSE_16_BIT_TICKS to 1.
Split xQueueGenericReceive() into xQueueReceive(), xQueuePeek() and xQueueSemaphoreTake() as the first step in refactoring xQueueGenericReceive().
Add Cortex-M3 port layer for Code Composer Studio - previously there was only a Cortex-M4F port.
Introduce configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING() to allow applications to prevent portSUPPRESS_TICKS_AND_SLEEP() being called.  Previously the portPRE_SLEEP_PROCESSING() macro could only be used to abort entry into sleep time after clocks had been re-programmed for the distant wake time.

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

14 files changed:
FreeRTOS/Demo/Common/Minimal/TaskNotify.c
FreeRTOS/Source/event_groups.c
FreeRTOS/Source/include/FreeRTOS.h
FreeRTOS/Source/include/mpu_prototypes.h
FreeRTOS/Source/include/mpu_wrappers.h
FreeRTOS/Source/include/queue.h
FreeRTOS/Source/include/semphr.h
FreeRTOS/Source/include/task.h
FreeRTOS/Source/portable/CCS/ARM_CM3/port.c [new file with mode: 0644]
FreeRTOS/Source/portable/CCS/ARM_CM3/portasm.asm [new file with mode: 0644]
FreeRTOS/Source/portable/CCS/ARM_CM3/portmacro.h [new file with mode: 0644]
FreeRTOS/Source/portable/Common/mpu_wrappers.c
FreeRTOS/Source/queue.c
FreeRTOS/Source/tasks.c

index 2eafef4649cce8162660eafc8dc9c9894f3476a0..a1d1f35dcbe996f8097ddd614523a52fe9855d92 100644 (file)
@@ -85,6 +85,8 @@
 \r
 #define notifyTASK_PRIORITY            ( tskIDLE_PRIORITY )\r
 #define notifyUINT32_MAX       ( ( uint32_t ) 0xffffffff )\r
+#define notifySUSPENDED_TEST_TIMER_PERIOD pdMS_TO_TICKS( 50 )\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
@@ -108,6 +110,14 @@ static void prvNotifyingTimer( TimerHandle_t xTimer );
  */\r
 static UBaseType_t prvRand( void );\r
 \r
+/*\r
+ * Callback for a timer that is used during preliminary testing.  The timer\r
+ * tests the behaviour when 1: a task waiting for a notification is suspended\r
+ * and then resumed without ever receiving a notification, and 2: when a task\r
+ * waiting for a notification receives a notification while it is suspended.\r
+ */\r
+static void prvSuspendedTaskTimerTestCallback( TimerHandle_t xExpiredTimer );\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /* Used to latch errors during the test's execution. */\r
@@ -151,8 +161,10 @@ uint32_t ulNotifiedValue, ulLoop, ulNotifyingValue, ulPreviousValue, ulExpectedV
 TickType_t xTimeOnEntering;\r
 const uint32_t ulFirstNotifiedConst = 100001UL, ulSecondNotifiedValueConst = 5555UL, ulMaxLoops = 5UL;\r
 const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;\r
+TimerHandle_t xSingleTaskTimer;\r
+\r
 \r
-       /* -------------------------------------------------------------------------\r
+       /* ------------------------------------------------------------------------\r
        Check blocking when there are no notifications. */\r
        xTimeOnEntering = xTaskGetTickCount();\r
        xReturned = xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, xTicksToWait );\r
@@ -168,7 +180,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
-       /* -------------------------------------------------------------------------\r
+       /* ------------------------------------------------------------------------\r
        Check no blocking when notifications are pending.  First notify itself -\r
        this would not be a normal thing to do and is done here for test purposes\r
        only. */\r
@@ -202,7 +214,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
+       /*-------------------------------------------------------------------------\r
        Check the non-overwriting functionality.  The notification is done twice\r
        using two different notification values.  The action says don't overwrite so\r
        only the first notification should pass and the value read back should also\r
@@ -224,7 +236,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
+       /*-------------------------------------------------------------------------\r
        Do the same again, only this time use the overwriting version.  This time\r
        both notifications should pass, and the value written the second time should\r
        overwrite the value written the first time, and so be the value that is read\r
@@ -240,7 +252,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
+       /*-------------------------------------------------------------------------\r
        Check notifications with no action pass without updating the value.  Even\r
        though ulFirstNotifiedConst is used as the value the value read back should\r
        remain at ulSecondNotifiedConst. */\r
@@ -252,7 +264,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
+       /*-------------------------------------------------------------------------\r
        Check incrementing values.  Send ulMaxLoop increment notifications, then\r
        ensure the received value is as expected - which should be\r
        ulSecondNotificationValueConst plus how ever many times to loop iterated. */\r
@@ -273,7 +285,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
+       /*-------------------------------------------------------------------------\r
        Check all bits can be set by notifying the task with one additional bit set\r
        on each notification, and exiting the loop when all the bits are found to be\r
        set.  As there are 32-bits the loop should execute 32 times before all the\r
@@ -309,7 +321,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
+       /*-------------------------------------------------------------------------\r
        Check bits are cleared on entry but not on exit when a notification fails\r
        to arrive before timing out - both with and without a timeout value.  Wait\r
        for the notification again - but this time it is not given by anything and\r
@@ -334,7 +346,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
+       /*-------------------------------------------------------------------------\r
        Now try clearing the bit on exit.  For that to happen a notification must be\r
        received, so the task is notified first. */\r
        xTaskNotify( xTaskToNotify, 0, eNoAction );\r
@@ -355,8 +367,8 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
-       /*--------------------------------------------------------------------------\r
-       Now try querying the previus value while notifying a task. */\r
+       /*-------------------------------------------------------------------------\r
+       Now try querying the previous value while notifying a task. */\r
        xTaskNotifyAndQuery( xTaskToNotify, 0x00, eSetBits, &ulPreviousValue );\r
        configASSERT( ulNotifiedValue == ( notifyUINT32_MAX & ~( ulBit0 | ulBit1 ) ) );\r
 \r
@@ -378,7 +390,7 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
-       /* -------------------------------------------------------------------------\r
+       /* ------------------------------------------------------------------------\r
        Clear the previous notifications. */\r
        xTaskNotifyWait( notifyUINT32_MAX, 0, &ulNotifiedValue, 0 );\r
 \r
@@ -397,6 +409,51 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 \r
 \r
 \r
+       /* ------------------------------------------------------------------------\r
+       Create a timer that will try notifying this task while it is suspended. */\r
+       xSingleTaskTimer = xTimerCreate( "SingleNotify", notifySUSPENDED_TEST_TIMER_PERIOD, pdFALSE, NULL, prvSuspendedTaskTimerTestCallback );\r
+       configASSERT( xSingleTaskTimer );\r
+\r
+       /* Incremented to show the task is still running. */\r
+       ulNotifyCycleCount++;\r
+\r
+       /* Ensure no notifications are pending. */\r
+       xTaskNotifyWait( notifyUINT32_MAX, 0, NULL, 0 );\r
+\r
+       /* Raise the task's priority so it can suspend itself before the timer\r
+       expires. */\r
+       vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );\r
+\r
+       /* Start the timer that will try notifying this task while it is\r
+       suspended, then wait for a notification.  The first time the callback\r
+       executes the timer will suspend the task, then resume the task, without\r
+       ever sending a notification to the task. */\r
+       ulNotifiedValue = 0;\r
+       xTimerStart( xSingleTaskTimer, portMAX_DELAY );\r
+\r
+       /* Check a notification is not received. */\r
+       xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, portMAX_DELAY );\r
+       configASSERT( xReturned == pdFALSE );\r
+       configASSERT( ulNotifiedValue == 0 );\r
+\r
+       /* Incremented to show the task is still running. */\r
+       ulNotifyCycleCount++;\r
+\r
+       /* Start the timer that will try notifying this task while it is\r
+       suspended, then wait for a notification.  The second time the callback\r
+       executes the timer will suspend the task, notify the task, then resume the\r
+       task (previously it was suspended and resumed without being notified). */\r
+       xTimerStart( xSingleTaskTimer, portMAX_DELAY );\r
+\r
+       /* Check a notification is received. */\r
+       xReturned = xTaskNotifyWait( 0, 0, &ulNotifiedValue, portMAX_DELAY );\r
+       configASSERT( xReturned == pdPASS );\r
+       configASSERT( ulNotifiedValue != 0 );\r
+\r
+       /* Return the task to its proper priority and delete the timer as it is\r
+       not used again. */\r
+       vTaskPrioritySet( NULL, notifyTASK_PRIORITY );\r
+       xTimerDelete( xSingleTaskTimer, portMAX_DELAY );\r
 \r
        /* Incremented to show the task is still running. */\r
        ulNotifyCycleCount++;\r
@@ -406,6 +463,43 @@ const uint32_t ulBit0 = 0x01UL, ulBit1 = 0x02UL;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+static void prvSuspendedTaskTimerTestCallback( TimerHandle_t xExpiredTimer )\r
+{\r
+static uint32_t ulCallCount = 0;\r
+\r
+       /* Remove compiler warnings about unused parameters. */\r
+       ( void ) xExpiredTimer;\r
+\r
+       /* Callback for a timer that is used during preliminary testing.  The timer\r
+       tests the behaviour when 1: a task waiting for a notification is suspended\r
+       and then resumed without ever receiving a notification, and 2: when a task\r
+       waiting for a notification receives a notification while it is suspended. */\r
+\r
+       if( ulCallCount == 0 )\r
+       {\r
+               vTaskSuspend( xTaskToNotify );\r
+               configASSERT( eTaskGetState( xTaskToNotify ) == eSuspended );\r
+               vTaskResume( xTaskToNotify );\r
+       }\r
+       else\r
+       {\r
+               vTaskSuspend( xTaskToNotify );\r
+\r
+               /* Sending a notification while the task is suspended should pass, but\r
+               not cause the task to resume.  ulCallCount is just used as a convenient\r
+               non-zero value. */\r
+               xTaskNotify( xTaskToNotify, ulCallCount, eSetValueWithOverwrite );\r
+\r
+               /* Make sure giving the notification didn't resume the task. */\r
+               configASSERT( eTaskGetState( xTaskToNotify ) == eSuspended );\r
+\r
+               vTaskResume( xTaskToNotify );\r
+       }\r
+\r
+       ulCallCount++;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 static void prvNotifyingTimer( TimerHandle_t xNotUsed )\r
 {\r
        ( void ) xNotUsed;\r
@@ -441,8 +535,8 @@ const uint32_t ulCyclesToRaisePriority = 50UL;
        for( ;; )\r
        {\r
                /* Start the timer again with a different period.  Sometimes the period\r
-               will be higher than the tasks block time, sometimes it will be lower\r
-               than the tasks block time. */\r
+               will be higher than the task's block time, sometimes it will be lower\r
+               than the task's block time. */\r
                xPeriod = prvRand() % xMaxPeriod;\r
                if( xPeriod < xMinPeriod )\r
                {\r
@@ -453,8 +547,8 @@ const uint32_t ulCyclesToRaisePriority = 50UL;
                xTimerChangePeriod( xTimer, xPeriod, portMAX_DELAY );\r
 \r
                /* Block waiting for the notification again with a different period.\r
-               Sometimes the period will be higher than the tasks block time, sometimes\r
-               it will be lower than the tasks block time. */\r
+               Sometimes the period will be higher than the task's block time,\r
+               sometimes it will be lower than the task's block time. */\r
                xPeriod = prvRand() % xMaxPeriod;\r
                if( xPeriod < xMinPeriod )\r
                {\r
@@ -487,13 +581,13 @@ const uint32_t ulCyclesToRaisePriority = 50UL;
                the path where the task is notified from an ISR and becomes the highest\r
                priority ready state task, but the pxHigherPriorityTaskWoken parameter\r
                is NULL (which it is in the tick hook that sends notifications to this\r
-               task. */\r
+               task). */\r
                if( ( ulNotifyCycleCount % ulCyclesToRaisePriority ) == 0 )\r
                {\r
                        vTaskPrioritySet( xTaskToNotify, configMAX_PRIORITIES - 1 );\r
 \r
-                       /* Wait for the next notification again, clearing all notifications if\r
-                       one is received, but this time blocking indefinitely. */\r
+                       /* Wait for the next notification again, clearing all notifications\r
+                       if one is received, but this time blocking indefinitely. */\r
                        ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );\r
 \r
                        /* Reset the priority. */\r
@@ -501,8 +595,8 @@ const uint32_t ulCyclesToRaisePriority = 50UL;
                }\r
                else\r
                {\r
-                       /* Wait for the next notification again, clearing all notifications if\r
-                       one is received, but this time blocking indefinitely. */\r
+                       /* Wait for the next notification again, clearing all notifications\r
+                       if one is received, but this time blocking indefinitely. */\r
                        ulTimerNotificationsReceived += ulTaskNotifyTake( pdTRUE, portMAX_DELAY );\r
                }\r
 \r
index 5a21e2d05c284bc7f849a16326d3236ba9d1fd90..f999d3588ff17bc7daa04c239de680e6c7fdb6d6 100644 (file)
@@ -643,7 +643,7 @@ const List_t *pxTasksWaitingForBits = &( pxEventBits->xTasksWaitingForBits );
                while( listCURRENT_LIST_LENGTH( pxTasksWaitingForBits ) > ( UBaseType_t ) 0 )\r
                {\r
                        /* Unblock the task, returning 0 as the event list is being deleted\r
-                       and     cannot therefore have any bits set. */\r
+                       and cannot therefore have any bits set. */\r
                        configASSERT( pxTasksWaitingForBits->xListEnd.pxNext != ( const ListItem_t * ) &( pxTasksWaitingForBits->xListEnd ) );\r
                        vTaskRemoveFromUnorderedEventList( pxTasksWaitingForBits->xListEnd.pxNext, eventUNBLOCKED_DUE_TO_BIT_SET );\r
                }\r
index aeb4b876ddf209945a371e55d58f5430f7d89b02..c2e47390ad6de4d72d1b22dd1705f3aa2d04da7e 100644 (file)
@@ -716,6 +716,10 @@ extern "C" {
        #define configUSE_TICKLESS_IDLE 0\r
 #endif\r
 \r
+#ifndef configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING\r
+       #define configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING( x )\r
+#endif\r
+\r
 #ifndef configPRE_SLEEP_PROCESSING\r
        #define configPRE_SLEEP_PROCESSING( x )\r
 #endif\r
@@ -790,6 +794,12 @@ extern "C" {
        #define configSUPPORT_DYNAMIC_ALLOCATION 1\r
 #endif\r
 \r
+#ifndef configSTACK_DEPTH_TYPE\r
+       /* Defaults to uint16_t for backward compatibility, but can be overridden\r
+       in FreeRTOSConfig.h if uint16_t is too restrictive. */\r
+       #define configSTACK_DEPTH_TYPE uint16_t\r
+#endif\r
+\r
 /* Sanity check the configuration. */\r
 #if( configUSE_TICKLESS_IDLE != 0 )\r
        #if( INCLUDE_vTaskSuspend != 1 )\r
@@ -805,6 +815,10 @@ extern "C" {
        #error configUSE_MUTEXES must be set to 1 to use recursive mutexes\r
 #endif\r
 \r
+#ifndef configINITIAL_TICK_COUNT\r
+       #define configINITIAL_TICK_COUNT 0\r
+#endif\r
+\r
 #if( portTICK_TYPE_IS_ATOMIC == 0 )\r
        /* Either variables of tick type cannot be read atomically, or\r
        portTICK_TYPE_IS_ATOMIC was not set - map the critical sections used when\r
index 205995757bbbc1e7da8e54b9af811a339aa7dc3a..aae985c8d62e07a70c8b212225881ab279d157dd 100644 (file)
@@ -125,7 +125,9 @@ BaseType_t MPU_xTaskGetSchedulerState( void );
 \r
 /* MPU versions of queue.h API function. */\r
 BaseType_t MPU_xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait, const BaseType_t xCopyPosition );\r
-BaseType_t MPU_xQueueGenericReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait, const BaseType_t xJustPeek );\r
+BaseType_t MPU_xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait );\r
+BaseType_t xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait );\r
+BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait );\r
 UBaseType_t MPU_uxQueueMessagesWaiting( const QueueHandle_t xQueue );\r
 UBaseType_t MPU_uxQueueSpacesAvailable( const QueueHandle_t xQueue );\r
 void MPU_vQueueDelete( QueueHandle_t xQueue );\r
index 622b0e2e02902757d21379fd19dc46f2a3026919..11e1cc019761e73be9ac2aa8b734c5cbab16d52d 100644 (file)
@@ -130,7 +130,9 @@ only for ports that are using the MPU. */
 \r
                /* Map standard queue.h API functions to the MPU equivalents. */\r
                #define xQueueGenericSend                                               MPU_xQueueGenericSend\r
-               #define xQueueGenericReceive                                    MPU_xQueueGenericReceive\r
+               #define xQueueReceive                                                   MPU_xQueueReceive\r
+               #define xQueuePeek                                                              MPU_xQueuePeek\r
+               #define xQueueSemaphoreTake                                             MPU_xQueueSemaphoreTake\r
                #define uxQueueMessagesWaiting                                  MPU_uxQueueMessagesWaiting\r
                #define uxQueueSpacesAvailable                                  MPU_uxQueueSpacesAvailable\r
                #define vQueueDelete                                                    MPU_vQueueDelete\r
index 5aaf709d8ab89b876e85b310b75e4007de361230..6d2aa0c02331ce1ce19bf2e06ae1faa01a5ad991 100644 (file)
@@ -696,12 +696,10 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQ
  * <pre>\r
  BaseType_t xQueuePeek(\r
                                                         QueueHandle_t xQueue,\r
-                                                        void *pvBuffer,\r
+                                                        void * const pvBuffer,\r
                                                         TickType_t xTicksToWait\r
                                                 );</pre>\r
  *\r
- * This is a macro that calls the xQueueGenericReceive() function.\r
- *\r
  * Receive an item from a queue without removing the item from the queue.\r
  * The item is received by copy so a buffer of adequate size must be\r
  * provided.  The number of bytes copied into the buffer was defined when\r
@@ -782,10 +780,10 @@ BaseType_t xQueueGenericSend( QueueHandle_t xQueue, const void * const pvItemToQ
        // ... Rest of task code.\r
  }\r
  </pre>\r
- * \defgroup xQueueReceive xQueueReceive\r
+ * \defgroup xQueuePeek xQueuePeek\r
  * \ingroup QueueManagement\r
  */\r
-#define xQueuePeek( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdTRUE )\r
+BaseType_t xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;\r
 \r
 /**\r
  * queue. h\r
@@ -829,8 +827,6 @@ BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void * const pvBuffer ) PRIV
                                                                 TickType_t xTicksToWait\r
                                                        );</pre>\r
  *\r
- * This is a macro that calls the xQueueGenericReceive() function.\r
- *\r
  * Receive an item from a queue.  The item is received by copy so a buffer of\r
  * adequate size must be provided.  The number of bytes copied into the buffer\r
  * was defined when the queue was created.\r
@@ -911,106 +907,7 @@ BaseType_t xQueuePeekFromISR( QueueHandle_t xQueue, void * const pvBuffer ) PRIV
  * \defgroup xQueueReceive xQueueReceive\r
  * \ingroup QueueManagement\r
  */\r
-#define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( ( xQueue ), ( pvBuffer ), ( xTicksToWait ), pdFALSE )\r
-\r
-\r
-/**\r
- * queue. h\r
- * <pre>\r
- BaseType_t xQueueGenericReceive(\r
-                                                                          QueueHandle_t        xQueue,\r
-                                                                          void *pvBuffer,\r
-                                                                          TickType_t   xTicksToWait\r
-                                                                          BaseType_t   xJustPeek\r
-                                                                       );</pre>\r
- *\r
- * It is preferred that the macro xQueueReceive() be used rather than calling\r
- * this function directly.\r
- *\r
- * Receive an item from a queue.  The item is received by copy so a buffer of\r
- * adequate size must be provided.  The number of bytes copied into the buffer\r
- * was defined when the queue was created.\r
- *\r
- * This function must not be used in an interrupt service routine.  See\r
- * xQueueReceiveFromISR for an alternative that can.\r
- *\r
- * @param xQueue The handle to the queue from which the item is to be\r
- * received.\r
- *\r
- * @param pvBuffer Pointer to the buffer into which the received item will\r
- * be copied.\r
- *\r
- * @param xTicksToWait The maximum amount of time the task should block\r
- * waiting for an item to receive should the queue be empty at the time\r
- * of the call.         The time is defined in tick periods so the constant\r
- * portTICK_PERIOD_MS should be used to convert to real time if this is required.\r
- * xQueueGenericReceive() will return immediately if the queue is empty and\r
- * xTicksToWait is 0.\r
- *\r
- * @param xJustPeek When set to true, the item received from the queue is not\r
- * actually removed from the queue - meaning a subsequent call to\r
- * xQueueReceive() will return the same item.  When set to false, the item\r
- * being received from the queue is also removed from the queue.\r
- *\r
- * @return pdTRUE if an item was successfully received from the queue,\r
- * otherwise pdFALSE.\r
- *\r
- * Example usage:\r
-   <pre>\r
- struct AMessage\r
- {\r
-       char ucMessageID;\r
-       char ucData[ 20 ];\r
- } xMessage;\r
-\r
- QueueHandle_t xQueue;\r
-\r
- // Task to create a queue and post a value.\r
- void vATask( void *pvParameters )\r
- {\r
- struct AMessage *pxMessage;\r
-\r
-       // Create a queue capable of containing 10 pointers to AMessage structures.\r
-       // These should be passed by pointer as they contain a lot of data.\r
-       xQueue = xQueueCreate( 10, sizeof( struct AMessage * ) );\r
-       if( xQueue == 0 )\r
-       {\r
-               // Failed to create the queue.\r
-       }\r
-\r
-       // ...\r
-\r
-       // Send a pointer to a struct AMessage object.  Don't block if the\r
-       // queue is already full.\r
-       pxMessage = & xMessage;\r
-       xQueueSend( xQueue, ( void * ) &pxMessage, ( TickType_t ) 0 );\r
-\r
-       // ... Rest of task code.\r
- }\r
-\r
- // Task to receive from the queue.\r
- void vADifferentTask( void *pvParameters )\r
- {\r
- struct AMessage *pxRxedMessage;\r
-\r
-       if( xQueue != 0 )\r
-       {\r
-               // Receive a message on the created queue.  Block for 10 ticks if a\r
-               // message is not immediately available.\r
-               if( xQueueGenericReceive( xQueue, &( pxRxedMessage ), ( TickType_t ) 10 ) )\r
-               {\r
-                       // pcRxedMessage now points to the struct AMessage variable posted\r
-                       // by vATask.\r
-               }\r
-       }\r
-\r
-       // ... Rest of task code.\r
- }\r
- </pre>\r
- * \defgroup xQueueReceive xQueueReceive\r
- * \ingroup QueueManagement\r
- */\r
-BaseType_t xQueueGenericReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait, const BaseType_t xJustPeek ) PRIVILEGED_FUNCTION;\r
+BaseType_t xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;\r
 \r
 /**\r
  * queue. h\r
@@ -1560,6 +1457,7 @@ QueueHandle_t xQueueCreateMutex( const uint8_t ucQueueType ) PRIVILEGED_FUNCTION
 QueueHandle_t xQueueCreateMutexStatic( const uint8_t ucQueueType, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION;\r
 QueueHandle_t xQueueCreateCountingSemaphore( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount ) PRIVILEGED_FUNCTION;\r
 QueueHandle_t xQueueCreateCountingSemaphoreStatic( const UBaseType_t uxMaxCount, const UBaseType_t uxInitialCount, StaticQueue_t *pxStaticQueue ) PRIVILEGED_FUNCTION;\r
+BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait ) PRIVILEGED_FUNCTION;\r
 void* xQueueGetMutexHolder( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;\r
 void* xQueueGetMutexHolderFromISR( QueueHandle_t xSemaphore ) PRIVILEGED_FUNCTION;\r
 \r
index 257cc9e907e0898e3d9e65f1f62a37c167c23bf5..58902b10f9585cabb1b089d415d3912a85577be4 100644 (file)
@@ -328,7 +328,7 @@ typedef QueueHandle_t SemaphoreHandle_t;
  * \defgroup xSemaphoreTake xSemaphoreTake\r
  * \ingroup Semaphores\r
  */\r
-#define xSemaphoreTake( xSemaphore, xBlockTime )               xQueueGenericReceive( ( QueueHandle_t ) ( xSemaphore ), NULL, ( xBlockTime ), pdFALSE )\r
+#define xSemaphoreTake( xSemaphore, xBlockTime )               xQueueSemaphoreTake( ( xSemaphore ), ( xBlockTime ) )\r
 \r
 /**\r
  * semphr. h\r
@@ -392,23 +392,23 @@ typedef QueueHandle_t SemaphoreHandle_t;
 \r
             // ...\r
             // For some reason due to the nature of the code further calls to\r
-                       // xSemaphoreTakeRecursive() are made on the same mutex.  In real\r
-                       // code these would not be just sequential calls as this would make\r
-                       // no sense.  Instead the calls are likely to be buried inside\r
-                       // a more complex call structure.\r
+            // xSemaphoreTakeRecursive() are made on the same mutex.  In real\r
+            // code these would not be just sequential calls as this would make\r
+            // no sense.  Instead the calls are likely to be buried inside\r
+            // a more complex call structure.\r
             xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );\r
             xSemaphoreTakeRecursive( xMutex, ( TickType_t ) 10 );\r
 \r
             // The mutex has now been 'taken' three times, so will not be\r
-                       // available to another task until it has also been given back\r
-                       // three times.  Again it is unlikely that real code would have\r
-                       // these calls sequentially, but instead buried in a more complex\r
-                       // call structure.  This is just for illustrative purposes.\r
+            // available to another task until it has also been given back\r
+            // three times.  Again it is unlikely that real code would have\r
+            // these calls sequentially, but instead buried in a more complex\r
+            // call structure.  This is just for illustrative purposes.\r
+            xSemaphoreGiveRecursive( xMutex );\r
+            xSemaphoreGiveRecursive( xMutex );\r
             xSemaphoreGiveRecursive( xMutex );\r
-                       xSemaphoreGiveRecursive( xMutex );\r
-                       xSemaphoreGiveRecursive( xMutex );\r
 \r
-                       // Now the mutex can be taken by other tasks.\r
+            // Now the mutex can be taken by other tasks.\r
         }\r
         else\r
         {\r
index 172e0b6d54bbe265f88b7e6ad4a4aad1e4d6db9c..54c93a34dcdcdccf9426e61450e2264785941c7f 100644 (file)
@@ -272,7 +272,7 @@ is used in assert() statements. */
  BaseType_t xTaskCreate(\r
                                                          TaskFunction_t pvTaskCode,\r
                                                          const char * const pcName,\r
-                                                         uint16_t usStackDepth,\r
+                                                         configSTACK_DEPTH_TYPE usStackDepth,\r
                                                          void *pvParameters,\r
                                                          UBaseType_t uxPriority,\r
                                                          TaskHandle_t *pvCreatedTask\r
@@ -362,7 +362,7 @@ is used in assert() statements. */
 #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 )\r
        BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,\r
                                                        const char * const pcName,      /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
-                                                       const uint16_t usStackDepth,\r
+                                                       const configSTACK_DEPTH_TYPE usStackDepth,\r
                                                        void * const pvParameters,\r
                                                        UBaseType_t uxPriority,\r
                                                        TaskHandle_t * const pxCreatedTask ) PRIVILEGED_FUNCTION;\r
@@ -2303,7 +2303,7 @@ BaseType_t xTaskGetSchedulerState( void ) PRIVILEGED_FUNCTION;
  * Raises the priority of the mutex holder to that of the calling task should\r
  * the mutex holder have a priority less than the calling task.\r
  */\r
-void vTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;\r
+BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder ) PRIVILEGED_FUNCTION;\r
 \r
 /*\r
  * Set the priority of a task back to its proper priority in the case that it\r
diff --git a/FreeRTOS/Source/portable/CCS/ARM_CM3/port.c b/FreeRTOS/Source/portable/CCS/ARM_CM3/port.c
new file mode 100644 (file)
index 0000000..3e65e22
--- /dev/null
@@ -0,0 +1,648 @@
+/*\r
+    FreeRTOS V9.0.0 - Copyright (C) 2016 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
+    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
+    ***************************************************************************\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
+\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.  Full license text is available on the following\r
+    link: http://www.freertos.org/a00114.html\r
+\r
+    ***************************************************************************\r
+     *                                                                       *\r
+     *    FreeRTOS provides completely free yet professionally developed,    *\r
+     *    robust, strictly quality controlled, supported, and cross          *\r
+     *    platform software that is more than just the market leader, it     *\r
+     *    is the industry's de facto standard.                               *\r
+     *                                                                       *\r
+     *    Help yourself get started quickly while simultaneously helping     *\r
+     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
+     *    tutorial book, reference manual, or both:                          *\r
+     *    http://www.FreeRTOS.org/Documentation                              *\r
+     *                                                                       *\r
+    ***************************************************************************\r
+\r
+    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
+    the FAQ page "My application does not run, what could be wrong?".  Have you\r
+    defined configASSERT()?\r
+\r
+    http://www.FreeRTOS.org/support - In return for receiving this top quality\r
+    embedded software for free we request you assist our global community by\r
+    participating in the support forum.\r
+\r
+    http://www.FreeRTOS.org/training - Investing in training allows your team to\r
+    be as productive as possible as early as possible.  Now you can receive\r
+    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
+    Ltd, and the world's leading authority on the world's leading RTOS.\r
+\r
+    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
+    including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
+    compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
+\r
+    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
+    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
+\r
+    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
+    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
+    licenses offer ticketed support, indemnification and commercial middleware.\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
+    1 tab == 4 spaces!\r
+*/\r
+\r
+/*-----------------------------------------------------------\r
+ * Implementation of functions defined in portable.h for the ARM CM4F port.\r
+ *----------------------------------------------------------*/\r
+\r
+/* Scheduler includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+\r
+#if configMAX_SYSCALL_INTERRUPT_PRIORITY == 0\r
+       #error configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to 0.  See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html\r
+#endif\r
+\r
+#ifndef configSYSTICK_CLOCK_HZ\r
+       #define configSYSTICK_CLOCK_HZ configCPU_CLOCK_HZ\r
+       /* Ensure the SysTick is clocked at the same frequency as the core. */\r
+       #define portNVIC_SYSTICK_CLK_BIT        ( 1UL << 2UL )\r
+#else\r
+       /* The way the SysTick is clocked is not modified in case it is not the same\r
+       as the core. */\r
+       #define portNVIC_SYSTICK_CLK_BIT        ( 0 )\r
+#endif\r
+\r
+/* Constants required to manipulate the core.  Registers first... */\r
+#define portNVIC_SYSTICK_CTRL_REG                      ( * ( ( volatile uint32_t * ) 0xe000e010 ) )\r
+#define portNVIC_SYSTICK_LOAD_REG                      ( * ( ( volatile uint32_t * ) 0xe000e014 ) )\r
+#define portNVIC_SYSTICK_CURRENT_VALUE_REG     ( * ( ( volatile uint32_t * ) 0xe000e018 ) )\r
+#define portNVIC_SYSPRI2_REG                           ( * ( ( volatile uint32_t * ) 0xe000ed20 ) )\r
+/* ...then bits in the registers. */\r
+#define portNVIC_SYSTICK_INT_BIT                       ( 1UL << 1UL )\r
+#define portNVIC_SYSTICK_ENABLE_BIT                    ( 1UL << 0UL )\r
+#define portNVIC_SYSTICK_COUNT_FLAG_BIT                ( 1UL << 16UL )\r
+#define portNVIC_PENDSVCLEAR_BIT                       ( 1UL << 27UL )\r
+#define portNVIC_PEND_SYSTICK_CLEAR_BIT                ( 1UL << 25UL )\r
+\r
+#define portNVIC_PENDSV_PRI                                    ( ( ( uint32_t ) configKERNEL_INTERRUPT_PRIORITY ) << 16UL )\r
+#define portNVIC_SYSTICK_PRI                           ( ( ( uint32_t ) configKERNEL_INTERRUPT_PRIORITY ) << 24UL )\r
+\r
+/* Constants required to check the validity of an interrupt priority. */\r
+#define portFIRST_USER_INTERRUPT_NUMBER                ( 16 )\r
+#define portNVIC_IP_REGISTERS_OFFSET_16        ( 0xE000E3F0 )\r
+#define portAIRCR_REG                                          ( * ( ( volatile uint32_t * ) 0xE000ED0C ) )\r
+#define portMAX_8_BIT_VALUE                                    ( ( uint8_t ) 0xff )\r
+#define portTOP_BIT_OF_BYTE                                    ( ( uint8_t ) 0x80 )\r
+#define portMAX_PRIGROUP_BITS                          ( ( uint8_t ) 7 )\r
+#define portPRIORITY_GROUP_MASK                                ( 0x07UL << 8UL )\r
+#define portPRIGROUP_SHIFT                                     ( 8UL )\r
+\r
+/* Masks off all bits but the VECTACTIVE bits in the ICSR register. */\r
+#define portVECTACTIVE_MASK                                    ( 0xFFUL )\r
+\r
+/* Constants required to set up the initial stack. */\r
+#define portINITIAL_XPSR                                       ( 0x01000000 )\r
+\r
+/* The systick is a 24-bit counter. */\r
+#define portMAX_24_BIT_NUMBER                          ( 0xffffffUL )\r
+\r
+/* A fiddle factor to estimate the number of SysTick counts that would have\r
+occurred while the SysTick counter is stopped during tickless idle\r
+calculations. */\r
+#define portMISSED_COUNTS_FACTOR                       ( 45UL )\r
+\r
+/* For strict compliance with the Cortex-M spec the task start address should\r
+have bit-0 clear, as it is loaded into the PC on exit from an ISR. */\r
+#define portSTART_ADDRESS_MASK         ( ( StackType_t ) 0xfffffffeUL )\r
+\r
+/* Required to allow portasm.asm access the configMAX_SYSCALL_INTERRUPT_PRIORITY\r
+setting. */\r
+const uint32_t ulMaxSyscallInterruptPriority = configMAX_SYSCALL_INTERRUPT_PRIORITY;\r
+\r
+/* Each task maintains its own interrupt status in the critical nesting\r
+variable. */\r
+static UBaseType_t uxCriticalNesting = 0xaaaaaaaa;\r
+\r
+/*\r
+ * Setup the timer to generate the tick interrupts.  The implementation in this\r
+ * file is weak to allow application writers to change the timer used to\r
+ * generate the tick interrupt.\r
+ */\r
+void vPortSetupTimerInterrupt( void );\r
+\r
+/*\r
+ * Exception handlers.\r
+ */\r
+void xPortSysTickHandler( void );\r
+\r
+/*\r
+ * Start first task is a separate function so it can be tested in isolation.\r
+ */\r
+extern void vPortStartFirstTask( void );\r
+\r
+/*\r
+ * Used to catch tasks that attempt to return from their implementing function.\r
+ */\r
+static void prvTaskExitError( void );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * The number of SysTick increments that make up one tick period.\r
+ */\r
+#if configUSE_TICKLESS_IDLE == 1\r
+       static uint32_t ulTimerCountsForOneTick = 0;\r
+#endif /* configUSE_TICKLESS_IDLE */\r
+\r
+/*\r
+ * The maximum number of tick periods that can be suppressed is limited by the\r
+ * 24 bit resolution of the SysTick timer.\r
+ */\r
+#if configUSE_TICKLESS_IDLE == 1\r
+       static uint32_t xMaximumPossibleSuppressedTicks = 0;\r
+#endif /* configUSE_TICKLESS_IDLE */\r
+\r
+/*\r
+ * Compensate for the CPU cycles that pass while the SysTick is stopped (low\r
+ * power functionality only.\r
+ */\r
+#if configUSE_TICKLESS_IDLE == 1\r
+       static uint32_t ulStoppedTimerCompensation = 0;\r
+#endif /* configUSE_TICKLESS_IDLE */\r
+\r
+/*\r
+ * Used by the portASSERT_IF_INTERRUPT_PRIORITY_INVALID() macro to ensure\r
+ * FreeRTOS API functions are not called from interrupts that have been assigned\r
+ * a priority above configMAX_SYSCALL_INTERRUPT_PRIORITY.\r
+ */\r
+#if ( configASSERT_DEFINED == 1 )\r
+        static uint8_t ucMaxSysCallPriority = 0;\r
+        static uint32_t ulMaxPRIGROUPValue = 0;\r
+        static const volatile uint8_t * const pcInterruptPriorityRegisters = ( uint8_t * ) portNVIC_IP_REGISTERS_OFFSET_16;\r
+#endif /* configASSERT_DEFINED */\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * See header file for description.\r
+ */\r
+StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
+{\r
+       /* Simulate the stack frame as it would be created by a context switch\r
+       interrupt. */\r
+\r
+       /* Offset added to account for the way the MCU uses the stack on entry/exit\r
+       of interrupts, and to ensure alignment. */\r
+       pxTopOfStack--;\r
+\r
+       *pxTopOfStack = portINITIAL_XPSR;       /* xPSR */\r
+       pxTopOfStack--;\r
+       *pxTopOfStack = ( ( StackType_t ) pxCode ) & portSTART_ADDRESS_MASK;    /* PC */\r
+       pxTopOfStack--;\r
+       *pxTopOfStack = ( StackType_t ) prvTaskExitError;       /* LR */\r
+\r
+       /* Save code space by skipping register initialisation. */\r
+       pxTopOfStack -= 5;      /* R12, R3, R2 and R1. */\r
+       *pxTopOfStack = ( StackType_t ) pvParameters;   /* R0 */\r
+\r
+       pxTopOfStack -= 8;      /* R11, R10, R9, R8, R7, R6, R5 and R4. */\r
+\r
+       return pxTopOfStack;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvTaskExitError( void )\r
+{\r
+       /* A function that implements a task must not exit or attempt to return to\r
+       its caller as there is nothing to return to.  If a task wants to exit it\r
+       should instead call vTaskDelete( NULL ).\r
+\r
+       Artificially force an assert() to be triggered if configASSERT() is\r
+       defined, then stop here so application writers can catch the error. */\r
+       configASSERT( uxCriticalNesting == ~0UL );\r
+       portDISABLE_INTERRUPTS();\r
+       for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * See header file for description.\r
+ */\r
+BaseType_t xPortStartScheduler( void )\r
+{\r
+       #if( configASSERT_DEFINED == 1 )\r
+       {\r
+               volatile uint32_t ulOriginalPriority;\r
+               volatile uint8_t * const pucFirstUserPriorityRegister = ( uint8_t * ) ( portNVIC_IP_REGISTERS_OFFSET_16 + portFIRST_USER_INTERRUPT_NUMBER );\r
+               volatile uint8_t ucMaxPriorityValue;\r
+\r
+               /* Determine the maximum priority from which ISR safe FreeRTOS API\r
+               functions can be called.  ISR safe functions are those that end in\r
+               "FromISR".  FreeRTOS maintains separate thread and ISR API functions to\r
+               ensure interrupt entry is as fast and simple as possible.\r
+\r
+               Save the interrupt priority value that is about to be clobbered. */\r
+               ulOriginalPriority = *pucFirstUserPriorityRegister;\r
+\r
+               /* Determine the number of priority bits available.  First write to all\r
+               possible bits. */\r
+               *pucFirstUserPriorityRegister = portMAX_8_BIT_VALUE;\r
+\r
+               /* Read the value back to see how many bits stuck. */\r
+               ucMaxPriorityValue = *pucFirstUserPriorityRegister;\r
+\r
+               /* Use the same mask on the maximum system call priority. */\r
+               ucMaxSysCallPriority = configMAX_SYSCALL_INTERRUPT_PRIORITY & ucMaxPriorityValue;\r
+\r
+               /* Calculate the maximum acceptable priority group value for the number\r
+               of bits read back. */\r
+               ulMaxPRIGROUPValue = portMAX_PRIGROUP_BITS;\r
+               while( ( ucMaxPriorityValue & portTOP_BIT_OF_BYTE ) == portTOP_BIT_OF_BYTE )\r
+               {\r
+                       ulMaxPRIGROUPValue--;\r
+                       ucMaxPriorityValue <<= ( uint8_t ) 0x01;\r
+               }\r
+\r
+               #ifdef __NVIC_PRIO_BITS\r
+               {\r
+                       /* Check the CMSIS configuration that defines the number of\r
+                       priority bits matches the number of priority bits actually queried\r
+                       from the hardware. */\r
+                       configASSERT( ( portMAX_PRIGROUP_BITS - ulMaxPRIGROUPValue ) == __NVIC_PRIO_BITS );\r
+               }\r
+               #endif\r
+\r
+               #ifdef configPRIO_BITS\r
+               {\r
+                       /* Check the FreeRTOS configuration that defines the number of\r
+                       priority bits matches the number of priority bits actually queried\r
+                       from the hardware. */\r
+                       configASSERT( ( portMAX_PRIGROUP_BITS - ulMaxPRIGROUPValue ) == configPRIO_BITS );\r
+               }\r
+               #endif\r
+\r
+               /* Shift the priority group value back to its position within the AIRCR\r
+               register. */\r
+               ulMaxPRIGROUPValue <<= portPRIGROUP_SHIFT;\r
+               ulMaxPRIGROUPValue &= portPRIORITY_GROUP_MASK;\r
+\r
+               /* Restore the clobbered interrupt priority register to its original\r
+               value. */\r
+               *pucFirstUserPriorityRegister = ulOriginalPriority;\r
+       }\r
+       #endif /* conifgASSERT_DEFINED */\r
+\r
+       /* Make PendSV and SysTick the lowest priority interrupts. */\r
+       portNVIC_SYSPRI2_REG |= portNVIC_PENDSV_PRI;\r
+       portNVIC_SYSPRI2_REG |= portNVIC_SYSTICK_PRI;\r
+\r
+       /* Start the timer that generates the tick ISR.  Interrupts are disabled\r
+       here already. */\r
+       vPortSetupTimerInterrupt();\r
+\r
+       /* Initialise the critical nesting count ready for the first task. */\r
+       uxCriticalNesting = 0;\r
+\r
+       /* Start the first task. */\r
+       vPortStartFirstTask();\r
+\r
+       /* Should not get here! */\r
+       return 0;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vPortEndScheduler( void )\r
+{\r
+       /* Not implemented in ports where there is nothing to return to.\r
+       Artificially force an assert. */\r
+       configASSERT( uxCriticalNesting == 1000UL );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vPortEnterCritical( void )\r
+{\r
+       portDISABLE_INTERRUPTS();\r
+       uxCriticalNesting++;\r
+\r
+       /* This is not the interrupt safe version of the enter critical function so\r
+       assert() if it is being called from an interrupt context.  Only API\r
+       functions that end in "FromISR" can be used in an interrupt.  Only assert if\r
+       the critical nesting count is 1 to protect against recursive calls if the\r
+       assert function also uses a critical section. */\r
+       if( uxCriticalNesting == 1 )\r
+       {\r
+               configASSERT( ( portNVIC_INT_CTRL_REG & portVECTACTIVE_MASK ) == 0 );\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vPortExitCritical( void )\r
+{\r
+       configASSERT( uxCriticalNesting );\r
+       uxCriticalNesting--;\r
+       if( uxCriticalNesting == 0 )\r
+       {\r
+               portENABLE_INTERRUPTS();\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void xPortSysTickHandler( void )\r
+{\r
+       /* The SysTick runs at the lowest interrupt priority, so when this interrupt\r
+       executes all interrupts must be unmasked.  There is therefore no need to\r
+       save and then restore the interrupt mask value as its value is already\r
+       known. */\r
+       ( void ) portSET_INTERRUPT_MASK_FROM_ISR();\r
+       {\r
+               /* Increment the RTOS tick. */\r
+               if( xTaskIncrementTick() != pdFALSE )\r
+               {\r
+                       /* A context switch is required.  Context switching is performed in\r
+                       the PendSV interrupt.  Pend the PendSV interrupt. */\r
+                       portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;\r
+               }\r
+       }\r
+       portCLEAR_INTERRUPT_MASK_FROM_ISR( 0 );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+#if configUSE_TICKLESS_IDLE == 1\r
+\r
+       #pragma WEAK( vPortSuppressTicksAndSleep )\r
+       void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime )\r
+       {\r
+       uint32_t ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickDecrements, ulSysTickCTRL;\r
+       TickType_t xModifiableIdleTime;\r
+\r
+               /* Make sure the SysTick reload value does not overflow the counter. */\r
+               if( xExpectedIdleTime > xMaximumPossibleSuppressedTicks )\r
+               {\r
+                       xExpectedIdleTime = xMaximumPossibleSuppressedTicks;\r
+               }\r
+\r
+               /* Stop the SysTick momentarily.  The time the SysTick is stopped for\r
+               is accounted for as best it can be, but using the tickless mode will\r
+               inevitably result in some tiny drift of the time maintained by the\r
+               kernel with respect to calendar time. */\r
+               portNVIC_SYSTICK_CTRL_REG &= ~portNVIC_SYSTICK_ENABLE_BIT;\r
+\r
+               /* Calculate the reload value required to wait xExpectedIdleTime\r
+               tick periods.  -1 is used because this code will execute part way\r
+               through one of the tick periods. */\r
+               ulReloadValue = portNVIC_SYSTICK_CURRENT_VALUE_REG + ( ulTimerCountsForOneTick * ( xExpectedIdleTime - 1UL ) );\r
+               if( ulReloadValue > ulStoppedTimerCompensation )\r
+               {\r
+                       ulReloadValue -= ulStoppedTimerCompensation;\r
+               }\r
+\r
+               /* Enter a critical section but don't use the taskENTER_CRITICAL()\r
+               method as that will mask interrupts that should exit sleep mode. */\r
+               __asm( "        cpsid i" );\r
+               __asm( "        dsb" );\r
+               __asm( "        isb" );\r
+\r
+\r
+               /* If a context switch is pending or a task is waiting for the scheduler\r
+               to be unsuspended then abandon the low power entry. */\r
+               if( eTaskConfirmSleepModeStatus() == eAbortSleep )\r
+               {\r
+                       /* Restart from whatever is left in the count register to complete\r
+                       this tick period. */\r
+                       portNVIC_SYSTICK_LOAD_REG = portNVIC_SYSTICK_CURRENT_VALUE_REG;\r
+\r
+                       /* Restart SysTick. */\r
+                       portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;\r
+\r
+                       /* Reset the reload register to the value required for normal tick\r
+                       periods. */\r
+                       portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;\r
+\r
+                       /* Re-enable interrupts - see comments above __disable_interrupt()\r
+                       call above. */\r
+                       __asm( "        cpsie i" );\r
+               }\r
+               else\r
+               {\r
+                       /* Set the new reload value. */\r
+                       portNVIC_SYSTICK_LOAD_REG = ulReloadValue;\r
+\r
+                       /* Clear the SysTick count flag and set the count value back to\r
+                       zero. */\r
+                       portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;\r
+\r
+                       /* Restart SysTick. */\r
+                       portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;\r
+\r
+                       /* Sleep until something happens.  configPRE_SLEEP_PROCESSING() can\r
+                       set its parameter to 0 to indicate that its implementation contains\r
+                       its own wait for interrupt or wait for event instruction, and so wfi\r
+                       should not be executed again.  However, the original expected idle\r
+                       time variable must remain unmodified, so a copy is taken. */\r
+                       xModifiableIdleTime = xExpectedIdleTime;\r
+                       configPRE_SLEEP_PROCESSING( xModifiableIdleTime );\r
+                       if( xModifiableIdleTime > 0 )\r
+                       {\r
+                               __asm( "        dsb" );\r
+                               __asm( "        wfi" );\r
+                               __asm( "        isb" );\r
+                       }\r
+                       configPOST_SLEEP_PROCESSING( xExpectedIdleTime );\r
+\r
+                       /* Stop SysTick.  Again, the time the SysTick is stopped for is\r
+                       accounted for as best it can be, but using the tickless mode will\r
+                       inevitably result in some tiny drift of the time maintained by the\r
+                       kernel with respect to calendar time. */\r
+                       ulSysTickCTRL = portNVIC_SYSTICK_CTRL_REG;\r
+                       portNVIC_SYSTICK_CTRL_REG = ( ulSysTickCTRL & ~portNVIC_SYSTICK_ENABLE_BIT );\r
+\r
+                       /* Re-enable interrupts - see comments above __disable_interrupt()\r
+                       call above. */\r
+                       __asm( "        cpsie i" );\r
+\r
+                       if( ( ulSysTickCTRL & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )\r
+                       {\r
+                               uint32_t ulCalculatedLoadValue;\r
+\r
+                               /* The tick interrupt has already executed, and the SysTick\r
+                               count reloaded with ulReloadValue.  Reset the\r
+                               portNVIC_SYSTICK_LOAD_REG with whatever remains of this tick\r
+                               period. */\r
+                               ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL ) - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );\r
+\r
+                               /* Don't allow a tiny value, or values that have somehow\r
+                               underflowed because the post sleep hook did something\r
+                               that took too long. */\r
+                               if( ( ulCalculatedLoadValue < ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue > ulTimerCountsForOneTick ) )\r
+                               {\r
+                                       ulCalculatedLoadValue = ( ulTimerCountsForOneTick - 1UL );\r
+                               }\r
+\r
+                               portNVIC_SYSTICK_LOAD_REG = ulCalculatedLoadValue;\r
+\r
+                               /* The tick interrupt handler will already have pended the tick\r
+                               processing in the kernel.  As the pending tick will be\r
+                               processed as soon as this function exits, the tick value\r
+                               maintained by the tick is stepped forward by one less than the\r
+                               time spent waiting. */\r
+                               ulCompleteTickPeriods = xExpectedIdleTime - 1UL;\r
+                       }\r
+                       else\r
+                       {\r
+                               /* Something other than the tick interrupt ended the sleep.\r
+                               Work out how long the sleep lasted rounded to complete tick\r
+                               periods (not the ulReload value which accounted for part\r
+                               ticks). */\r
+                               ulCompletedSysTickDecrements = ( xExpectedIdleTime * ulTimerCountsForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE_REG;\r
+\r
+                               /* How many complete tick periods passed while the processor\r
+                               was waiting? */\r
+                               ulCompleteTickPeriods = ulCompletedSysTickDecrements / ulTimerCountsForOneTick;\r
+\r
+                               /* The reload value is set to whatever fraction of a single tick\r
+                               period remains. */\r
+                               portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1UL ) * ulTimerCountsForOneTick ) - ulCompletedSysTickDecrements;\r
+                       }\r
+\r
+                       /* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG\r
+                       again, then set portNVIC_SYSTICK_LOAD_REG back to its standard\r
+                       value.  The critical section is used to ensure the tick interrupt\r
+                       can only execute once in the case that the reload register is near\r
+                       zero. */\r
+                       portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;\r
+                       portENTER_CRITICAL();\r
+                       {\r
+                               portNVIC_SYSTICK_CTRL_REG |= portNVIC_SYSTICK_ENABLE_BIT;\r
+                               vTaskStepTick( ulCompleteTickPeriods );\r
+                               portNVIC_SYSTICK_LOAD_REG = ulTimerCountsForOneTick - 1UL;\r
+                       }\r
+                       portEXIT_CRITICAL();\r
+               }\r
+       }\r
+\r
+#endif /* #if configUSE_TICKLESS_IDLE */\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * Setup the systick timer to generate the tick interrupts at the required\r
+ * frequency.\r
+ */\r
+#pragma WEAK( vPortSetupTimerInterrupt )\r
+void vPortSetupTimerInterrupt( void )\r
+{\r
+       /* Calculate the constants required to configure the tick interrupt. */\r
+       #if configUSE_TICKLESS_IDLE == 1\r
+       {\r
+               ulTimerCountsForOneTick = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ );\r
+               xMaximumPossibleSuppressedTicks = portMAX_24_BIT_NUMBER / ulTimerCountsForOneTick;\r
+               ulStoppedTimerCompensation = portMISSED_COUNTS_FACTOR / ( configCPU_CLOCK_HZ / configSYSTICK_CLOCK_HZ );\r
+       }\r
+       #endif /* configUSE_TICKLESS_IDLE */\r
+\r
+       /* Stop and clear the SysTick. */\r
+       portNVIC_SYSTICK_CTRL_REG = 0UL;\r
+       portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;\r
+\r
+       /* Configure SysTick to interrupt at the requested rate. */\r
+       portNVIC_SYSTICK_LOAD_REG = ( configSYSTICK_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL;\r
+       portNVIC_SYSTICK_CTRL_REG = ( portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+#if( configASSERT_DEFINED == 1 )\r
+\r
+       void vPortValidateInterruptPriority( void )\r
+       {\r
+       extern uint32_t ulPortGetIPSR( void );\r
+       uint32_t ulCurrentInterrupt;\r
+       uint8_t ucCurrentPriority;\r
+\r
+               ulCurrentInterrupt = ulPortGetIPSR();\r
+\r
+               /* Is the interrupt number a user defined interrupt? */\r
+               if( ulCurrentInterrupt >= portFIRST_USER_INTERRUPT_NUMBER )\r
+               {\r
+                       /* Look up the interrupt's priority. */\r
+                       ucCurrentPriority = pcInterruptPriorityRegisters[ ulCurrentInterrupt ];\r
+\r
+                       /* The following assertion will fail if a service routine (ISR) for\r
+                       an interrupt that has been assigned a priority above\r
+                       configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API\r
+                       function.  ISR safe FreeRTOS API functions must *only* be called\r
+                       from interrupts that have been assigned a priority at or below\r
+                       configMAX_SYSCALL_INTERRUPT_PRIORITY.\r
+\r
+                       Numerically low interrupt priority numbers represent logically high\r
+                       interrupt priorities, therefore the priority of the interrupt must\r
+                       be set to a value equal to or numerically *higher* than\r
+                       configMAX_SYSCALL_INTERRUPT_PRIORITY.\r
+\r
+                       Interrupts that use the FreeRTOS API must not be left at their\r
+                       default priority of     zero as that is the highest possible priority,\r
+                       which is guaranteed to be above configMAX_SYSCALL_INTERRUPT_PRIORITY,\r
+                       and     therefore also guaranteed to be invalid.\r
+\r
+                       FreeRTOS maintains separate thread and ISR API functions to ensure\r
+                       interrupt entry is as fast and simple as possible.\r
+\r
+                       The following links provide detailed information:\r
+                       http://www.freertos.org/RTOS-Cortex-M3-M4.html\r
+                       http://www.freertos.org/FAQHelp.html */\r
+                       configASSERT( ucCurrentPriority >= ucMaxSysCallPriority );\r
+               }\r
+\r
+               /* Priority grouping:  The interrupt controller (NVIC) allows the bits\r
+               that define each interrupt's priority to be split between bits that\r
+               define the interrupt's pre-emption priority bits and bits that define\r
+               the interrupt's sub-priority.  For simplicity all bits must be defined\r
+               to be pre-emption priority bits.  The following assertion will fail if\r
+               this is not the case (if some bits represent a sub-priority).\r
+\r
+               If the application only uses CMSIS libraries for interrupt\r
+               configuration then the correct setting can be achieved on all Cortex-M\r
+               devices by calling NVIC_SetPriorityGrouping( 0 ); before starting the\r
+               scheduler.  Note however that some vendor specific peripheral libraries\r
+               assume a non-zero priority group setting, in which cases using a value\r
+               of zero will result in unpredicable behaviour. */\r
+               configASSERT( ( portAIRCR_REG & portPRIORITY_GROUP_MASK ) <= ulMaxPRIGROUPValue );\r
+       }\r
+\r
+#endif /* configASSERT_DEFINED */\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
diff --git a/FreeRTOS/Source/portable/CCS/ARM_CM3/portasm.asm b/FreeRTOS/Source/portable/CCS/ARM_CM3/portasm.asm
new file mode 100644 (file)
index 0000000..72e93fc
--- /dev/null
@@ -0,0 +1,186 @@
+;/*\r
+;    FreeRTOS V9.0.0 - Copyright (C) 2016 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
+;    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
+;    ***************************************************************************\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
+;\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.  Full license text is available on the following\r
+;    link: http://www.freertos.org/a00114.html\r
+;\r
+;    ***************************************************************************\r
+;     *                                                                       *\r
+;     *    FreeRTOS provides completely free yet professionally developed,    *\r
+;     *    robust, strictly quality controlled, supported, and cross          *\r
+;     *    platform software that is more than just the market leader, it     *\r
+;     *    is the industry's de facto standard.                               *\r
+;     *                                                                       *\r
+;     *    Help yourself get started quickly while simultaneously helping     *\r
+;     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
+;     *    tutorial book, reference manual, or both:                          *\r
+;     *    http://www.FreeRTOS.org/Documentation                              *\r
+;     *                                                                       *\r
+;    ***************************************************************************\r
+;\r
+;    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
+;    the FAQ page "My application does not run, what could be wrong?".  Have you\r
+;    defined configASSERT()?\r
+;\r
+;    http://www.FreeRTOS.org/support - In return for receiving this top quality\r
+;    embedded software for free we request you assist our global community by\r
+;    participating in the support forum.\r
+;\r
+;    http://www.FreeRTOS.org/training - Investing in training allows your team to\r
+;    be as productive as possible as early as possible.  Now you can receive\r
+;    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
+;    Ltd, and the world's leading authority on the world's leading RTOS.\r
+;\r
+;    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
+;    including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
+;    compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
+;\r
+;    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
+;    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
+;\r
+;    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
+;    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
+;    licenses offer ticketed support, indemnification and commercial middleware.\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
+;    1 tab == 4 spaces!\r
+;*/\r
+\r
+       .thumb\r
+\r
+       .ref pxCurrentTCB\r
+       .ref vTaskSwitchContext\r
+       .ref ulMaxSyscallInterruptPriority\r
+\r
+       .def xPortPendSVHandler\r
+       .def ulPortGetIPSR\r
+       .def vPortSVCHandler\r
+       .def vPortStartFirstTask\r
+\r
+NVICOffsetConst:                                       .word   0xE000ED08\r
+CPACRConst:                                                    .word   0xE000ED88\r
+pxCurrentTCBConst:                                     .word   pxCurrentTCB\r
+ulMaxSyscallInterruptPriorityConst: .word ulMaxSyscallInterruptPriority\r
+\r
+; -----------------------------------------------------------\r
+\r
+       .align 4\r
+ulPortGetIPSR: .asmfunc\r
+       mrs r0, ipsr\r
+       bx r14\r
+       .endasmfunc\r
+ ; -----------------------------------------------------------\r
+\r
+       .align 4\r
+vPortSetInterruptMask: .asmfunc\r
+       push {r0}\r
+       ldr r0, ulMaxSyscallInterruptPriorityConst\r
+       msr basepri, r0\r
+       pop {r0}\r
+       bx r14\r
+       .endasmfunc\r
+; -----------------------------------------------------------\r
+\r
+       .align 4\r
+xPortPendSVHandler: .asmfunc\r
+       mrs r0, psp\r
+       isb\r
+\r
+       ;/* Get the location of the current TCB. */\r
+       ldr     r3, pxCurrentTCBConst\r
+       ldr     r2, [r3]\r
+\r
+       ;/* Save the core registers. */\r
+       stmdb r0!, {r4-r11}\r
+\r
+       ;/* Save the new top of stack into the first member of the TCB. */\r
+       str r0, [r2]\r
+\r
+       stmdb sp!, {r3, r14}\r
+       ldr r0, ulMaxSyscallInterruptPriorityConst\r
+       ldr r1, [r0]\r
+       msr basepri, r1\r
+       dsb\r
+       isb\r
+       bl vTaskSwitchContext\r
+       mov r0, #0\r
+       msr basepri, r0\r
+       ldmia sp!, {r3, r14}\r
+\r
+       ;/* The first item in pxCurrentTCB is the task top of stack. */\r
+       ldr r1, [r3]\r
+       ldr r0, [r1]\r
+\r
+       ;/* Pop the core registers. */\r
+       ldmia r0!, {r4-r11}\r
+\r
+       msr psp, r0\r
+       isb\r
+       bx r14\r
+       .endasmfunc\r
+\r
+; -----------------------------------------------------------\r
+\r
+       .align 4\r
+vPortSVCHandler: .asmfunc\r
+       ;/* Get the location of the current TCB. */\r
+       ldr     r3, pxCurrentTCBConst\r
+       ldr r1, [r3]\r
+       ldr r0, [r1]\r
+       ;/* Pop the core registers. */\r
+       ldmia r0!, {r4-r11}\r
+       msr psp, r0\r
+       isb\r
+       mov r0, #0\r
+       msr     basepri, r0\r
+       orr r14, #0xd\r
+       bx r14\r
+       .endasmfunc\r
+\r
+; -----------------------------------------------------------\r
+\r
+       .align 4\r
+vPortStartFirstTask: .asmfunc\r
+       ;/* Use the NVIC offset register to locate the stack. */\r
+       ldr r0, NVICOffsetConst\r
+       ldr r0, [r0]\r
+       ldr r0, [r0]\r
+       ;/* Set the msp back to the start of the stack. */\r
+       msr msp, r0\r
+       ;/* Clear the bit that indicates the FPU is in use in case the FPU was used\r
+       ;before the scheduler was started - which would otherwise result in the\r
+       ;unnecessary leaving of space in the SVC stack for lazy saving of FPU\r
+       ;registers. */\r
+       mov r0, #0\r
+       msr control, r0\r
+       ;/* Call SVC to start the first task. */\r
+       cpsie i\r
+       cpsie f\r
+       dsb\r
+       isb\r
+       svc #0\r
+       .endasmfunc\r
+\r
+; -----------------------------------------------------------\r
+\r
diff --git a/FreeRTOS/Source/portable/CCS/ARM_CM3/portmacro.h b/FreeRTOS/Source/portable/CCS/ARM_CM3/portmacro.h
new file mode 100644 (file)
index 0000000..47302ca
--- /dev/null
@@ -0,0 +1,207 @@
+/*\r
+    FreeRTOS V9.0.0 - Copyright (C) 2016 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
+    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
+    ***************************************************************************\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
+\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.  Full license text is available on the following\r
+    link: http://www.freertos.org/a00114.html\r
+\r
+    ***************************************************************************\r
+     *                                                                       *\r
+     *    FreeRTOS provides completely free yet professionally developed,    *\r
+     *    robust, strictly quality controlled, supported, and cross          *\r
+     *    platform software that is more than just the market leader, it     *\r
+     *    is the industry's de facto standard.                               *\r
+     *                                                                       *\r
+     *    Help yourself get started quickly while simultaneously helping     *\r
+     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
+     *    tutorial book, reference manual, or both:                          *\r
+     *    http://www.FreeRTOS.org/Documentation                              *\r
+     *                                                                       *\r
+    ***************************************************************************\r
+\r
+    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
+    the FAQ page "My application does not run, what could be wrong?".  Have you\r
+    defined configASSERT()?\r
+\r
+    http://www.FreeRTOS.org/support - In return for receiving this top quality\r
+    embedded software for free we request you assist our global community by\r
+    participating in the support forum.\r
+\r
+    http://www.FreeRTOS.org/training - Investing in training allows your team to\r
+    be as productive as possible as early as possible.  Now you can receive\r
+    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
+    Ltd, and the world's leading authority on the world's leading RTOS.\r
+\r
+    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
+    including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
+    compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
+\r
+    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
+    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
+\r
+    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
+    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
+    licenses offer ticketed support, indemnification and commercial middleware.\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
+    1 tab == 4 spaces!\r
+*/\r
+\r
+\r
+#ifndef PORTMACRO_H\r
+#define PORTMACRO_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/*-----------------------------------------------------------\r
+ * Port specific definitions.\r
+ *\r
+ * The settings in this file configure FreeRTOS correctly for the\r
+ * given hardware and compiler.\r
+ *\r
+ * These settings should not be altered.\r
+ *-----------------------------------------------------------\r
+ */\r
+\r
+/* Type definitions. */\r
+#define portCHAR               char\r
+#define portFLOAT              float\r
+#define portDOUBLE             double\r
+#define portLONG               long\r
+#define portSHORT              short\r
+#define portSTACK_TYPE uint32_t\r
+#define portBASE_TYPE  long\r
+\r
+typedef portSTACK_TYPE StackType_t;\r
+typedef long BaseType_t;\r
+typedef unsigned long UBaseType_t;\r
+\r
+#if( configUSE_16_BIT_TICKS == 1 )\r
+       typedef uint16_t TickType_t;\r
+       #define portMAX_DELAY ( TickType_t ) 0xffff\r
+#else\r
+       typedef uint32_t TickType_t;\r
+       #define portMAX_DELAY ( TickType_t ) 0xffffffffUL\r
+\r
+       /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do\r
+       not need to be guarded with a critical section. */\r
+       #define portTICK_TYPE_IS_ATOMIC 1\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+/* Architecture specifics. */\r
+#define portSTACK_GROWTH                       ( -1 )\r
+#define portTICK_PERIOD_MS                     ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
+#define portBYTE_ALIGNMENT                     8\r
+/*-----------------------------------------------------------*/\r
+\r
+/* Scheduler utilities. */\r
+#define portYIELD()                                                                                    \\r
+{                                                                                                                      \\r
+       /* Set a PendSV to request a context switch. */                 \\r
+       portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;                 \\r
+       __asm( "        dsb" );                                                                         \\r
+       __asm( "        isb" );                                                                         \\r
+}\r
+\r
+#define portNVIC_INT_CTRL_REG          ( * ( ( volatile uint32_t * ) 0xe000ed04 ) )\r
+#define portNVIC_PENDSVSET_BIT         ( 1UL << 28UL )\r
+#define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) portYIELD()\r
+#define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* Architecture specific optimisations. */\r
+#ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION\r
+       #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1\r
+#endif\r
+\r
+#if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\r
+\r
+       /* Check the configuration. */\r
+       #if( configMAX_PRIORITIES > 32 )\r
+               #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32.  It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice.\r
+       #endif\r
+\r
+       /* Store/clear the ready priorities in a bit map. */\r
+       #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )\r
+       #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )\r
+\r
+       /*-----------------------------------------------------------*/\r
+\r
+       #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - __clz( ( uxReadyPriorities ) ) )\r
+\r
+#endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */\r
+/*-----------------------------------------------------------*/\r
+\r
+/* Critical section management. */\r
+extern void vPortEnterCritical( void );\r
+extern void vPortExitCritical( void );\r
+\r
+#define portDISABLE_INTERRUPTS()                                                                               \\r
+{                                                                                                                                              \\r
+       _set_interrupt_priority( configMAX_SYSCALL_INTERRUPT_PRIORITY );        \\r
+       __asm( "        dsb" );                                                                                                 \\r
+       __asm( "        isb" );                                                                                                 \\r
+}\r
+\r
+#define portENABLE_INTERRUPTS()                                        _set_interrupt_priority( 0 )\r
+#define portENTER_CRITICAL()                                   vPortEnterCritical()\r
+#define portEXIT_CRITICAL()                                            vPortExitCritical()\r
+#define portSET_INTERRUPT_MASK_FROM_ISR()              _set_interrupt_priority( configMAX_SYSCALL_INTERRUPT_PRIORITY ); __asm( "       dsb" ); __asm( "        isb" )\r
+#define portCLEAR_INTERRUPT_MASK_FROM_ISR(x)   _set_interrupt_priority( x )\r
+/*-----------------------------------------------------------*/\r
+\r
+/* Tickless idle/low power functionality. */\r
+#ifndef portSUPPRESS_TICKS_AND_SLEEP\r
+       extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime );\r
+       #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) vPortSuppressTicksAndSleep( xExpectedIdleTime )\r
+#endif\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/* Task function macros as described on the FreeRTOS.org WEB site.  These are\r
+not necessary for to use this port.  They are defined so the common demo files\r
+(which build with all the ports) will build. */\r
+#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
+#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
+/*-----------------------------------------------------------*/\r
+\r
+#ifdef configASSERT\r
+       void vPortValidateInterruptPriority( void );\r
+       #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID()      vPortValidateInterruptPriority()\r
+#endif\r
+\r
+/* portNOP() is not required by this port. */\r
+#define portNOP()\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* PORTMACRO_H */\r
+\r
index 0fae3c65c6c7db86fae1818c3882011860cbf27f..3e18be7f85dc9e88fabc8f5a071bacf63a875404 100644 (file)
@@ -629,12 +629,34 @@ UBaseType_t uxReturn;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-BaseType_t MPU_xQueueGenericReceive( QueueHandle_t pxQueue, void * const pvBuffer, TickType_t xTicksToWait, BaseType_t xJustPeeking )\r
+BaseType_t MPU_xQueueReceive( QueueHandle_t pxQueue, void * const pvBuffer, TickType_t xTicksToWait )\r
 {\r
 BaseType_t xRunningPrivileged = xPortRaisePrivilege();\r
 BaseType_t xReturn;\r
 \r
-       xReturn = xQueueGenericReceive( pxQueue, pvBuffer, xTicksToWait, xJustPeeking );\r
+       xReturn = xQueueReceive( pxQueue, pvBuffer, xTicksToWait );\r
+       vPortResetPrivilege( xRunningPrivileged );\r
+       return xReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+BaseType_t MPU_xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait )\r
+{\r
+BaseType_t xRunningPrivileged = xPortRaisePrivilege();\r
+BaseType_t xReturn;\r
+\r
+       xReturn = xQueuePeek( xQueue, pvBuffer, xTicksToWait );\r
+       vPortResetPrivilege( xRunningPrivileged );\r
+       return xReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+BaseType_t MPU_xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait )\r
+{\r
+BaseType_t xRunningPrivileged = xPortRaisePrivilege();\r
+BaseType_t xReturn;\r
+\r
+       xReturn = xQueueSemaphoreTake( xQueue, xTicksToWait );\r
        vPortResetPrivilege( xRunningPrivileged );\r
        return xReturn;\r
 }\r
index 824c263e1dd5db278598c916d24060085c7b206c..7325148b48d546121750b0c874029af2aaa5526a 100644 (file)
@@ -669,7 +669,7 @@ static void prvInitialiseNewQueue( const UBaseType_t uxQueueLength, const UBaseT
                }\r
                else\r
                {\r
-                       xReturn = xQueueGenericReceive( pxMutex, NULL, xTicksToWait, pdFALSE );\r
+                       xReturn = xQueueSemaphoreTake( pxMutex, xTicksToWait );\r
 \r
                        /* pdPASS will only be returned if the mutex was successfully\r
                        obtained.  The calling task may have entered the Blocked state\r
@@ -1260,21 +1260,27 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
 }\r
 /*-----------------------------------------------------------*/\r
 \r
-BaseType_t xQueueGenericReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait, const BaseType_t xJustPeeking )\r
+BaseType_t xQueueReceive( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait )\r
 {\r
 BaseType_t xEntryTimeSet = pdFALSE;\r
 TimeOut_t xTimeOut;\r
-int8_t *pcOriginalReadPosition;\r
 Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
 \r
-       configASSERT( pxQueue );\r
-       configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
+       /* Check the pointer is not NULL. */\r
+       configASSERT( ( pxQueue ) );\r
+\r
+       /* The buffer into which data is received can only be NULL if the data size\r
+       is zero (so no data is copied into the buffer. */\r
+       configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
+\r
+       /* Cannot block if the scheduler is suspended. */\r
        #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
        {\r
                configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );\r
        }\r
        #endif\r
 \r
+\r
        /* This function relaxes the coding standard somewhat to allow return\r
        statements within the function itself.  This is done in the interest\r
        of execution time efficiency. */\r
@@ -1289,44 +1295,19 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        must be the highest priority task wanting to access the queue. */\r
                        if( uxMessagesWaiting > ( UBaseType_t ) 0 )\r
                        {\r
-                               /* Remember the read position in case the queue is only being\r
-                               peeked. */\r
-                               pcOriginalReadPosition = pxQueue->u.pcReadFrom;\r
-\r
+                               /* Data available, remove one item. */\r
                                prvCopyDataFromQueue( pxQueue, pvBuffer );\r
+                               traceQUEUE_RECEIVE( pxQueue );\r
+                               pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1;\r
 \r
-                               if( xJustPeeking == pdFALSE )\r
+                               /* There is now space in the queue, were any tasks waiting to\r
+                               post to the queue?  If so, unblock the highest priority waiting\r
+                               task. */\r
+                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
                                {\r
-                                       traceQUEUE_RECEIVE( pxQueue );\r
-\r
-                                       /* Actually removing data, not just peeking. */\r
-                                       pxQueue->uxMessagesWaiting = uxMessagesWaiting - ( UBaseType_t ) 1;\r
-\r
-                                       #if ( configUSE_MUTEXES == 1 )\r
-                                       {\r
-                                               if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
-                                               {\r
-                                                       /* Record the information required to implement\r
-                                                       priority inheritance should it become necessary. */\r
-                                                       pxQueue->pxMutexHolder = ( int8_t * ) pvTaskIncrementMutexHeldCount(); /*lint !e961 Cast is not redundant as TaskHandle_t is a typedef. */\r
-                                               }\r
-                                               else\r
-                                               {\r
-                                                       mtCOVERAGE_TEST_MARKER();\r
-                                               }\r
-                                       }\r
-                                       #endif /* configUSE_MUTEXES */\r
-\r
-                                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
+                                       if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
                                        {\r
-                                               if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
-                                               {\r
-                                                       queueYIELD_IF_USING_PREEMPTION();\r
-                                               }\r
-                                               else\r
-                                               {\r
-                                                       mtCOVERAGE_TEST_MARKER();\r
-                                               }\r
+                                               queueYIELD_IF_USING_PREEMPTION();\r
                                        }\r
                                        else\r
                                        {\r
@@ -1335,31 +1316,167 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                }\r
                                else\r
                                {\r
-                                       traceQUEUE_PEEK( pxQueue );\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+\r
+                               taskEXIT_CRITICAL();\r
+                               return pdPASS;\r
+                       }\r
+                       else\r
+                       {\r
+                               if( xTicksToWait == ( TickType_t ) 0 )\r
+                               {\r
+                                       /* The queue was empty and no block time is specified (or\r
+                                       the block time has expired) so leave now. */\r
+                                       taskEXIT_CRITICAL();\r
+                                       traceQUEUE_RECEIVE_FAILED( pxQueue );\r
+                                       return errQUEUE_EMPTY;\r
+                               }\r
+                               else if( xEntryTimeSet == pdFALSE )\r
+                               {\r
+                                       /* The queue was empty and a block time was specified so\r
+                                       configure the timeout structure. */\r
+                                       vTaskSetTimeOutState( &xTimeOut );\r
+                                       xEntryTimeSet = pdTRUE;\r
+                               }\r
+                               else\r
+                               {\r
+                                       /* Entry time was already set. */\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+                       }\r
+               }\r
+               taskEXIT_CRITICAL();\r
 \r
-                                       /* The data is not being removed, so reset the read\r
-                                       pointer. */\r
-                                       pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
+               /* Interrupts and other tasks can send to and receive from the queue\r
+               now the critical section has been exited. */\r
 \r
-                                       /* The data is being left in the queue, so see if there are\r
-                                       any other tasks waiting for the data. */\r
-                                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+               vTaskSuspendAll();\r
+               prvLockQueue( pxQueue );\r
+\r
+               /* Update the timeout state to see if it has expired yet. */\r
+               if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
+               {\r
+                       /* The timeout has not expired.  If the queue is still empty place\r
+                       the task on the list of tasks waiting to receive from the queue. */\r
+                       if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
+                       {\r
+                               traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\r
+                               vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
+                               prvUnlockQueue( pxQueue );\r
+                               if( xTaskResumeAll() == pdFALSE )\r
+                               {\r
+                                       portYIELD_WITHIN_API();\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               /* The queue contains data again.  Loop back to try and read the\r
+                               data. */\r
+                               prvUnlockQueue( pxQueue );\r
+                               ( void ) xTaskResumeAll();\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       /* Timed out.  If there is no data in the queue exit, otherwise loop\r
+                       back and attempt to read the data. */\r
+                       prvUnlockQueue( pxQueue );\r
+                       ( void ) xTaskResumeAll();\r
+\r
+                       if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
+                       {\r
+                               traceQUEUE_RECEIVE_FAILED( pxQueue );\r
+                               return errQUEUE_EMPTY;\r
+                       }\r
+                       else\r
+                       {\r
+                               mtCOVERAGE_TEST_MARKER();\r
+                       }\r
+               }\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+BaseType_t xQueueSemaphoreTake( QueueHandle_t xQueue, TickType_t xTicksToWait )\r
+{\r
+BaseType_t xEntryTimeSet = pdFALSE;\r
+TimeOut_t xTimeOut;\r
+Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+\r
+       /* Check the queue pointer is not NULL. */\r
+       configASSERT( ( pxQueue ) );\r
+\r
+       /* Check this really is a semaphore, in which case the item size will be\r
+       0. */\r
+       configASSERT( pxQueue->uxItemSize == 0 );\r
+\r
+       /* Cannot block if the scheduler is suspended. */\r
+       #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
+       {\r
+               configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );\r
+       }\r
+       #endif\r
+\r
+\r
+       /* This function relaxes the coding standard somewhat to allow return\r
+       statements within the function itself.  This is done in the interest\r
+       of execution time efficiency. */\r
+\r
+       for( ;; )\r
+       {\r
+               taskENTER_CRITICAL();\r
+               {\r
+                       /* Semaphores are queues with an item size of 0, and where the\r
+                       number of messages in the queue is the semaphore's count value. */\r
+                       const UBaseType_t uxSemaphoreCount = pxQueue->uxMessagesWaiting;\r
+\r
+                       /* Is there data in the queue now?  To be running the calling task\r
+                       must be the highest priority task wanting to access the queue. */\r
+                       if( uxSemaphoreCount > ( UBaseType_t ) 0 )\r
+                       {\r
+                               traceQUEUE_RECEIVE( pxQueue );\r
+\r
+                               /* Semaphores are queues with a data size of zero and where the\r
+                               messages waiting is the semaphore's count.  Reduce the count. */\r
+                               pxQueue->uxMessagesWaiting = uxSemaphoreCount - ( UBaseType_t ) 1;\r
+\r
+                               #if ( configUSE_MUTEXES == 1 )\r
+                               {\r
+                                       if( pxQueue->uxQueueType == queueQUEUE_IS_MUTEX )\r
                                        {\r
-                                               if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
-                                               {\r
-                                                       /* The task waiting has a higher priority than this task. */\r
-                                                       queueYIELD_IF_USING_PREEMPTION();\r
-                                               }\r
-                                               else\r
-                                               {\r
-                                                       mtCOVERAGE_TEST_MARKER();\r
-                                               }\r
+                                               /* Record the information required to implement\r
+                                               priority inheritance should it become necessary. */\r
+                                               pxQueue->pxMutexHolder = ( int8_t * ) pvTaskIncrementMutexHeldCount(); /*lint !e961 Cast is not redundant as TaskHandle_t is a typedef. */\r
                                        }\r
                                        else\r
                                        {\r
                                                mtCOVERAGE_TEST_MARKER();\r
                                        }\r
                                }\r
+                               #endif /* configUSE_MUTEXES */\r
+\r
+                               /* Check to see if other tasks are blocked waiting to give the\r
+                               semaphore, and if so, unblock the highest priority such task. */\r
+                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE )\r
+                               {\r
+                                       if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) != pdFALSE )\r
+                                       {\r
+                                               queueYIELD_IF_USING_PREEMPTION();\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               mtCOVERAGE_TEST_MARKER();\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
 \r
                                taskEXIT_CRITICAL();\r
                                return pdPASS;\r
@@ -1368,16 +1485,16 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        {\r
                                if( xTicksToWait == ( TickType_t ) 0 )\r
                                {\r
-                                       /* The queue was empty and no block time is specified (or\r
-                                       the block time has expired) so leave now. */\r
+                                       /* The semaphore count was 0 and no block time is specified\r
+                                       (or the block time has expired) so exit now. */\r
                                        taskEXIT_CRITICAL();\r
                                        traceQUEUE_RECEIVE_FAILED( pxQueue );\r
                                        return errQUEUE_EMPTY;\r
                                }\r
                                else if( xEntryTimeSet == pdFALSE )\r
                                {\r
-                                       /* The queue was empty and a block time was specified so\r
-                                       configure the timeout structure. */\r
+                                       /* The semaphore count was 0 and a block time was specified\r
+                                       so configure the timeout structure ready to block. */\r
                                        vTaskSetTimeOutState( &xTimeOut );\r
                                        xEntryTimeSet = pdTRUE;\r
                                }\r
@@ -1390,7 +1507,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                }\r
                taskEXIT_CRITICAL();\r
 \r
-               /* Interrupts and other tasks can send to and receive from the queue\r
+               /* Interrupts and other tasks can give to and take from the semaphore\r
                now the critical section has been exited. */\r
 \r
                vTaskSuspendAll();\r
@@ -1399,6 +1516,10 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                /* Update the timeout state to see if it has expired yet. */\r
                if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
                {\r
+                       /* A block time is specified and not expired.  If the semaphore\r
+                       count is 0 then enter the Blocked state to wait for a semaphore to\r
+                       become available.  As semaphores are implemented with queues the\r
+                       queue being empty is equivalent to the semaphore count being 0. */\r
                        if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
                        {\r
                                traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\r
@@ -1409,7 +1530,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                        {\r
                                                taskENTER_CRITICAL();\r
                                                {\r
-                                                       vTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );\r
+                                                       xTaskPriorityInherit( ( void * ) pxQueue->pxMutexHolder );\r
                                                }\r
                                                taskEXIT_CRITICAL();\r
                                        }\r
@@ -1433,13 +1554,169 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        }\r
                        else\r
                        {\r
-                               /* Try again. */\r
+                               /* There was no timeout and the semaphore count was not 0, so\r
+                               attempt to take the semaphore again. */\r
+                               prvUnlockQueue( pxQueue );\r
+                               ( void ) xTaskResumeAll();\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       /* Timed out. */\r
+                       prvUnlockQueue( pxQueue );\r
+                       ( void ) xTaskResumeAll();\r
+\r
+                       /* If the semaphore count is 0 exit now as the timeout has\r
+                       expired.  Otherwise return to attempt to take the semaphore that is\r
+                       known to be available.  As semaphores are implemented by queues the\r
+                       queue being empty is equivalent to the semaphore count being 0. */\r
+                       if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
+                       {\r
+                               traceQUEUE_RECEIVE_FAILED( pxQueue );\r
+                               return errQUEUE_EMPTY;\r
+                       }\r
+                       else\r
+                       {\r
+                               mtCOVERAGE_TEST_MARKER();\r
+                       }\r
+               }\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+BaseType_t xQueuePeek( QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait )\r
+{\r
+BaseType_t xEntryTimeSet = pdFALSE;\r
+TimeOut_t xTimeOut;\r
+int8_t *pcOriginalReadPosition;\r
+Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+\r
+       /* Check the pointer is not NULL. */\r
+       configASSERT( ( pxQueue ) );\r
+\r
+       /* The buffer into which data is received can only be NULL if the data size\r
+       is zero (so no data is copied into the buffer. */\r
+       configASSERT( !( ( ( pvBuffer ) == NULL ) && ( ( pxQueue )->uxItemSize != ( UBaseType_t ) 0U ) ) );\r
+\r
+       /* Cannot block if the scheduler is suspended. */\r
+       #if ( ( INCLUDE_xTaskGetSchedulerState == 1 ) || ( configUSE_TIMERS == 1 ) )\r
+       {\r
+               configASSERT( !( ( xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED ) && ( xTicksToWait != 0 ) ) );\r
+       }\r
+       #endif\r
+\r
+\r
+       /* This function relaxes the coding standard somewhat to allow return\r
+       statements within the function itself.  This is done in the interest\r
+       of execution time efficiency. */\r
+\r
+       for( ;; )\r
+       {\r
+               taskENTER_CRITICAL();\r
+               {\r
+                       const UBaseType_t uxMessagesWaiting = pxQueue->uxMessagesWaiting;\r
+\r
+                       /* Is there data in the queue now?  To be running the calling task\r
+                       must be the highest priority task wanting to access the queue. */\r
+                       if( uxMessagesWaiting > ( UBaseType_t ) 0 )\r
+                       {\r
+                               /* Remember the read position so it can be reset after the data\r
+                               is read from the queue as this function is only peeking the\r
+                               data, not removing it. */\r
+                               pcOriginalReadPosition = pxQueue->u.pcReadFrom;\r
+\r
+                               prvCopyDataFromQueue( pxQueue, pvBuffer );\r
+                               traceQUEUE_PEEK( pxQueue );\r
+\r
+                               /* The data is not being removed, so reset the read pointer. */\r
+                               pxQueue->u.pcReadFrom = pcOriginalReadPosition;\r
+\r
+                               /* The data is being left in the queue, so see if there are\r
+                               any other tasks waiting for the data. */\r
+                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+                               {\r
+                                       if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+                                       {\r
+                                               /* The task waiting has a higher priority than this task. */\r
+                                               queueYIELD_IF_USING_PREEMPTION();\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               mtCOVERAGE_TEST_MARKER();\r
+                                       }\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+\r
+                               taskEXIT_CRITICAL();\r
+                               return pdPASS;\r
+                       }\r
+                       else\r
+                       {\r
+                               if( xTicksToWait == ( TickType_t ) 0 )\r
+                               {\r
+                                       /* The queue was empty and no block time is specified (or\r
+                                       the block time has expired) so leave now. */\r
+                                       taskEXIT_CRITICAL();\r
+                                       traceQUEUE_RECEIVE_FAILED( pxQueue );\r
+                                       return errQUEUE_EMPTY;\r
+                               }\r
+                               else if( xEntryTimeSet == pdFALSE )\r
+                               {\r
+                                       /* The queue was empty and a block time was specified so\r
+                                       configure the timeout structure ready to enter the blocked\r
+                                       state. */\r
+                                       vTaskSetTimeOutState( &xTimeOut );\r
+                                       xEntryTimeSet = pdTRUE;\r
+                               }\r
+                               else\r
+                               {\r
+                                       /* Entry time was already set. */\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+                       }\r
+               }\r
+               taskEXIT_CRITICAL();\r
+\r
+               /* Interrupts and other tasks can send to and receive from the queue\r
+               now the critical section has been exited. */\r
+\r
+               vTaskSuspendAll();\r
+               prvLockQueue( pxQueue );\r
+\r
+               /* Update the timeout state to see if it has expired yet. */\r
+               if( xTaskCheckForTimeOut( &xTimeOut, &xTicksToWait ) == pdFALSE )\r
+               {\r
+                       /* Timeout has not expired yet, check to see if there is data in the\r
+                       queue now, and if not enter the Blocked state to wait for data. */\r
+                       if( prvIsQueueEmpty( pxQueue ) != pdFALSE )\r
+                       {\r
+                               traceBLOCKING_ON_QUEUE_RECEIVE( pxQueue );\r
+                               vTaskPlaceOnEventList( &( pxQueue->xTasksWaitingToReceive ), xTicksToWait );\r
+                               prvUnlockQueue( pxQueue );\r
+                               if( xTaskResumeAll() == pdFALSE )\r
+                               {\r
+                                       portYIELD_WITHIN_API();\r
+                               }\r
+                               else\r
+                               {\r
+                                       mtCOVERAGE_TEST_MARKER();\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               /* There is data in the queue now, so don't enter the blocked\r
+                               state, instead return to try and obtain the data. */\r
                                prvUnlockQueue( pxQueue );\r
                                ( void ) xTaskResumeAll();\r
                        }\r
                }\r
                else\r
                {\r
+                       /* The timeout has expired.  If there is still no data in the queue\r
+                       exit, otherwise go back and try to read the data again. */\r
                        prvUnlockQueue( pxQueue );\r
                        ( void ) xTaskResumeAll();\r
 \r
@@ -2504,7 +2781,7 @@ BaseType_t xReturn;
        {\r
        QueueSetMemberHandle_t xReturn = NULL;\r
 \r
-               ( void ) xQueueGenericReceive( ( QueueHandle_t ) xQueueSet, &xReturn, xTicksToWait, pdFALSE ); /*lint !e961 Casting from one typedef to another is not redundant. */\r
+               ( void ) xQueueReceive( ( QueueHandle_t ) xQueueSet, &xReturn, xTicksToWait ); /*lint !e961 Casting from one typedef to another is not redundant. */\r
                return xReturn;\r
        }\r
 \r
index 1cdb016db6c83724e02104ab354666592624afaf..a0cb524c605d20eead31059210728246e33a4bc7 100644 (file)
@@ -134,7 +134,7 @@ that if portUSING_MPU_WRAPPERS is 1 then a protected task can be created with
 a statically allocated stack and a dynamically allocated TCB.\r
 !!!NOTE!!! If the definition of tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE is\r
 changed then the definition of StaticTask_t must also be updated. */\r
-#define tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE   ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
+#define tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE      ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
 #define tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB                 ( ( uint8_t ) 0 )\r
 #define tskSTATICALLY_ALLOCATED_STACK_ONLY                     ( ( uint8_t ) 1 )\r
 #define tskSTATICALLY_ALLOCATED_STACK_AND_TCB          ( ( uint8_t ) 2 )\r
@@ -405,7 +405,7 @@ PRIVILEGED_DATA static List_t xPendingReadyList;                                            /*< Tasks that have been r
 \r
 /* Other file private variables. --------------------------------*/\r
 PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks     = ( UBaseType_t ) 0U;\r
-PRIVILEGED_DATA static volatile TickType_t xTickCount                          = ( TickType_t ) 0U;\r
+PRIVILEGED_DATA static volatile TickType_t xTickCount                          = ( TickType_t ) configINITIAL_TICK_COUNT;\r
 PRIVILEGED_DATA static volatile UBaseType_t uxTopReadyPriority                 = tskIDLE_PRIORITY;\r
 PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunning           = pdFALSE;\r
 PRIVILEGED_DATA static volatile UBaseType_t uxPendedTicks                      = ( UBaseType_t ) 0U;\r
@@ -694,7 +694,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
                                pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_AND_TCB;\r
                        }\r
                        #endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
-                       \r
+\r
                        prvInitialiseNewTask(   pxTaskDefinition->pvTaskCode,\r
                                                                        pxTaskDefinition->pcName,\r
                                                                        ( uint32_t ) pxTaskDefinition->usStackDepth,\r
@@ -762,7 +762,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
 \r
        BaseType_t xTaskCreate( TaskFunction_t pxTaskCode,\r
                                                        const char * const pcName,              /*lint !e971 Unqualified char types are allowed for strings and single characters only. */\r
-                                                       const uint16_t usStackDepth,\r
+                                                       const configSTACK_DEPTH_TYPE usStackDepth,\r
                                                        void * const pvParameters,\r
                                                        UBaseType_t uxPriority,\r
                                                        TaskHandle_t * const pxCreatedTask )\r
@@ -1692,6 +1692,17 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                        }\r
 \r
                        vListInsertEnd( &xSuspendedTaskList, &( pxTCB->xStateListItem ) );\r
+\r
+                       #if( configUSE_TASK_NOTIFICATIONS == 1 )\r
+                       {\r
+                               if( pxTCB->ucNotifyState == taskWAITING_NOTIFICATION )\r
+                               {\r
+                                       /* The task was blocked to wait for a notification, but is\r
+                                       now suspended, so no notification was received. */\r
+                                       pxTCB->ucNotifyState = taskNOT_WAITING_NOTIFICATION;\r
+                               }\r
+                       }\r
+                       #endif\r
                }\r
                taskEXIT_CRITICAL();\r
 \r
@@ -1811,12 +1822,12 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB )
                                {\r
                                        traceTASK_RESUME( pxTCB );\r
 \r
-                                       /* As we are in a critical section we can access the ready\r
-                                       lists even if the scheduler is suspended. */\r
+                                       /* The ready list can be accessed even if the scheduler is\r
+                                       suspended because this is inside a critical section. */\r
                                        ( void ) uxListRemove(  &( pxTCB->xStateListItem ) );\r
                                        prvAddTaskToReadyList( pxTCB );\r
 \r
-                                       /* We may have just resumed a higher priority task. */\r
+                                       /* A higher priority task may have just been resumed. */\r
                                        if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority )\r
                                        {\r
                                                /* This yield may not cause the task just resumed to run,\r
@@ -3308,6 +3319,11 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
                                        configASSERT( xNextTaskUnblockTime >= xTickCount );\r
                                        xExpectedIdleTime = prvGetExpectedIdleTime();\r
 \r
+                                       /* Define the following macro to set xExpectedIdleTime to 0\r
+                                       if the application does not want\r
+                                       portSUPPRESS_TICKS_AND_SLEEP() to be called. */\r
+                                       configPRE_SUPPRESS_TICKS_AND_SLEEP_PROCESSING( xExpectedIdleTime );\r
+\r
                                        if( xExpectedIdleTime >= configEXPECTED_IDLE_TIME_BEFORE_SLEEP )\r
                                        {\r
                                                traceLOW_POWER_IDLE_BEGIN();\r
@@ -3799,12 +3815,14 @@ TCB_t *pxTCB;
 \r
 #if ( configUSE_MUTEXES == 1 )\r
 \r
-       void vTaskPriorityInherit( TaskHandle_t const pxMutexHolder )\r
+       BaseType_t xTaskPriorityInherit( TaskHandle_t const pxMutexHolder )\r
        {\r
        TCB_t * const pxTCB = ( TCB_t * ) pxMutexHolder;\r
+       BaseType_t xReturn = pdFALSE;\r
 \r
                /* If the mutex was given back by an interrupt while the queue was\r
-               locked then the mutex holder might now be NULL. */\r
+               locked then the mutex holder might now be NULL.  _RB_ Is this still\r
+               needed as interrupt can no longer use mutexes? */\r
                if( pxMutexHolder != NULL )\r
                {\r
                        /* If the holder of the mutex has a priority below the priority of\r
@@ -3848,6 +3866,9 @@ TCB_t *pxTCB;
                                }\r
 \r
                                traceTASK_PRIORITY_INHERIT( pxTCB, pxCurrentTCB->uxPriority );\r
+\r
+                               /* Inheritance occurred. */\r
+                               xReturn = pdTRUE;\r
                        }\r
                        else\r
                        {\r
@@ -3858,6 +3879,8 @@ TCB_t *pxTCB;
                {\r
                        mtCOVERAGE_TEST_MARKER();\r
                }\r
+\r
+               return xReturn;\r
        }\r
 \r
 #endif /* configUSE_MUTEXES */\r
@@ -4411,7 +4434,7 @@ TickType_t uxReturn;
                        blocked state (because a notification was already pending) or the\r
                        task unblocked because of a notification.  Otherwise the task\r
                        unblocked because of a timeout. */\r
-                       if( pxCurrentTCB->ucNotifyState == taskWAITING_NOTIFICATION )\r
+                       if( pxCurrentTCB->ucNotifyState != taskNOTIFICATION_RECEIVED )\r
                        {\r
                                /* A notification was not received. */\r
                                xReturn = pdFALSE;\r