📄 group__task.html
字号:
<td class="paramname"> <em>t</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">uint8_t </td> <td class="paramname"> <em>wait_for_mutexes</em></td><td> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td><td width="100%"></td> </tr> </table></div><div class="memdoc"><p>Stop a task. <p>The arguments are <ul><li><code>t</code> the task to stop </li><li><code>wait_for_mutexes</code> - if not zero, the task will not be stopped until it has released all of its mutexes. If zero, then the tasks will stop immediately. Note that if you are using a memory mutex, you <b>must</b> set <code>wait_for_mutexes</code> when stopping any task that uses the memory mutex - see <a class="el" href="howdoi.html#malloc">How do I use malloc() and free() safely?</a></li></ul>This function can be called by the current task (stop_task(current_task, ...)), or by a higher-priority task, or by an ISR, and may be called on any non-zero-priority task.<p>If this function is called by the current task, and <code>wait_for_mutexes</code> isn't set, then the "cleaning up" of the task (<a class="el" href="task_8c.html#b1c4cc247bd379e340e25bd86911919d" title="The entry point for all tasks that are stopping">task_stopper()</a>) will start executing immediately - i.e. the stop_task(current_task, 0) call won't "return". If <code>wait_for_mutexes</code> is set, then the <a class="el" href="group__mutex.html#g327f419711064b7407f6f47011221cc4" title="Unlock a mutex.">lock_off()</a> that releases the tasks' last mutex won't return - the <a class="el" href="task_8c.html#b1c4cc247bd379e340e25bd86911919d" title="The entry point for all tasks that are stopping">task_stopper()</a> will run instead.<p>If this function is called by a higher priority task, then it will not return until the task in question has completely stopped executing.<p>If this function is called from within an ISR, it will return immediately.<p>A return value of -1 means that the calling task doesn't have the required permission. A return value of -2 means that an attempt was made to stop a zero-priority task. A return value of zero indicates success, and a return value of 1 means that the task was already stopped.<p>See <a class="el" href="task_8c.html#b1c4cc247bd379e340e25bd86911919d" title="The entry point for all tasks that are stopping">task_stopper()</a> for a description of what happens to the task that is being stopped. </div></div><p><a class="anchor" name="g1398c4d9f97349ea3fa7d91349298521"></a><!-- doxytag: member="task.h::task_switcher_start" ref="g1398c4d9f97349ea3fa7d91349298521" args="(void(*idle)(void *), void *idle_data, uint16_t idle_stacklen, uint16_t system_stacklen) __attribute__((naked))" --><div class="memitem"><div class="memproto"> <table class="memname"> <tr> <td class="memname">void task_switcher_start </td> <td>(</td> <td class="paramtype">void(*)(void *) </td> <td class="paramname"> <em>idle</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">void * </td> <td class="paramname"> <em>idle_data</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">uint16_t </td> <td class="paramname"> <em>idle_stacklen</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">uint16_t </td> <td class="paramname"> <em>system_stacklen</em></td><td> </td> </tr> <tr> <td></td> <td>)</td> <td></td><td></td><td width="100%"></td> </tr> </table></div><div class="memdoc"><p>Start the whole process running. <p>Note that this method will never return. The arguments are <ul><li><code>idle</code> - the "idle" function (the function to execute when we have nothing else to do) </li><li><code>idle_data</code> - the value of the argument to <code>idle</code> when it starts </li><li><code>idle_stacklen</code> - the length of the stack for the "idle" function - see <a class="el" href="group__task.html#g9b849c9a0e0b29417cf47da99226dcc3" title="Create a task, ready to be run.">create_task()</a> </li><li><code>system_stacklen</code> - the length of the system stack - this is the stack that will be in use during all ISRs</li></ul>A recommended idle task is - <div class="fragment"><pre class="fragment"> <span class="keywordtype">void</span> idle_task() { set_sleep_mode(SLEEP_MODE_IDLE); sleep_enable(); sei(); sleep_cpu(); }</pre></div><p>See <a class="el" href="example.html">the example application</a> for an example of how to start the task switcher.<p>Note that, if you are using the <a class="el" href="group__isr.html#g3d04938242a5060aac8a64b72c055eb0" title="The macro for ISRs.">TASK_ISR()</a> macro to give your ISRs access to the system stack (and you should!), then all interrupts must remain disabled right up until this function is called. Interrupts will be enabled as soon as the first task switch starts. </div></div><p><a class="anchor" name="g1a2a5bbefa85516b8c1d0e0361a834db"></a><!-- doxytag: member="task.h::yield" ref="g1a2a5bbefa85516b8c1d0e0361a834db" args="() __attribute__((naked))" --><div class="memitem"><div class="memproto"> <table class="memname"> <tr> <td class="memname">void yield </td> <td>(</td> <td class="paramname"> </td> <td> ) </td> <td width="100%"></td> </tr> </table></div><div class="memdoc"><p>Stop executing the current task and try and execute a higher-priority task or another task of the same priority. <p>Note that all API calls that could theoretically cause a higher-priority task to be re-enabled will call <a class="el" href="group__task.html#g1a2a5bbefa85516b8c1d0e0361a834db" title="Stop executing the current task and try and execute a higher-priority task or another...">yield()</a>, which will cause an automatic and immediate task switch to that higher-priority task. (This also means that if there is another task of the same priority that hasn't been disabled, all such API calls will cause a task switch to that task).<p>Obviously this function can only be called by tasks, and it will "return" the next time it is the turn of the current task to execute. </div></div><p><hr><h2>Variable Documentation</h2><a class="anchor" name="g4743b3673a8794b8e7bd0b6c91a63cd5"></a><!-- doxytag: member="task.h::current_task" ref="g4743b3673a8794b8e7bd0b6c91a63cd5" args="" --><div class="memitem"><div class="memproto"> <table class="memname"> <tr> <td class="memname"><a class="el" href="structtask__t.html">task_t</a>* <a class="el" href="group__task.html#g4743b3673a8794b8e7bd0b6c91a63cd5">current_task</a> </td> </tr> </table></div><div class="memdoc"><p>The current task. <p>This value may be used in <a class="el" href="group__task.html#ge1337adc1d63d7cd874a376d6513c04a" title="Stop a task.">stop_task()</a> to stop the current task </div></div><p><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 + -