新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 单片机操作系统RTX51原理分析与移植

单片机操作系统RTX51原理分析与移植

作者: 时间:2013-01-07 来源:网络 收藏

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. 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. 动态内存管理

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-51 in this area (see system function "os_create_pool").

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. 时间管理

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)函数纵览(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)

三.移植

本试验是用的RTX的Tiny版本。也就是说没有优先级之分,没有邮箱机制,没有动态内存的管理。移植它很简单,就是配置一下它带的配置文件,然后和写好的程序一起编译连接,连接的时候加一个rtxtny参数,意思是说当我连接的时候,我把RTXtiny的库文件连接上,也就等于是程序和编译在一起了。该配置文件能在安装目的rtxtiny2底下找到。文件名称为Conf_tny.A51,例如,在我的电脑中,路径为:D:Keilc语言RtxTiny2SourceCode Conf_tny.A51。如下图所示:

linux操作系统文章专题:linux操作系统详解(linux不再难懂)


评论


相关推荐

技术专区

关闭