Diploma Thesis RTAI Networking Mailboxes
Total Page:16
File Type:pdf, Size:1020Kb
Diploma Thesis RTAI Networking Mailboxes Víctor Rafael Escobar Olmos Submitted on 10.08.2011 Institut I2AR Hochschule Emden / Leer Faculty of engineering Course of studies Computer Software Engineering Diploma Thesis Topic of Diploma Thesis: Create an API to communicate nodes from Real Time tasks, using the user network libraries. Presented by: Name, first name Birthday: in: Escobar Olmos, Víctor Rafael (5025774) 18.11.1986 Barcelona Examiner: Prof. Dr. Uwe Schmidtmann Second examiner: Dipl. Ing. Matthias Wermann Start date: 01.06.2010 Submission deadline: 10.08.2011 The work was the examination board or a person entitled filed in: E R K L Ä R U N G (Official statement) Soweit meine Rechte berührt sind, erkläre ich mich einverstanden, dass die Diploma Thesis Angehörigen der Hochschule Emden / Leer für Studium / Lehre / Forschung uneingeschränkt zugänglich gemacht werden kann. E I D E S S T A T T L I C H E E R K L Ä R U N G (Affidavit) Hiermit erkläre ich an Eides statt, dass ich die vorliegende Diploma Thesis bis auf die of- fizielle Betreuung selbst und ohne fremde Hilfe angefertigt habe und die benutzten Quellen und Hilfsmittel vollständig angegeben sind. Datum, Unterschrift (Víctor Rafael Escobar Olmos) Prüfungskommissionssitzung vom 14. März 2008 Beschluss: 140408/3 5 : 0 : 0 Abstract The task was to design and implement a mailbox system with a public API for Real Time Linux Tasks, using only the user net- work functions for compatibility with the unsupported natively network cards for the Real Time Linux. Extracte La tasca va consistir en dissenyar i implementar un sistema de bústies de correu amb una API pública per a tasques de Real Time Linux, utilitzant només les funcions de xarxa d’usuari per a la compatibilitat amb les targetes de xarxa no suportades nativament per Real Time Linux. Keywords (paraules clau): RTAI, Linux, real time application interface, real time computing, programming in real-time environment, real-time communication, real-time mailboxes. Acknowledgements My sincere thanks to Dipl. Ing. Wermann, Prof. Dr. Schmidtmann and Prof. Dr. Tomaschewski the given chance of working on this project. I am also grateful for the daily support and all the funny moments that I had at the labora- tories E13 and E14 with my colleagues: Jeffrey, Carlos, Kevin, Patrick and the coffee machine. A special thank to Antonio, who gave more help than I could expect from a friend. Finally, a last thank to my family. Contents Contents 1 Introduction 1 1.1 Objectives and justification . .1 2 Basic Information 2 2.1 Used Technology . .2 2.1.1 Real Time Linux and Real Time API Interface . .2 2.2 Technology and software used . .2 3 Analysis and specification 3 3.1 General Description . .3 3.1.1 Glossary and definitions . .3 3.1.2 Project Overview . .4 3.1.3 Project Features and requirements . .4 3.2 Restrictions . .4 3.2.1 Hardware restrictions . .4 3.2.2 Customer restrictions . .5 3.2.3 Software restrictions . .6 3.3 Assumptions and dependencies . .7 4 Design and Solutions 9 4.1 Design decisions . .9 4.2 Software Components based on classes . .9 4.3 Static Vision . 11 4.3.1 Use Cases . 11 4.4 Dynamic Vision . 13 4.4.1 Sequence diagrams . 13 5 Implementation 28 5.1 Previous considerations about the implementation . 28 5.1.1 C Programming language . 28 5.1.2 Coding style . 28 5.1.3 Note about why are a lot of pointers to pointers . 29 5.1.4 Messages and buffers . 31 5.2 Implementation decisions . 32 5.2.1 The Real Time FIFOs and FIFO Handlers . 32 5.2.2 The Internet protocol . 33 5.2.3 Concurrency . 34 5.2.4 Data structures . 36 5.3 Software Components and Classes . 37 5.3.1 Queue . 37 5.3.2 LinuxThread Structure (LTS) . 37 5.3.3 Operation Table (optab) . 38 i Contents 5.3.4 Name IP Table (NIT) . 40 5.3.5 Local Name Table (LNT) . 40 5.3.6 Net Name Table (NNT) . 41 5.4 Macros like functions and customization of some options . 41 5.4.1 Macros like functions . 42 5.4.2 Customization of some options . 42 6 Testing 44 6.1 Tests . 44 6.1.1 Individual testing . 44 6.1.2 Global testing . 44 6.2 Issues and bugs found . 45 Unexpected hang up for segmentation fault: . 45 An Internet packet lost: . 45 Three nodes hangs up at time to load the module: . 45 7 Instalation and User Manual 46 7.1 Installation process . 46 7.1.1 Dependences . 46 7.1.2 Building the rt_net_mbx binaries . 46 7.2 Execution of the program . 47 7.2.1 Load the kernel module . 47 7.2.2 The daemon, the arguments and the configuration file . 48 7.2.3 Load an End User Kernel Module . 49 7.3 How to make an End User Module . 49 7.3.1 Compile a Module . 49 7.3.2 Example of an End User Module . 50 7.3.3 How to load the Module . 55 8 Conclusions 56 9 Bibliography 58 10 Appendix 59 10.1 Public API . 59 10.1.1 Previous considerations . 59 10.1.2 Functions . 59 ii List of Figures List of Figures 1 Original purposed communication map . .5 2 Communication map . .8 3 Sequence diagram: rt_net_mbx_create . 14 4 Sequence diagram: NNT adding a Mailbox . 15 5 Sequence diagram: rt_net_mbx_send the mailbox is on the local node . 16 6 Sequence diagram: rt_net_mbx_send the mailbox does not exist . 17 7 Sequence diagram: rt_net_mbx_send the mailbox exist on a remote node, lo- cal node at kernel space . 18 8 Sequence diagram: rt_net_mbx_send the mailbox exist on a remote node, lo- cal node at user space . 19 9 Sequence diagram: rt_net_mbx_send the mailbox exist on a remote node, re- mote node at user space . 20 10 Sequence diagram: rt_net_mbx_send the mailbox exist on a remote node, re- mote node at kernel space . 21 11 Sequence diagram: rt_net_mbx_exist . 23 12 Sequence diagram: rt_net_mbx_receive . 24 13 Sequence diagram: rt_net_mbx_delete . 26 14 Sequence diagram: NNT deleting a Mailbox . 27 15 Stack when an external initialization has been bad. 30 16 Stack when an external initialization has been good. 31 iii Source codes Source codes 1 Class Queue . 29 2 Kernighan&Ritchie/Kernel code style . 29 3 Basic code style . 29 4 How should not be initialized a variable inside an external function . 30 5 How should be initialized a variable inside an external function . 31 6 Example of buffer to send a message over the network . 31 7 FIFO Handler creation for a RT Task . 33 8 Create a thread and wait for it using the LTS . 38 9 Makefile . 46 10 Check if the RTAI module was previously loaded. 48 11 Load the rtainetd daemon. 48 12 Example of configuration file . 49 13 Example of Makefile for an external module . 49 14 Example of end user module . 50 iv 1 INTRODUCTION 1 Introduction 1.1 Objectives and justification The objective of this project is to design and implement a software solution for the Real Time Linux computers connected to the MPS System made by Festo Didactic GmbH1 placed in the the laboratory for distributed operating systems and applications of the Hochschule Em- den/Leer 2. The MPS System is a flexible manufacturing system model that allows the students of com- puter science and electrical engineering of the Hochschule Emden / Leer to learn the possibil- ities of program in a Real Time system. This system has nine modbus nodes, industrial computers with Real Time Linux, three of them are S-MAX 5006 CE PB from the company Phoenix Contact3 and the other six are SIMATIC Microbox PC from Siemens. The nodes from Siemens have a network card Via-Rhine III which does not have a compatible driver module for Real Time Linux RTNet4 but it also has a compatible driver module for the Linux Kernel. That means that the networking card do not work for the Real Time calls and the manufacturer of the Rhine Network Card5 does not support and provide any compatible Real Time Linux driver for them. To allow the students to have the possibility of use the RTAI functions in a network context with the current hardware, appears the justification of this project: to find alternative ways to communicate the RTAI Tasks between nodes and implement it. During the current document it will be explained how it was possible to design and implement a network system of mailboxes to communicate the Real Time Tasks of all the nodes of the MPS System. 1Festo Didactic GmbH http://www.festo-didactic.com 2Abteilung Technik, Fachbereich Elektrotechnik und Informatik, Labor für verteilte Betriebssysteme und App- likationen. 3Phoenix Contact Deutschland GmbH http://www.phoenixcontact.de 4List of supported Network Adapters by the project RTNet: http://www.rtnet.org/doc.html [9]. 5VIA Technologies, Inc http://www.via.com.tw/en/support/drivers.jsp. 1 2 BASIC INFORMATION 2 Basic Information 2.1 Used Technology 2.1.1 Real Time Linux and Real Time API Interface In computer science, when we refer to the term Real Time operative system it means that the operations that this OS execute will be executed inside of a strict time interval using an optimized algorithm for scheduling to have a much better response. It means that the time of the operation are predictably; or as fast as possible. Some example of uses of real time operative system can be all the systems that need a response inside an interval like the software that controls a motor, or a nuclear plant.