1 / 15

手把手教你构筑实验性实时操作系统

手把手教你构筑实验性实时操作系统. 殷德军 工学系研究科电气工程 Hori 研究室. 典型的实验性电动汽车 --COMS3. 典型的实验性电动汽车 — 系统图. Main Battery (72V). Motor. Charger. Auxiliary Battery (12V). Main Relay. Forward/Reverse Shift Switch. Select Switch. Rotation. Meter Indicator. Control Computer. ODO/Trip Select Switch. Motor

parson
Download Presentation

手把手教你构筑实验性实时操作系统

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 手把手教你构筑实验性实时操作系统 殷德军 工学系研究科电气工程 Hori研究室

  2. 典型的实验性电动汽车--COMS3

  3. 典型的实验性电动汽车—系统图 Main Battery (72V) Motor Charger Auxiliary Battery (12V) Main Relay Forward/Reverse Shift Switch Select Switch Rotation Meter Indicator Control Computer ODO/Trip Select Switch Motor Control ECU Torque Reference AD Power MOSFET Power MOSFET Vehicle Control ECU Turn Signal System Down OR Brake Lamp Switch Rotation Command Accelerator Pedal Torque Reference AD Front/Brake Lamp Relay RS232C TTL Rotation Rotation/2ms Key Switch Motor LAN Note Computer

  4. 实时操作系统的构成例 通用计算机 一级传感器群 嵌入式系统群 一级执行机构群 二级传感器群 二级执行机构群

  5. 安装标准的Linux发行版 • 安装标准的Linux发行版: • Vine Linux3.2 下载http://ftp.ecc.u-tokyo.ac.jp/VINELINUX/ • 安装建议: • 单核英特尔CPU,1GHz以上,内存1G以上。 • 安装Linux时,不要开辟磁盘交换区。 • 可以联上互联网 参考:http://www.toyota.nitech.ac.jp/~takesue/rt_ctrl/art0701.html

  6. 升级已经安装好的标准Linux发行版 • 升级已经安装好的标准Linux发行版: • # export http_proxy=“http://proxy.xxx.yyy.zzz.jp:8080”//如果是通过代理上的网,请类似这样设定。 • # apt-get update //要等几分钟 • # apt-get upgrade //要花十几分钟 • # /usr/sbin/ntsysv //如果有必要,停止不需要的服务 参考:http://www.toyota.nitech.ac.jp/~takesue/rt_ctrl/art0701.html

  7. ART-Linux的安装 • 实时Linux补丁下载: • http://sourceforge.net/projects/art-linux/ • 例如下载了配合Linux2.4.34版本的实时补丁-- ART-Linux-2.4.34-20070125.diff.bz2 • 并把这个补丁放入/usr/src目录内 • 解压缩这个补丁: • # cd /usr/src • # bunzip2 ART-Linux-2.4.34-20070125.diff.bz2 参考:http://www.toyota.nitech.ac.jp/~takesue/rt_ctrl/art0701.html

  8. 实时Linux补丁下载 • 实时Linux补丁下载: • http://sourceforge.net/projects/art-linux/ • 例如下载了对应2.4.34内核版本的Linux的实时补丁-- ART-Linux-2.4.34-20070125.diff.bz2 • 并把这个补丁放入/usr/src目录内 • 解压缩这个补丁: • # cd /usr/src • # bunzip2 ART-Linux-2.4.34-20070125.diff.bz2 //解压缩之后会得到ART-Linux-2.4.34-20070125.diff 这个文件 参考:http://www.toyota.nitech.ac.jp/~takesue/rt_ctrl/art0701.html

  9. 标准Linux内核源文件下载 • 标准Linux内核源文件下载: • http://www.kernel.org/pub/linux/kernel/v2.4/ • 例如下载了2.4.34内核版本的Linux的内核源文件-- linux-2.4.34.tar.bz2 • 并把这个补丁放入/usr/src目录内 • 解压缩这个Linux内核源文件: • # tar jxvf linux-2.4.34.tar.bz2 //解压缩后会得到linux-2.4.34这个目录 参考:http://www.toyota.nitech.ac.jp/~takesue/rt_ctrl/art0701.html

  10. 给内核源文件打补丁 # rm -f /usr/src/linux // 删除已有的连接 # cd /usr/src # ln -s linux-2.4.34 linux //建立新的连接 # cd /usr/src/linux # patch -p1 < ../ART-Linux-2.4.34-20070125.diff //给内核源文件打补丁 # cd /usr/src/linux # cp ../linux-2.4.33/configs/kernel-2.4.33-i686.config ./.config //拷贝老的源文件的编译选项 # make oldconfig //配置已经打了补丁的内核源文件的编译选项 参考:http://www.toyota.nitech.ac.jp/~takesue/rt_ctrl/art0701.html

  11. ART-Linux的选项 在输入了make oldconfig以后,会有很多内核编译选项可供选择,遇到不会的,就选默认值。 关于ART-Linux的选项有以下几个: [Symmetric multi-processing support] 选n [ART scheduler Support] 选y [ART error reporting]选n [ART monitor support]选n [Use local APIC for ART scheduling]选y [ART scheduling period in micro second] 最小核心定时时间,单位为微妙,1毫秒的话,就填写1000 # make xconfig //编译选项的确认,在这里要注意修改两个地方才能保证编译顺利完成: [General setup] => PCI Hotplug Support => PCI ACPI Hotplug选n [General setup] => ACPI Support => ACPI Support选n 参考:http://www.toyota.nitech.ac.jp/~takesue/rt_ctrl/art0701.html

  12. 编译ART-Linux内核 要花2个小时左右 # make dep # make clean # make bzImage # make modules # make modules_install # make install # cp /usr/src/linux/lib/art_syscall.o /usr/lib 参考:http://www.toyota.nitech.ac.jp/~takesue/rt_ctrl/art0701.html

  13. 编辑启动文件 • 编辑/etc/lilo.conf • 在这个文件的最后添加下面的 • image=/boot/vmlinuz-2.4.34-ART • label=art • read-only • root=/dev/hda5 //注意这个hda5是内核的安装目录,请按照vmlinuz-2.4.34所在目录填写。 • 启动文件生效: • # /sbin/lilo -D art 参考:http://www.toyota.nitech.ac.jp/~takesue/rt_ctrl/art0701.html

  14. 实验一下 重新启动机器,进入ART-Linux,用根用户登录 下载这个源文件 http://www.toyota.nitech.ac.jp/~takesue/rt_ctrl/sample04/nsample0.tgz 这个程序操作PC喇叭发出频率高低不同的声音。 解压缩: $ tar xzvf nsample0.tgz $ cd nsample0 编译: $ make 或者 $ gcc -Wall -O2 -o sample0 sample0.c /usr/lib/art_syscalls.o 执行: $ ./artsample 100 参考:http://www.toyota.nitech.ac.jp/~takesue/rt_ctrl/art0702.html

  15. 实验的源文件 1: #include <stdio.h> 2: #include <stdlib.h> 3: #include <sys/io.h> 4: #include <linux/art_task.h> 5: 6: #define TRUE 1 7: 8: #define KBD_PORT 0x61 9: #define SPK_BIT 0x02 10: 11: int main(int argc, char *argv[]) 12: { 13: int temp, hz, i; 14: 15: if (argc != 2 || (hz = atoi(argv[1])) == 0) { 16: fprintf(stderr, "usage: %s hz\n", argv[0]); 17: exit(1); 18: } 19: if (ioperm(KBD_PORT, 1, TRUE) == -1) { 20: perror("ioperm"); 21: exit(1); 22: } 23: if (art_enter(ART_PRIO_MAX, ART_TASK_PERIODIC, 500000 / hz) == -1) { 24: perror("art_enter"); 25: exit(1); 26: } 27: for (i = 0; i < hz * 5; ++i) { 27: if (art_wait() == -1) { 29: perror("art_wait"); 30: exit(1); 31: } 32: temp = inb(KBD_PORT); 33: temp = (i & 1) ? temp | SPK_BIT : temp & ~SPK_BIT; 34: outb(temp, KBD_PORT); 35: } 36: if (art_exit() == -1) { 37: perror("art_exit"); 38: exit(1); 39: } 40: return 0; 41: } 注意:第23行的“500000 / hz”,这个运算的结果就是该程序的定时周期,这个数值应该是最小核心定时时间的整数倍。 参考:http://www.toyota.nitech.ac.jp/~takesue/rt_ctrl/art0702.html

More Related