Real-Time Systems Development This Page Intentionally Left Blank Real-Time Systems Development
Total Page:16
File Type:pdf, Size:1020Kb
Real-Time Systems Development This page intentionally left blank Real-Time Systems Development Rob Williams AMSTERDAM • BOSTON • HEIDELBERG • LONDON • NEW YORK • OXFORD PARIS • SAN DIEGO • SAN FRANCISCO • SINGAPORE • SYDNEY • TOKYO Butterworth-Heinemann is an imprint of Elsevier Butterworth-Heinemann is an imprint of Elsevier Linacre House, Jordan Hill, Oxford OX2 8DP 30 Corporate Drive, Suite 400, Burlington MA 01803 First published 2006 Copyright c 2006, Rob Williams. All rights reserved The right of Rob Williams to be identified as the author of this work has been asserted in accordance with the Copyright, Designs and Patents Act 1988 No part of this publication may be reproduced in any material form (including photocopying or storing in any medium by electronic means and whether or not transiently or incidentally to some other use of this publication) without the written permission of the copyright holder except in accordance with the provisions of the Copyright, Designs and Patents Act 1988 or under the terms of a licence issued by the Copyright Licensing Agency Ltd, 90 Tottenham Court Road, London, England W1T 4LP. Applications for the copyright holder’s written permission to reproduce any part of this publication should be addressed to the publisher Permissions may be sought directly from Elsevier’s Science and Technology Rights Department in Oxford, UK: phone: (+44) (0) 1865 843830; fax: (+44) (0) 1865 853333; e-mail: [email protected]. You may also complete your request on-line via the Elsevier homepage (www.elsevier.com), by selecting ‘Customer Support’ and then ‘Obtaining Permissions’ British Library Cataloguing in Publication Data A catalogue record for this book is available from the British Library Library of Congress Cataloguing in Publication Data A catalogue record for this title is available from the Library of Congress ISBN-13: 978-0-7506-6471-4 ISBN-10: 0-7506-6471-1 For information on all Butterworth-Heinemann publications visit our website at http://books.elsevier.com Typeset by Charon Tec Pvt. Ltd, Chennai, India www.charontec.com Printed and bound in Great Britain Contents Preface vii Recommended lab sessions ix Acknowledgements and thanks xi 1 Introduction to real-time systems 1 2 Implementing simple real-time systems 29 3 Basic input and output 46 4 Cyclic executives for bare hardware 81 5 Finite state machines – design tool 94 6 Finite state machines – implementation options 110 7 Why multi-task? 150 8 Task communication and synchronization 169 9 Real-time executives 201 10 Using input/output interfaces 224 11 Structured design for real-time systems 241 12 Designing for multi-tasking 267 13 UML for real-time systems 285 14 Object-oriented approach for real-time systems 297 15 System integrity 311 16 Languages for RTS development – C, Ada and Java 341 17 Cross-development techniques 358 18 Microcontroller embedded systems 393 19 Linux device drivers 410 20 Hardware/software co-design 435 Appendix A: Using an oscilloscope for software debugging 445 Index 451 v This page intentionally left blank Preface As more and more of our daily technology depends on embedded micro- processors, the demand for good real-time software has grown enormously. So it is unfortunate that computer science students frequently only develop and run programs on standard desktop Windows platforms. This leaves them somewhat unprepared for the extra problems encountered should they end up producing code for a new DVD player, a mobile handset or an Internet packet router. This text reveals some of the particular difficulties encountered when designing for real-time systems, and the alternative routes available for software realization. It is perhaps a shame that so few programmers have the opportunity to study the science and art of real-time systems before being confronted by their first real-time project. As a large proportion of new domestic and leisure equipment relies on microprocessors for basic operations, the world might be a safer and less frustrating experience for all of us if this situation could be rectified. My own commercial experience in the field of microprocessor applica- tions influenced my academic direction when I returned to university life. It had struck me that the normal computer science courses did not cover enough basic material in low-level programming and electronics which was necessary to support a career in real-time, embedded development. There had also been a continuing trend to separate the study of hardware from software, reducing students’ ability to understand the operational totality of microprocessor-based systems. When debugging faulty equipment, comput- ing graduates suffered from a serious disadvantage. Should they require some more graphical evidence from their limping software, they dared not turn on an oscilloscope. On the other side of the fence, electronic engineers scratched away at assembler spaghetti code, or naively marvelled at the irredeemable wonders of Basic. What was needed was a synthesis of the two disciplines, a harmonization of software and electronic engineering. With this in mind we proposed and validated the BSc Computing for Real-time Systems. This text came from the experience of teaching on that four-year honours programme. It represents the content of a two-semester, senior year module called ‘Real-time Systems vii viii Preface Design’ which we have presented to our undergraduates, in a variety of evolv- ing versions, for 20 years. It has also been delivered in a modified, accelerated form as a masters-level module within our MSc Software Engineering. On the whole, students enjoy the module, and manage to gain considerable benefit from the down-to-earth approach and practical challenges. Recommended lab sessions It is anticipated that the majority of the readers of this text will be advanced undergraduates or masters-level students pursuing a course called Computer Science, Computing, Software Engineering, or some similar title. They will probably have chosen to take an option in Real-time Systems Design, or Development. Such modules normally include weekly lectures and practical work in laboratories. So, the material covered in the following chapters rep- resents only one component of their learning experience. The following list of extended practical exercises is not a recommended schedule for a single semester’s laboratory activity because each individual student will bring dif- ferent experience and skills to the course. They have different ambitions and expectations, so what they actually decide to do during the practical sessions will vary. A variety and choice of laboratory work is always a popular factor with students. 1. Introduction to I/O programming with Linux 2. Real-time motor control 3. Finite state methodology 4. SA/SD, real-time Yourdon, case study 5. OOD, case study 6. Configuring gcc cross-compilers 7. Cross-development methods 8. Synchronization and communications 9. Petri net methods 10. Point Of Sale (POS) network case study An alternative and very effective strategy is to organize an extended case study project, which involves design, implementation and test activities. This develops and extends the students’ understanding throughout the semester, and can be subdivided into component parts for each member of the team. In this way, a wide range of technical skills and interests, from embedded microcontrollers to Oracle database servers, can be integrated into a sin- gle project, and assessed partly individually and partly as a team. Such ix x Recommended lab sessions activity offers the extra benefit of enabling groups to work together on a much larger assignment, certainly an important experience for undergraduate students. A suitable idea which we have used recently is the development of a POS network, with POS terminals, data concentrator and central database server. This supplies a broad scope for design variation and allows for regular enhancement to keep the technology up to date. Acknowledgements and thanks There are many individuals, colleagues, students and graduates from our BSc Computing for Real-time Systems degree, who have contributed to this text, directly or indirectly. In particular I would like to thank a colleague Bob Lang who generously provided detailed, technical reviews of all the chapters, based partly on his own commercial experience working with real- time systems. Also, Craig Duffy tolerating the repeated requests to read drafts and responded with a sustained counterstream of cross-development news from his Linux porting activities. In addition, I have enjoyed useful discussions on many real-time topics with Richard Barry, Adam Budd, Andy Clymer, Mark Cridge, Tony Gibbs, Will Skinner, and Rob Voisey. They may recognize their influence in some parts of the book. The duckshoot game, among many other ideas, was lucidly explained to me many years ago by Jonathan Bromley, and it has survived to provide an intriguing programming exercise. I must also warmly thank my colleagues Jeff Graham, Nigel Gunton, Ian Johnson, Peter Martin, Laurence O’Brien and Chris Wallace for engaging so generously in technical discussions and accepting the regular outbreaks of author’s obsession. There are too many students to mention individually, but throughout the past 20 years, they have trusted us with their careers by enrolling onto our BSc Computing for Real-time Systems degree. Fundamentally, it is their good humour and continuing curiosity which provided the spur for this text. The best reward for any teacher is to see students progress and develop their technical confidence, leading to successful graduation and rewarding careers. I must also once again give praise to Brian Kernighan for his wonderfully small pic language, which I used to construct all the line diagrams throughout the book. The original text was edited with emacs and the formatting was all carried out using groff from Richard Stallman’s GNU suite. It was here that I discovered the fun of using pic to code diagrams. I would also like to thank Richard Stallman for the guidance he generously offered concerning the General Public License which is discussed in Section 9.13.