From f333c34b87b7cd60c58d792f70aa61bbab7947f8 Mon Sep 17 00:00:00 2001 From: rtel Date: Tue, 16 Sep 2014 14:54:32 +0000 Subject: [PATCH] Core kernel code: + Introduce xSemaphoreGenericGiveFromISR() as an optimisation when giving semaphores and mutexes from an interrupt. Demo applications: + Update IntSemTest.c to provide more code coverage in xSemaphoreGenericGiveFromISR(). + Ensure the MMU is turned on in the RZ IAR demo. It was already on in the RZ ARM demo. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2306 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../IAR/settings/RTOSDemo.dbgdt | 10 +- .../IAR/settings/RTOSDemo.dni | 5 +- .../IAR/settings/RTOSDemo.wsdt | 8 +- .../RTOSDemo.atsuo | Bin 59904 -> 61952 bytes FreeRTOS/Demo/Common/Minimal/IntSemTest.c | 438 ++++++++++++------ FreeRTOS/Source/include/queue.h | 4 +- FreeRTOS/Source/include/semphr.h | 2 +- FreeRTOS/Source/queue.c | 172 ++++++- FreeRTOS/Source/tasks.c | 17 +- 9 files changed, 493 insertions(+), 163 deletions(-) diff --git a/FreeRTOS/Demo/CORTEX_A9_RZ_R7S72100_IAR_DS-5/IAR/settings/RTOSDemo.dbgdt b/FreeRTOS/Demo/CORTEX_A9_RZ_R7S72100_IAR_DS-5/IAR/settings/RTOSDemo.dbgdt index bc1b04294..175b58bf4 100644 --- a/FreeRTOS/Demo/CORTEX_A9_RZ_R7S72100_IAR_DS-5/IAR/settings/RTOSDemo.dbgdt +++ b/FreeRTOS/Demo/CORTEX_A9_RZ_R7S72100_IAR_DS-5/IAR/settings/RTOSDemo.dbgdt @@ -39,7 +39,7 @@ - + TabID-6824-27546 @@ -55,7 +55,7 @@ TabID-11794-23690Find in FilesFind-in-Files - 0 + 0 TabID-17573-27549 @@ -67,20 +67,20 @@ - 0TabID-8721-7680DisassemblyDisassembly0 + 0TabID-8721-7680DisassemblyDisassembly0 - TextEditor$WS_DIR$\..\Source\Full-Demo\main_full.c000006481238123TextEditor$WS_DIR$\..\Source\Blinky-Demo\main_blinky.c000006499799979TextEditor$WS_DIR$\..\Source\main.c0000011260906090TextEditor$WS_DIR$\cstartup.s0000013254565456TextEditor$WS_DIR$\LowLevelInitialise.c0000024134113414TextEditor$WS_DIR$\modules\armv7a_cp15_drv.c0000072720604206040100000010000001 + TextEditor$WS_DIR$\..\Source\Blinky-Demo\main_blinky.c000006400TextEditor$WS_DIR$\..\Source\main.c0000012263486348TextEditor$WS_DIR$\cstartup.s0000012036723672TextEditor$WS_DIR$\LowLevelInitialise.c0000014108010803TextEditor$WS_DIR$\modules\armv7a_cp15_drv.c000005731678016780TextEditor$WS_DIR$\..\Source\LEDs.c000006442474247TextEditor$WS_DIR$\..\Source\RenesasFiles\board_settings\siochar.c000006346694669TextEditor$WS_DIR$\..\Source\Full-Demo\main_full.c0000034017554175540100000010000001 - iaridepm.enu1debuggergui.enu1-2-2718302-2-2200200119048203252180952731707-2-2718699-2-2200200119048203252417262731707-2-21981682-2-216842001002381203252119048203252 + iaridepm.enu1debuggergui.enu1-2-2718302-2-2200200119048203252180952731707-2-2718699-2-2200200119048203252417262731707-2-21981682-2-216842001002381203252119048203252 diff --git a/FreeRTOS/Demo/CORTEX_A9_RZ_R7S72100_IAR_DS-5/IAR/settings/RTOSDemo.dni b/FreeRTOS/Demo/CORTEX_A9_RZ_R7S72100_IAR_DS-5/IAR/settings/RTOSDemo.dni index c22cb97f8..4f7098e1e 100644 --- a/FreeRTOS/Demo/CORTEX_A9_RZ_R7S72100_IAR_DS-5/IAR/settings/RTOSDemo.dni +++ b/FreeRTOS/Demo/CORTEX_A9_RZ_R7S72100_IAR_DS-5/IAR/settings/RTOSDemo.dni @@ -14,7 +14,7 @@ Watch0=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0 Watch1=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0 CStepIntDis=_ 0 [DebugChecksum] -Checksum=-1045357403 +Checksum=72368941 [Jet] JetConnSerialNo=73866 JetConnFoundProbes= @@ -109,7 +109,8 @@ Exclusions= [Disassemble mode] mode=0 [Breakpoints2] -Count=0 +Bp0=_ 1 "EMUL_CODE" "{$PROJ_DIR$\..\Source\main.c}.136.2" 0 0 1 "" 0 "" 0 +Count=1 [Aliases] Count=0 SuppressDialog=0 diff --git a/FreeRTOS/Demo/CORTEX_A9_RZ_R7S72100_IAR_DS-5/IAR/settings/RTOSDemo.wsdt b/FreeRTOS/Demo/CORTEX_A9_RZ_R7S72100_IAR_DS-5/IAR/settings/RTOSDemo.wsdt index f5a6e5bd5..1757579d8 100644 --- a/FreeRTOS/Demo/CORTEX_A9_RZ_R7S72100_IAR_DS-5/IAR/settings/RTOSDemo.wsdt +++ b/FreeRTOS/Demo/CORTEX_A9_RZ_R7S72100_IAR_DS-5/IAR/settings/RTOSDemo.wsdt @@ -38,7 +38,7 @@ Workspace - RTOSDemoRTOSDemo/Blinky-Demo + RTOSDemo @@ -58,20 +58,20 @@ TabID-959-438Ambiguous DefinitionsSelect-Ambiguous-DefinitionsTabID-21579-10611Find All DeclarationsFind-All-Declarations - 1 + 3 - TextEditor$WS_DIR$\..\Source\Full-Demo\main_full.c000006481238123TextEditor$WS_DIR$\..\Source\Blinky-Demo\main_blinky.c000006400TextEditor$WS_DIR$\..\Source\main.c0000011200TextEditor$WS_DIR$\cstartup.s0000013254565456TextEditor$WS_DIR$\LowLevelInitialise.c0000014134113414TextEditor$WS_DIR$\modules\armv7a_cp15_drv.c0000072720604206040100000010000001 + TextEditor$WS_DIR$\..\Source\Blinky-Demo\main_blinky.c000006400TextEditor$WS_DIR$\..\Source\main.c0000012263486348TextEditor$WS_DIR$\cstartup.s0000012036723672TextEditor$WS_DIR$\LowLevelInitialise.c0000023106710823TextEditor$WS_DIR$\modules\armv7a_cp15_drv.c0000028385238523TextEditor$WS_DIR$\..\Source\LEDs.c000006442474247TextEditor$WS_DIR$\..\Source\RenesasFiles\board_settings\siochar.c000006346694669TextEditor$WS_DIR$\..\Source\Full-Demo\main_full.c0000034017554175540100000010000001 - iaridepm.enu1-2-2693380-2-2200200119048203252227381706301-2-22471682-2-216842491002381253049119048203252 + iaridepm.enu1-2-2693380-2-2200200119048203252227381706301-2-22471682-2-216842491002381253049119048203252 diff --git a/FreeRTOS/Demo/CORTEX_M4_ATSAM4S_Atmel_Studio/RTOSDemo.atsuo b/FreeRTOS/Demo/CORTEX_M4_ATSAM4S_Atmel_Studio/RTOSDemo.atsuo index f2ad135f456c55a7dc55cee8c782c2c8d9e4734a..e72f99e07a5dbf3d7453108ab8bd0f541b39d0ea 100644 GIT binary patch delta 3051 zcmbW3dr(t%7RT=|xr77|h>3t87(^LFK~PsKN(m4w4+T^dtLO@X8dn2ouu3ZgUsVK! zd~pRujp*)(t5vww?!y9tk5b)AD_ZM1PUvXSS$DNNxT8+j?71PJ?w|X+^T|Eu{2upr zf9H{F>Xw=wNYBU=g@sF zF;CQKV<>R0;AtIOvpi9Pma6g4y7SoRG7Fc~5l%yBRJiccB}Gyl!4LByZ6lY#>AB_H zZ|H3D=_Cw@^#~G7LoP|>;=8yL=&BBZQJJRT#OZDhi_oV`lc2*d8YZ<)KA)`Oa^hH7 zCcXLLA$X-ua^gHhqqq&@ux+dxFNYP*pG>BY$t4r%MH9HG++_NV>zF3kX=!zxcxoPw}(|*O%=*?U>m&<*GR<9+VJ;v7!@n3W)Kl9}*ogTIh1oCP@ z>n)WkI6r!*%CSMg=*u(7WQkDhx0>O^sCtih97%7g&Y!Nx{CPJDQH-Xako;TU}?jfcMs*eaHy*IoO#- zbBmi&v*b~HYv_N>W$m}>wsbcB-2<_aDp+R)v)j0M{W1#n3{~EG(v*EPedNu~)z2>O zy_9&*O&lZ5=dxhSxTtKIwrEAg)S8s_ky*P=#?{Z2*;nYA;LAAJ#^@BxlOC-kM9&Du z;0gv){8{C%PTw7JFn+DgL)*T=cso~bUleVj7m zT$H83_U&n9=gb{aoA=7834hCoU2w4RoYMZlwoyA_nXjQ#2*Ssv9@dVZi>l2R+_7vj z-yGH^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bbgSAM=Vo$ z^Iw(2AD3xTxLock == queueUNLOCKED ) { - /* This is a special case that can only be executed if a task - holds multiple mutexes and then gives the mutexes back in an - order that is different to that in which they were taken. */ - if( pxHigherPriorityTaskWoken != NULL ) + #if ( configUSE_QUEUE_SETS == 1 ) { - *pxHigherPriorityTaskWoken = pdTRUE; + if( pxQueue->pxQueueSetContainer != NULL ) + { + if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE ) + { + /* The queue is a member of a queue set, and posting + to the queue set caused a higher priority task to + unblock. A context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so + record that a context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } } - else + #else /* configUSE_QUEUE_SETS */ { - mtCOVERAGE_TEST_MARKER(); + if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE ) + { + if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) + { + /* The task waiting has a higher priority so record that a + context switch is required. */ + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } + } + else + { + mtCOVERAGE_TEST_MARKER(); + } } + #endif /* configUSE_QUEUE_SETS */ } + else + { + /* Increment the lock count so the task that unlocks the queue + knows that data was posted while it was locked. */ + ++( pxQueue->xTxLock ); + } + + xReturn = pdPASS; + } + else + { + traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue ); + xReturn = errQUEUE_FULL; + } + } + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + + return xReturn; +} +/*-----------------------------------------------------------*/ + +BaseType_t xQueueGenericGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherPriorityTaskWoken ) +{ +BaseType_t xReturn; +UBaseType_t uxSavedInterruptStatus; +Queue_t * const pxQueue = ( Queue_t * ) xQueue; + + configASSERT( pxQueue ); + + /* xQueueGenericSendFromISR() should be used in the item size is not 0. */ + configASSERT( pxQueue->uxItemSize == 0 ); + + /* RTOS ports that support interrupt nesting have the concept of a maximum + system call (or maximum API call) interrupt priority. Interrupts that are + above the maximum system call priority are kept permanently enabled, even + when the RTOS kernel is in a critical section, but cannot make any calls to + FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h + then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion + failure if a FreeRTOS API function is called from an interrupt that has been + assigned a priority above the configured maximum system call priority. + Only FreeRTOS functions that end in FromISR can be called from interrupts + that have been assigned a priority at or (logically) below the maximum + system call interrupt priority. FreeRTOS maintains a separate interrupt + safe API to ensure interrupt entry is as fast and as simple as possible. + More information (albeit Cortex-M specific) is provided on the following + link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */ + portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); + + /* Similar to xQueueGenericSendFromISR() but used with semaphores where the + item size is 0. Don't directly wake a task that was blocked on a queue + read, instead return a flag to say whether a context switch is required or + not (i.e. has a task with a higher priority than us been woken by this + post). */ + uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); + { + /* When the queue is used to implement a semaphore no data is ever + moved through the queue but it is still valid to see if the queue 'has + space'. */ + if( pxQueue->uxMessagesWaiting < pxQueue->uxLength ) + { + traceQUEUE_SEND_FROM_ISR( pxQueue ); + + /* A task can only have an inherited priority if it is a mutex + holder - and if there is a mutex holder then the mutex cannot be + given from an ISR. Therefore, unlike the xQueueGenericGive() + function, there is no need to determine the need for priority + disinheritance here or to clear the mutex holder TCB member. */ + + ++( pxQueue->uxMessagesWaiting ); /* The event list is not altered if the queue is locked. This will be done when the queue is unlocked later. */ @@ -1097,11 +1243,11 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue; { if( pxQueue->pxQueueSetContainer != NULL ) { - if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE ) + if( prvNotifyQueueSetContainer( pxQueue, queueSEND_TO_BACK ) == pdTRUE ) { - /* The queue is a member of a queue set, and posting - to the queue set caused a higher priority task to - unblock. A context switch is required. */ + /* The semaphore is a member of a queue set, and + posting to the queue set caused a higher priority + task to unblock. A context switch is required. */ if( pxHigherPriorityTaskWoken != NULL ) { *pxHigherPriorityTaskWoken = pdTRUE; @@ -1188,7 +1334,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue; xReturn = errQUEUE_FULL; } } - portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); + portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); //0.36 return xReturn; } diff --git a/FreeRTOS/Source/tasks.c b/FreeRTOS/Source/tasks.c index 010a05baf..565b65c34 100644 --- a/FreeRTOS/Source/tasks.c +++ b/FreeRTOS/Source/tasks.c @@ -3254,8 +3254,11 @@ TCB_t *pxTCB; /* Only disinherit if no other mutexes are held. */ if( pxTCB->uxMutexesHeld == ( UBaseType_t ) 0 ) { - /* The holding task must be the running task to be able to give - the mutex back. Remove the holding task from the ready list. */ + /* A task can only have an inhertied priority if it holds + the mutex. If the mutex is held by a task then it cannot be + given from an interrupt, and if a mutex is given by the + holding task then it must be the running state task. Remove + the holding task from the ready list. */ if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 ) { taskRESET_READY_PRIORITY( pxTCB->uxPriority ); @@ -3265,8 +3268,8 @@ TCB_t *pxTCB; mtCOVERAGE_TEST_MARKER(); } - /* Disinherit the priority before adding the task into the new - ready list. */ + /* Disinherit the priority before adding the task into the + new ready list. */ traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority ); pxTCB->uxPriority = pxTCB->uxBasePriority; @@ -3279,7 +3282,11 @@ TCB_t *pxTCB; /* Return true to indicate that a context switch is required. This is only actually required in the corner case whereby multiple mutexes were held and the mutexes were given back - in an order different to that in which they were taken. */ + in an order different to that in which they were taken. + If a context switch did not occur when the first mutex was + returned, even if a task was waiting on it, then a context + switch should occur when the last mutex is returned whether + a task is waiting on it or not. */ xReturn = pdTRUE; } else -- 2.39.5