0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看威廉希尔官方网站 视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

如何将单片机操作系统RTX51移植到单片机实验平台

Wildesbeast 来源:单片机教程网 作者:单片机教程网 2020-09-26 11:07 次阅读

RTX51原理注释:由于英文原文会比较好,所以我没有翻译过来(不过也写了部分的翻译),直接提取出来一些英文,总结在一起。

1. 进程管理( Task Management )

1) 进程类型( 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.

每一个标准进程都包含一个设备上下文在扩展内存(XDATA)中。在标准进程执行进程切换的时候,会把它自己的Register和Stack存储到对应的设备上下文中(在扩展内存中的一个区域)。之后,Register和Statck又从设备上下文中重新载入,继续执行。(交换威廉希尔官方网站 )

相比而言,快速进程则不用这么麻烦,因为它们有各自独立的Register和Stack,所以只要激活对应的Register(修改PSW)和指向Stack的指针(Mov SP,#XX)即可。

2) 进程状态(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) 进程调度(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) 进程通信和同步(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

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)

三.RTX51移植

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

由于试验箱里面的芯片是AT89C51,所以要配置Conf_tny.A51的RAMTOP EQU 07F,目的是说配置内部RAM为128字节。

四.源程序代码

源程序代码如下,说明请看代码里面的注释。

/*

** RTX-51的移植

** 移植到AT89S52

** 此程序是循环花样显示LED灯

** 有三个显示样式,分别对应下面的三个进程

** 下面的算法中用到了“时间到空间”的转换,使得算法简化不少

** 此程序我已在最小系统板上试验通过。

*/

#include 《reg51.h》

#include 《rtx51tny.h》

const unsigned char table[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80

,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0xFF,0x00};

/*时间到空间的转换,如果table是:

const unsigned char table[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};

则算法和代码会多出一倍来。table数组虽然增加了一倍,算法也随之减少了一半,

好处当然不止在这里体现,下面的进程2也减少了一半*/

//进程0 左-》右-》左

void LED0 (void) _task_ 0

{

int i;

os_create_task(1);//创建进程1

os_create_task(2);//创建进程2

while(1)

{

for (i = 0; i 《 15; i++)

{

P1 = table[i];

os_wait(K_TMO,30,0);//等待30*10000微妙 = 0.3秒

}

os_send_signal(1); //发送Signal信号,激活进程1

os_wait(K_SIG,0,0); //等待信号

}

}

//进程1 全亮-》全灭-》全亮

void LED1 (void) _task_ 1

{

int i;

while(1)

{

os_wait(K_SIG,0,0);

for (i = 0; i 《 3; i++)

{

P1 = table[15]; //全亮

os_wait(K_TMO,30,0);

P1 = table[16]; //全灭

os_wait(K_TMO,30,0);

}

os_send_signal(2);

}

}

//进程2 两边-》中间中间-》两边

void LED2 (void) _task_ 2

{

int i;

while(1)

{

os_wait(K_SIG,0,0);

for (i = 0; i 《 8; i++)

{

P1 = table[i] | table[i+7]; //由于table长度多一倍,省去了一个循环,而且算法也简化了。

os_wait(K_TMO,30,0);

}

os_send_signal(0);

}

}

五.总结:

本试验用的RTX 的Tiny 版本。许多比较高级的功能没有去实现。目的主要是理解RTX的原理,然后移植它到某个单片机上面,编写个小程序来测试一下。通过阅读RTX附带的英文文档,我对此操作系统有了深刻的认识,感到此操作系统有很多优点,也有很多不足的地方。比如支持的任务较少,不过由于是单片机,“承受”能力也有限,也能理解。总的来说,对于单片机来说是个不错的操作系统。

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 单片机
    +关注

    关注

    6037

    文章

    44558

    浏览量

    635258
  • RAM
    RAM
    +关注

    关注

    8

    文章

    1368

    浏览量

    114686
  • 内存
    +关注

    关注

    8

    文章

    3025

    浏览量

    74043
收藏 人收藏

    评论

    相关推荐

    多任务实时操作系统RTX51 Tiny的概念和应用问题探究

    多任务实时操作系统,可用来设计具有实时性要求的多任务软件。 RTx51有2个版本:RTX51 Tiny和RTX51 Full。RTX51 T
    的头像 发表于 09-03 17:48 5501次阅读
    多任务实时<b class='flag-5'>操作系统</b><b class='flag-5'>RTX51</b> Tiny的概念和应用问题探究

    基于RTX51的多功能电子钟

    基于51单片机的实时操作系统RTX51编写的多功能电子钟,有电子钟、时间可调、温度测量、串口通信、方波发生器(频率可调)等功能。内含完整Keil工程代码和proteus仿真文件。实物本
    发表于 07-25 12:47

    RTX51 Tiny内核应用中有什么常见问题?

    多任务实时操作系统,可用来设计具有实时性要求的多任务软件。RTx51有2个版本:RTX51 Tiny和RTX51 Full。RTX51 Ti
    发表于 09-20 08:17

    如何将FreeRTOS实时操作系统移植STM32单片机

    前言本文主要讲解如何将FreeRTOS实时操作系统移植STM32单片机中,在本文之前已经基于MDK集成开发环境
    发表于 01-11 08:15

    基于RTX51单片机软件设计

    随着单片机应用的日益广泛,对它的软件开发效率要求越来越高,从汇编到C 语言,然后过渡到了操作系统。MCS51 作为单片机世界的长生不衰的主力军,应用于其上的
    发表于 04-16 11:02 122次下载

    基于RTX51单片机软件设计

    随着单片机应用的日益广泛,对它的软件开发效率要求越来越高,从汇编到C 语言,然后过渡到了操作系统。MCS51 作为单片机世界的长生不衰的主力军,应用于其上的
    发表于 05-14 16:01 41次下载

    RTX-51实时操作系统

    RTX-51 实时操作系统,最基本的单片机系统资料
    发表于 01-13 11:48 38次下载

    51单片机多任务操作系统的原理与实现

    51单片机多任务操作系统的原理与实现,在51单片机上模拟操作系统
    发表于 02-28 15:09 16次下载

    怎么样把51单片机的程序移植AVR单片机

    讲解如何把51单片机的程序移植AVR单片机
    的头像 发表于 07-10 04:18 6918次阅读
    怎么样把<b class='flag-5'>51</b><b class='flag-5'>单片机</b>的程序<b class='flag-5'>移植</b><b class='flag-5'>到</b>AVR<b class='flag-5'>单片机</b>中

    使用RTX51进行单片机软件设计的资料说明

    很多单片机的应用中都需要同时执行很多任务。对于这样的应用,我们可以利用实时操作系统来灵活地安排系统资源。RTX51 是德国 Keil公司开发的一种应用于MCS
    发表于 09-03 17:28 5次下载
    使用<b class='flag-5'>RTX51</b>进行<b class='flag-5'>单片机</b>软件设计的资料说明

    使用C51单片机和Proteus仿真进行的RTX51操作系统应用实例资料说明

    本文档的主要内容详细介绍的是使用C51单片机和Proteus仿真进行的RTX51操作系统应用实例资料说明。
    发表于 05-20 08:00 8次下载
    使用C<b class='flag-5'>51</b><b class='flag-5'>单片机</b>和Proteus仿真进行的<b class='flag-5'>RTX51</b><b class='flag-5'>操作系统</b>应用实例资料说明

    51单片机多线程神器:Tiny-51操作系统

    给STC89C52RC单片机移植RTX-Tiny操作系统,简单爆,B格拉满了,好吧?
    发表于 11-11 20:51 59次下载
    <b class='flag-5'>51</b><b class='flag-5'>单片机</b>多线程神器:Tiny-<b class='flag-5'>51</b><b class='flag-5'>操作系统</b>

    华大单片机移植RTThread操作系统

    华大单片机移植RTThread-国产操作系统文章目录华大单片机移植RTThread-国产操作系统
    发表于 11-17 17:21 53次下载
    华大<b class='flag-5'>单片机</b><b class='flag-5'>移植</b>RTThread<b class='flag-5'>操作系统</b>

    C51单片机与实时系统RTX51(Tiny / Full)

    C51单片机与实时系统RTX51(Tiny / Full)
    发表于 11-18 14:51 50次下载
    C<b class='flag-5'>51</b><b class='flag-5'>单片机</b>与实时<b class='flag-5'>系统</b><b class='flag-5'>RTX51</b>(Tiny / Full)

    如何将FreeRTOS移植STM32单片机

    本文详细介绍如何移植FreeRTOSSTM32单片机上。移植操作系统是嵌入式开发的入门基础,单片机
    的头像 发表于 01-20 17:36 3382次阅读
    <b class='flag-5'>如何将</b>FreeRTOS<b class='flag-5'>移植</b><b class='flag-5'>到</b>STM32<b class='flag-5'>单片机</b>上