group__CMSIS__RTOS__MutexMgmt.html 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <title>Mutexes</title>
  7. <title>CMSIS-RTOS: Mutexes</title>
  8. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  9. <link href="cmsis.css" rel="stylesheet" type="text/css" />
  10. <script type="text/javascript" src="jquery.js"></script>
  11. <script type="text/javascript" src="dynsections.js"></script>
  12. <script type="text/javascript" src="printComponentTabs.js"></script>
  13. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  14. <script type="text/javascript" src="resize.js"></script>
  15. <script type="text/javascript" src="navtree.js"></script>
  16. <script type="text/javascript">
  17. $(document).ready(initResizable);
  18. $(window).load(resizeHeight);
  19. </script>
  20. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  21. <script type="text/javascript" src="search/search.js"></script>
  22. <script type="text/javascript">
  23. $(document).ready(function() { searchBox.OnSelectItem(0); });
  24. </script>
  25. </head>
  26. <body>
  27. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  28. <div id="titlearea">
  29. <table cellspacing="0" cellpadding="0">
  30. <tbody>
  31. <tr style="height: 46px;">
  32. <td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
  33. <td style="padding-left: 0.5em;">
  34. <div id="projectname">CMSIS-RTOS
  35. &#160;<span id="projectnumber">Version 1.03</span>
  36. </div>
  37. <div id="projectbrief">Real-Time Operating System: API and RTX Reference Implementation.</div>
  38. </td>
  39. </tr>
  40. </tbody>
  41. </table>
  42. </div>
  43. <!-- end header part -->
  44. <div id="CMSISnav" class="tabs1">
  45. <ul class="tablist">
  46. <script type="text/javascript">
  47. <!--
  48. writeComponentTabs.call(this);
  49. //-->
  50. </script>
  51. </ul>
  52. </div>
  53. <!-- Generated by Doxygen 1.8.6 -->
  54. <script type="text/javascript">
  55. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  56. </script>
  57. <div id="navrow1" class="tabs">
  58. <ul class="tablist">
  59. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  60. <li><a href="pages.html"><span>Usage&#160;and&#160;Description</span></a></li>
  61. <li><a href="modules.html"><span>Reference</span></a></li>
  62. <li>
  63. <div id="MSearchBox" class="MSearchBoxInactive">
  64. <span class="left">
  65. <img id="MSearchSelect" src="search/mag_sel.png"
  66. onmouseover="return searchBox.OnSearchSelectShow()"
  67. onmouseout="return searchBox.OnSearchSelectHide()"
  68. alt=""/>
  69. <input type="text" id="MSearchField" value="Search" accesskey="S"
  70. onfocus="searchBox.OnSearchFieldFocus(true)"
  71. onblur="searchBox.OnSearchFieldFocus(false)"
  72. onkeyup="searchBox.OnSearchFieldChange(event)"/>
  73. </span><span class="right">
  74. <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
  75. </span>
  76. </div>
  77. </li>
  78. </ul>
  79. </div>
  80. </div><!-- top -->
  81. <div id="side-nav" class="ui-resizable side-nav-resizable">
  82. <div id="nav-tree">
  83. <div id="nav-tree-contents">
  84. <div id="nav-sync" class="sync"></div>
  85. </div>
  86. </div>
  87. <div id="splitbar" style="-moz-user-select:none;"
  88. class="ui-resizable-handle">
  89. </div>
  90. </div>
  91. <script type="text/javascript">
  92. $(document).ready(function(){initNavTree('group__CMSIS__RTOS__MutexMgmt.html','');});
  93. </script>
  94. <div id="doc-content">
  95. <!-- window showing the filter options -->
  96. <div id="MSearchSelectWindow"
  97. onmouseover="return searchBox.OnSearchSelectShow()"
  98. onmouseout="return searchBox.OnSearchSelectHide()"
  99. onkeydown="return searchBox.OnSearchSelectKey(event)">
  100. <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Pages</a></div>
  101. <!-- iframe showing the search results (closed by default) -->
  102. <div id="MSearchResultsWindow">
  103. <iframe src="javascript:void(0)" frameborder="0"
  104. name="MSearchResults" id="MSearchResults">
  105. </iframe>
  106. </div>
  107. <div class="header">
  108. <div class="summary">
  109. <a href="#define-members">Macros</a> &#124;
  110. <a href="#func-members">Functions</a> </div>
  111. <div class="headertitle">
  112. <div class="title">Mutexes<div class="ingroups"><a class="el" href="group__CMSIS__RTOS__InterThread.html">Inter-Thread Communication and Resource Sharing</a></div></div> </div>
  113. </div><!--header-->
  114. <div class="contents">
  115. <p>Synchronize resource access using Mutual Exclusion (Mutex).
  116. <a href="#details">More...</a></p>
  117. <table class="memberdecls">
  118. <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="define-members"></a>
  119. Macros</h2></td></tr>
  120. <tr class="memitem:ga9b522438489d7c402c95332b58bc94f3"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga9b522438489d7c402c95332b58bc94f3">osMutexDef</a>(name)&#160;&#160;&#160;const <a class="el" href="cmsis__os_8h.html#structosMutexDef__t">osMutexDef_t</a> os_mutex_def_##name = { 0 }</td></tr>
  121. <tr class="memdesc:ga9b522438489d7c402c95332b58bc94f3"><td class="mdescLeft">&#160;</td><td class="mdescRight">Define a Mutex. <a href="#ga9b522438489d7c402c95332b58bc94f3">More...</a><br/></td></tr>
  122. <tr class="separator:ga9b522438489d7c402c95332b58bc94f3"><td class="memSeparator" colspan="2">&#160;</td></tr>
  123. <tr class="memitem:ga1122a86faa64b4a0880c76cf68d0c934"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga1122a86faa64b4a0880c76cf68d0c934">osMutex</a>(name)&#160;&#160;&#160;&amp;os_mutex_def_##name</td></tr>
  124. <tr class="memdesc:ga1122a86faa64b4a0880c76cf68d0c934"><td class="mdescLeft">&#160;</td><td class="mdescRight">Access a Mutex definition. <a href="#ga1122a86faa64b4a0880c76cf68d0c934">More...</a><br/></td></tr>
  125. <tr class="separator:ga1122a86faa64b4a0880c76cf68d0c934"><td class="memSeparator" colspan="2">&#160;</td></tr>
  126. </table><table class="memberdecls">
  127. <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
  128. Functions</h2></td></tr>
  129. <tr class="memitem:ga5c9de56e717016e39e788064e9a291cc"><td class="memItemLeft" align="right" valign="top"><a class="el" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga5c9de56e717016e39e788064e9a291cc">osMutexCreate</a> (const <a class="el" href="cmsis__os_8h.html#structosMutexDef__t">osMutexDef_t</a> *mutex_def)</td></tr>
  130. <tr class="memdesc:ga5c9de56e717016e39e788064e9a291cc"><td class="mdescLeft">&#160;</td><td class="mdescRight">Create and Initialize a Mutex object. <a href="#ga5c9de56e717016e39e788064e9a291cc">More...</a><br/></td></tr>
  131. <tr class="separator:ga5c9de56e717016e39e788064e9a291cc"><td class="memSeparator" colspan="2">&#160;</td></tr>
  132. <tr class="memitem:ga5e1752b73f573ee015dbd9ef1edaba13"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__Status.html#gae2e091fefc4c767117727bd5aba4d99e">osStatus</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga5e1752b73f573ee015dbd9ef1edaba13">osMutexWait</a> (<a class="el" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a> mutex_id, uint32_t millisec)</td></tr>
  133. <tr class="memdesc:ga5e1752b73f573ee015dbd9ef1edaba13"><td class="mdescLeft">&#160;</td><td class="mdescRight">Wait until a Mutex becomes available. <a href="#ga5e1752b73f573ee015dbd9ef1edaba13">More...</a><br/></td></tr>
  134. <tr class="separator:ga5e1752b73f573ee015dbd9ef1edaba13"><td class="memSeparator" colspan="2">&#160;</td></tr>
  135. <tr class="memitem:ga006e4744d741e8e132c3d5bbc295afe1"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__Status.html#gae2e091fefc4c767117727bd5aba4d99e">osStatus</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga006e4744d741e8e132c3d5bbc295afe1">osMutexRelease</a> (<a class="el" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a> mutex_id)</td></tr>
  136. <tr class="memdesc:ga006e4744d741e8e132c3d5bbc295afe1"><td class="mdescLeft">&#160;</td><td class="mdescRight">Release a Mutex that was obtained by <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga5e1752b73f573ee015dbd9ef1edaba13">osMutexWait</a>. <a href="#ga006e4744d741e8e132c3d5bbc295afe1">More...</a><br/></td></tr>
  137. <tr class="separator:ga006e4744d741e8e132c3d5bbc295afe1"><td class="memSeparator" colspan="2">&#160;</td></tr>
  138. <tr class="memitem:gac27e24135185d51d18f3dabc20910219"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__Status.html#gae2e091fefc4c767117727bd5aba4d99e">osStatus</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#gac27e24135185d51d18f3dabc20910219">osMutexDelete</a> (<a class="el" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a> mutex_id)</td></tr>
  139. <tr class="memdesc:gac27e24135185d51d18f3dabc20910219"><td class="mdescLeft">&#160;</td><td class="mdescRight">Delete a Mutex that was created by <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga5c9de56e717016e39e788064e9a291cc">osMutexCreate</a>. <a href="#gac27e24135185d51d18f3dabc20910219">More...</a><br/></td></tr>
  140. <tr class="separator:gac27e24135185d51d18f3dabc20910219"><td class="memSeparator" colspan="2">&#160;</td></tr>
  141. </table>
  142. <a name="details" id="details"></a><h2 class="groupheader">Description</h2>
  143. <p><b>Mutual exclusion</b> (widely known as <b>Mutex</b>) is used in various operating systems for resource management. Many resources in a microcontroller device can be used repeatedly, but only by one thread at a time (for example communication channels, memory, and files). Mutexes are used to protect access to a shared resource. A mutex is created and then passed between the threads (they can acquire and release the mutex).</p>
  144. <div class="image">
  145. <img src="Mutex.png" alt="Mutex.png"/>
  146. <div class="caption">
  147. CMSIS-RTOS Mutex</div></div>
  148. <p> A mutex is a special version of a <a class="el" href="group__CMSIS__RTOS__SemaphoreMgmt.html">semaphore</a>. Like the semaphore, it is a container for tokens. But instead of being able to have multiple tokens, a mutex can only carry one (representing the resource). Thus, a mutex token is binary and bounded. The advantage of a mutex is that it introduces thread ownership. When a thread acquires a mutex and becomes its owner, subsequent mutex acquires from that thread will succeed immediately without any latency. Thus, mutex acquires/releases can be nested.</p>
  149. <dl class="section note"><dt>Note</dt><dd><ul>
  150. <li>Mutex management functions cannot be called from interrupt service routines (ISR), unlike a binary semaphore that can be released from an ISR.</li>
  151. <li>CMSIS-RTOS uses <a href="https://en.wikipedia.org/wiki/Reentrant_mutex" target="_blank">reentrant/recursive mutexes</a> only.</li>
  152. </ul>
  153. </dd></dl>
  154. <h2>Working with Mutexes </h2>
  155. <p>To use mutexes, you need to follow these steps for creating and using them:</p>
  156. <ol type="1">
  157. <li>Declare the mutex container and initialize the mutex: <div class="fragment"><div class="line"><a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga9b522438489d7c402c95332b58bc94f3">osMutexDef</a> (uart_mutex); <span class="comment">// Declare mutex</span></div>
  158. <div class="line"><a class="code" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a> (uart_mutex_id); <span class="comment">// Mutex ID</span></div>
  159. </div><!-- fragment --></li>
  160. <li>Create the mutex in a thread: <div class="fragment"><div class="line">uart_mutex_id = <a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga5c9de56e717016e39e788064e9a291cc">osMutexCreate</a>(<a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga1122a86faa64b4a0880c76cf68d0c934">osMutex</a>(uart_mutex));</div>
  161. </div><!-- fragment --></li>
  162. <li>Acquire the mutex when peripheral access is required: <div class="fragment"><div class="line"><a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga5e1752b73f573ee015dbd9ef1edaba13">osMutexWait</a>(uart_mutex_id, <a class="code" href="cmsis__os_8h.html#a9eb9a7a797a42e4b55eb171ecc609ddb">osWaitForever</a>);</div>
  163. </div><!-- fragment --></li>
  164. <li>When finished with the peripheral access, release the mutex: <div class="fragment"><div class="line"><a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga006e4744d741e8e132c3d5bbc295afe1">osMutexRelease</a>(uart_mutex_id);</div>
  165. </div><!-- fragment --> </li>
  166. </ol>
  167. <h2 class="groupheader">Macro Definition Documentation</h2>
  168. <a class="anchor" id="ga1122a86faa64b4a0880c76cf68d0c934"></a>
  169. <div class="memitem">
  170. <div class="memproto">
  171. <table class="memname">
  172. <tr>
  173. <td class="memname">#define osMutex</td>
  174. <td>(</td>
  175. <td class="paramtype">&#160;</td>
  176. <td class="paramname">name</td><td>)</td>
  177. <td>&#160;&#160;&#160;&amp;os_mutex_def_##name</td>
  178. </tr>
  179. </table>
  180. </div><div class="memdoc">
  181. <p>Access to mutex object for the functions <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga5c9de56e717016e39e788064e9a291cc">osMutexCreate</a>.</p>
  182. <dl class="params"><dt>Parameters</dt><dd>
  183. <table class="params">
  184. <tr><td class="paramname">name</td><td>name of the mutex object. </td></tr>
  185. </table>
  186. </dd>
  187. </dl>
  188. <dl class="section note"><dt>Note</dt><dd>CAN BE CHANGED: The parameter to <b>osMutex</b> shall be consistent but the macro body is implementation specific in every CMSIS-RTOS. </dd></dl>
  189. </div>
  190. </div>
  191. <a class="anchor" id="ga9b522438489d7c402c95332b58bc94f3"></a>
  192. <div class="memitem">
  193. <div class="memproto">
  194. <table class="memname">
  195. <tr>
  196. <td class="memname">#define osMutexDef</td>
  197. <td>(</td>
  198. <td class="paramtype">&#160;</td>
  199. <td class="paramname">name</td><td>)</td>
  200. <td>&#160;&#160;&#160;const <a class="el" href="cmsis__os_8h.html#structosMutexDef__t">osMutexDef_t</a> os_mutex_def_##name = { 0 }</td>
  201. </tr>
  202. </table>
  203. </div><div class="memdoc">
  204. <p>Define a mutex object that is referenced by <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga1122a86faa64b4a0880c76cf68d0c934">osMutex</a>.</p>
  205. <dl class="params"><dt>Parameters</dt><dd>
  206. <table class="params">
  207. <tr><td class="paramname">name</td><td>name of the mutex object. </td></tr>
  208. </table>
  209. </dd>
  210. </dl>
  211. <dl class="section note"><dt>Note</dt><dd>CAN BE CHANGED: The parameter to <b>osMutexDef</b> shall be consistent but the macro body is implementation specific in every CMSIS-RTOS. </dd></dl>
  212. </div>
  213. </div>
  214. <h2 class="groupheader">Function Documentation</h2>
  215. <a class="anchor" id="ga5c9de56e717016e39e788064e9a291cc"></a>
  216. <div class="memitem">
  217. <div class="memproto">
  218. <table class="memname">
  219. <tr>
  220. <td class="memname"><a class="el" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a> osMutexCreate </td>
  221. <td>(</td>
  222. <td class="paramtype">const <a class="el" href="cmsis__os_8h.html#structosMutexDef__t">osMutexDef_t</a> *&#160;</td>
  223. <td class="paramname"><em>mutex_def</em></td><td>)</td>
  224. <td></td>
  225. </tr>
  226. </table>
  227. </div><div class="memdoc">
  228. <dl class="params"><dt>Parameters</dt><dd>
  229. <table class="params">
  230. <tr><td class="paramdir">[in]</td><td class="paramname">mutex_def</td><td>mutex definition referenced with <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga1122a86faa64b4a0880c76cf68d0c934">osMutex</a>. </td></tr>
  231. </table>
  232. </dd>
  233. </dl>
  234. <dl class="section return"><dt>Returns</dt><dd>mutex ID for reference by other functions or NULL in case of error. </dd></dl>
  235. <dl class="section note"><dt>Note</dt><dd>MUST REMAIN UNCHANGED: <b>osMutexCreate</b> shall be consistent in every CMSIS-RTOS.</dd></dl>
  236. <p>Create and initialize a Mutex object.</p>
  237. <dl class="section note"><dt>Note</dt><dd>Cannot be called from <a class="el" href="functionOverview.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
  238. <p><b>Code Example</b> </p>
  239. <div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="cmsis__os_8h.html">cmsis_os.h</a>&quot;</span></div>
  240. <div class="line"> </div>
  241. <div class="line"><a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga9b522438489d7c402c95332b58bc94f3">osMutexDef</a> (MutexIsr); <span class="comment">// Mutex name definition</span></div>
  242. <div class="line"> </div>
  243. <div class="line"><span class="keywordtype">void</span> CreateMutex (<span class="keywordtype">void</span>) {</div>
  244. <div class="line"><a class="code" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a> mutex_id; </div>
  245. <div class="line"> </div>
  246. <div class="line"> mutex_id = <a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga5c9de56e717016e39e788064e9a291cc">osMutexCreate</a> (<a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga1122a86faa64b4a0880c76cf68d0c934">osMutex</a> (MutexIsr));</div>
  247. <div class="line"> <span class="keywordflow">if</span> (mutex_id != NULL) {</div>
  248. <div class="line"> <span class="comment">// Mutex object created</span></div>
  249. <div class="line"> } </div>
  250. <div class="line">}</div>
  251. </div><!-- fragment -->
  252. </div>
  253. </div>
  254. <a class="anchor" id="gac27e24135185d51d18f3dabc20910219"></a>
  255. <div class="memitem">
  256. <div class="memproto">
  257. <table class="memname">
  258. <tr>
  259. <td class="memname"><a class="el" href="group__CMSIS__RTOS__Status.html#gae2e091fefc4c767117727bd5aba4d99e">osStatus</a> osMutexDelete </td>
  260. <td>(</td>
  261. <td class="paramtype"><a class="el" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a>&#160;</td>
  262. <td class="paramname"><em>mutex_id</em></td><td>)</td>
  263. <td></td>
  264. </tr>
  265. </table>
  266. </div><div class="memdoc">
  267. <dl class="params"><dt>Parameters</dt><dd>
  268. <table class="params">
  269. <tr><td class="paramdir">[in]</td><td class="paramname">mutex_id</td><td>mutex ID obtained by <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga5c9de56e717016e39e788064e9a291cc">osMutexCreate</a>. </td></tr>
  270. </table>
  271. </dd>
  272. </dl>
  273. <dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function. </dd></dl>
  274. <dl class="section note"><dt>Note</dt><dd>MUST REMAIN UNCHANGED: <b>osMutexDelete</b> shall be consistent in every CMSIS-RTOS.</dd></dl>
  275. <p>Delete a Mutex object. The function releases internal memory obtained for Mutex handling. After this call the <em>mutex_id</em> is no longer valid and cannot be used. The Mutex may be created again using the function <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga5c9de56e717016e39e788064e9a291cc">osMutexCreate</a>.</p>
  276. <p><b><a class="el" href="group__CMSIS__RTOS__Status.html">Status and Error Codes</a></b><br/>
  277. </p>
  278. <ul>
  279. <li><em>osOK:</em> the mutex object has been deleted.</li>
  280. <li><em>osErrorISR:</em> <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#gac27e24135185d51d18f3dabc20910219">osMutexDelete</a> cannot be called from interrupt service routines.</li>
  281. <li><em>osErrorResource:</em> all tokens have already been released.</li>
  282. <li><em>osErrorParameter:</em> the parameter <em>mutex_id</em> is incorrect.</li>
  283. </ul>
  284. <dl class="section note"><dt>Note</dt><dd>Cannot be called from <a class="el" href="functionOverview.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
  285. <p><b>Code Example</b> </p>
  286. <div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="cmsis__os_8h.html">cmsis_os.h</a>&quot;</span></div>
  287. <div class="line"> </div>
  288. <div class="line"><a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga9b522438489d7c402c95332b58bc94f3">osMutexDef</a> (MutexIsr); <span class="comment">// Mutex name definition </span></div>
  289. <div class="line"><a class="code" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a> mutex_id; <span class="comment">// Mutex id populated by the function CreateMutex()</span></div>
  290. <div class="line"><a class="code" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a> CreateMutex (<span class="keywordtype">void</span>); <span class="comment">// function prototype that creates the Mutex</span></div>
  291. <div class="line"> </div>
  292. <div class="line"><span class="keywordtype">void</span> DeleteMutex (<a class="code" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a> mutex_id) {</div>
  293. <div class="line"><a class="code" href="group__CMSIS__RTOS__Status.html#gae2e091fefc4c767117727bd5aba4d99e">osStatus</a> status;</div>
  294. <div class="line"> </div>
  295. <div class="line"> <span class="keywordflow">if</span> (mutex_id != NULL) {</div>
  296. <div class="line"> status = <a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#gac27e24135185d51d18f3dabc20910219">osMutexDelete</a>(mutex_id);</div>
  297. <div class="line"> <span class="keywordflow">if</span> (status != <a class="code" href="group__CMSIS__RTOS__Status.html#gae2e091fefc4c767117727bd5aba4d99ea9e1c9e2550bb4de8969a935acffc968f">osOK</a>) {</div>
  298. <div class="line"> <span class="comment">// handle failure code</span></div>
  299. <div class="line"> }</div>
  300. <div class="line"> }</div>
  301. <div class="line">}</div>
  302. </div><!-- fragment -->
  303. </div>
  304. </div>
  305. <a class="anchor" id="ga006e4744d741e8e132c3d5bbc295afe1"></a>
  306. <div class="memitem">
  307. <div class="memproto">
  308. <table class="memname">
  309. <tr>
  310. <td class="memname"><a class="el" href="group__CMSIS__RTOS__Status.html#gae2e091fefc4c767117727bd5aba4d99e">osStatus</a> osMutexRelease </td>
  311. <td>(</td>
  312. <td class="paramtype"><a class="el" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a>&#160;</td>
  313. <td class="paramname"><em>mutex_id</em></td><td>)</td>
  314. <td></td>
  315. </tr>
  316. </table>
  317. </div><div class="memdoc">
  318. <dl class="params"><dt>Parameters</dt><dd>
  319. <table class="params">
  320. <tr><td class="paramdir">[in]</td><td class="paramname">mutex_id</td><td>mutex ID obtained by <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga5c9de56e717016e39e788064e9a291cc">osMutexCreate</a>. </td></tr>
  321. </table>
  322. </dd>
  323. </dl>
  324. <dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function. </dd></dl>
  325. <dl class="section note"><dt>Note</dt><dd>MUST REMAIN UNCHANGED: <b>osMutexRelease</b> shall be consistent in every CMSIS-RTOS.</dd></dl>
  326. <p>Release a Mutex that was obtained with <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga5e1752b73f573ee015dbd9ef1edaba13">osMutexWait</a>. Other threads that currently wait for the same mutex will be now put into the state <b>READY</b>.</p>
  327. <p><b><a class="el" href="group__CMSIS__RTOS__Status.html">Status and Error Codes</a></b><br/>
  328. </p>
  329. <ul>
  330. <li><em>osOK:</em> the mutex has been correctly released.</li>
  331. <li><em>osErrorResource:</em> the mutex was not obtained before.</li>
  332. <li><em>osErrorParameter:</em> the parameter <em>mutex_id</em> is incorrect.</li>
  333. <li><em>osErrorISR:</em> <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga006e4744d741e8e132c3d5bbc295afe1">osMutexRelease</a> cannot be called from interrupt service routines.</li>
  334. </ul>
  335. <dl class="section note"><dt>Note</dt><dd>Cannot be called from <a class="el" href="functionOverview.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
  336. <p><b>Code Example</b> </p>
  337. <div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="cmsis__os_8h.html">cmsis_os.h</a>&quot;</span></div>
  338. <div class="line"> </div>
  339. <div class="line"><a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga9b522438489d7c402c95332b58bc94f3">osMutexDef</a> (MutexIsr); <span class="comment">// Mutex name definition </span></div>
  340. <div class="line"><a class="code" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a> mutex_id; <span class="comment">// Mutex id populated by the function CreateMutex()</span></div>
  341. <div class="line"><a class="code" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a> CreateMutex (<span class="keywordtype">void</span>); <span class="comment">// function prototype that creates the Mutex</span></div>
  342. <div class="line"> </div>
  343. <div class="line"><span class="keywordtype">void</span> ReleaseMutex (<a class="code" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a> mutex_id) {</div>
  344. <div class="line"><a class="code" href="group__CMSIS__RTOS__Status.html#gae2e091fefc4c767117727bd5aba4d99e">osStatus</a> status;</div>
  345. <div class="line"> </div>
  346. <div class="line"> <span class="keywordflow">if</span> (mutex_id != NULL) {</div>
  347. <div class="line"> status = <a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga006e4744d741e8e132c3d5bbc295afe1">osMutexRelease</a>(mutex_id);</div>
  348. <div class="line"> <span class="keywordflow">if</span> (status != <a class="code" href="group__CMSIS__RTOS__Status.html#gae2e091fefc4c767117727bd5aba4d99ea9e1c9e2550bb4de8969a935acffc968f">osOK</a>) {</div>
  349. <div class="line"> <span class="comment">// handle failure code</span></div>
  350. <div class="line"> }</div>
  351. <div class="line"> }</div>
  352. <div class="line">}</div>
  353. </div><!-- fragment -->
  354. </div>
  355. </div>
  356. <a class="anchor" id="ga5e1752b73f573ee015dbd9ef1edaba13"></a>
  357. <div class="memitem">
  358. <div class="memproto">
  359. <table class="memname">
  360. <tr>
  361. <td class="memname"><a class="el" href="group__CMSIS__RTOS__Status.html#gae2e091fefc4c767117727bd5aba4d99e">osStatus</a> osMutexWait </td>
  362. <td>(</td>
  363. <td class="paramtype"><a class="el" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a>&#160;</td>
  364. <td class="paramname"><em>mutex_id</em>, </td>
  365. </tr>
  366. <tr>
  367. <td class="paramkey"></td>
  368. <td></td>
  369. <td class="paramtype">uint32_t&#160;</td>
  370. <td class="paramname"><em>millisec</em>&#160;</td>
  371. </tr>
  372. <tr>
  373. <td></td>
  374. <td>)</td>
  375. <td></td><td></td>
  376. </tr>
  377. </table>
  378. </div><div class="memdoc">
  379. <dl class="params"><dt>Parameters</dt><dd>
  380. <table class="params">
  381. <tr><td class="paramdir">[in]</td><td class="paramname">mutex_id</td><td>mutex ID obtained by <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga5c9de56e717016e39e788064e9a291cc">osMutexCreate</a>. </td></tr>
  382. <tr><td class="paramdir">[in]</td><td class="paramname">millisec</td><td><a class="el" href="functionOverview.html#CMSIS_RTOS_TimeOutValue">Timout Value</a> or 0 in case of no time-out. </td></tr>
  383. </table>
  384. </dd>
  385. </dl>
  386. <dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function. </dd></dl>
  387. <dl class="section note"><dt>Note</dt><dd>MUST REMAIN UNCHANGED: <b>osMutexWait</b> shall be consistent in every CMSIS-RTOS.</dd></dl>
  388. <p>Wait until a Mutex becomes available. If no other thread has obtained the Mutex, the function instantly returns and blocks the mutex object.</p>
  389. <p>The argument <em>millisec</em> specifies how long the system waits for a mutex. While the system waits the thread that is calling this function is put into the state <b>WAITING</b>. The <em>millisec</em> timeout can have the following values:</p>
  390. <ul>
  391. <li>when <em>millisec</em> is 0, the function returns instantly.</li>
  392. <li>when <em>millisec</em> is set to <b>osWaitForever</b> the function will wait for an infinite time until the mutex becomes available.</li>
  393. <li>all other values specify a time in millisecond for a timeout.</li>
  394. </ul>
  395. <p><b><a class="el" href="group__CMSIS__RTOS__Status.html">Status and Error Codes</a></b><br/>
  396. </p>
  397. <ul>
  398. <li><em>osOK:</em> the mutex has been obtained.</li>
  399. <li><em>osErrorTimeoutResource:</em> the mutex could not be obtained in the given time.</li>
  400. <li><em>osErrorResource:</em> the mutex could not be obtained when no timeout was specified.</li>
  401. <li><em>osErrorParameter:</em> the parameter <em>mutex_id</em> is incorrect.</li>
  402. <li><em>osErrorISR:</em> <a class="el" href="group__CMSIS__RTOS__MutexMgmt.html#ga5e1752b73f573ee015dbd9ef1edaba13">osMutexWait</a> cannot be called from interrupt service routines.</li>
  403. </ul>
  404. <dl class="section note"><dt>Note</dt><dd>Cannot be called from <a class="el" href="functionOverview.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
  405. <p><b>Code Example</b> </p>
  406. <div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="cmsis__os_8h.html">cmsis_os.h</a>&quot;</span></div>
  407. <div class="line"> </div>
  408. <div class="line"><a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga9b522438489d7c402c95332b58bc94f3">osMutexDef</a> (MutexIsr);</div>
  409. <div class="line"> </div>
  410. <div class="line"><span class="keywordtype">void</span> WaitMutex (<span class="keywordtype">void</span>) {</div>
  411. <div class="line"><a class="code" href="cmsis__os_8h.html#a3263c1ad9fd79b84f908d65e8da44ac2">osMutexId</a> mutex_id; </div>
  412. <div class="line"><a class="code" href="group__CMSIS__RTOS__Status.html#gae2e091fefc4c767117727bd5aba4d99e">osStatus</a> status;</div>
  413. <div class="line"> </div>
  414. <div class="line"> mutex_id = <a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga5c9de56e717016e39e788064e9a291cc">osMutexCreate</a> (<a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga1122a86faa64b4a0880c76cf68d0c934">osMutex</a> (MutexIsr));</div>
  415. <div class="line"> <span class="keywordflow">if</span> (mutex_id != NULL) {</div>
  416. <div class="line"> status = <a class="code" href="group__CMSIS__RTOS__MutexMgmt.html#ga5e1752b73f573ee015dbd9ef1edaba13">osMutexWait</a> (mutex_id, 0);</div>
  417. <div class="line"> <span class="keywordflow">if</span> (status != <a class="code" href="group__CMSIS__RTOS__Status.html#gae2e091fefc4c767117727bd5aba4d99ea9e1c9e2550bb4de8969a935acffc968f">osOK</a>) {</div>
  418. <div class="line"> <span class="comment">// handle failure code</span></div>
  419. <div class="line"> }</div>
  420. <div class="line"> }</div>
  421. <div class="line">}</div>
  422. </div><!-- fragment -->
  423. </div>
  424. </div>
  425. </div><!-- contents -->
  426. </div><!-- doc-content -->
  427. <!-- start footer part -->
  428. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  429. <ul>
  430. <li class="footer">Generated on Mon Mar 18 2019 16:06:29 for CMSIS-RTOS by Arm Ltd. All rights reserved.
  431. <!--
  432. <a href="http://www.doxygen.org/index.html">
  433. <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6
  434. -->
  435. </li>
  436. </ul>
  437. </div>
  438. </body>
  439. </html>