單片機(jī)操作系統(tǒng)RTX51原理分析與移植
Each mailbox is internally consists of three wait lists.(Figure 2)
Figure 2
1. Message list
List of the messages written in the mailbox. These comprise a maximum of eight messages.
2. Write wait list
Wait list for tasks which want to write a message in the message list of the mailbox (maximum 16 tasks).
3. Read wait list
Wait list for tasks which want to read a message from the message list of the mailbox (maximum 16 tasks).
3. Semaphore
n By means of the semaphore concept, resources can be shared free of conflicts between the individual tasks.
n A semaphore contains a token that your code acquires to continue execution. If the resource is already in use, the requesting task is blocked until the token is returned to the semaphore by its current owner.
n There are two types of semaphores: binary semaphores and counting semaphores. As its name implies, a binary semaphore can only take two values: zero or one (token is in or out). A counting semaphore, however, allows values between zero and 65535.
RTX-51 provides a fixed number of eight semaphores of the binary type.
Semaphores allow the following operations:
l Wait for token
l Return (send) token
2. 中斷管理
RTX-51 performs task synchronisation for external events by means of the interrupt system.
Two types of interrupt processing are basically supported in this case:
1. 單片機(jī)c語言 Interrupt Functions (Interrupt are processed by c51 interrupt funcions)
l Very sudden, periodically occurring interrupts without large coupling with the rest of the system (only infrequent communication with RTX-51 tasks, etc.).
l Very important interrupts which must be served immediately independent of the current system state.
2. Task Interrupts(Interrupt are processed by fast or standard tasks of RTX-51
l Fast Task Interrupts
Important or periodic interrupts which must heavily communicate with the rest of the system when they occur.
l Standard Task Interrupts
Only seldom occurring interrupts which must not be served immediately.
RTX-51 shows considerable different response times for fast and standard tasks.
u The INTERRUPT ENABLE registers of the 8051 are managed by RTX-51 and must not be directly manipulated by the user!
u The Interrupt Priority registers of the 8051 (not to be confused with the softwaretask priorities) are not influenced by RTX-51.
3. 動(dòng)態(tài)內(nèi)存管理
RTX-51 uses a simple and effective algorithm, which functions with memory blocks of a fixed size. All memory blocks of the same size are managed in a socalled memory pool. A maximum of 16 memory pools each a different block size can be defined. A maximum of 255 memory blocks can be managed in each pool.
n Generate Memory Pool
The application can generate a maximum of 16 memory pools with various block sizes. The application must provide an XDATA area for this purpose. The pool is stored and managed by RTX
n Request Memory Block from Pool
As soon as a pool has been generated, the application can request memory
blocks. The individual pools are identified by their block size in this case.
If an additional block is still free in the pool, RTX-51 supplies the start address
of this block to the application. If no block is free, a null pointer is returned (see
system function "os_get_block").
n Return Memory Block to Pool
If the application no longer needs a requested memory block, it can be returned
to the pool for additional use (see system function "os_free_block").
4. 時(shí)間管理
RTX-51 maintains an internal time counter, which measures the relative time passed since system start. The physical source of this time base is a hardware timer that generates an interrupt periodically. The time passed between these interrupts is called a system time slice or a system tick.
This time base is used to support time dependent services, such as pause or timeout on a task wait.
Three time-related functions are supported:
n Set system time slice
The period between the interrupts of the system timer sets the "granularity" of the time base. The length of this period, also called a time slice, can be set by the application in a wide range (see system function "os_set_slice").
n Delay a task
A task may be delayed for a selectable number of time slices. Upon calling this system function the task will be blocked (sleep) until the specified number of system ticks has passed (see system function "os_wait").
n Cyclic task activation
For many real-time applications it is a requirement to do something on a regular basis. A periodic task activation can be achieved by the RTX interval wait function (see system function "os_wait"). The amount of time spent between two execution periods of the same task is controlled, using os_wait, and is measured in number of system ticks and may be set by the application.
5. RTX(FULL)函數(shù)縱覽(Functions Overview)
Initialize and Start the System:
os_start_system (task_number)
Task Management:
os_create_task (task_number)
os_delete_task (task_number)
os_ running_task_id ()
Interrupt Management:
os_attach_interrupt (interrupt)
os_detach_interrupt (interrupt)
os_enable_isr (interrupt)
os_disable_isr (interrupt)
os_wait (event_selector, timeout, 0)
oi_set_int_masks (ien0, ien1, ien2)
oi_reset_int_masks (ien0, ien1, ien2)
Signal Functions:
os_send_signal (task_number)
os_wait (event_selector, timeout, 0)
os_clear_signal (task_number)
isr_send_signal (task_number)
Message Functions:
os_send_message (mailbox, message, timeout)
os_wait (event_selector, timeout, *message)
isr_send_message (mailbox, message)
isr_recv_message (mailbox, *message)
Semaphore Functions:
os_send_token (semaphore)
os_wait (event_selector, timeout, 0)
Dynamic Memory Management:
os_create_pool (block_size, *memory, mem_size)
os_get_block (block_size)
os_free_block (block_size, *block)
Functions with the System Clock:
os_set_slice (timeslice)
os_wait (event_selector, timeout, 0)
Debug Functions:
os_check_tasks (*table)
os_check_task (task_number, *table)
os_check_mailboxes (*table)
os_check_mailbox (mailbox, *table)
os_check_semaphores (*table)
os_check_semaphore (semaphore, *table)
os_check_pool (block_size, *table)
三.RTX51移植
本試驗(yàn)是用的RTX的Tiny版本。也就是說沒有優(yōu)先級(jí)之分,沒有郵箱機(jī)制,沒有動(dòng)態(tài)內(nèi)存的管理。移植它很簡單,就是配置一下它帶的配置文件,然后和寫好的程序一起編譯連接,連接的時(shí)候加一個(gè)rtxtny參數(shù),意思是說當(dāng)我連接的時(shí)候,我把RTXtiny的庫文件連接上,也就等于是程序和操作系統(tǒng)編譯在一起了。該配置文件能在安裝目的rtxtiny2底下找到。文件名稱為Conf_tny.A51,例如,在我的電腦中,路徑為:D:Keil單片機(jī)c語言RtxTiny2SourceCode Conf_tny.A51。如下圖所示:
linux操作系統(tǒng)文章專題:linux操作系統(tǒng)詳解(linux不再難懂)
評(píng)論