?? usage-mutex.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 Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li><a href="pages.html"><span>Related 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>(&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>(&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>(&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>(&pin_mutex); ...}</pre></div> <hr><p align="center"><font size="-1">YAVRTOS and YAVRTOS documentation Copyright © 2007-2008 Chris O'Byrne. Email - chris <at> obyrne <dot> com</font></p></body></html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -