]> git.sur5r.net Git - freertos/commitdiff
Core kernel code:
authorrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Tue, 16 Sep 2014 14:54:32 +0000 (14:54 +0000)
committerrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Tue, 16 Sep 2014 14:54:32 +0000 (14:54 +0000)
+ 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

FreeRTOS/Demo/CORTEX_A9_RZ_R7S72100_IAR_DS-5/IAR/settings/RTOSDemo.dbgdt
FreeRTOS/Demo/CORTEX_A9_RZ_R7S72100_IAR_DS-5/IAR/settings/RTOSDemo.dni
FreeRTOS/Demo/CORTEX_A9_RZ_R7S72100_IAR_DS-5/IAR/settings/RTOSDemo.wsdt
FreeRTOS/Demo/CORTEX_M4_ATSAM4S_Atmel_Studio/RTOSDemo.atsuo
FreeRTOS/Demo/Common/Minimal/IntSemTest.c
FreeRTOS/Source/include/queue.h
FreeRTOS/Source/include/semphr.h
FreeRTOS/Source/queue.c
FreeRTOS/Source/tasks.c

index bc1b04294406b61fca0282bc520dc1eacbb006ad..175b58bf4089c88320ea82a9415bfa9d48b9daa1 100644 (file)
@@ -39,7 +39,7 @@
       \r
       \r
       \r
-    <Wnd3>\r
+    <Wnd0>\r
         <Tabs>\r
           <Tab>\r
             <Identity>TabID-6824-27546</Identity>\r
@@ -55,7 +55,7 @@
           </Tab>\r
         <Tab><Identity>TabID-11794-23690</Identity><TabName>Find in Files</TabName><Factory>Find-in-Files</Factory><Session/></Tab></Tabs>\r
         \r
-      <SelectedTab>0</SelectedTab></Wnd3><Wnd4>\r
+      <SelectedTab>0</SelectedTab></Wnd0><Wnd1>\r
         <Tabs>\r
           <Tab>\r
             <Identity>TabID-17573-27549</Identity>\r
           </Tab>\r
         </Tabs>\r
         \r
-      <SelectedTab>0</SelectedTab></Wnd4><Wnd5><Tabs><Tab><Identity>TabID-8721-7680</Identity><TabName>Disassembly</TabName><Factory>Disassembly</Factory><Session/></Tab></Tabs><SelectedTab>0</SelectedTab></Wnd5></Windows>\r
+      <SelectedTab>0</SelectedTab></Wnd1><Wnd2><Tabs><Tab><Identity>TabID-8721-7680</Identity><TabName>Disassembly</TabName><Factory>Disassembly</Factory><Session/></Tab></Tabs><SelectedTab>0</SelectedTab></Wnd2></Windows>\r
     <Editor>\r
       \r
       \r
       \r
       \r
-    <Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\Full-Demo\main_full.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>64</YPos2><SelStart2>8123</SelStart2><SelEnd2>8123</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\Blinky-Demo\main_blinky.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>64</YPos2><SelStart2>9979</SelStart2><SelEnd2>9979</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>112</YPos2><SelStart2>6090</SelStart2><SelEnd2>6090</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\cstartup.s</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>132</YPos2><SelStart2>5456</SelStart2><SelEnd2>5456</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\LowLevelInitialise.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>24</YPos2><SelStart2>1341</SelStart2><SelEnd2>1341</SelEnd2></Tab><ActiveTab>4</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\modules\armv7a_cp15_drv.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>727</YPos2><SelStart2>20604</SelStart2><SelEnd2>20604</SelEnd2></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>\r
+    <Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\Blinky-Demo\main_blinky.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>64</YPos2><SelStart2>0</SelStart2><SelEnd2>0</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>122</YPos2><SelStart2>6348</SelStart2><SelEnd2>6348</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\cstartup.s</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>120</YPos2><SelStart2>3672</SelStart2><SelEnd2>3672</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\LowLevelInitialise.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>14</YPos2><SelStart2>1080</SelStart2><SelEnd2>1080</SelEnd2></Tab><ActiveTab>3</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\modules\armv7a_cp15_drv.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>573</YPos2><SelStart2>16780</SelStart2><SelEnd2>16780</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\LEDs.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>64</YPos2><SelStart2>4247</SelStart2><SelEnd2>4247</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\RenesasFiles\board_settings\siochar.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>63</YPos2><SelStart2>4669</SelStart2><SelEnd2>4669</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\Full-Demo\main_full.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>340</YPos2><SelStart2>17554</SelStart2><SelEnd2>17554</SelEnd2></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>\r
     <Positions>\r
       \r
       \r
       \r
       \r
       \r
-    <Top><Row0><Sizes><Toolbar-00D172A8><key>iaridepm.enu1</key></Toolbar-00D172A8></Sizes></Row0><Row1><Sizes><Toolbar-12B3ABF8><key>debuggergui.enu1</key></Toolbar-12B3ABF8></Sizes></Row1></Top><Left><Row0><Sizes><Wnd4><Rect><Top>-2</Top><Left>-2</Left><Bottom>718</Bottom><Right>302</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>180952</sizeVertCX><sizeVertCY>731707</sizeVertCY></Rect></Wnd4></Sizes></Row0></Left><Right><Row0><Sizes><Wnd5><Rect><Top>-2</Top><Left>-2</Left><Bottom>718</Bottom><Right>699</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>417262</sizeVertCX><sizeVertCY>731707</sizeVertCY></Rect></Wnd5></Sizes></Row0></Right><Bottom><Row0><Sizes><Wnd3><Rect><Top>-2</Top><Left>-2</Left><Bottom>198</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>200</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>119048</sizeVertCX><sizeVertCY>203252</sizeVertCY></Rect></Wnd3></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>\r
+    <Top><Row0><Sizes><Toolbar-00D672A8><key>iaridepm.enu1</key></Toolbar-00D672A8></Sizes></Row0><Row1><Sizes><Toolbar-07472A10><key>debuggergui.enu1</key></Toolbar-07472A10></Sizes></Row1></Top><Left><Row0><Sizes><Wnd1><Rect><Top>-2</Top><Left>-2</Left><Bottom>718</Bottom><Right>302</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>180952</sizeVertCX><sizeVertCY>731707</sizeVertCY></Rect></Wnd1></Sizes></Row0></Left><Right><Row0><Sizes><Wnd2><Rect><Top>-2</Top><Left>-2</Left><Bottom>718</Bottom><Right>699</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>417262</sizeVertCX><sizeVertCY>731707</sizeVertCY></Rect></Wnd2></Sizes></Row0></Right><Bottom><Row0><Sizes><Wnd0><Rect><Top>-2</Top><Left>-2</Left><Bottom>198</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>200</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>119048</sizeVertCX><sizeVertCY>203252</sizeVertCY></Rect></Wnd0></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>\r
   </Desktop>\r
 </Project>\r
 \r
index c22cb97f8c45a36d9846202a25c71a250d669240..4f7098e1e53ae6d87c99d3d79dbeb01f1db222d5 100644 (file)
@@ -14,7 +14,7 @@ Watch0=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0
 Watch1=_ 0 "" 0 "" 0 "" 0 "" 0 0 0 0\r
 CStepIntDis=_ 0\r
 [DebugChecksum]\r
-Checksum=-1045357403\r
+Checksum=72368941\r
 [Jet]\r
 JetConnSerialNo=73866\r
 JetConnFoundProbes=\r
@@ -109,7 +109,8 @@ Exclusions=
 [Disassemble mode]\r
 mode=0\r
 [Breakpoints2]\r
-Count=0\r
+Bp0=_ 1 "EMUL_CODE" "{$PROJ_DIR$\..\Source\main.c}.136.2" 0 0 1 "" 0 "" 0\r
+Count=1\r
 [Aliases]\r
 Count=0\r
 SuppressDialog=0\r
index f5a6e5bd5417ccdf6b2aef2a6fa18bcb1200b60a..1757579d8989116ad9dcc4a6ccdefb1e23fee1fa 100644 (file)
@@ -38,7 +38,7 @@
             <Factory>Workspace</Factory>\r
             <Session>\r
               \r
-            <NodeDict><ExpandedNode>RTOSDemo</ExpandedNode><ExpandedNode>RTOSDemo/Blinky-Demo</ExpandedNode></NodeDict></Session>\r
+            <NodeDict><ExpandedNode>RTOSDemo</ExpandedNode></NodeDict></Session>\r
           </Tab>\r
         </Tabs>\r
         \r
           </Tab>\r
         <Tab><Identity>TabID-959-438</Identity><TabName>Ambiguous Definitions</TabName><Factory>Select-Ambiguous-Definitions</Factory><Session/></Tab><Tab><Identity>TabID-21579-10611</Identity><TabName>Find All Declarations</TabName><Factory>Find-All-Declarations</Factory><Session/></Tab></Tabs>\r
         \r
-      <SelectedTab>1</SelectedTab></Wnd3></Windows>\r
+      <SelectedTab>3</SelectedTab></Wnd3></Windows>\r
     <Editor>\r
       \r
       \r
       \r
       \r
-    <Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\Full-Demo\main_full.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>64</YPos2><SelStart2>8123</SelStart2><SelEnd2>8123</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\Blinky-Demo\main_blinky.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>64</YPos2><SelStart2>0</SelStart2><SelEnd2>0</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>112</YPos2><SelStart2>0</SelStart2><SelEnd2>0</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\cstartup.s</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>132</YPos2><SelStart2>5456</SelStart2><SelEnd2>5456</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\LowLevelInitialise.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>14</YPos2><SelStart2>1341</SelStart2><SelEnd2>1341</SelEnd2></Tab><ActiveTab>4</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\modules\armv7a_cp15_drv.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>727</YPos2><SelStart2>20604</SelStart2><SelEnd2>20604</SelEnd2></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>\r
+    <Pane><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\Blinky-Demo\main_blinky.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>64</YPos2><SelStart2>0</SelStart2><SelEnd2>0</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\main.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>122</YPos2><SelStart2>6348</SelStart2><SelEnd2>6348</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\cstartup.s</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>120</YPos2><SelStart2>3672</SelStart2><SelEnd2>3672</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\LowLevelInitialise.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>23</YPos2><SelStart2>1067</SelStart2><SelEnd2>1082</SelEnd2></Tab><ActiveTab>3</ActiveTab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\modules\armv7a_cp15_drv.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>283</YPos2><SelStart2>8523</SelStart2><SelEnd2>8523</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\LEDs.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>64</YPos2><SelStart2>4247</SelStart2><SelEnd2>4247</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\RenesasFiles\board_settings\siochar.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>63</YPos2><SelStart2>4669</SelStart2><SelEnd2>4669</SelEnd2></Tab><Tab><Factory>TextEditor</Factory><Filename>$WS_DIR$\..\Source\Full-Demo\main_full.c</Filename><XPos>0</XPos><YPos>0</YPos><SelStart>0</SelStart><SelEnd>0</SelEnd><XPos2>0</XPos2><YPos2>340</YPos2><SelStart2>17554</SelStart2><SelEnd2>17554</SelEnd2></Tab></Pane><ActivePane>0</ActivePane><Sizes><Pane><X>1000000</X><Y>1000000</Y></Pane></Sizes><SplitMode>1</SplitMode></Editor>\r
     <Positions>\r
       \r
       \r
       \r
       \r
       \r
-    <Top><Row0><Sizes><Toolbar-00D172A8><key>iaridepm.enu1</key></Toolbar-00D172A8></Sizes></Row0><Row1><Sizes/></Row1></Top><Left><Row0><Sizes><Wnd2><Rect><Top>-2</Top><Left>-2</Left><Bottom>693</Bottom><Right>380</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>227381</sizeVertCX><sizeVertCY>706301</sizeVertCY></Rect></Wnd2></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd3><Rect><Top>-2</Top><Left>-2</Left><Bottom>247</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>249</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>253049</sizeHorzCY><sizeVertCX>119048</sizeVertCX><sizeVertCY>203252</sizeVertCY></Rect></Wnd3></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>\r
+    <Top><Row0><Sizes><Toolbar-00D672A8><key>iaridepm.enu1</key></Toolbar-00D672A8></Sizes></Row0><Row1><Sizes/></Row1></Top><Left><Row0><Sizes><Wnd2><Rect><Top>-2</Top><Left>-2</Left><Bottom>693</Bottom><Right>380</Right><x>-2</x><y>-2</y><xscreen>200</xscreen><yscreen>200</yscreen><sizeHorzCX>119048</sizeHorzCX><sizeHorzCY>203252</sizeHorzCY><sizeVertCX>227381</sizeVertCX><sizeVertCY>706301</sizeVertCY></Rect></Wnd2></Sizes></Row0></Left><Right><Row0><Sizes/></Row0></Right><Bottom><Row0><Sizes><Wnd3><Rect><Top>-2</Top><Left>-2</Left><Bottom>247</Bottom><Right>1682</Right><x>-2</x><y>-2</y><xscreen>1684</xscreen><yscreen>249</yscreen><sizeHorzCX>1002381</sizeHorzCX><sizeHorzCY>253049</sizeHorzCY><sizeVertCX>119048</sizeVertCX><sizeVertCY>203252</sizeVertCY></Rect></Wnd3></Sizes></Row0></Bottom><Float><Sizes/></Float></Positions>\r
   </Desktop>\r
 </Workspace>\r
 \r
index f2ad135f456c55a7dc55cee8c782c2c8d9e4734a..e72f99e07a5dbf3d7453108ab8bd0f541b39d0ea 100644 (file)
Binary files a/FreeRTOS/Demo/CORTEX_M4_ATSAM4S_Atmel_Studio/RTOSDemo.atsuo and b/FreeRTOS/Demo/CORTEX_M4_ATSAM4S_Atmel_Studio/RTOSDemo.atsuo differ
index 310047a2b62070ce0e3239574d4391b83419d5e6..9736731788e102824ba54b5a3e7f38b0a3290372 100644 (file)
 /* A block time of 0 means 'don't block'. */\r
 #define intsemNO_BLOCK                         0\r
 \r
+/* The maximum count value for the counting semaphore given from an\r
+interrupt. */\r
+#define intsemMAX_COUNT                                3\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /*\r
 static void vInterruptMutexSlaveTask( void *pvParameters );\r
 static void vInterruptMutexMasterTask( void *pvParameters );\r
 \r
+/*\r
+ * A test whereby the master takes the shared and interrupt mutexes in that\r
+ * order, then gives them back in the same order, ensuring the priority\r
+ * inheritance is behaving as expected at each step.\r
+ */\r
+static void prvTakeAndGiveInTheSameOrder( void );\r
+\r
+/*\r
+ * A test whereby the master takes the shared and interrupt mutexes in that\r
+ * order, then gives them back in the opposite order to which they were taken,\r
+ * ensuring the priority inheritance is behaving as expected at each step.\r
+ */\r
+static void prvTakeAndGiveInTheOppositeOrder( void );\r
+\r
+/*\r
+ * A simple task that interacts with an interrupt using a counting semaphore,\r
+ * primarily for code coverage purposes.\r
+ */\r
+static void vInterruptCountingSemaphoreTask( void *pvParameters );\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 /* Flag that will be latched to pdTRUE should any unexpected behaviour be\r
@@ -114,7 +138,7 @@ static volatile BaseType_t xErrorDetected = pdFALSE;
 \r
 /* Counters that are incremented on each cycle of a test.  This is used to\r
 detect a stalled task - a test that is no longer running. */\r
-static volatile uint32_t ulMasterLoops = 0;\r
+static volatile uint32_t ulMasterLoops = 0, ulCountingSemaphoreLoops = 0;\r
 \r
 /* Handles of the test tasks that must be accessed from other test tasks. */\r
 static TaskHandle_t xSlaveHandle;\r
@@ -124,6 +148,9 @@ not be used given in interrupts (and definitely never taken in an interrupt)
 there are some circumstances when it may be desirable. */\r
 static SemaphoreHandle_t xISRMutex = NULL;\r
 \r
+/* A counting semaphore which is given from an interrupt. */\r
+static SemaphoreHandle_t xISRCountingSemaphore = NULL;\r
+\r
 /* A mutex which is shared between the master and slave tasks - the master\r
 does both sharing of this mutex with the slave and receiving a mutex from the\r
 interrupt. */\r
@@ -132,15 +159,20 @@ static SemaphoreHandle_t xMasterSlaveMutex = NULL;
 /* Flag that allows the master task to control when the interrupt gives or does\r
 not give the mutex.  There is no mutual exclusion on this variable, but this is\r
 only test code and it should be fine in the 32=bit test environment. */\r
-static BaseType_t xOkToGiveMutex = pdFALSE;\r
+static BaseType_t xOkToGiveMutex = pdFALSE, xOkToGiveCountingSemaphore = pdFALSE;\r
+\r
+/* Used to coordinate timing between tasks and the interrupt. */\r
+const TickType_t xInterruptGivePeriod = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
 void vStartInterruptSemaphoreTasks( void )\r
 {\r
-       /* Create the mutex that is given from an interrupt. */\r
+       /* Create the semaphores that are given from an interrupt. */\r
        xISRMutex = xSemaphoreCreateMutex();\r
        configASSERT( xISRMutex );\r
+       xISRCountingSemaphore = xSemaphoreCreateCounting( intsemMAX_COUNT, 0 );\r
+       configASSERT( xISRCountingSemaphore );\r
 \r
        /* Create the mutex that is shared between the master and slave tasks (the\r
        master receives a mutex from an interrupt and shares a mutex with the\r
@@ -151,168 +183,226 @@ void vStartInterruptSemaphoreTasks( void )
        /* Create the tasks that share mutexes between then and with interrupts. */\r
        xTaskCreate( vInterruptMutexSlaveTask, "IntMuS", configMINIMAL_STACK_SIZE, NULL, intsemSLAVE_PRIORITY, &xSlaveHandle );\r
        xTaskCreate( vInterruptMutexMasterTask, "IntMuM", configMINIMAL_STACK_SIZE, NULL, intsemMASTER_PRIORITY, NULL );\r
+\r
+       /* Create the task that blocks on the counting semaphore. */\r
+       xTaskCreate( vInterruptCountingSemaphoreTask, "IntCnt", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 static void vInterruptMutexMasterTask( void *pvParameters )\r
 {\r
-const TickType_t xInterruptGivePeriod = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );\r
-\r
        /* Just to avoid compiler warnings. */\r
        ( void ) pvParameters;\r
 \r
        for( ;; )\r
        {\r
-               /* Ensure the slave is suspended, and that this task is running at the\r
-               lower priority as expected as the start conditions. */\r
-               #if( INCLUDE_eTaskGetState == 1 )\r
-               {\r
-                       configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );\r
-               }\r
-               #endif /* INCLUDE_eTaskGetState */\r
+               prvTakeAndGiveInTheSameOrder();\r
 \r
-               if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )\r
-               {\r
-                       xErrorDetected = pdTRUE;\r
-               }\r
+               /* Ensure not to starve out other tests. */\r
+               ulMasterLoops++;\r
+               vTaskDelay( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );\r
 \r
-               /* Take the semaphore that is shared with the slave. */\r
-               if( xSemaphoreTake( xMasterSlaveMutex, intsemNO_BLOCK ) != pdPASS )\r
-               {\r
-                       xErrorDetected = pdTRUE;\r
-               }\r
+               prvTakeAndGiveInTheOppositeOrder();\r
 \r
-               /* This task now has the mutex.  Unsuspend the slave so it too\r
-               attempts to take the mutex. */\r
-               vTaskResume( xSlaveHandle );\r
+               /* Ensure not to starve out other tests. */\r
+               ulMasterLoops++;\r
+               vTaskDelay( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
 \r
-               /* The slave has the higher priority so should now have executed and\r
-               blocked on the semaphore. */\r
-               #if( INCLUDE_eTaskGetState == 1 )\r
-               {\r
-                       configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );\r
-               }\r
-               #endif /* INCLUDE_eTaskGetState */\r
+static void prvTakeAndGiveInTheSameOrder( void )\r
+{\r
+       /* Ensure the slave is suspended, and that this task is running at the\r
+       lower priority as expected as the start conditions. */\r
+       #if( INCLUDE_eTaskGetState == 1 )\r
+       {\r
+               configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );\r
+       }\r
+       #endif /* INCLUDE_eTaskGetState */\r
 \r
-               /* This task should now have inherited the priority of the slave\r
-               task. */\r
-               if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
-               {\r
-                       xErrorDetected = pdTRUE;\r
-               }\r
+       if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
 \r
-               /* Now wait a little longer than the time between ISR gives to also\r
-               obtain the ISR mutex. */\r
-               xOkToGiveMutex = pdTRUE;\r
-               if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )\r
-               {\r
-                       xErrorDetected = pdTRUE;\r
-               }\r
-               xOkToGiveMutex = pdFALSE;\r
+       /* Take the semaphore that is shared with the slave. */\r
+       if( xSemaphoreTake( xMasterSlaveMutex, intsemNO_BLOCK ) != pdPASS )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
 \r
-               /* Attempting to take again immediately should fail as the mutex is\r
-               already held. */\r
-               if( xSemaphoreTake( xISRMutex, intsemNO_BLOCK ) != pdFAIL )\r
-               {\r
-                       xErrorDetected = pdTRUE;\r
-               }\r
+       /* This task now has the mutex.  Unsuspend the slave so it too\r
+       attempts to take the mutex. */\r
+       vTaskResume( xSlaveHandle );\r
 \r
-               /* Should still be at the priority of the slave task. */\r
-               if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
-               {\r
-                       xErrorDetected = pdTRUE;\r
-               }\r
+       /* The slave has the higher priority so should now have executed and\r
+       blocked on the semaphore. */\r
+       #if( INCLUDE_eTaskGetState == 1 )\r
+       {\r
+               configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );\r
+       }\r
+       #endif /* INCLUDE_eTaskGetState */\r
 \r
-               /* Give back the ISR semaphore to ensure the priority is not\r
-               disinherited as the shared mutex (which the higher priority task is\r
-               attempting to obtain) is still held. */\r
-               if( xSemaphoreGive( xISRMutex ) != pdPASS )\r
-               {\r
-                       xErrorDetected = pdTRUE;\r
-               }\r
+       /* This task should now have inherited the priority of the slave\r
+       task. */\r
+       if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
 \r
-               if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
-               {\r
-                       xErrorDetected = pdTRUE;\r
-               }\r
+       /* Now wait a little longer than the time between ISR gives to also\r
+       obtain the ISR mutex. */\r
+       xOkToGiveMutex = pdTRUE;\r
+       if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
+       xOkToGiveMutex = pdFALSE;\r
 \r
-               /* Finally give back the shared mutex.  This time the higher priority\r
-               task should run before this task runs again - so this task should have\r
-               disinherited the priority and the higher priority task should be in the\r
-               suspended state again. */\r
-               if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )\r
-               {\r
-                       xErrorDetected = pdTRUE;\r
-               }\r
+       /* Attempting to take again immediately should fail as the mutex is\r
+       already held. */\r
+       if( xSemaphoreTake( xISRMutex, intsemNO_BLOCK ) != pdFAIL )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
 \r
-               if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )\r
-               {\r
-                       xErrorDetected = pdTRUE;\r
-               }\r
+       /* Should still be at the priority of the slave task. */\r
+       if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
 \r
-               #if( INCLUDE_eTaskGetState == 1 )\r
-               {\r
-                       configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );\r
-               }\r
-               #endif /* INCLUDE_eTaskGetState */\r
+       /* Give back the ISR semaphore to ensure the priority is not\r
+       disinherited as the shared mutex (which the higher priority task is\r
+       attempting to obtain) is still held. */\r
+       if( xSemaphoreGive( xISRMutex ) != pdPASS )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
 \r
-               /* Ensure not to starve out other tests. */\r
-               ulMasterLoops++;\r
-               vTaskDelay( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );\r
+       if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
 \r
+       /* Finally give back the shared mutex.  This time the higher priority\r
+       task should run before this task runs again - so this task should have\r
+       disinherited the priority and the higher priority task should be in the\r
+       suspended state again. */\r
+       if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
 \r
-               /* Repeat exactly up to the point where the mutexes are given back.\r
-               This time the shared mutex is given back first. */\r
-               if( xSemaphoreTake( xMasterSlaveMutex, intsemNO_BLOCK ) != pdPASS )\r
-               {\r
-                       xErrorDetected = pdTRUE;\r
-               }\r
+       if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
 \r
-               vTaskResume( xSlaveHandle );\r
+       #if( INCLUDE_eTaskGetState == 1 )\r
+       {\r
+               configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );\r
+       }\r
+       #endif /* INCLUDE_eTaskGetState */\r
 \r
-               #if( INCLUDE_eTaskGetState == 1 )\r
-               {\r
-                       configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );\r
-               }\r
-               #endif /* INCLUDE_eTaskGetState */\r
+       /* Reset the mutex ready for the next round. */\r
+       xQueueReset( xISRMutex );\r
+}\r
+/*-----------------------------------------------------------*/\r
 \r
-               if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
-               {\r
-                       xErrorDetected = pdTRUE;\r
-               }\r
+static void prvTakeAndGiveInTheOppositeOrder( void )\r
+{\r
+       /* Ensure the slave is suspended, and that this task is running at the\r
+       lower priority as expected as the start conditions. */\r
+       #if( INCLUDE_eTaskGetState == 1 )\r
+       {\r
+               configASSERT( eTaskGetState( xSlaveHandle ) == eSuspended );\r
+       }\r
+       #endif /* INCLUDE_eTaskGetState */\r
 \r
-               xOkToGiveMutex = pdTRUE;\r
-               if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )\r
-               {\r
-                       xErrorDetected = pdTRUE;\r
-               }\r
-               xOkToGiveMutex = pdFALSE;\r
+       if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
 \r
-               if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
-               {\r
-                       xErrorDetected = pdTRUE;\r
-               }\r
+       /* Take the semaphore that is shared with the slave. */\r
+       if( xSemaphoreTake( xMasterSlaveMutex, intsemNO_BLOCK ) != pdPASS )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
 \r
-               /* This is where the differences start as this time the shared mutex is\r
-               given back first.  This time to the higher priority task should run\r
-               before this task gets to the point of releasing the interrupt mutex - so\r
-               this task should have disinherited the priority and the higher priority\r
-               task should be in the suspended state again. */\r
-               if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )\r
-               {\r
-                       xErrorDetected = pdTRUE;\r
-               }\r
+       /* This task now has the mutex.  Unsuspend the slave so it too\r
+       attempts to take the mutex. */\r
+       vTaskResume( xSlaveHandle );\r
 \r
-               /* Give back the interrupt semaphore too, so the mutex held count goes\r
-               back to 0.  The mutex will then have to be reset so the ISR can give it\r
-               in the next cycle. */\r
-               xSemaphoreGive( xISRMutex );\r
-               xQueueReset( ( QueueHandle_t ) xISRMutex );\r
+       /* The slave has the higher priority so should now have executed and\r
+       blocked on the semaphore. */\r
+       #if( INCLUDE_eTaskGetState == 1 )\r
+       {\r
+               configASSERT( eTaskGetState( xSlaveHandle ) == eBlocked );\r
+       }\r
+       #endif /* INCLUDE_eTaskGetState */\r
 \r
-               /* Ensure not to starve out other tests. */\r
-               ulMasterLoops++;\r
-               vTaskDelay( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS );\r
+       /* This task should now have inherited the priority of the slave\r
+       task. */\r
+       if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
+\r
+       /* Now wait a little longer than the time between ISR gives to also\r
+       obtain the ISR mutex. */\r
+       xOkToGiveMutex = pdTRUE;\r
+       if( xSemaphoreTake( xISRMutex, ( xInterruptGivePeriod * 2 ) ) != pdPASS )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
+       xOkToGiveMutex = pdFALSE;\r
+\r
+       /* Attempting to take again immediately should fail as the mutex is\r
+       already held. */\r
+       if( xSemaphoreTake( xISRMutex, intsemNO_BLOCK ) != pdFAIL )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
+\r
+       /* Should still be at the priority of the slave task. */\r
+       if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
+\r
+       /* Give back the shared semaphore to ensure the priority is not disinherited\r
+       as the ISR mutex is still held.  The higher priority slave task should run\r
+       before this task runs again. */\r
+       if( xSemaphoreGive( xMasterSlaveMutex ) != pdPASS )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
+\r
+       /* Should still be at the priority of the slave task as this task still\r
+       holds one semaphore (this is a simplification in the priority inheritance\r
+       mechanism. */\r
+       if( uxTaskPriorityGet( NULL ) != intsemSLAVE_PRIORITY )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
        }\r
+\r
+       /* Give back the ISR semaphore, which should result in the priority being\r
+       disinherited as it was the last mutex held. */\r
+       if( xSemaphoreGive( xISRMutex ) != pdPASS )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
+\r
+       if( uxTaskPriorityGet( NULL ) != intsemMASTER_PRIORITY )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
+\r
+       /* Reset the mutex ready for the next round. */\r
+       xQueueReset( xISRMutex );\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -343,9 +433,76 @@ static void vInterruptMutexSlaveTask( void *pvParameters )
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+static void vInterruptCountingSemaphoreTask( void *pvParameters )\r
+{\r
+BaseType_t xCount;\r
+const TickType_t xDelay = pdMS_TO_TICKS( intsemINTERRUPT_MUTEX_GIVE_PERIOD_MS ) * ( intsemMAX_COUNT + 1 );\r
+\r
+       ( void ) pvParameters;\r
+\r
+       for( ;; )\r
+       {\r
+               /* Expect to start with the counting semaphore empty. */\r
+               if( uxQueueMessagesWaiting( ( QueueHandle_t ) xISRCountingSemaphore ) != 0 )\r
+               {\r
+                       xErrorDetected = pdTRUE;\r
+               }\r
+\r
+               /* Wait until it is expected that the interrupt will have filled the\r
+               counting semaphore. */\r
+               xOkToGiveCountingSemaphore = pdTRUE;\r
+               vTaskDelay( xDelay );\r
+               xOkToGiveCountingSemaphore = pdFALSE;\r
+\r
+               /* Now it is expected that the counting semaphore is full. */\r
+               if( uxQueueMessagesWaiting( ( QueueHandle_t ) xISRCountingSemaphore ) != intsemMAX_COUNT )\r
+               {\r
+                       xErrorDetected = pdTRUE;\r
+               }\r
+\r
+               if( uxQueueSpacesAvailable( ( QueueHandle_t ) xISRCountingSemaphore ) != 0 )\r
+               {\r
+                       xErrorDetected = pdTRUE;\r
+               }\r
+\r
+               ulCountingSemaphoreLoops++;\r
+\r
+               /* Expect to be able to take the counting semaphore intsemMAX_COUNT\r
+               times.  A block time of 0 is used as the semaphore should already be\r
+               there. */\r
+               xCount = 0;\r
+               while( xSemaphoreTake( xISRCountingSemaphore, 0 ) == pdPASS )\r
+               {\r
+                       xCount++;\r
+               }\r
+\r
+               if( xCount != intsemMAX_COUNT )\r
+               {\r
+                       xErrorDetected = pdTRUE;\r
+               }\r
+\r
+               /* Now raise the priority of this task so it runs immediately that the\r
+               semaphore is given from the interrupt. */\r
+               vTaskPrioritySet( NULL, configMAX_PRIORITIES - 1 );\r
+\r
+               /* Block to wait for the semaphore to be given from the interrupt. */\r
+               xOkToGiveCountingSemaphore = pdTRUE;\r
+               xSemaphoreTake( xISRCountingSemaphore, portMAX_DELAY );\r
+               xSemaphoreTake( xISRCountingSemaphore, portMAX_DELAY );\r
+               xOkToGiveCountingSemaphore = pdFALSE;\r
+\r
+               /* Reset the priority so as not to disturbe other tests too much. */\r
+               vTaskPrioritySet( NULL, tskIDLE_PRIORITY );\r
+\r
+               ulCountingSemaphoreLoops++;\r
+       }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
 void vInterruptSemaphorePeriodicTest( void )\r
 {\r
 static TickType_t xLastGiveTime = 0;\r
+BaseType_t xHigherPriorityTaskWoken = pdFALSE;\r
 TickType_t xTimeNow;\r
 \r
        /* No mutual exclusion on xOkToGiveMutex, but this is only test code (and\r
@@ -356,20 +513,30 @@ TickType_t xTimeNow;
                configASSERT( xISRMutex );\r
                if( xOkToGiveMutex != pdFALSE )\r
                {\r
+                       /* Null is used as the second parameter in this give, and non-NULL\r
+                       in the other gives for code coverage reasons. */\r
                        xSemaphoreGiveFromISR( xISRMutex, NULL );\r
 \r
                        /* Second give attempt should fail. */\r
-                       configASSERT( xSemaphoreGiveFromISR( xISRMutex, NULL ) == pdFAIL );\r
+                       configASSERT( xSemaphoreGiveFromISR( xISRMutex, &xHigherPriorityTaskWoken ) == pdFAIL );\r
+               }\r
+\r
+               if( xOkToGiveCountingSemaphore != pdFALSE )\r
+               {\r
+                       xSemaphoreGiveFromISR( xISRCountingSemaphore, &xHigherPriorityTaskWoken );\r
                }\r
                xLastGiveTime = xTimeNow;\r
        }\r
+\r
+       /* Remove compiler warnings about the value being set but not used. */\r
+       ( void ) xHigherPriorityTaskWoken;\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
 /* This is called to check that all the created tasks are still running. */\r
 BaseType_t xAreInterruptSemaphoreTasksStillRunning( void )\r
 {\r
-static uint32_t ulLastMasterLoopCounter = 0;\r
+static uint32_t ulLastMasterLoopCounter = 0, ulLastCountingSemaphoreLoops = 0;\r
 \r
        /* If the demo tasks are running then it is expected that the loop counters\r
        will have changed since this function was last called. */\r
@@ -380,6 +547,13 @@ static uint32_t ulLastMasterLoopCounter = 0;
 \r
        ulLastMasterLoopCounter = ulMasterLoops;\r
 \r
+       if( ulLastCountingSemaphoreLoops == ulCountingSemaphoreLoops )\r
+       {\r
+               xErrorDetected = pdTRUE;\r
+       }\r
+\r
+       ulLastCountingSemaphoreLoops = ulCountingSemaphoreLoops++;\r
+\r
        /* Errors detected in the task itself will have latched xErrorDetected\r
        to true. */\r
 \r
index b4553b31043eabe972158e5857c2f3aa0ce81d5e..b62f1853a4aafea8dd2b374478b964729c57369b 100644 (file)
@@ -1269,7 +1269,8 @@ uint32_t ulVarToSend, ulValReceived;
  *\r
  * It is preferred that the macros xQueueSendFromISR(),\r
  * xQueueSendToFrontFromISR() and xQueueSendToBackFromISR() be used in place\r
- * of calling this function directly.\r
+ * of calling this function directly.  xQueueGenericGiveFromISR() is an\r
+ * equivalent for use by semaphores that don't actually copy any data.\r
  *\r
  * Post an item on a queue.  It is safe to use this function from within an\r
  * interrupt service routine.\r
@@ -1333,6 +1334,7 @@ uint32_t ulVarToSend, ulValReceived;
  * \ingroup QueueManagement\r
  */\r
 BaseType_t xQueueGenericSendFromISR( QueueHandle_t xQueue, const void * const pvItemToQueue, BaseType_t * const pxHigherPriorityTaskWoken, const BaseType_t xCopyPosition ) PRIVILEGED_FUNCTION;\r
+BaseType_t xQueueGenericGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION;\r
 \r
 /**\r
  * queue. h\r
index 96d483c6e142d965838241f293f380c2cfbf26b2..612aaaf7559ed9867605d4701621ec46c50760f5 100644 (file)
@@ -605,7 +605,7 @@ typedef QueueHandle_t SemaphoreHandle_t;
  * \defgroup xSemaphoreGiveFromISR xSemaphoreGiveFromISR\r
  * \ingroup Semaphores\r
  */\r
-#define xSemaphoreGiveFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( QueueHandle_t ) ( xSemaphore ), NULL, ( pxHigherPriorityTaskWoken ), queueSEND_TO_BACK )\r
+#define xSemaphoreGiveFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueGenericGiveFromISR( ( QueueHandle_t ) ( xSemaphore ), ( pxHigherPriorityTaskWoken ) )\r
 \r
 /**\r
  * semphr. h\r
index 12a79f93cedff2defc56bf1af269151015c564db..2bdbdcf2b53aca1060324a8bbac46417a66ce5c4 100644 (file)
@@ -1074,20 +1074,166 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                {\r
                        traceQUEUE_SEND_FROM_ISR( pxQueue );\r
 \r
-                       if( prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition ) != pdFALSE )\r
+                       /* A task can only have an inherited priority if it is a mutex\r
+                       holder - and if there is a mutex holder then the mutex cannot be\r
+                       given from an ISR.  Therefore, unlike the xQueueGenericGive()\r
+                       function, there is no need to determine the need for priority\r
+                       disinheritance here or to clear the mutex holder TCB member. */\r
+                       ( void ) prvCopyDataToQueue( pxQueue, pvItemToQueue, xCopyPosition );\r
+\r
+                       /* The event list is not altered if the queue is locked.  This will\r
+                       be done when the queue is unlocked later. */\r
+                       if( pxQueue->xTxLock == queueUNLOCKED )\r
                        {\r
-                               /* This is a special case that can only be executed if a task\r
-                               holds multiple mutexes and then gives the mutexes back in an\r
-                               order that is different to that in which they were taken. */\r
-                               if( pxHigherPriorityTaskWoken != NULL )\r
+                               #if ( configUSE_QUEUE_SETS == 1 )\r
                                {\r
-                                       *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                       if( pxQueue->pxQueueSetContainer != NULL )\r
+                                       {\r
+                                               if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE )\r
+                                               {\r
+                                                       /* The queue is a member of a queue set, and posting\r
+                                                       to the queue set caused a higher priority task to\r
+                                                       unblock.  A context switch is required. */\r
+                                                       if( pxHigherPriorityTaskWoken != NULL )\r
+                                                       {\r
+                                                               *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               mtCOVERAGE_TEST_MARKER();\r
+                                                       }\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       mtCOVERAGE_TEST_MARKER();\r
+                                               }\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+                                               {\r
+                                                       if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+                                                       {\r
+                                                               /* The task waiting has a higher priority so\r
+                                                               record that a context switch is required. */\r
+                                                               if( pxHigherPriorityTaskWoken != NULL )\r
+                                                               {\r
+                                                                       *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       mtCOVERAGE_TEST_MARKER();\r
+                                                               }\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               mtCOVERAGE_TEST_MARKER();\r
+                                                       }\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       mtCOVERAGE_TEST_MARKER();\r
+                                               }\r
+                                       }\r
                                }\r
-                               else\r
+                               #else /* configUSE_QUEUE_SETS */\r
                                {\r
-                                       mtCOVERAGE_TEST_MARKER();\r
+                                       if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )\r
+                                       {\r
+                                               if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE )\r
+                                               {\r
+                                                       /* The task waiting has a higher priority so record that a\r
+                                                       context switch is required. */\r
+                                                       if( pxHigherPriorityTaskWoken != NULL )\r
+                                                       {\r
+                                                               *pxHigherPriorityTaskWoken = pdTRUE;\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               mtCOVERAGE_TEST_MARKER();\r
+                                                       }\r
+                                               }\r
+                                               else\r
+                                               {\r
+                                                       mtCOVERAGE_TEST_MARKER();\r
+                                               }\r
+                                       }\r
+                                       else\r
+                                       {\r
+                                               mtCOVERAGE_TEST_MARKER();\r
+                                       }\r
                                }\r
+                               #endif /* configUSE_QUEUE_SETS */\r
                        }\r
+                       else\r
+                       {\r
+                               /* Increment the lock count so the task that unlocks the queue\r
+                               knows that data was posted while it was locked. */\r
+                               ++( pxQueue->xTxLock );\r
+                       }\r
+\r
+                       xReturn = pdPASS;\r
+               }\r
+               else\r
+               {\r
+                       traceQUEUE_SEND_FROM_ISR_FAILED( pxQueue );\r
+                       xReturn = errQUEUE_FULL;\r
+               }\r
+       }\r
+       portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+\r
+       return xReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+BaseType_t xQueueGenericGiveFromISR( QueueHandle_t xQueue, BaseType_t * const pxHigherPriorityTaskWoken )\r
+{\r
+BaseType_t xReturn;\r
+UBaseType_t uxSavedInterruptStatus;\r
+Queue_t * const pxQueue = ( Queue_t * ) xQueue;\r
+\r
+       configASSERT( pxQueue );\r
+\r
+       /* xQueueGenericSendFromISR() should be used in the item size is not 0. */\r
+       configASSERT( pxQueue->uxItemSize == 0 );\r
+\r
+       /* RTOS ports that support interrupt nesting have the concept of a maximum\r
+       system call (or maximum API call) interrupt priority.  Interrupts that are\r
+       above the maximum system call priority are kept permanently enabled, even\r
+       when the RTOS kernel is in a critical section, but cannot make any calls to\r
+       FreeRTOS API functions.  If configASSERT() is defined in FreeRTOSConfig.h\r
+       then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion\r
+       failure if a FreeRTOS API function is called from an interrupt that has been\r
+       assigned a priority above the configured maximum system call priority.\r
+       Only FreeRTOS functions that end in FromISR can be called from interrupts\r
+       that have been assigned a priority at or (logically) below the maximum\r
+       system call     interrupt priority.  FreeRTOS maintains a separate interrupt\r
+       safe API to ensure interrupt entry is as fast and as simple as possible.\r
+       More information (albeit Cortex-M specific) is provided on the following\r
+       link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */\r
+       portASSERT_IF_INTERRUPT_PRIORITY_INVALID();\r
+\r
+       /* Similar to xQueueGenericSendFromISR() but used with semaphores where the\r
+       item size is 0.  Don't directly wake a task that was blocked on a queue\r
+       read, instead return a flag to say whether a context switch is required or\r
+       not (i.e. has a task with a higher priority than us been woken by this\r
+       post). */\r
+       uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR();\r
+       {\r
+               /* When the queue is used to implement a semaphore no data is ever\r
+               moved through the queue but it is still valid to see if the queue 'has\r
+               space'. */\r
+               if( pxQueue->uxMessagesWaiting < pxQueue->uxLength )\r
+               {\r
+                       traceQUEUE_SEND_FROM_ISR( pxQueue );\r
+\r
+                       /* A task can only have an inherited priority if it is a mutex\r
+                       holder - and if there is a mutex holder then the mutex cannot be\r
+                       given from an ISR.  Therefore, unlike the xQueueGenericGive()\r
+                       function, there is no need to determine the need for priority\r
+                       disinheritance here or to clear the mutex holder TCB member. */\r
+\r
+                       ++( pxQueue->uxMessagesWaiting );\r
 \r
                        /* The event list is not altered if the queue is locked.  This will\r
                        be done when the queue is unlocked later. */\r
@@ -1097,11 +1243,11 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                                {\r
                                        if( pxQueue->pxQueueSetContainer != NULL )\r
                                        {\r
-                                               if( prvNotifyQueueSetContainer( pxQueue, xCopyPosition ) == pdTRUE )\r
+                                               if( prvNotifyQueueSetContainer( pxQueue, queueSEND_TO_BACK ) == pdTRUE )\r
                                                {\r
-                                                       /* The queue is a member of a queue set, and posting\r
-                                                       to the queue set caused a higher priority task to\r
-                                                       unblock.  A context switch is required. */\r
+                                                       /* The semaphore is a member of a queue set, and\r
+                                                       posting to the queue set caused a higher priority\r
+                                                       task to unblock.  A context switch is required. */\r
                                                        if( pxHigherPriorityTaskWoken != NULL )\r
                                                        {\r
                                                                *pxHigherPriorityTaskWoken = pdTRUE;\r
@@ -1188,7 +1334,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
                        xReturn = errQUEUE_FULL;\r
                }\r
        }\r
-       portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus );\r
+       portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedInterruptStatus ); //0.36\r
 \r
        return xReturn;\r
 }\r
index 010a05bafb4cceff39b8c76d2f3b2a720ee9489b..565b65c34449c65f07fb56793da6e9917bca9c48 100644 (file)
@@ -3254,8 +3254,11 @@ TCB_t *pxTCB;
                                /* Only disinherit if no other mutexes are held. */\r
                                if( pxTCB->uxMutexesHeld == ( UBaseType_t ) 0 )\r
                                {\r
-                                       /* The holding task must be the running task to be able to give\r
-                                       the mutex back.  Remove the holding task from the ready list. */\r
+                                       /* A task can only have an inhertied priority if it holds\r
+                                       the mutex.  If the mutex is held by a task then it cannot be\r
+                                       given from an interrupt, and if a mutex is given by the\r
+                                       holding task then it must be the running state task.  Remove\r
+                                       the     holding task from the ready     list. */\r
                                        if( uxListRemove( &( pxTCB->xGenericListItem ) ) == ( UBaseType_t ) 0 )\r
                                        {\r
                                                taskRESET_READY_PRIORITY( pxTCB->uxPriority );\r
@@ -3265,8 +3268,8 @@ TCB_t *pxTCB;
                                                mtCOVERAGE_TEST_MARKER();\r
                                        }\r
 \r
-                                       /* Disinherit the priority before adding the task into the new\r
-                                       ready list. */\r
+                                       /* Disinherit the priority before adding the task into the\r
+                                       new     ready list. */\r
                                        traceTASK_PRIORITY_DISINHERIT( pxTCB, pxTCB->uxBasePriority );\r
                                        pxTCB->uxPriority = pxTCB->uxBasePriority;\r
 \r
@@ -3279,7 +3282,11 @@ TCB_t *pxTCB;
                                        /* Return true to indicate that a context switch is required.\r
                                        This is only actually required in the corner case whereby\r
                                        multiple mutexes were held and the mutexes were given back\r
-                                       in an order different to that in which they were taken. */\r
+                                       in an order different to that in which they were taken.\r
+                                       If a context switch did not occur when the first mutex was\r
+                                       returned, even if a task was waiting on it, then a context\r
+                                       switch should occur when the last mutex is returned whether\r
+                                       a task is waiting on it or not. */\r
                                        xReturn = pdTRUE;\r
                                }\r
                                else\r