1 / 20

How to write a RTLinux program

How to write a RTLinux program. Real-Time System Project g916704 徐 瑩 g916303 余坤庭 g916703 吳建達. How to write a RTLinux program. 0.Introduction RTLinux 1.How To Setup RTLinux Environment 2.Write a RTLinux program. Introduction RTLinux. Introduction RTLinux.

dyre
Download Presentation

How to write a RTLinux program

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. How to write a RTLinux program Real-Time System Project g916704 徐 瑩 g916303 余坤庭 g916703 吳建達

  2. How to write a RTLinux program 0.Introduction RTLinux 1.How To Setup RTLinux Environment 2.Write a RTLinux program

  3. Introduction RTLinux

  4. Introduction RTLinux

  5. Introduction RTLinux 1.RTLinux is a hard realtime operation system. 2.Virtual Machine Layer between RTLinux Kernel and standard Linux Kernel. (Intercept all hardware interrupts) 3. Hardware interrupt RTLinux Kernel(idle)  software interruptsLinux kernel(running)

  6. Introduction RTLinux 4.RTLinux owns fixed-priority scheduler, and assigns the lowest priority to the standard Linux kernel. 5.All tasks in RTLinux: (1)direct access to hardware (2)do not use virtual memory 6.RTLinux manages to convert the existing Linux kernel into a hard realtime environment without hindering futrue Linux development.

  7. How To Setup RTLinux Environment 1.How To Setup RTLinux Environment (C:\rtlinux-3.1\doc\html\Installation\Installation.html)

  8. DownLoad and UnPack RTLinux • Download rtlinux source • Example: ftp://debella.ikk.sztaki.hu/mirrors/ftp.fsmlabs.com/pub/rtlinux/v3/ rtlinux-3.1.tar.gz • Unpack rtlinux-3.1.tar.gz • tar zxvf rtlinux-3.1.tar.gz • mv rtlinux-3.1 /usr/src/ • Check the Linux kernel version • kernel_patch-2.4.4(uname -a)

  9. Download and Unpack Linux Kernel • Download kernel source • http://www.kernel.org • Example: ftp://ftp.kernel.org/pub/linux/kernel/v2.4/linux-2.4.4.tar.bz2 • Unpack kernel source • bunzip2 linux-2.4.4.tar.bz2 • tar xvf linux-2.4.4.tar • mv linux /usr/src/

  10. Patch and Build Kernel • Patch the kernel • cd /usr/src/linux • patch –p1 < /usr/src/rtlinux-3.1/kernel_patch-2.4.4 • Build the new kernel • make config / menuconfig / xconfig • make dep • make bzImage • make modules • make modules_install • cp arch/i386/boot/bzImage /boot/rtzImage-2.4.4

  11. Modify Boot Loader Configuration • Lilo: /etc/lilo.conf • Image=/boot/vmlinuz-2.4.18-0.13(old) label=linux(old) Initrd=/boot/initrd-2.4.18-0.13.img Read-only Root=/dev/hda2 • Image=/boot/rtzImage-2.4.4(new) label=rtlinux(new) Initrd=/boot/initrd-2.4.18-0.13.img Read-only Root=/dev/hda2 Execute /sbin/lilo !!!Restart computer by typing:/sbin/shutdown –r now

  12. Compile RTLinux • Compile RTLinux • cd /usr/src/rtlinux-3.1 • make config / menuconfig / xconfig • make • make devices • make install Congratulations!

  13. How to write a RTLinux program 2.Write a RTLinux program (C:~\rtlinux-3.1\examples\hello.c)

  14. Examples – Hello.c #include <rtl.h> #include <time.h> #include <pthread.h> pthread_t thread; void * start_routine(void *arg){ struct sched_param p; p . sched_priority = 1; pthread_setschedparam (pthread_self(), SCHED_FIFO, &p); pthread_make_periodic_np (pthread_self(), gethrtime(), 500000000); while (1) { pthread_wait_np(); rtl_printf("I'm here; my arg is %x\n", (unsigned) arg); } return 0;}

  15. Hello.c(con’t) int init_module(void) { return pthread_create (&thread, NULL, start_routine, 0); } void cleanup_module(void) { pthread_cancel (thread); pthread_join (thread, NULL); }

  16. Write a RTLinux program 1.Creating RTLinux Threads 2.Cancel a Thread 3.Time Facilities 4.Scheduling Threads

  17. 1.Creating RTLinux Threads (1)A realtime application is usually composed of several ``threads'' of execution. (2)To create a new realtime thread, we use the pthread_create() function. This function must only be called from the Linux kernel thread (i.e., using init_module()): (3)#include <pthread.h> int pthread_create(pthread_t * thread, pthread_attr_t * attr, void *(*start_routine)(void *), void * arg);

  18. 2.Cancel a Thread • To cancel a thread : • pthread_cancel(pthread_t thread); pthread_join(pthread_t thread, void**thread_return) (resource deallocated) • pthread_delete_np(pthread_t thread) 1.You should join the thread in cleanup_module with pthread_join() for its resources to be deallocated. 2.You must make sure the thread is cancelled before calling pthread_join() from cleanup_module(). Otherwise, Linux will hang waiting for the thread to finish. 3.If unsure, use pthread_delete_np(3) instead of pthread_cancel()/pthread_join().

  19. Compiling and Executing ``Hello World'' In order to execute our program, we must first do the following: • Compile the source code and create a module. We can normally accomplish this by using the Linux GCC compiler directly from the command line. To simplify things, however, we'll create a Makefile. Then we'll only need to type ``make'' to compile our code. • Locate and copy the rtl.mk file. The rtl.mk file is an include file which contains all the flags needed to compile our code. For simplicity, we'll copy it from the RTLinux source tree and place it alongside of our hello.c file. • Insert the module into the running RTLinux kernel. The resulting object binary must be ``plugged in'' to the kernel, where it will be executed by RTLinux.

  20. cp /usr/include/rtlinux/rtl.mk . make -f rtl.mk hello.o <方法一> rtlinux start hello rtlinux stop hello rtlinux staus hello <方法二> modprobe -a rtl rtl_time rtl_sched rtl_posixio rtl_fifo insmod hello.o rmmod hello

More Related