2
Contents
List of Figures.............................................................................v
List of Tables .............................................................................vi
Preface ........................................................................................1
1 Requirements..............................................................................3
1.1 General Requirements .................................................................................3
1.2 Memory Requirements................................................................................3
1.3 Performance.................................................................................................4
1.4 Portability ....................................................................................................5
2 Concepts .....................................................................................7
2.1 Specification and Execution of Programs....................................................7
2.1.1 Compiling and Linking ...............................................................................7
2.2 Loading and Execution of Programs.........................................................11
2.3 Preemptive Multitasking............................................................................12
2.3.1 Duplication of Hardware...........................................................................12
2.3.2 Task Switch ...............................................................................................14
2.3.3 Task Control Blocks ..................................................................................16
2.3.4 De-Scheduling...........................................................................................19
2.4 Semaphores ...............................................................................................21
2.5 Queues.......................................................................................................26
2.5.1 Ring Buffers ..............................................................................................26
2.5.2 Ring Buffer with Get Semaphore..............................................................28
2.5.3 Ring Buffer with Put Semaphore ..............................................................29
2.5.4 Ring Buffer with Get and Put Semaphores ...............................................30
3 Kernel Implementation.............................................................33
3.1 Kernel Architecture ...................................................................................33
3.2 Hardware Model........................................................................................34
3.2.1 Processor ...................................................................................................34
3.2.2 Memory Map.............................................................................................35
3.2.3 Peripherals.................................................................................................35
3.2.4 Interrupt Assignment.................................................................................36
3.2.5 Data Bus Usage .........................................................................................36
3.3 Task Switching ..........................................................................................39
3.4 Semaphores ...............................................................................................46
3.4.1 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 Bootstrap...................................................................................81
4.1 Introduction ...............................................................................................81
4.2 System Start-up .........................................................................................81
4.3 Task Start-up..............................................................................................87
4.3.1 Task Parameters.........................................................................................87
4.3.2 Task Creation.............................................................................................89
4.3.3 Task Activation..........................................................................................92
4.3.4 Task Deletion.............................................................................................92
5 An Application .........................................................................95
5.1 Introduction ...............................................................................................95
5.2 Using the Monitor .....................................................................................95
5.3 A Monitor Session.....................................................................................98
5.4 Monitor Implementation.........................................................................102
6 Development Environment .....................................................107
6.1 General ....................................................................................................107
6.2 Terminology ............................................................................................107
6.3 Prerequisites ............................................................................................109
. iii
6.3.1 Scenario 1: UNIX or Linux Host ............................................................109
6.3.2 Scenario 2: DOS Host .............................................................................110
6.3.3 Scenario 3: Other Host or Scenarios 1 and 2 Failed................................110
6.4 Building the Cross-Environment.............................................................112
6.4.1 Building the GNU cross-binutils package...............................................112
6.4.2 Building the GNU cross-gcc package .....................................................113
6.4.3 The libgcc.a library..................................................................................114
6.5 The Target Environment..........................................................................117
6.5.1 The Target Makefile.................................................................................117
6.5.2 The skip_aout Utility...............................................................................121
7 Miscellaneous.........................................................................123
7.1 General ....................................................................................................123
7.2 Porting to different Processors ................................................................123
7.2.1 Porting to MC68000 or MC68008 Processors ........................................123
7.2.2 Porting to Other Processor families.........................................................124
7.3 Saving Registers in Interrupt Service Routines.......................................125
7.4 Semaphores with time-out.......................................................................127
A Appendices .............................................................................130
A.1 Startup Code (crt0.S) ..............................................................................130
A.2 Task.hh ....................................................................................................137
A.3 Task.cc ....................................................................................................140
A.4 os.hh .......................................................................................................143
A.5 os.cc ........................................................................................................145
A.6 Semaphore.hh .........................................................................................150
A.7 Queue.hh .................................................................................................151
A.8 Queue.cc .................................................................................................153
A.9 Message.hh .............................................................................................157
A.10 Channels.hh ............................................................................................158
A.11 SerialOut.hh ............................................................................................159
A.12 SerialOut.cc ............................................................................................160
A.13 SerialIn.hh ..............................................................................................166
A.14 SerialIn.cc ...............................................................................................167
A.15 TaskId.hh ................................................................................................170
A.16 duart.hh ...................................................................................................171
A.17 System.config .........................................................................................175
A.18 ApplicationStart.cc .................................................................................176
A.19 Monitor.hh ..............................................................................................177
A.20 Monitor.cc ...............................................................................................178
A.21 Makefile ..................................................................................................187
A.22 SRcat.cc ..................................................................................................189