General
This example is a simple hello world program written in Ada
for 68HC11 boards. It does not use any Ada runtime and provides
its own BSP to write on the 68HC11 serial port.
Compilation
You must use the GNU Ada compiler gcc 3.2.1 or above.
Type:
make
This will create hello.elf and hello.s19.
By hand, type the following (longish) commands:
m6811-elf-gcc -c -Ignat -m68hc11 -mrelax -ffunction-sections \
-fdata-sections -mshort -Os -msoft-reg-count=0 \
-fomit-frame-pointer \
hello.adb bsp.ads bsp-param.ads bsp-sio.adb
m6811-elf-gcc -c -gnatg -Ignat -m68hc11 -mrelax \
-ffunction-sections -fdata-sections -mshort -Os \
-msoft-reg-count=0 -fomit-frame-pointer gnat/system.ads
m6811-elf-gcc -Ignat -m68hc11 -mrelax -ffunction-sections \
-fdata-sections -mshort -Os -msoft-reg-count=0 \
-fomit-frame-pointer -Wl,-relax -Wl,--gc-sections \
-Wl,-defsym,_io_ports=0x1000 -Wl,-m,m68hc11elfb \
-o hello.elf hello.o bsp.o bsp-io.o bsp-param.o \
bsp-sio.o system.o
Note:
- -ffunction-sections, -fdata-sections and -Wl,--gc-sections are used
to remove the unused code generated by the compiler.
- -mrelax -msoft-reg-count=0 -Os -mshort -fomit-frame-pointer minimizes
the size of the generated code (no soft register, 16-bit int, linker
relaxation, ...)
- -Wl,-defsym,_io_ports=0x1000 defines the address of the 68HC11
IO registers which are accessed by BSP.IO.Ios global variable.
Execution
The program is designed for the 68HC11 bootstrap mode.
It is located at 0x0000 and uses less than 256 bytes.
Check that your board is configured for bootstrap mode.
You must upload the program using a loader that controls the serial
line connected to your board. You should start the loader before
powering on your board:
loader -s /dev/ttyS0 hello.elf
or
loader -s /dev/ttyS0 hello.s19
Once you've started the loader, power-on your 68HC11 board or
reset it.
Once loaded the program continuously sends 'Hello World' on the
serial line at 1200 bauds.
Program Description
The board is abstracted by the BSP package which provides the
information and low level functions to access to the low level
devices (IO ports and others).
BSP
_____|_________
/ | \
Param IO Sio
The 68HC11 IO ports are represented by BSP.IO package. Several
IO ports are strongly typed to enforce the correct association of
IO flags and port. For example the serial port SCSR is represented
by:
type T_SCSR is new Byte;
And its flags are defined as follows:
F_TDRE : constant T_SCSR := 16#80#; -- Transmit Data Register Empty
F_TC : constant T_SCSR := 16#40#; -- Transmit Complete
The IO ports are defined in the Port_Map record and can be accessed
by the Ios global variable. The address of the IO ports is defined
at link time. The record is defined as 'Volatile' to ensure that its
content can change beneath the program.
The BSP.Sio package provides functions and procedures to control
the serial controller in polling mode. While waiting for a character
to be transmitted or received the COP timer is reset. This ensure
continuous operation on board which have their watchdog enabled.
A character is sent very easily on the serial controller by putting
the character in the SCDR port and setting the transmitter enable flag:
Ios.SCDR := C;
Ios.SCCR2 := Ios.SCCR2 or F_TE;
The hello program uses the BSP to write on the serial line. It first
configures the serial line (not truely necessary for 68HC11 bootstrap)
and then sends the 'Hello World' string.
SIO.Send ("Hello world!" & LT);
The LT character is appended to output the \n at end of the line.
|