This commit is contained in:
gferg 2004-03-08 23:27:27 +00:00
parent 5376bd63ee
commit a4e62c11dd
1 changed files with 17 additions and 11 deletions

View File

@ -28,6 +28,12 @@
</authorgroup>
<revhistory>
<revision>
<revnumber>2.1</revnumber>
<date>2003-03-08</date>
<authorinitials>gjf</authorinitials>
<revremark>Modified code example per author</revremark>
</revision>
<revision>
<revnumber>2.0</revnumber>
<date>2002-06-13</date>
@ -261,19 +267,19 @@ is it really booting?</para>
and the oldest way is good here - printing to the screen. Obviously, we couldn't use <function>printk()</function>, so we wrote a short function which pushes characters straight into the serial port. We used the boot process <quote>map</quote> shown in the previous section, and inserted some prints along the way. This helped us to know at what stage we are completing and where we're dying. The following piece of code prints a single character to the serial port, by polling it and waiting for it to be free.
<programlisting>
/* tx holding reg empty or tx */
#define LSR_THREMPTY 0x20 /* fifo is empty (in fifo mode ) */
#define THR_REG 0x00 /* Transmit holding reg */
#define LSR_REG 0x05 /* Line status reg */
#define COM1_ADDRESS 0xFF600300
/* tx holding reg empty or tx */
#define LSR_THREMPTY 0x20 /* fifo is empty (in fifo mode ) */
#define THR_REG 0x00 /* Transmit holding reg */
#define LSR_REG 0x05 /* Line status reg */
#define COM1_ADDRESS 0xFF600300 /* == replace with your UART address */
void print_char (char ch) {
volatile UINT8 status;
/* read status reg */
status = *((volatile unsigned char *)(COM1_ADDRESS + LSR_REG));
/* wait until txempty */
while ( (status & LSR_THREMPTY ) == 0);
*((volatile unsigned char *)(COM1_ADDRESS + THR_REG)) = ch;
volatile unsigned char status = 0;
/* wait until txempty */
while ((status & LSR_THREMPTY ) == 0)
status = *((volatile unsigned char *)(COM1_ADDRESS + LSR_REG));
*((volatile unsigned char *)(COM1_ADDRESS + THR_REG)) = ch;
}
</programlisting>