2 * PROJECT: ReactOS Boot Loader
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: boot/freeldr/arch/arm/ferouart.c
5 * PURPOSE: Implements code for Feroceon boards using the 16550 UART
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES *******************************************************************/
13 /* GLOBALS ********************************************************************/
18 #define UART0_RBR (ArmBoardBlock->UartRegisterBase + 0x00)
19 #define UART0_THR UART0_RBR
20 #define UART0_IER (ArmBoardBlock->UartRegisterBase + 0x04)
21 #define UART0_FCR (ArmBoardBlock->UartRegisterBase + 0x08)
22 #define UART0_LCR (ArmBoardBlock->UartRegisterBase + 0x0C)
23 #define UART0_MCR (ArmBoardBlock->UartRegisterBase + 0x10)
24 #define UART0_LSR (ArmBoardBlock->UartRegisterBase + 0x14)
25 #define UART0_MSR (ArmBoardBlock->UartRegisterBase + 0x18)
26 #define UART0_SCR (ArmBoardBlock->UartRegisterBase + 0x1C)
29 // When we enable the divisor latch
31 #define UART0_DLL UART0_RBR
32 #define UART0_DLM UART0_IER
37 #define FCR_FIFO_EN 0x01
44 #define LCR_WLS_8 0x03
45 #define LCR_1_STB 0x00
46 #define LCR_DIVL_EN 0x80
47 #define LCR_NO_PAR 0x00
55 /* FUNCTIONS ******************************************************************/
58 ArmFeroSerialInit(IN ULONG Baudrate
)
63 // Calculate baudrate clock divider to set the baud rate
65 BaudClock
= (ArmBoardBlock
->ClockRate
/ 16) / Baudrate
;
70 WRITE_REGISTER_UCHAR(UART0_IER
, 0);
73 // Set the baud rate to 115200 bps
75 WRITE_REGISTER_UCHAR(UART0_LCR
, LCR_DIVL_EN
);
76 WRITE_REGISTER_UCHAR(UART0_DLL
, BaudClock
);
77 WRITE_REGISTER_UCHAR(UART0_DLM
, (BaudClock
>> 8) & 0xFF);
80 // Set 8 bits for data, 1 stop bit, no parity
82 WRITE_REGISTER_UCHAR(UART0_LCR
, LCR_WLS_8
| LCR_1_STB
| LCR_NO_PAR
);
85 // Clear and enable FIFO
87 WRITE_REGISTER_UCHAR(UART0_FCR
, FCR_FIFO_EN
| FCR_RXSR
| FCR_TXSR
);
91 ArmFeroPutChar(IN INT Char
)
94 // Properly support new-lines
96 if (Char
== '\n') ArmFeroPutChar('\r');
101 while ((READ_REGISTER_UCHAR(UART0_LSR
) & LSR_THRE
) == 0);
104 // Send the character
106 WRITE_REGISTER_UCHAR(UART0_THR
, Char
);
115 while ((READ_REGISTER_UCHAR(UART0_LSR
) & LSR_DR
) == 0);
118 // Read the character
120 return READ_REGISTER_UCHAR(UART0_RBR
);
127 // Return if something is ready
129 return ((READ_REGISTER_UCHAR(UART0_LSR
) & LSR_DR
) != 0);