IO Initialization

I/O Initialization

With start() complete, basic initialization completes, and the system is at C-level. The monitor has initialized memory and stack; the next step is to access the peripherals. First, I make sure that all peripherals are settled down. To this end, I reset and disable all I/O [1] and then initialize the UART.

The UART should always be the first device (after memory) to be configured so that the system can use printf() to report status to the user . Continuing with the "tiny steps" philosophy, I only tackle one thing at a time. The UART interface is a polled interface, [2 ] which allows me to avoid the complexity of interrupt handlers. Remember, I am still somewhat unsure of the footing, so I want to continue taking small and easy steps. I use four functions to interface to the UART: init() , putchar () , getchar () , and gotachar() . The first two functions are the most important. After you can boot your target and actually see a character come out of the serial port, you are almost home. (Not really, but it sure is a good feeling to get to that point!)

The UART functions putchar() , getchar() , and gotachar() are written in polled mode. Listing 4.4 is an example implementation for putchar() .

Note that the polling loop that waits for the transmit hold buffer to become empty is not an infinite loop. Providing an exit to this loop is especially important when first establishing this function because if you get something wrong in the interface, the error routine lets you know about it (instead of just hanging in the loop).

[1] If you have anything to say about it during the hardware design, try to make sure that the micro processor has the ability to reset each of its peripherals independently, without the need to power-cycle or hard-reset the target. This feature becomes very handy.

[2 ] Actually, the monitor doesnt even use interrupts, which keeps the porting process from one CPU/target to the next much simpler.



Embedded Systems Firmware Demystified
Embedded Systems Firmware Demystified (With CD-ROM)
ISBN: 1578200997
EAN: 2147483647
Year: 2002
Pages: 118
Authors: Ed Sutter

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net