📄 group__task.html
字号:
<td class="paramname"> <em>pri</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype"><a class="el" href="structmutex__t.html">mutex_t</a> * </td> <td class="paramname"> <em>memory_mutex</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>Create a task, ready to be run. <p><dl class="attention" compact><dt><b>Attention:</b></dt><dd><a class="el" href="group__task.html#g9b849c9a0e0b29417cf47da99226dcc3" title="Create a task, ready to be run.">create_task()</a> can call malloc(), and disables interrupts during any call to malloc(). Therefore, depending on the amount of time your malloc() algorithm takes, and depending on what your time margin for the launch of ISRs is, <a class="el" href="group__task.html#g9b849c9a0e0b29417cf47da99226dcc3" title="Create a task, ready to be run.">create_task()</a> could disable interrupts for "too long". See the description of the <code>memory_mutex</code> argument, and <a class="el" href="howdoi.html#malloc">How do I use malloc() and free() safely?</a></dd></dl>The arguments are <ul><li><code>proc</code> - this is the task function. Upon entry, interrupts will be enabled, and the value of the argument will be that of <code>init_data</code>. This function does not need to contain an infinite loop - if it returns (and if the priority is greater than zero), a stop will be performed on the task. </li><li><code>cleanup</code> - this is the task cleanup function, which will be called as the task is dying. May be null if the task doesn't need to clean up after itself. See <a class="el" href="task_8c.html#b1c4cc247bd379e340e25bd86911919d" title="The entry point for all tasks that are stopping">task_stopper()</a> </li><li><code>init_data</code> - this is the value that will be given in the argument to <code>proc</code> when it starts </li><li><code>stacklen</code> - the number of bytes to reserve for the task stack. Note that it must be long enough to hold a copy of the value of all 32 registers when a task switch occurs, and it needs a couple of extra bytes to handle interrupts, function calls etc. </li><li><code>pri</code> - the priority of the task. The highest-priority available task will "hog" the CPU. If the task has a priority of zero (an "idle" task), then it may not suspend itself on a mutex, semaphore or mailbox, and it may not be stopped. </li><li><code>memory_mutex</code> - if not null, and if called from within a non-idle task, this mutex will be locked on to during the call to malloc(), otherwise interrupts will be disabled during the call to malloc() - see <a class="el" href="howdoi.html#malloc">How do I use malloc() and free() safely?</a> </li></ul><p>This function will scan through the task list in memory, looking for one that is not being used with a matching pri and a stacklen that is at least as large as that required. If it cannot find such a task, it will create a brand new one. See <a class="el" href="group__task.html#g934155282a1d689b554e90b5138e5135" title="Tasks are kept in a linked list in memory - this function reserves an "empty"...">reserve_task()</a> </div></div><p><a class="anchor" name="g6984a5336b36a4ca99682a2cf5ae044f"></a><!-- doxytag: member="task.h::disable_interrupts" ref="g6984a5336b36a4ca99682a2cf5ae044f" args="()" --><div class="memitem"><div class="memproto"> <table class="memname"> <tr> <td class="memname">interrupt_store_t disable_interrupts </td> <td>(</td> <td class="paramname"> </td> <td> ) </td> <td width="100%"></td> </tr> </table></div><div class="memdoc"><p>Disable interrupts system-wide. <p>Returns a value which is non-zero if interrupts were enabled. Can be called from anywhere. </div></div><p><a class="anchor" name="g934155282a1d689b554e90b5138e5135"></a><!-- doxytag: member="task.h::reserve_task" ref="g934155282a1d689b554e90b5138e5135" args="(uint16_t stacklen, uint8_t pri, mutex_t *memory_mutex)" --><div class="memitem"><div class="memproto"> <table class="memname"> <tr> <td class="memname"><a class="el" href="structtask__t.html">task_t</a>* reserve_task </td> <td>(</td> <td class="paramtype">uint16_t </td> <td class="paramname"> <em>stacklen</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype">uint8_t </td> <td class="paramname"> <em>pri</em>, </td> </tr> <tr> <td class="paramkey"></td> <td></td> <td class="paramtype"><a class="el" href="structmutex__t.html">mutex_t</a> * </td> <td class="paramname"> <em>memory_mutex</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>Tasks are kept in a linked list in memory - this function reserves an "empty" task on that list, ready to be subsequently utilised by a call to <a class="el" href="group__task.html#g9b849c9a0e0b29417cf47da99226dcc3" title="Create a task, ready to be run.">create_task()</a>. <p><dl class="attention" compact><dt><b>Attention:</b></dt><dd><a class="el" href="group__task.html#g934155282a1d689b554e90b5138e5135" title="Tasks are kept in a linked list in memory - this function reserves an "empty"...">reserve_task()</a> calls malloc(), and disables interrupts during the call to malloc(). Therefore, depending on the amount of time your malloc() algorithm takes, and depending on what your time margin for the launch of ISRs is, <a class="el" href="group__task.html#g934155282a1d689b554e90b5138e5135" title="Tasks are kept in a linked list in memory - this function reserves an "empty"...">reserve_task()</a> could disable interrupts for "too long". See the description of the <code>memory_mutex</code> argument, and <a class="el" href="howdoi.html#malloc">How do I use malloc() and free() safely?</a></dd></dl>The arguments are <ul><li><code>stacklen</code> - the number of bytes to reserve for the task stack. Note that it must be long enough to hold a copy of the value of all 32 registers when a task switch occurs, and it needs a couple of extra bytes to handle interrupts, function calls etc. </li><li><code>pri</code> - the priority of the task. The highest-priority available task will "hog" the CPU. If the task has a priority of zero (an "idle" task), then it may not suspend itself on a mutex, semaphore or mailbox. </li><li><code>memory_mutex</code> - if not null, and if called from within a non-idle task, this mutex will be locked on to during the call to malloc(), otherwise interrupts will be disabled during the call to malloc() - see <a class="el" href="howdoi.html#malloc">How do I use malloc() and free() safely?</a>. </li></ul></div></div><p><a class="anchor" name="gecf8a8e43c2afae89e46503ff1c887bf"></a><!-- doxytag: member="task.h::restore_interrupts" ref="gecf8a8e43c2afae89e46503ff1c887bf" args="(interrupt_store_t interrupts)" --><div class="memitem"><div class="memproto"> <table class="memname"> <tr> <td class="memname">void restore_interrupts </td> <td>(</td> <td class="paramtype">interrupt_store_t </td> <td class="paramname"> <em>interrupts</em> </td> <td> ) </td> <td width="100%"></td> </tr> </table></div><div class="memdoc"><p>Restore the state of the system-wide interrupts. <p>A non-zero argument enables interrupts. Can be called from anywhere. </div></div><p><a class="anchor" name="ge1337adc1d63d7cd874a376d6513c04a"></a><!-- doxytag: member="task.h::stop_task" ref="ge1337adc1d63d7cd874a376d6513c04a" args="(task_t *t, uint8_t wait_for_mutexes)" --><div class="memitem"><div class="memproto"> <table class="memname"> <tr> <td class="memname">int8_t stop_task </td> <td>(</td> <td class="paramtype"><a class="el" href="structtask__t.html">task_t</a> * </td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -