1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

Embedded realtime systems programming

264 282 0
Tài liệu được quét OCR, nội dung có thể không chính xác
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 264
Dung lượng 11,66 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Chapter 1_\ntroduction to Embedded Realtime Systems 1.1_Challenges for Embedded Systems _5 1.2 Fundamental Components of Embedded Systems 7 1.3 Examples of Embedded Systems 2 1.4 Lang

Trang 2

Information contained in this work has been obtained by

Tata McGraw-Hill, from sources believed to be reliable

However, neither Tata McGraw-Hill nor its authors

guarantee the accuracy or completeness of any information

published herein, and neither Tata McGraw-Hill nor its

authors shall be responsible for any errors, omissions, or

damages arising out of use of this information This work is

published with the understanding that Tata McGraw-Hill

and its authors are supplying information but are not

attempting to render engineering or other professional

services If such services are required, the assistance of an

appropriate professional should be sought

‘No part of this publication can be reproduced in any form or by any means

without the prior written permission of the publishers

This edition can be exported from India only by the publishers,

Tata McGraw-Hill Publishing Company Limited

ISBN-13: 978-0-07-048284-5

ISBN-10: 0-07-048284-5

Published by Tata McGraw-Hill Publishing Company Limited,

7 West Patel Nagar, New Delhi 110 008, Typeset by Devendra M Sharma,

+#5/5, 1st Cross, Gowdanapalya Main Road, Bangalore 560 061 and text and cover printed at Shee! Print-N-Pack, D-132, Hosiery Complex, Phase II Extn, Noida 201 305

McGraw-Hi Tard

Trang 3

Chapter 1_\ntroduction to Embedded Realtime Systems

1.1_Challenges for Embedded Systems _5

1.2 Fundamental Components of Embedded Systems 7

1.3 Examples of Embedded Systems 2

1.4 Languages for Programming Embedded Systems 4

1.5 Organisation of the Book 4

L6 Lessons Learnt 7

L.7_ Review Questions 8

Section Two: Embedded nitty-gritty

Chapter 2_ The Build Process for Embedded Systems

Trang 4

Contents

Linker Scripts and Scatter Loading 34

Loading on the Target đã

4.1 Memory Management Methods 69

42 General Observations on Pointerrelated Bugs 89

5.8 Looking under the Hood on How interrupts Work 173

Guidelines for Writing ISRs_ 777

Trang 5

7.8 ISRs and Scheduling 774

84 Requirement Engineering Process 7/95

8.5 Common Problems in Requirement Engineering 200

8.6 Requirements of Card Verifier 207

94 Architecture of Card Verification System 222

9.5 Practices Followed in Design 226

9.6 Design Checklist 235

Trang 6

11.5 Factors Affecting Estimation 266

11.6 The Basic Steps of Estimation 267

11.7 How to Perform Estimation 270

118 Do’s and Don'ts of Estimation 274

119 Lessons Learnt 225

11.10 Review Questions 276

12.1 Introduction 277

12.2 Why is Software Testing Difficult? 277

12.3 Differences between Application and Embedded Testing 280

12.4 Validation Types and Methods 287

12.5 TargetTesting 288

126 The Last Word about Source Code 293

12.7 A Few Well Known Errors and their Causes 293

Trang 7

puddled inside a shroud of mystery, far from the normal world, being able to be unraveled

=; only by elderly professors with flowing beards ©

No, embedded systems are not confined to these hal- lowed places alone This section shall endeavor to intro- duce the reader to the common world applications of embedded systems, And it is our attempt to transform the: _

reader’s knowledge to an extent that (s)he looks at ordi- nary appliances at home or at work in a totally different

light Yes, we are talking of really ordinary appliances that have embedded systems inside them in some form or the other We will then look at the unique challenges that lie

in the path of engineers who create such systems and

how it is different from normal systems, So, fasten your

Trang 8

Chapter

1

Introduction to Embedded Realtime Systems

many smart and intelligent devices The personal computer (PC)/workstation is mov-

ing away from the focal point of the computing /programming industry

We are flooded with embedded systems that seem to be everywhere (ubiquitous) and

inconspicuous These systems should ideally communicate with each other (distributed)

to achieve a feel of a complete system

Before we delve further, we can define what an embedded system actually is An embedded system is defined as “A microprocessor based system that does not look like

a computer”.*

If we look around, we will realise that there are a lot of devices with limited intelli-

gence Let us consider the good old washing machine The main purpose of a washing

machine is to wash clothes But the modern world has extended it to include extra func-

tions and give more control thereby optimising the actual process of washing clothes Present day washing machines come complete with sensors, which maintain optimum water temperature, cloth dependent spin-speed, number of spins, etc They take care of

filling water, heating it to a particular temperature, mixing the optimum amount of

detergent, soaking the clothes in water for just the right time, the soft tumble for

*Any correlation with any Zen quotation is purely coincidental.

Trang 9

Embedded Realtime Systems Programming

extracting dirt, the aggressive tumble for removing stains, and excessive detergent from

clothes, and finally the spin-dry All this happens with minimum user intervention The

user may just have to select what kind of clothes are being put inside the machine and

possibly how dirty they are!

This is not magic All this is possible because somebody hit upon a brilliant idea that

we can use a small microprocessor to automate a lot of the dreary process of washing

Since microprocessor cannot function in isolation, it needs inputs from sensors and

other controlling devices so as to feel what is going around and then “decide” what actions need to be performed, which parts of the system have to run and in what order The sensors detect that the quantity of water inside the machine is at a certain level and indicate this to the processor The processor computes the required quantity of water that is necessary for the number of clothes and based on user settings It then generates

a control signal to stop the flow of water inside the machine and switch on the heater The temperature detector keeps giving indications about the current temperature inside the washing machine compartment At the optimum temperature for the kind of clothes

to be washed, the processor generates a control signal to stop the heater Then it gives

a signal to start the soft tumble action to soak the clothes properly in water and mix the

detergent The processor will keep a watch on the amount of time the soft tumble action

is going on At the optimum time, it will stop the soft tumble action and start the aggres-

sive tumble action to fight the stains So, we can see that washing machine is an

example of an embedded system As illustrated, the seemingly simple task of washing clothes is a big exercise for the processor!

‘As embedded systems started progressing, they started becoming more and more

complex Additionally, new attributes that got added to these systems were smart and

intelligent Not only were the embedded devices able to do their jobs but also were able

to do them smartly What exactly do we mean by intelligence? Intelligence is one of the terms that cannot still be defined in a single concrete way (If it was indeed definable,

we would have a laptop typing these pages on its own!) We can define a smart device

as a device with the following attributes:

2 Computational Power All these devices have some amount of computing power This could be provided by a very simple 8-bit controller or a high-end 64-bit

microprocessor

a Memory The next requirement is memory These devices possess some amount

of memory that can be used by the processor and also some to remember user data and preferences.

Trang 10

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 11

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 12

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 13

Embedded Realtime Systems Programming

Remote Control to change

settings in music system Fig 1.2 Input from the User of an embedded system

For example, a refrigerator or an air-conditioner is more than just a compressor

regulated by a thermostat They have a control system that implements various

functions like defrost, air circulation, apart from the seemingly dumb function of temp-

erature control Most of these systems come loaded with various settings Some

advanced refrigerators may have sensors to deodorize and detect inactivity These control systems are usually implemented as software They respond to environment

apart from the user For example, an air-conditioner will try to run the compressor for

a longer duration if the ambient temperature is higher than the required level and based

on the user preferences/presets he chooses

To compute and regulate the various parameters a system may require various levels

of computing power The microcontroller can be chosen based on the required level of

computing power

1.2.2 Memory

Memory is a very precious resource and is always found wanting in many embedded

systems (including human systems ©)

It is indeed true that memory is becoming cheaper nowadays But, in these days

of intense price wars, every resource must be handled with extreme care And, in many systems, some space has to be allocated for future expansions Also, we cannot

afford expansion slots as in PC for embedded systems due to cost constraints,

Trang 14

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 15

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 16

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 17

12 Embedded Realtime Systems Programming

which are not immediately required These tactics are highly dependent on soft- ware This factor has reached new dimensions with new processors being designed

such that some of their parts can be shut down whenever not required This

requires a shift to a new era of programming with more dimensions being added

to embedded software programming The programmer for mobile devices is

becoming increasingly aware of the power-saving features in his programming

platform (peripherals and processors)

These are some of the soft factors that drive design of embedded systems and its software

MN 1.3 EXAMPLES OF EMBEDDED SYSTEMS

Let us see some of the typical embedded systems that surround us

Trang 18

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 19

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 20

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 21

16 Embedded Realtime Systems Programming

The content of the book in all the chapters is based on the Learning Pyramid™ as

indicated in ancient Indian texts (Vedas) (Fig 1.3)

Fig 1.3 The Learning pyramid

Learning is usually completed in four steps that are described below:

The first stage is knowledge—This consists of the definitions and the theory that go

along Knowledge as information is the foundation of learning cycle At the beginning

of any learning cycle, knowledge is not usually exhaustive

The next stage is comprehension—This consists of explanation of the theory and how

the things happen the way they happen At this stage, the learner is able to generalise

information

B

Copyrighted material

Trang 22

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 23

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 24

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 25

The process of translating the code that is written by humans to the code that is under-

standable by the microprocessor is called the build process (Fig 2.1)

Build Process

Fig 2.1 The Build Process

‘An embedded programmer must understand build process deeper than an applica- tion developer This chapter describes the build process in detail The process in embedded systems is almost the same as PC based development, but for some subtle changes that will be indicated when appropriate

Some of the topics discussed here may not be specific to embedded systems per se

But, the discussions common to both embedded and applications (nonembedded) are added in this chapter to make the chapter complete and the book, a stand alone

entity

For C/C++ programs, the initiation of the build process varies from using a simple command from the command line (mostly in case of trivial programs) to huge make- files and sophisticated build tools.

Trang 26

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 27

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 28

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 29

The Build Process for Embedded Systems

After preprocessing foo.c will look like above Note that the header file foo.h is expanded (foo.c lines are in bold) Look at the lines foo.c #5 and foo.c #9 respectively

‘The preprocessor has expanded the macros SQR and replaced PI

It should be noted that the compiler sees the c file only after preprocessing So, the compiler cannot see if we had manually typed in 3.14159 or the preprocessor replaced

ied material

Trang 30

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 31

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 32

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 33

The Build Process for Embedded Systems

|] 2.4 LINKING

The process of compilation ends after creating object files for every source file (trans-

lation unit) We still do not have a single executable The object files though in machine

understandable format, are incomplete Some of the incomplete parts could be:

a References to external variables: Consider the case when a project consists of two

files The t2.c declares a global variable foo that is an integer and tl.c refers to it

by an external reference Since the compiler works only on a single translation

unit at a time, while compiling tl.c, the compiler can only assume about the

existence of foo and does not know about exact location of foo In the case of t1.c,

the compiler adds the name of foo to the list of ‘imported’ symbols when it

adds it to list of ‘exported’ symbols while compiling t2.c It is the duty of the linker

to resolve these external symbols (now does the linker error ‘unresolved exter-

nal XXXX’ mean more to you?) This is not limited to variables The linker

also links the references to functions that are defined in other source files and

Fig 2.3 Extern references

b No binding to real address: Again, due to the nature of the compiler (working

with one file at a time), the addresses of different variables in different files will be

assigned relative to the particular file When all the object files are linked togeth-

er to a single executable file, the address assigned to all these variables must be

unique The linker takes care of assigning correct addresses to these variables

Code in a file may also refer to a function in some other file The linker fills these

addresses of the functions Then, the code for a particular function may be in a

library, The linker will search the library and link appropriate code with the

application

29

Trang 34

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 35

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 36

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 37

The Build Process for Embedded Systems 33:°

startup code gets executed before the main() is reached A typical flowchart for thẻ

startup code is given in Fig 2.5

Start

| Disable Interrupts Wes =

Initialise Board, Memory, Peripherals

Trang 38

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 39

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Trang 40

You have either reached a page that is unavailable for viewing or reached your viewing limit for this,

book

Ngày đăng: 08/03/2016, 11:30

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN