單片機(jī)操作系統(tǒng)RTX51原理分析與移植
一.課題要求:
仔細(xì)分析單片機(jī)操作系統(tǒng)RTX51的原理,將其移植到單片機(jī)實驗平臺上,并要求編寫一個簡短的程序來驗證其運(yùn)行的正確性(比如,編寫兩個具有顯示不一樣內(nèi)容的任務(wù))。
二.RTX51原理
注釋:由于英文原文會比較好,所以我沒有翻譯過來(不過也寫了部分的翻譯),直接提取出來一些英文,總結(jié)在一起。
1. 進(jìn)程管理( Task Management )
1) 進(jìn)程類型( Classes of Tasks )
RTX-51 recognizes two classes of tasks:
1. Fast tasks
n Contain especially short responses and interrupt disable times.
n Contain a separate register bank and a separate stack area (register banks 1, 2 and 3).(Figure 1)
n Contain the highest task priority (priority 3) and can therefore interrupt standard tasks.
n All contain the same priority and can therefore not be mutually interrupted.
n Can be interrupted by c51 interrupt functions.
n A maximum of three fast tasks can be active in the system.
2. Standard tasks
n Require somewhat more time for the task switching compared to fast tasks.
n Share a common register bank and a common stack area (register bank 0).
n The current contents of registers and stack are stored in the external (XDATA) memory during a task change.
n Can be interrupted by fast tasks.
n Can interrupt themselves mutually.
n Can be interrupt by c51 interrupt functions.
n A maximum 16 standard tasks can be active in the system.
Figure 3: Task Classes and Memory Allocation
每一個標(biāo)準(zhǔn)進(jìn)程都包含一個設(shè)備上下文在擴(kuò)展內(nèi)存(XDATA)中。在標(biāo)準(zhǔn)進(jìn)程執(zhí)行進(jìn)程切換的時候,會把它自己的Register和Stack存儲到對應(yīng)的設(shè)備上下文中(在擴(kuò)展內(nèi)存中的一個區(qū)域)。之后,Register和Statck又從設(shè)備上下文中重新載入,繼續(xù)執(zhí)行。(交換技術(shù))
相比而言,快速進(jìn)程則不用這么麻煩,因為它們有各自獨立的Register和Stack,所以只要激活對應(yīng)的Register(修改PSW)和指向Stack的指針(Mov SP,#XX)即可。
2) 進(jìn)程狀態(tài)(Task states)
RTX-51 recognizes four task states:
1. READY All tasks which can run are READY. One of these tasks is the RUNNING (ACTIVE)task.
2. RUNNING (ACTIVE) Task which is currently being executed bythe processor. Only one task (maximum) can be in this state at a time.
3. BLOCKED (WAITING) Task waits for an event.
4. SLEEPING All tasks which were not started or which have terminated themselves are in this state.
3) 進(jìn)程調(diào)度(Task switch)
The RTX-51 system section which the processors assigns to the individual tasks is referred to as the scheduler (also dispatcher).
The RTX_51 scheduler works according to the following rules:
1. The task with the highest priority of all tasks in the READY state is executed.
2. If several tasks of the same priority are in the READY state,the task that has been ready the longest will be the next to execute.
3. Task switchings are only executed if the first rule would have been otherwise violated (exception: round-robin scheduling).
Time-slice task change (round-robin scheduling) are executed if the following conditions are satisfied:
1. Round-robin scheduling must be enabled (see configuration).
2. The RUNNING task has the priority of 0 and is currently not executing a floating-point operation (see section "Floating-Point Operations", page 28).
3. At least one task with the priority zero must be in the READY state.
4. The last task change must have occurred after the selected system time interval (see system function "os_set_slice"). The system time interval can be changed dynamically during program execution.
4) 進(jìn)程通信和同步(Task Communication and Synchronisation)
There three two mechanisms:
1. Signal
Signals represent the simplest and fastest form of task communication. These can always be used when a pure task synchronisation is required without data exchange.
Each active task contains its own signal flag with which the following operations can be executed:
l Wait for a signal
l Send signal
l Clear signal
The task number (see section section "Task Declaration") of the receiver task is used for identifying the signals for the individual operations.
2. Message(via MailBoxes(FIFO))
n By means of the mailbox concept, messages can be exchanged free of conflicts between the individual tasks.
n RTX-51 provides a fixed number of eight mailboxes. Messages can be exchanged in words (2 bytes) via these mailboxes. In this case, a message can represent the actual data to be transferred or the identification of a data buffer(defined by the user). In comparison to the signals, mailboxes are not assigned a fixed task, but can be freely used by all tasks and interrupt functions. These are identified with a mailbox number.
Mailboxes allow the following operations:
l Send a message
l Read a message
linux操作系統(tǒng)文章專題:linux操作系統(tǒng)詳解(linux不再難懂)
評論