Linux嵌入式实时操作系统开发与应用 By杨立峰 Copyright2002杨立峰
I Linux 嵌入式实时操作系统开发与应用 By 杨立峰 Copyright 2002 杨立峰
Abstract In the fast-changing world of science and technology.Appeared information appliances,handheld and wireless devices.There are many hardware and software design changes taking place.Many devices now feature 32-bit microprocessors from Intel,MIPS and Motorola,as well as larger LCD graphical displays.In order to leverage the significant results gained in the last ten years,many developers are turning to using friendly user interface operating systems with these new embedded designs. One of the most promising emerging areas seems to be running Linux in these environments,for a couple of good reasons:Linux on embedded systems brings with it the entire power of desktop computing,along with many solutions already running.Linux,being open source,allows any aspect of the solution to be fully understood and then customized for a particular application. Linux also supports all the new microprocessors typically included in embedded designs,including StrongARM,MIPS and PowerPC.Finally,Linux is free,with no royalty payments required for its use.So using Linux as operating system,with a GUI system built on,seems to be a good solution. For the handled devices on the market such as PDA,as to the poor hardware in old days,the function was very simple;we could hardly see the GUI and network support.But recently we found that some embedded operating systems such as Windows CE and Palm OS,have supported complete GUI features.With the great performance improvement of the hardware,we think that the need for embedded OS is urgent. I got interest with Linux operating system several years ago. Combination my specialty,Then I did some research for real-time Linux. Based on these facts,this thesis demonstrates architecture and internals of Linux system used on embedded systems. At first,the thesis outlines the history of embedded systems and real-time systems.Chapter 2 describes related research in area of real-time Linux systems.Chapter 3 details the design and implementation of real-time Linux. Chapter 4 contain a discussion of the application model of real-time Linux.The measurements results of real-time Linux performance can be found in Chapter 5.The last chapter gives some conclusion and foresight. Keywords:Real Time System;Embedded System;RTLinux;Linux Ⅲ
III Abstract In the fast-changing world of science and technology. Appeared information appliances, handheld and wireless devices. There are many hardware and software design changes taking place. Many devices now feature 32-bit microprocessors from Intel, MIPS and Motorola, as well as larger LCD graphical displays. In order to leverage the significant results gained in the last ten years, many developers are turning to using friendly user interface operating systems with these new embedded designs. One of the most promising emerging areas seems to be running Linux in these environments, for a couple of good reasons: Linux on embedded systems brings with it the entire power of desktop computing, along with many solutions already running. Linux, being open source, allows any aspect of the solution to be fully understood and then customized for a particular application. Linux also supports all the new microprocessors typically included in embedded designs, including StrongARM, MIPS and PowerPC. Finally, Linux is free, with no royalty payments required for its use. So using Linux as operating system , with a GUI system built on, seems to be a good solution. For the handled devices on the market such as PDA, as to the poor hardware in old days, the function was very simple; we could hardly see the GUI and network support. But recently we found that some embedded operating systems such as Windows CE and Palm OS, have supported complete GUI features. With the great performance improvement of the hardware, we think that the need for embedded OS is urgent. I got interest with Linux operating system several years ago. Combination my specialty, Then I did some research for real-time Linux. Based on these facts, this thesis demonstrates architecture and internals of Linux system used on embedded systems. At first, the thesis outlines the history of embedded systems and real-time systems. Chapter 2 describes related research in area of real-time Linux systems. Chapter 3 details the design and implementation of real-time Linux. Chapter 4 contain a discussion of the application model of real-time Linux. The measurements results of real-time Linux performance can be found in Chapter 5. The last chapter gives some conclusion and foresight. Keywords: Real Time System; Embedded System; RTLinux; Linux
摘 要 伴随着科技不断的日新月异推陈出新。信息家电,手持设备,无线设 备等个性化设备的出现,相应的硬件和软件的迅速发展。许多设备都配有 Intel,MIPS,摩托罗拉等公司生产的32位微处理器。许多开发商也开始 为这些设备提供嵌入式操作系统。嵌入式系统与实时系统将会有越来越重 要作用。 利用Liux搭建嵌入式操作系统是近年来出现的最令人振奋的方案。 这有多方面的原因。首先,运行在嵌入式系统上的Liuⅸ能够提供全功能 的桌面计算(Desktop Computing),且由于其开放代码,定制变得非常方 便。其次,Liux已经支持大多数嵌入式系统上使用的芯片,包括 StrongARM,MIPS和PowerPC。最后,Linux是免费的,使用Linux不 需要付出任何费用。现今风行世界的Liux操作系统,本着开放自由的精 神,吸引了全世界的目光,越来越多的程序员加入到它的行列中来。所以 利用Liux作为底层操作系统,在其上进行实时化改造,建立一个具有实 时应用能力的操作系统是现在日益流行的嵌入式操作系统的解决方案。 市场上常见的PDA等小型手持式设备上,以前由于硬件条件等的限 制,我们看到功能都非常简单,没有网络、GUI等非常实用方便的功能。 但最近出现的Palm等手持式电脑或者在Windows CE等面向嵌入式系 统的操作系统上,我们已经看到了完整的网络、图形用户界面支持。随着 手持式设备的硬件条件的提高,估计嵌入式系统对嵌入式操作系统的需求 会越来越迫切。 本人长期以来对Liux操作系统比较感兴趣,并结合本专业,对Linuⅸ 应用于嵌入式实时环境进行了一定的研究。本论文基于这些事实,对面向 嵌入式实时环境的Liuⅸ系统的体系结构和一些技术内幕做了较深入的 探讨。 论文首先概述了嵌入式系统及实时系统的发展情况。第二章介绍了在 实时Linux领域的相关研究。第三章介绍了典型的实时系统RTLinux的设 计与实现,第四章介绍了RTLinux的编程模型和一些应用实例。本文的第 五章将对RTLinux的性能进行测试评估。最后是一点感想和展望。 关键词: Linux;RTLinux; 实时系统:嵌入式系统。 IV
IV 摘 要 伴随着科技不断的日新月异推陈出新。信息家电,手持设备,无线设 备等个性化设备的出现,相应的硬件和软件的迅速发展。许多设备都配有 Intel,MIPS,摩托罗拉等公司生产的 32 位微处理器。许多开发商也开始 为这些设备提供嵌入式操作系统。嵌入式系统与实时系统将会有越来越重 要作用。 利用 Linux 搭建嵌入式操作系统是近年来出现的最令人振奋的方案。 这有多方面的原因。首先,运行在嵌入式系统上的 Linux 能够提供全功能 的桌面计算(Desktop Computing),且由于其开放代码,定制变得非常方 便。其次,Linux 已经支持大多数嵌入式系统上使用的芯片,包括 StrongARM , MIPS 和 PowerPC。最后,Linux 是免费的,使用 Linux 不 需要付出任何费用。现今风行世界的 Linux 操作系统,本着开放自由的精 神,吸引了全世界的目光,越来越多的程序员加入到它的行列中来。所以 利用 Linux 作为底层操作系统, 在其上进行实时化改造,建立一个具有实 时应用能力的操作系统是现在日益流行的嵌入式操作系统的解决方案。 市场上常见的 PDA 等小型手持式设备上,以前由于硬件条件等的限 制,我们看到功能都非常简单,没有网络、GUI 等非常实用方便的功能。 但最近出现的 Palm 等手持式电脑或者在 Windows CE 等面向嵌入式系 统的操作系统上,我们已经看到了完整的网络、图形用户界面支持。随着 手持式设备的硬件条件的提高,估计嵌入式系统对嵌入式操作系统的需求 会越来越迫切。 本人长期以来对 Linux 操作系统比较感兴趣,并结合本专业,对 Linux 应用于嵌入式实时环境进行了一定的研究。本论文基于这些事实,对面向 嵌入式实时环境的 Linux 系统的体系结构和一些技术内幕做了较深入的 探讨。 论文首先概述了嵌入式系统及实时系统的发展情况。第二章介绍了在 实时 Linux 领域的相关研究。第三章介绍了典型的实时系统 RTLinux 的设 计与实现,第四章介绍了 RTLinux 的编程模型和一些应用实例。本文的第 五章将对 RTLinux 的性能进行测试评估。最后是一点感想和展望。 关键词: Linux; RTLinux; 实时系统; 嵌入式系统
目录 ABSTRACT.... 摘要… 目录… 图表及程序目录… 缩略语… VI 第一章嵌入式实时系统概况… 1.1嵌入式系统概况 1.1.1嵌入式技术的历史发展 1.1.2嵌入式系统的技术特点和应用前景 1.1.3典型的嵌入式系统 1.2实时系统概况 4 1.2.1什么是实时系统 1.2.2实时操作系统的特点 第二章实时系统的相关研究, .6 2.1LNUX的分时特性 ..6 2.2LNUX的性能测试, …8 2.2.1中断延迟测试… 8 2.2.2上下文切换测试 .11 2.3当前的实时操作系统 12 第三章嵌入式实时LINUX系统RTLINUX的设计与实现… .16 3.1 RTLINUX的结构 6 3.2中断模拟. 17 3.3实时任务 .19 3.3.1实时线程数据结构 .20 3.3.2创建线程和线程调度 .21 3.4实时调度 21 3.4.1实现的调度器 2 3.4.2设计用户自己的调度器 .22 3.5计时.… 22
V 目 录 ABSTRACT................................................................................................................ I 摘 要........................................................................................................................ II 目 录.......................................................................................................................III 图表及程序目录 ........................................................................................................V 缩略语....................................................................................................................... VI 第一章 嵌入式实时系统概况.................................................................................1 1.1 嵌入式系统概况..........................................................................................1 1.1.1 嵌入式技术的历史发展 .......................................................................1 1.1.2 嵌入式系统的技术特点和应用前景...................................................2 1.1.3 典型的嵌入式系统................................................................................3 1.2 实时系统概况..............................................................................................4 1.2.1 什么是实时系统....................................................................................4 1.2.2 实时操作系统的特点 ...........................................................................4 第二章 实时系统的相关研究.................................................................................6 2.1 LINUX 的分时特性....................................................................................6 2.2 LINUX 的性能测试....................................................................................8 2.2.1 中断延迟测试........................................................................................8 2.2.2 上下文切换测试..................................................................................11 2.3 当前的实时操作系统 ...............................................................................12 第三章 嵌入式实时 LINUX 系统 RTLINUX 的设计与实现...........................16 3.1 RTLINUX 的结构.....................................................................................16 3.2 中断模拟....................................................................................................17 3.3 实时任务....................................................................................................19 3.3.1 实时线程数据结构..............................................................................20 3.3.2 创建线程和线程调度 .........................................................................21 3.4 实时调度....................................................................................................21 3.4.1 实现的调度器......................................................................................21 3.4.2 设计用户自己的调度器 .....................................................................22 3.5 计时............................................................................................................22
3.5.1时间相关函数 23 3.6进程间通信 23 3.6.1F1F0设备 .23 3.6.2共享内存 24 3.6.3mbf驱动程序 25 第四章RTLINUX应用程序设计. .26 4.1 程序结构 26 4.2基本API 26 4.2.1POSX线程创建函数 26 4.2.2时间相关函数 28 4.2.3线程调度函数 29 4.3编程示例. 30 4.31实时部分 30 4.3.2非实时部分 .34 4.3.3编译和运行程序 35 第五章RTLINUX的性能测试. .37 第六章感想与体会 38 参考文献 .40 致谢… .42 附绿A …43 附录B 59 VI
VI 3.5.1 时间相关函数......................................................................................23 3.6 进程间通信................................................................................................23 3.6.1 FIFO 设备............................................................................................23 3.6.2 共享内存..............................................................................................24 3.6.3 mbuff 驱动程序....................................................................................25 第四章 RTLINUX 应用程序设计........................................................................26 4.1 程序结构....................................................................................................26 4.2 基本 API ....................................................................................................26 4.2.1 POSIX 线程创建函数 .........................................................................26 4.2.2 时间相关函数......................................................................................28 4.2.3 线程调度函数......................................................................................29 4.3 编程示例....................................................................................................30 4.3.1 实时部分..............................................................................................30 4.3.2 非实时部分..........................................................................................34 4.3.3 编译和运行程序..................................................................................35 第五章 RTLINUX 的性能测试............................................................................37 第六章 感想与体会 ...............................................................................................38 参考文献....................................................................................................................40 致 谢..........................................................................................................................42 附录 A........................................................................................................................43 附录 B ........................................................................................................................59