You are on page 1of 9

Embedded

An Embedded

Design

Patterns for

Systems

in C

Software Engineering Toolkit


Bruce Powel

Douglass, PhD

AMSTERDAM

BOSTON

HEIDELBERG LONDON

NEW YORK

OXFORD

PARIS

SAN DIEGO

SAN FRANCISCO SINGAPORE


Newnes is
an

SYDNEY TOKYO

imprint of Elsevier

Newnes

Contents
Preface
xv

Acknowledgements
About the Author

xvii

xviii

Chapter

What Is Embedded

Programming?

/ 1 3 4 5 6 7 8 9 10 13

1.1 What's

Special About Embedded Systems? 1.1.1 Embedded Design Constraints


1.1.3

1.1.2 The Embedded Tool Chain

OS, RTOS,

or

Bareback?

1.1.4 Embedded Middleware 1.1.5 1.1.6 1.2 00


or

Codevelopment with Hardware Debugging and Testing


Structured
It's Your Choice
-

1.2.1 Classes 1.2.2 1.2.3 1.2.4

Objects

Polymorphism
Subclassing

and Virtual Functions

14 15 25

1.2.5 Finite State Machines 1.3 What Did We Learn?

33 with The

Chapter 2
2.1

Embedded

Programming

Harmony for

Embedded 35
36 36 44 45 46 47 66 77

RealTime Process Basic Elements of the Harmony Process 2.1.1 A Quick Overview of the Development Workflow 2.1.2 What Is
to
a

Design Pattern?
Patterns

2.1.3 Basic Structure of

Design 2.1.4 How Read Design Patterns in This Book 2.1.5 Using Design Patterns in Development
2.1.6 Observer Pattern
2.2 The 2.3 What's

Approach Coming Up
Patterns

78

Chapter 3 Design
3.1

for Accessing Hardware


Concepts
vii

79
81

Basic Hardware Access

Contents 3.2 Hardware

Proxy

Pattern

85 85 86 86 87 88
89 89 89

3.2.1 Abstract 3.2.2 Problem


3.2.3 Pattern Structure 3.2.4 Collaboration Roles 3.2.5 3.2.6 3.2.8 3.3.1

Consequences

Implementation Strategies

3.2.7 Related Patterns

Example 3.3 Hardware Adapter Pattern


Abstract 3.3.2 Problem 3.3.3 Pattern Structure 3.3.4 Collaboration Roles 3.3.5 3.3.6

96 96 96 96 96 97
98

Consequences

Implementation Strategies Example

3.3.7 Related Patterns

98 98 100 100 100


101 101 102 102 102

3.3.8

3.4 Mediator Pattern 3.4.1 Abstract 3.4.2 Problem


3.4.3 Pattern Structure 3.4.4 Collaboration Roles 3.4.5 3.4.6 3.4.8

Consequences
Implementation Strategies Example

3.4.7 Related Patterns 3.5 Observer Pattern 3.5.1 Abstract 3.5.2 Problem 3.5.3 Pattern Structure

103
Ill Ill 112 112 112 114 114 115 115 122

3.5.4 Collaboration Roles 3.5.5 Consequences 3.5.6 Implementation Strategies 3.5.7 Related Patterns 3.5.8 Example
3.6

Debouncing

Pattern

3.6.1 Abstract
3.6.2 Problem

123
123 123 123 125

3.6.3 Pattern Structure


3.6.4 Collaboration Roles 3.6.5

Consequences

viii

Contents

3.6.6 Implementation 3.6.7 Related Patterns 3.6.8 Example 3.7

Strategies

125 126 126 130 130 130 131 131 132


134 135 135 138 138 138 138 138 141

Interrupt Pattern
3.7.1 Abstract 3.7.2 Problem 3.7.3 Pattern Structure
3.7.4 Collaboration Roles 3.7.5

Consequences

3.7.6 Implementation Strategies 3.7.7 Related Patterns 3.7.8 Example


3.8

Polling
3.8.1

Pattern

Abstract

3.8.2 Problem 3.8.3 Pattern Structure 3.8.4 Collaboration Roles

3.8.5 Consequences
3.8.6 3.8.8 3.9

Implementation Strategies Example


Patterns

141
142

3.8.7 Related Patterns

142 147

So, What Did We Learn?

Chapter 4 Design Management


4.1

for Embedding Concurrency and Resource


149
152 160 161 163 164 164 165 165 165

Concurrency Concepts Identifying Tasks 4.1.2 Concurrency in the UML 4.1.3 Real-Time Operating Systems Scheduling Patterns 4.2 Cyclic Executive Pattern
4.1.1 4.2.1 Abstract 4.2.2 Problem 4.2.3 Pattern Structure 4.2.4 Collaboration Roles 4.2.5 ConcreteCEThread 4.2.6 4.2.7 4.2.9

Basic

165 166 167 167


167 167 170 170 171

Consequences
Implementation Strategies

4.2.8 Related Patterns

Example 4.3 Static Priority Pattern


4.3.1 Abstract

4.3.2 Problem

ix

Contents 4.3.3 Pattern Structure 4.3.4 Collaboration Roles 4.3.5 4.3.6

171 172 173


173

Consequences

Implementation Strategies Example Region


Abstract Pattern Structure

4.3.7 Related Patterns

174 175 182


182 182 182

4.3.8
4.4 Critical 4.4.1 4.4.3 4.4.5 4.4.6 4.4.8 4.5.1

Task Coordination Patterns Pattern

4.4.2 Problem 4.4.4 Collaboration Roles

182 183 184 184


184

Consequences Implementation Strategies Example


Abstract

4.4.7 Related Patterns 4.5 Guarded Call Pattern 4.5.2 Problem 4.5.3 Pattern Structure 4.5.4 Collaboration Roles 4.5.5
4.5.6

184 190 190


190

190
191

Consequences Implementation Strategies

192

192 193 194 207


207 207 208 208

4.5.7 Related Patterns


4.6

Example Queuing Pattern


4.6.1 Abstract 4.6.2 Problem 4.6.3 Pattern Structure 4.6.4 Collaboration Roles 4.6.5 4.6.6 4.6.8

4.5.8

Consequences Implementation Strategies Example


Abstract

209
210 210 210 224 225 226 226 226 227 228

4.6.7 Related Patterns


4.7

Rendezvous Pattern
4.7.1

4.7.2 Problem 4.7.3 Pattern Structure 4.7.4 Collaboration Roles 4.7.5


4.7.6

Consequences Implementation Strategies

Contents 4.7.7 Related Patterns

228
228 231 232 232

4.7.8 Example Deadlock Avoidance Patterns


4.8 Simultaneous

Locking

Pattern

4.8.1 Abstract 4.8.2 Problem 4.8.3 Pattern Structure

233 233 234


236

4.8.4 Collaboration Roles


4.8.5 4.8.6 4.8.8 4.9.1

Consequences Implementation Strategies


Example

236 236
236 242 242 243 243 244 247 248 248 248 255

4.8.7 Related Patterns

4.9 Ordered

Locking

Abstract

4.9.2 Problem

4.9.3 Pattern Structure 4.9.4 Collaboration Roles


4.9.5

Consequences

4.9.6
4.9.8

Implementation Strategies
Example

4.9.7 Related Patterns

4.10 So, What Have We Learned?

Chapter
5.1

Design

Patterns

for

State Machines

257
259 261 263 265 267 270

Oh Behave!

5.2 Basic State Machine 5.2.1 OR-States 5.2.2 AND-States

Concepts

5.3

Timeouts, Conditionals, and More Special Synchronous versus Asynchronous? Single Event Receptor Pattern
5.2.4 5.3.1 Abstract 5.3.2 Problem 5.3.3 Pattern Structure 5.3.4 Collaboration Roles 5.3.5 5.3.6 5.3.8

5.2.3

Stuff:

274
274 274 274 275 278 278 278 278 287

Consequences
Implementation Strategies

5.3.7 Related Patterns


5.4

Example Multiple Event Receptor Pattern


5.4.1 Abstract 5.4.2 Problem

287 287

xi

Contents 5.4.3 Pattern Structure 5.4.4 Collaboration Roles 5.4.5 5.4.6

288
288 290 290

Consequences Implementation Strategies Example

5.4.7 Related Patterns 5.4.8


5.5 State Table Pattern

290 290 296


296 296 296 297 299 299 299 300 308 308 308 308 310 312 313 313 314 327 330 331 331 331 331 333 333 334 334 356

5.5.1 Abstract
5.5.2 Problem 5.5.3 Pattern Structure 5.5.4 Collaboration Roles 5.5.5 5.5.6 5.5.8

Consequences

Implementation Strategies
Example

5.5.7 Related Patterns 5.6 State Pattern 5.6.1 Abstract

5.6.2 Problem 5.6.3 Pattern Structure 5.6.4 Collaboration Roles


5.6.5 5.6.6 5.6.8 5.8

Consequences Implementation Strategies Example


AND-State Pattern

5.6.7 Related Patterns 5.7 AND-States

Decomposed

5.8.1 Abstract 5.8.2 Problem 5.8.3 Pattern Structure

5.8.4 Collaboration Roles 5.8.5

Consequences

5.8.6 Implementation Strategies 5.8.7 Related Patterns


5.8.8 5.9

Example
Patterns

OK, What Have We Learned?

Chapter 6 Safety and Reliability


6.1 A Little Bit About 6.1.1

357
359 360 361 362 362 362

6.2

Safety Reliability Safety and Reliability Related Faults 6.1.2 Achieving Safety and Reliability One's Complement Pattern
6.2.1 Abstract 6.2.2 Problem

and

xii

Contents

6.2.3 Pattern Structure


6.2.4 Collaboration Roles

362 362 363 363 363 363 367 367 367 368 368 369 369 369 369 380 380 381 381

6.2.5 Consequences 6.2.6 Implementation 6.2.7 Related Patterns 6.2.8 Example 6.3 CRC Pattern
6.3.1

Strategies

Abstract

6.3.2 Problem

6.3.3 Pattern Structure 6.3.4 Collaboration Roles 6.3.5 Consequences 6.3.6 Implementation
6.3.7 6.3.8

Strategies

Related Patterns

Example
Abstract

6.4 Smart Data Pattern 6.4.1

6.4.2 Problem 6.4.3 Pattern Structure


6.4.4 Collaboration Roles 6.4.5

382 382 383 383 383 395


395 395 395

Consequences

6.4.6

Implementation Strategies

6.4.7 Related Patterns 6.4.8 Example 6.5 Channel Pattern


6.5.1

Abstract

6.5.2 Problem 6.5.3 Pattern Structure

6.5.4 Collaboration Roles

395
396 397 397 397

Consequences 6.5.6 Implementation Strategies


6.5.7 Related Patterns 6.5.8 6.6.1

6.5.5

Example

6.6 Protected

Single Channel

Pattern

402 402 402

Abstract

6.6.2 Problem 6.6.3 Pattern Structure 6.6.4 Collaboration Roles 6.6.5 6.6.7

403
404

Implementation Strategies Example

405 405 405

6.6.6 Related Patterns

x/7/*

Contents
6.7 Dual

Channel Pattern
Abstract

413 413 414 414 414 417 417 417 421 422 425

6.7.1

6.7.2 Problem 6.7.3 Pattern Structure 6.7.4 Collaboration Roles

Consequences 6.7.6 Implementation Strategies


6.7.5 6.7.7 Related Patterns

6.7.8 Example
6.8 Summary

Appendix A

UML Notation

1.1 Class 1.2

Diagram

425 425 429


429 430
430

1.1.1 Semantic Elements

Sequence Diagram
1.2.1 Semantic Elements

1.3 State 1.3.1

Diagram
Semantic Elements

index

437

You might also like