Deploying to gh-pages from @ Klipper3d/klipper@a709ba43af 🚀
This commit is contained in:
@@ -1404,7 +1404,7 @@
|
||||
<h2 id="_3">微處理器的程式碼流<a class="headerlink" href="#_3" title="Permanent link">¶</a></h2>
|
||||
<p>微控制器的程式碼從對應架構的程式碼(即<strong>src/avr/main.c</strong>)開始執行,前述程式碼會持續呼叫<strong>src/sched.c</strong>中的 sched_main() 函式。sched_main() 程式碼會先執行經 DECL_INIT() 宏標註的所有函式。之後它將不斷重複執行由 DECL_TASK() 宏所標註的函式。</p>
|
||||
<p>其中一個主要的任務函式為<strong>src/command.c</strong> 中的command_dispatch()。上述函式經由微處理器特定的 輸入/輸出 程式碼呼叫(即<strong>src/avr/serial.c</strong>, <strong>src/generic/serial_irq.c</strong>),並執行輸入流中的命令所對應的命令函式。命令函式通過 DECL_COMMAND() 宏進行定義 (詳情參照<a href="Protocol.html">協議</a> 文件)。</p>
|
||||
<p>Task, init, and command functions always run with interrupts enabled (however, they can temporarily disable interrupts if needed). These functions should avoid long pauses, delays, or do work that lasts a significant time. (Long delays in these "task" functions result in scheduling jitter for other "tasks" - delays over 100us may become noticeable, delays over 500us may result in command retransmissions, delays over 100ms may result in watchdog reboots.) These functions schedule work at specific times by scheduling timers.</p>
|
||||
<p>任務”功能的長時間延遲會導致其他“任務”的調度抖動 - 超過 100us 的延遲可能會變得很明顯,超過 500us 的延遲可能會導致命令重傳,超過 100ms 的延遲可能會導致看門狗重新啟動。)這些功能將工作安排在通過安排計時器的特定時間。</p>
|
||||
<p>定時函式通過呼叫sched_add_timer() (即 <strong>src/sched.c</strong>)方法進行註冊。排程器會在設定的時間點對註冊的函式進行呼叫。定時器中斷會在微處理器架構特定的初始化處理器中處理(例如 <strong>src/avr/timer.c</strong>),該程式碼會呼叫 <strong>src/sched.c</strong>中的sched_timer_dispatch()。通過定時器中斷執行註冊的定時函式。定時函式總在中斷禁用下執行。定時函式應總能在數微秒內完成。在定時函式結束時,該函式可對自身進行重新定時。</p>
|
||||
<p>如果事件中拋出錯誤, 程式碼可呼叫shutdown()(<strong>src/sched.c</strong>中的sched_shutdown())。呼叫shutdown()會導致所有標記為DECL_SHUTDOWN()宏的函式被執行。shutdown()總是在禁用中斷的情況下執行。</p>
|
||||
<p>微控制器的大部分功能涉及到通用輸入輸出引腳(GPIO)的操作。爲了從高級任務程式碼中抽像出特定架構底層程式碼,所有的GPIO事件都在特定架構的包裝器中實現(如,<strong>src/avr/gpio.c</strong>)。程式碼使用gcc的"-flto -fwhole-program "來優化編譯,以實現行內函數的高效能交叉編譯,大多數微小的GPIO操作函式內聯到它們的呼叫器中,使用這些GPIO將沒有任何執行時成本。</p>
|
||||
|
||||
Reference in New Issue
Block a user