Realtime Operating Systems - Concepts & Implementation of Microkernels for Embedded Systems(1).pdf

(1290 KB) Pobierz
Realtime Operating Systems
Concepts and Implementation of Microkernels
for Embedded Systems
Dr. Jürgen Sauermann, Melanie Thelen
2
Contents
List of Figures.............................................................................v
List of Tables .............................................................................vi
Preface ........................................................................................1
1
1.1
1.2
1.3
1.4
Requirements ..............................................................................3
General Requirements ................................................................................. 3
Memory Requirements ................................................................................ 3
Performance................................................................................................. 4
Portability .................................................................................................... 5
2
2.1
2.1.1
2.2
2.3
2.3.1
2.3.2
2.3.3
2.3.4
2.4
2.5
2.5.1
2.5.2
2.5.3
2.5.4
Concepts .....................................................................................7
Specification and Execution of Programs.................................................... 7
Compiling and Linking ............................................................................... 7
Loading and Execution of Programs ......................................................... 11
Preemptive Multitasking............................................................................ 12
Duplication of Hardware ........................................................................... 12
Task Switch ............................................................................................... 14
Task Control Blocks .................................................................................. 16
De-Scheduling ........................................................................................... 19
Semaphores ............................................................................................... 21
Queues ....................................................................................................... 26
Ring Buffers .............................................................................................. 26
Ring Buffer with Get Semaphore .............................................................. 28
Ring Buffer with Put Semaphore .............................................................. 29
Ring Buffer with Get and Put Semaphores ............................................... 30
3
3.1
3.2
3.2.1
3.2.2
3.2.3
3.2.4
3.2.5
3.3
3.4
3.4.1
Kernel Implementation .............................................................33
Kernel Architecture ................................................................................... 33
Hardware Model........................................................................................ 34
Processor ................................................................................................... 34
Memory Map ............................................................................................. 35
Peripherals ................................................................................................. 35
Interrupt Assignment ................................................................................. 36
Data Bus Usage ......................................................................................... 36
Task Switching .......................................................................................... 39
Semaphores ............................................................................................... 46
Semaphore Constructors............................................................................ 46
ii
3.4.2 Semaphore Destructor ............................................................................... 46
3.4.3 Semaphore P() ........................................................................................... 46
3.4.4 Semaphore Poll() ....................................................................................... 48
3.4.5 Semaphore V() .......................................................................................... 49
3.5 Queues ....................................................................................................... 51
3.5.1 Ring Buffer Constructor and Destructor ................................................... 51
3.5.2 RingBuffer Member Functions.................................................................. 52
3.5.3 Queue Put and Get Functions .................................................................... 53
3.5.4 Queue Put and Get Without Disabling Interrupts...................................... 53
3.6 Interprocess Communication..................................................................... 54
3.7 Serial Input and Output ............................................................................. 59
3.7.1 Channel Numbers ...................................................................................... 62
3.7.2 SerialIn and SerialOut Classes and Constructors/Destructors .................. 63
3.7.3 Public SerialOut Member Functions ......................................................... 65
3.7.4 Public SerialIn Member Functions............................................................ 69
3.8 Interrupt Processing................................................................................... 71
3.8.1 Hardware Initialization.............................................................................. 71
3.8.2 Interrupt Service Routine .......................................................................... 73
3.9 Memory Management ............................................................................... 77
3.10 Miscellaneous Functions ........................................................................... 79
3.10.1Miscellaneous Functions in Task.cc ......................................................... 79
3.10.2Miscellaneous Functions in os.cc ............................................................. 80
4
4.1
4.2
4.3
4.3.1
4.3.2
4.3.3
4.3.4
Bootstrap...................................................................................81
Introduction ............................................................................................... 81
System Start-up ......................................................................................... 81
Task Start-up.............................................................................................. 87
Task Parameters......................................................................................... 87
Task Creation............................................................................................. 89
Task Activation.......................................................................................... 92
Task Deletion............................................................................................. 92
5
5.1
5.2
5.3
5.4
An Application .........................................................................95
Introduction ............................................................................................... 95
Using the Monitor ..................................................................................... 95
A Monitor Session..................................................................................... 98
Monitor Implementation......................................................................... 102
6
6.1
6.2
6.3
Development Environment .....................................................107
General .................................................................................................... 107
Terminology ............................................................................................ 107
Prerequisites ............................................................................................ 109
.
iii
6.3.1
6.3.2
6.3.3
6.4
6.4.1
6.4.2
6.4.3
6.5
6.5.1
6.5.2
Scenario 1: UNIX or Linux Host ............................................................ 109
Scenario 2: DOS Host ............................................................................. 110
Scenario 3: Other Host or Scenarios 1 and 2 Failed................................ 110
Building the Cross-Environment ............................................................. 112
Building the GNU cross-binutils package............................................... 112
Building the GNU cross-gcc package ..................................................... 113
The libgcc.a library.................................................................................. 114
The Target Environment .......................................................................... 117
The Target Makefile................................................................................. 117
The skip_aout Utility............................................................................... 121
7
7.1
7.2
7.2.1
7.2.2
7.3
7.4
Miscellaneous .........................................................................123
General .................................................................................................... 123
Porting to different Processors ................................................................ 123
Porting to MC68000 or MC68008 Processors ........................................ 123
Porting to Other Processor families......................................................... 124
Saving Registers in Interrupt Service Routines....................................... 125
Semaphores with time-out....................................................................... 127
A
A.1
A.2
A.3
A.4
A.5
A.6
A.7
A.8
A.9
A.10
A.11
A.12
A.13
A.14
A.15
A.16
A.17
A.18
A.19
A.20
A.21
A.22
Appendices .............................................................................130
Startup Code (crt0.S) .............................................................................. 130
Task.hh .................................................................................................... 137
Task.cc .................................................................................................... 140
os.hh ....................................................................................................... 143
os.cc ........................................................................................................ 145
Semaphore.hh ......................................................................................... 150
Queue.hh ................................................................................................. 151
Queue.cc ................................................................................................. 153
Message.hh ............................................................................................. 157
Channels.hh ............................................................................................ 158
SerialOut.hh ............................................................................................ 159
SerialOut.cc ............................................................................................ 160
SerialIn.hh .............................................................................................. 166
SerialIn.cc ............................................................................................... 167
TaskId.hh ................................................................................................ 170
duart.hh ................................................................................................... 171
System.config ......................................................................................... 175
ApplicationStart.cc ................................................................................. 176
Monitor.hh .............................................................................................. 177
Monitor.cc ............................................................................................... 178
Makefile .................................................................................................. 187
SRcat.cc .................................................................................................. 189
Zgłoś jeśli naruszono regulamin