- •List of Figures
- •List of Tables
- •Preface
- •1 Requirements
- •1.1 General Requirements
- •1.2 Memory Requirements
- •1.3 Performance
- •1.4 Portability
- •2 Concepts
- •2.1.1 Compiling and Linking
- •2.2 Loading and Execution of Programs
- •2.3 Preemptive Multitasking
- •2.3.1 Duplication of Hardware
- •2.3.2 Task Switch
- •2.3.3 Task Control Blocks
- •2.3.4 De-Scheduling
- •2.4 Semaphores
- •2.5 Queues
- •2.5.1 Ring Buffers
- •2.5.2 Ring Buffer with Get Semaphore
- •2.5.3 Ring Buffer with Put Semaphore
- •2.5.4 Ring Buffer with Get and Put Semaphores
- •3 Kernel Implementation
- •3.1 Kernel Architecture
- •3.2 Hardware Model
- •3.2.1 Processor
- •3.2.2 Memory Map
- •3.2.3 Peripherals
- •3.2.4 Interrupt Assignment
- •3.2.5 Data Bus Usage
- •3.3 Task Switching
- •3.4 Semaphores
- •3.4.1 Semaphore Constructors
- •3.4.2 Semaphore Destructor
- •3.4.3 Semaphore P()
- •3.4.4 Semaphore Poll()
- •3.4.5 Semaphore V()
- •3.5 Queues
- •3.5.1 Ring Buffer Constructor and Destructor
- •3.5.2 RingBuffer Member Functions
- •3.5.3 Queue Put and Get Functions
- •3.5.4 Queue Put and Get Without Disabling Interrupts
- •3.6 Interprocess Communication
- •3.7 Serial Input and Output
- •3.7.1 Channel Numbers
- •3.7.2 SerialIn and SerialOut Classes and Constructors/Destructors
- •3.7.3 Public SerialOut Member Functions
- •3.7.4 Public SerialIn Member Functions
- •3.8 Interrupt Processing
- •3.8.1 Hardware Initialization
- •3.8.2 Interrupt Service Routine
- •3.9 Memory Management
- •3.10 Miscellaneous Functions
- •4 Bootstrap
- •4.1 Introduction
- •4.3.1 Task Parameters
- •4.3.2 Task Creation
- •4.3.3 Task Activation
- •4.3.4 Task Deletion
- •5 An Application
- •5.1 Introduction
- •5.2 Using the Monitor
- •5.3 A Monitor Session
- •5.4 Monitor Implementation
- •6 Development Environment
- •6.1 General
- •6.2 Terminology
- •6.3 Prerequisites
- •6.3.1 Scenario 1: UNIX or Linux Host
- •6.3.2 Scenario 2: DOS Host
- •6.3.3 Scenario 3: Other Host or Scenarios 1 and 2 Failed
- •6.4 Building the Cross-Environment
- •6.4.1 Building the GNU cross-binutils package
- •6.4.2 Building the GNU cross-gcc package
- •6.4.3 The libgcc.a library
- •6.5 The Target Environment
- •6.5.2 The skip_aout Utility
- •7 Miscellaneous
- •7.1 General
- •7.2 Porting to different Processors
- •7.2.1 Porting to MC68000 or MC68008 Processors
- •7.2.2 Porting to Other Processor families
- •7.3 Saving Registers in Interrupt Service Routines
- •A Appendices
- •A.1 Startup Code (crt0.S)
- •A.3 Task.cc
- •A.6 Semaphore.hh
- •A.7 Queue.hh
- •A.8 Queue.cc
- •A.9 Message.hh
- •A.10 Channels.hh
- •A.11 SerialOut.hh
- •A.12 SerialOut.cc
- •A.13 SerialIn.hh
- •A.14 SerialIn.cc
- •A.15 TaskId.hh
- •A.18 ApplicationStart.cc
- •A.19 Monitor.hh
- •A.20 Monitor.cc
- •A.22 SRcat.cc
- •Index
5. An Application |
95 |
|
|
5 An Application
5.1Introduction
In this chapter, we present a simple application: a monitor program that receives commands from a serial port, executes them, and prints the result on the same serial port. The commands are mainly concerned with retrieving information about the running system, such as the status of tasks, or the memory used. This monitor has shown to be quite useful in practice, so it is recommended to include it in any application. In order to use the monitor, a terminal or a computer running a terminal emulation, for example the kermit program, is connected to the serial port used by the monitor.
5.2Using the Monitor
The monitor supports a collection of commands that are grouped in menus: the main menu, the info menu, the duart menu, the memory menu, and the task menu. Other menus can easily be added if required. The only purpose of the main menu is to enter one of the other menus.
96 |
5.2 Using the Monitor |
|
|
Main
Menu
Command
Command
Command
Command
Command 
Your |
Info |
Duart |
Memory |
Task |
Menu |
Menu |
Menu |
Menu |
Menu |
Command |
Command |
Command |
Command |
Command |
Command |
Command |
|
Command |
Command |
|
Command |
|
|
|
Your |
|
|
|
|
Sub-menu |
|
|
|
|
Command |
|
|
|
|
FIGURE 5.1 Monitor Menu Structure
In each menu, the monitor prints a prompt, such as “ Main >” when the monitor is ready to accept a command. A command consists of a single character and, for some commands, of an additional argument. Some commands may be activated by different characters (e.g. H or ? for help), and commands are not casesensitive. It is not possible to edit commands or arguments.
The two commands shown in Table 1 are valid for all menus:
5. An Application |
97 |
|
|
Command |
Action |
|
|
H h ? |
Print Help on commands available in menu. |
|
|
Q q ESC |
Return from this menu (ignored in main menu). |
|
|
TABLE 1. Commands available in all menus
The remaining commands shown in Table 2 are only valid in their specific menus.
Menu |
Command |
Action |
Argument |
|
|
|
|
Main |
I i |
Enter Info Menu |
- |
|
|
|
|
Main |
D d |
Enter Duart Menu |
- |
|
|
|
|
Main |
M m |
Enter Memory Menu |
- |
|
|
|
|
Main |
T t |
Enter Task Menu |
- |
|
|
|
|
Info |
O s |
Display Overflows |
- |
|
|
|
|
Info |
S s |
Display Top of Memory |
- |
|
|
|
|
Info |
T t |
Display System Time |
- |
|
|
|
|
Duart |
B b |
Set Baud Rate |
Baud Rate |
|
|
|
|
Duart |
C c |
Change Channel |
- |
|
|
|
|
Duart |
M m |
Set Serial Mode |
Data bits and Parity |
|
|
|
|
Duart |
T t |
Transmit Character |
Character (hex) |
|
|
|
|
Memory |
D |
Display Memory |
Address (hex) |
|
|
|
|
Memory |
\n |
Continue Display Memory |
- |
|
|
|
|
Task |
S s |
Display all Tasks |
- |
|
|
|
|
Task |
T t |
Display particular Task |
Task number |
|
|
|
|
Task |
P p |
Set Task Priority |
Priority (decimal) |
|
|
|
|
TABLE 2. Specific commands
98 |
5.3 A Monitor Session |
|
|
5.3A Monitor Session
The commands of the monitor are best understood by looking at a commented monitor session. Commands and arguments entered are shown in bold font. When the monitor is started, it prints a start-up message:
Monitor started on channel 1.
Type H or ? for help.
Main Menu [D I M T H]
Main >
H (or ?) shows the options available in the (main) menu:
Main > h
D - |
Duart Menu |
||
I - |
Info |
Menu |
|
M |
- |
Memory Menu |
|
T |
- |
Task |
Menu |
D enters the duart menu and h shows the options available:
Main > d
Duart Menu [B C M T H Q]
Duart_A > ?
B - Set Baud Rate
C - Change Channel
M - Change Mode
T - Transmit Character
B sets the baud rate of the duart channel A (SERIAL_0), M sets the data format. The monitor itself is running on SERIAL_1 so that this setting does not disturb the monitor session.
Duart_A > b
Baud Rate ? 9600
Duart_A >
Duart_A > m
Data Bits (5-8) ? 8
Parity (N O E M S) ? n
Databits = 8 / Parity = n set.
C toggles the duart channel, which changes the prompt of the duart menu.
Duart_A > c
Duart_B >
T transmits a character. The character is entered in hex (0x44 is ASCII ’D’).
Duart_B > t 44
Sending 0x44D
Duart_B >
5. An Application |
99 |
|
|
The last character (’D’) in the line above is the character transmitted. Q exits the duart menu and i enters the info menu.
Duart_B > q
Main > i
Info > ?
O - Overflows
S - System Memory
T - System Time
Info Menu [O S T H Q]
O displays the overflows of the serial input queues.
Info |
> o |
|
|
|
Ch |
0 |
in |
: |
0 |
Ch |
1 |
in |
: |
0 |
S displays the top of the system RAM used. Since the RAM is starting at address 0x20000, the total amount of RAM required is slightly more than 4 kBytes:
Info > s
Top of System Memory: 20001050
T shows the time since system start-up in milliseconds (i.e. 23 seconds) and q leaves the info menu.
Info > t
System Time: 0:23140
Info > q
M enters the memory menu and h shows the available options.
Main > m
Memory Menu [D H Q]
Memory > h
D - Dump Memory
D dumps the memory from the address specified. The memory dump may be continued after the last address by typing return (not shown). Here, the address is 0; thus dumping the vector table at the beginning of crt0.S. Q leaves the memory menu.
Memory > d Dump Mamory at address 0x0 |
|
|
|
|
00000000: 6000 00FE 0000 0100 0000 0172 0000 0172 ‘.......... |
|
r... |
r |
|
00000010: 0000 0172 0000 0172 0000 0172 0000 0172 ...r... |
r... |
r... |
r |
|
00000020: 0000 0172 0000 0172 0000 0172 0000 0172 ...r... |
r... |
r... |
r |
|
00000030: 0000 0172 0000 0172 0000 0172 0000 0172 ...r... |
r... |
r... |
r |
|
00000040: 0000 0172 0000 0172 0000 0172 0000 0172 ...r... |
r... |
r... |
r |
|
00000050: 0000 0172 0000 0172 0000 0172 0000 0172 |
...r... |
r... |
r... |
r |
00000060: 0000 0172 0000 0172 0000 01A4 0000 0172 |
...r... |
r....... |
|
r |
00000070: 0000 0172 0000 0172 0000 0172 0000 0172 |
...r... |
r... |
r... |
r |
100 |
5.3 A Monitor Session |
|
|
00000080: 0000 02F6 0000 0306 0000 0172 0000 03AC ........... |
|
r |
.... |
00000090: 0000 03FE 0000 0444 0000 0172 0000 0172 ....... |
D... |
r... |
r |
000000A0: 0000 0172 0000 0172 0000 0172 0000 0172 ...r... |
r... |
r... |
r |
000000B0: 0000 0172 0000 0458 0000 046A 0000 0474 ...r... |
X... |
j... |
t |
000000C0: FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF ................ |
|
|
|
000000D0: FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF ................ |
|
|
|
000000E0: FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF ................ |
|
|
|
000000F0: FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF ................ |
|
|
|
Memory > q |
|
|
|
T enters the task menu and h shows the available options.
Main > t
Task Menu [P S T H Q]
Task > h
P - Set Task Priority
S - Show Tasks
T - Show Task
S displays a list of all tasks. The current task is marked with an arrow:
Task > s Show Tasks:
----------------------------------------------------
TCB Status Pri TaskName ID US Usage
----------------------------------------------------
--> 20000664 |
RUN |
240 |
Monitor Task |
1 |
0000014C |
20000FB4 |
RUN |
0 |
Idle Task |
0 |
000000A0 |
====================================================
T shows details of a particular task. The task number entered is the position of the task in the display of the previous command, starting at 0, rather than the task ID. Thus entering 1 displays the idle task rather than the monitor task.
Task > t Show Task: |
|
|
Task number = 1 |
|
|
Task Name: |
Idle Task |
|
Priority: |
0 |
|
TCB Address: |
20000FB4 |
|
Status: |
RUN |
|
US Base: |
2000020C |
|
US Size: |
00000200 |
|
US Usage: |
000000A0 |
(31%) |
Task > |
|
|
Apparently the user stack of 512 bytes for the idle task could be reduced to 160 bytes. Finally, p sets the monitor task priority and q returns to the main menu:
Task > p Set Task Priority:
Task number = 0
Task priority = 200
5. An Application |
101 |
|
|
Set Monitor Task Priority to 200
Task >
Task > q
Main >
In some cases, an additional prompt is printed after having entered numbers. The function accepting numbers waits until a non-digit, such as carriage return, is entered. If this carriage return is not caught, then it is interpreted as a command. Except for the memory menu, carriage return is not a valid command; it is ignored and a new prompt is displayed.
