Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Sauermann J.Realtime operating systems.Concepts and implementation of microkernels for embedded systems.1997.pdf
Скачиваний:
29
Добавлен:
23.08.2013
Размер:
1.32 Mб
Скачать

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.