_using_o_s.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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>CMSIS-RTOS: Using a CMSIS RTOS Implementation</title>
  7. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  8. <link href="cmsis.css" rel="stylesheet" type="text/css" />
  9. <script type="text/javascript" src="jquery.js"></script>
  10. <script type="text/javascript" src="dynsections.js"></script>
  11. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  12. <script type="text/javascript" src="resize.js"></script>
  13. <script type="text/javascript" src="navtree.js"></script>
  14. <script type="text/javascript">
  15. $(document).ready(initResizable);
  16. </script>
  17. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  18. <script type="text/javascript" src="search/search.js"></script>
  19. <script type="text/javascript">
  20. $(document).ready(function() { searchBox.OnSelectItem(0); });
  21. </script>
  22. <link href="stylsheetf" rel="stylesheet" type="text/css" />
  23. </head>
  24. <body>
  25. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  26. <div id="titlearea">
  27. <table cellspacing="0" cellpadding="0">
  28. <tbody>
  29. <tr style="height: 46px;">
  30. <td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
  31. <td style="padding-left: 0.5em;">
  32. <div id="projectname">CMSIS-RTOS
  33. &#160;<span id="projectnumber">Version 1.02</span>
  34. </div>
  35. <div id="projectbrief">CMSIS-RTOS API: Generic RTOS interface for Cortex-M processor-based devices.</div>
  36. </td>
  37. </tr>
  38. </tbody>
  39. </table>
  40. </div>
  41. <!-- end header part -->
  42. <div id="CMSISnav" class="tabs1">
  43. <ul class="tablist">
  44. <li><a href="../../General/html/index.html"><span>CMSIS</span></a></li>
  45. <li><a href="../../Core/html/index.html"><span>CORE</span></a></li>
  46. <li><a href="../../Driver/html/index.html"><span>Driver</span></a></li>
  47. <li><a href="../../DSP/html/index.html"><span>DSP</span></a></li>
  48. <li class="current"><a href="../../RTOS/html/index.html"><span>RTOS API</span></a></li>
  49. <li><a href="../../Pack/html/index.html"><span>Pack</span></a></li>
  50. <li><a href="../../SVD/html/index.html"><span>SVD</span></a></li>
  51. </ul>
  52. </div>
  53. <!-- Generated by Doxygen 1.8.2 -->
  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 class="current"><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('_using_o_s.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="headertitle">
  109. <div class="title">Using a CMSIS RTOS Implementation </div> </div>
  110. </div><!--header-->
  111. <div class="contents">
  112. <div class="textblock"><p>A CMSIS RTOS implementation is typically provided as a library. To add the RTOS functionality to an existing CMSIS-based application the RTOS library (and typically a configuration file) needs to be added. The available functionality of the RTOS library is defined in the file <b><a class="el" href="cmsis__os_8h.html">cmsis_os.h</a></b> that is specific for each RTOS implementation.</p>
  113. <div class="image">
  114. <img src="CMSIS_RTOS_Files.png" alt="CMSIS_RTOS_Files.png"/>
  115. <div class="caption">
  116. CMSIS-RTOS File Structure</div></div>
  117. <p> Depending on the CMSIS-RTOS implementation, execution may start with the <b>main</b> function as the first thread. This has the benefit that an application programmer may use other middleware libraries that create threads internally, but the remaining part of the user application just uses the <b>main</b> thread. Therefore, the usage of the RTOS can be invisible to the application programmer, but libraries can use CMSIS-RTOS features.</p>
  118. <p>Once the files are added to a project, the user can start using the CMSIS-RTOS functions. A code example is provided below:</p>
  119. <p><b>Example</b> </p>
  120. <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> <span class="comment">// CMSIS RTOS header file</span></div>
  121. <div class="line"></div>
  122. <div class="line"><span class="keywordtype">void</span> job1 (<span class="keywordtype">void</span> <span class="keyword">const</span> *argument) { <span class="comment">// thread function &#39;job1&#39;</span></div>
  123. <div class="line"> <span class="keywordflow">while</span> (1) {</div>
  124. <div class="line"> : <span class="comment">// execute some code</span></div>
  125. <div class="line"> <a class="code" href="group___c_m_s_i_s___r_t_o_s___wait.html#ga02e19d5e723bfb06ba9324d625162255" title="Wait for Timeout (Time Delay).">osDelay</a> (10); <span class="comment">// delay execution for 10 milliseconds</span></div>
  126. <div class="line"> }</div>
  127. <div class="line">}</div>
  128. <div class="line"><span class="comment">// define job1 as thread function</span></div>
  129. <div class="line"><a class="code" href="group___c_m_s_i_s___r_t_o_s___thread_mgmt.html#gaee93d929beb350f16e5cc7fa602e229f" title="Create a Thread Definition with function, priority, and stack requirements.">osThreadDef</a>(job1, <a class="code" href="group___c_m_s_i_s___r_t_o_s___thread_mgmt.html#ga7f2b42f1983b9107775ec2a1c69a849aa17b36cd9cd38652c2bc6d4803990674b" title="priority: above normal">osPriorityAboveNormal</a>, 1, 0); <span class="comment">// define job1 as thread function</span></div>
  130. <div class="line"></div>
  131. <div class="line"></div>
  132. <div class="line"><span class="keywordtype">void</span> job2 (<span class="keywordtype">void</span> <span class="keyword">const</span> *argument) { <span class="comment">// thread function &#39;job2&#39;</span></div>
  133. <div class="line"> <a class="code" href="group___c_m_s_i_s___r_t_o_s___thread_mgmt.html#gac59b5713cb083702dce759c73fd90dff" title="Create a thread and add it to Active Threads and set it to state READY.">osThreadCreate</a>(<a class="code" href="group___c_m_s_i_s___r_t_o_s___thread_mgmt.html#gaf0c7c6b5e09f8be198312144b5c9e453" title="Access a Thread definition.">osThread</a>(job1),NULL); <span class="comment">// create job1 thread</span></div>
  134. <div class="line"> <span class="keywordflow">while</span> (1) {</div>
  135. <div class="line"> : <span class="comment">// execute some code</span></div>
  136. <div class="line"> }</div>
  137. <div class="line">}</div>
  138. <div class="line"></div>
  139. <div class="line"><a class="code" href="group___c_m_s_i_s___r_t_o_s___thread_mgmt.html#gaee93d929beb350f16e5cc7fa602e229f" title="Create a Thread Definition with function, priority, and stack requirements.">osThreadDef</a>(job2, <a class="code" href="group___c_m_s_i_s___r_t_o_s___thread_mgmt.html#ga7f2b42f1983b9107775ec2a1c69a849aa45a2895ad30c79fb97de18cac7cc19f1" title="priority: normal (default)">osPriorityNormal</a>, 1, 0); <span class="comment">// define job2 as thread function</span></div>
  140. <div class="line"></div>
  141. <div class="line"><span class="keywordtype">void</span> job3 (<span class="keywordtype">void</span> <span class="keyword">const</span> *argument) { <span class="comment">// thread function &#39;job3&#39;</span></div>
  142. <div class="line"> <span class="keywordflow">while</span> (1) {</div>
  143. <div class="line"> : <span class="comment">// execute some code</span></div>
  144. <div class="line"> <a class="code" href="group___c_m_s_i_s___r_t_o_s___wait.html#ga02e19d5e723bfb06ba9324d625162255" title="Wait for Timeout (Time Delay).">osDelay</a> (20); <span class="comment">// delay execution for 20 milliseconds</span></div>
  145. <div class="line"> }</div>
  146. <div class="line">}</div>
  147. <div class="line"></div>
  148. <div class="line"><a class="code" href="group___c_m_s_i_s___r_t_o_s___thread_mgmt.html#gaee93d929beb350f16e5cc7fa602e229f" title="Create a Thread Definition with function, priority, and stack requirements.">osThreadDef</a>(job3, <a class="code" href="group___c_m_s_i_s___r_t_o_s___thread_mgmt.html#ga7f2b42f1983b9107775ec2a1c69a849aa45a2895ad30c79fb97de18cac7cc19f1" title="priority: normal (default)">osPriorityNormal</a>, 1, 0); <span class="comment">// define job3 as thread function</span></div>
  149. <div class="line"></div>
  150. <div class="line"><span class="keywordtype">int</span> main (<span class="keywordtype">void</span>) { <span class="comment">// program execution starts here</span></div>
  151. <div class="line"> <a class="code" href="group___c_m_s_i_s___r_t_o_s___kernel_ctrl.html#ga53d078a801022e202e8115c083ece68e" title="Initialize the RTOS Kernel for creating objects.">osKernelInitialize</a> (); <span class="comment">// initialize RTOS kernel</span></div>
  152. <div class="line"> : <span class="comment">// setup and initialize peripherals</span></div>
  153. <div class="line"> <a class="code" href="group___c_m_s_i_s___r_t_o_s___thread_mgmt.html#gac59b5713cb083702dce759c73fd90dff" title="Create a thread and add it to Active Threads and set it to state READY.">osThreadCreate</a> (<a class="code" href="group___c_m_s_i_s___r_t_o_s___thread_mgmt.html#gaf0c7c6b5e09f8be198312144b5c9e453" title="Access a Thread definition.">osThread</a>(job2));</div>
  154. <div class="line"> <a class="code" href="group___c_m_s_i_s___r_t_o_s___thread_mgmt.html#gac59b5713cb083702dce759c73fd90dff" title="Create a thread and add it to Active Threads and set it to state READY.">osThreadCreate</a> (<a class="code" href="group___c_m_s_i_s___r_t_o_s___thread_mgmt.html#gaf0c7c6b5e09f8be198312144b5c9e453" title="Access a Thread definition.">osThread</a>(job3));</div>
  155. <div class="line"> <a class="code" href="group___c_m_s_i_s___r_t_o_s___kernel_ctrl.html#gaab668ffd2ea76bb0a77ab0ab385eaef2" title="Start the RTOS Kernel.">osKernelStart</a> (); <span class="comment">// start kernel with job2 execution</span></div>
  156. <div class="line">}</div>
  157. </div><!-- fragment --> </div></div><!-- contents -->
  158. </div><!-- doc-content -->
  159. <!-- start footer part -->
  160. <div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  161. <ul>
  162. <li class="footer">Generated on Tue Sep 23 2014 18:52:52 for CMSIS-RTOS by ARM Ltd. All rights reserved.
  163. <!--
  164. <a href="http://www.doxygen.org/index.html">
  165. <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.2
  166. -->
  167. </li>
  168. </ul>
  169. </div>
  170. </body>
  171. </html>