⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usage-mutex.html

📁 yavrtos,一款用于广泛用于AVR单片机的RTOS,文件里是这款OS的源码
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>YAVRTOS: Using mutexes</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.5.4 --><div class="tabs">  <ul>    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>    <li><a href="modules.html"><span>Modules</span></a></li>    <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>    <li><a href="files.html"><span>Files</span></a></li>    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>  </ul></div><div class="nav"><a class="el" href="usage.html">Using YAVRTOS</a></div><h1><a class="anchor" name="usage-mutex">Using mutexes </a></h1>A mutex is used to ensure that only one task is using a shared resource at any one time.<h2><a class="anchor" name="usage-mutex-1">Example - sharing I/O pins</a></h2>Given that microcontrollers only have a limited number of I/O pins, it is common for pins to be dual-purpose.<p><div class="fragment"><pre class="fragment"><a class="code" href="structmutex__t.html" title="A structure describing a mutex.">mutex_t</a> pin_mutex;<span class="keywordtype">void</span> task1(<span class="keywordtype">void</span> *p) {        ...        <span class="comment">// task 1 now needs to use the dual-purpose pins</span>        <a class="code" href="group__mutex.html#gdff77e0b451c30c07d2990e669f937c5" title="Lock on a mutex.">lock_on</a>(&amp;pin_mutex);        <span class="comment">// we now "own" the mutex, so we "own" the pins</span>        do_stuff_with_the_dual_purpose_pins();        <span class="comment">// release the pins</span>        <a class="code" href="group__mutex.html#g327f419711064b7407f6f47011221cc4" title="Unlock a mutex.">lock_off</a>(&amp;pin_mutex);        ...}<span class="keywordtype">void</span> task2(<span class="keywordtype">void</span> *p) {        ...        <span class="comment">// task 2 now needs to use the dual-purpose pins</span>        <a class="code" href="group__mutex.html#gdff77e0b451c30c07d2990e669f937c5" title="Lock on a mutex.">lock_on</a>(&amp;pin_mutex);        <span class="comment">// we now "own" the mutex, so we "own" the pins</span>        do_other_stuff_with_the_dual_purpose_pins();        <span class="comment">// release the pins</span>        <a class="code" href="group__mutex.html#g327f419711064b7407f6f47011221cc4" title="Unlock a mutex.">lock_off</a>(&amp;pin_mutex);        ...}</pre></div> <hr><p align="center"><font size="-1">YAVRTOS and YAVRTOS documentation Copyright &copy; 2007-2008 Chris O'Byrne. Email - chris &lt;at&gt; obyrne &lt;dot&gt; com</font></p></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -