ilya101010 wrote:
How are memory mapped serial ports usually handled?
reading/writing from/to its registers.
Here is a live example of a very basic initialization and use of such a UART on a mips machine, made in the very beginning of the FW start.
Code:
/* UART4 */
/* configure UART4 TxD, RxD pins - GPIO bank C ports 10 and 20, set as pins of device function 2. */
li $t1, (PIN_UART4_TXD | PIN_UART4_RXD)
sw $t1, (GPIO_C + GPIO_INTC)($s0) /* interrupt clear, not an interrupt */
sw $t1, (GPIO_C + GPIO_MSKC)($s0) /* mask clear, port is a pin of device, not gpio */
sw $t1, (GPIO_C + GPIO_PAT1S)($s0) /* patern1 set, port is function 2 or 3 */
sw $t1, (GPIO_C + GPIO_PAT0C)($s0) /* patern0 clear, port is function 2 */
sw $t1, (GPIO_C + GPIO_PEC)($s0)
/* Enable UART4 clock. UARTs are clocked from EXTCLK: no PLL required. */
la $s0, CPM_BASE /* read-modify-write sequence for */
lw $t2, CPM_CLKGR1($s0)
andi $t3, $t2, %lo(~CLKGR1_UART4) /* clear the UART4 clock gate bit */
sw $t3, CPM_CLKGR1($s0) /* ungating the clock for UART4 */
/* Uart4Init */
lui $s0, %hi(UART4_BASE)
ori $s0, %lo(UART4_BASE)
1: lw $t0, UART_ULSR($s0)
andi $t0, $t0, ULSR_TEMP /* TEMP is set when UTHR and shift register are empty */
beq $zero, $t0, 1b
nop
sw $zero, UART_UIER($s0) /* disable interrupts */
li $t3, (ULCR_DLAB | ULCR_WLS_8)
sw $t3, UART_ULCR($s0)
sw $zero, UART_UDLLR($s0)
sw $zero, UART_UDLHR($s0)
li $t3, ULCR_WLS_8
sw $t3, UART_ULCR($s0)
li $t1, UMCR_RTS
sw $t1, UART_UMCR($s0) /* modem control: RTS - Request To Send */
li $t2, (UFCR_FME | UFCR_RFRT | UFCR_TFRT | UFCR_UME)
sw $t2, UART_UFCR($s0) /* Enable FIFO, reset Rx, Tx, enable the module */
li $t3, (ULCR_DLAB | ULCR_WLS_8) /* Divisor Latch Access Bit and Word Length Select set */
sw $t3, UART_ULCR($s0) /* Now we can access DLLR and DLHR to setup the baud rate */
li $t4, (UART_DIVISOR & 0x00ff) /* lower byte into DLLR */
sw $t4, UART_UDLLR($s0)
li $t5, ((UART_DIVISOR & 0x0000ff00) >> 8) /* higher byte into DLHR */
sw $t5, UART_UDLHR($s0)
li $t6, ULCR_WLS_8
sw $t6, UART_ULCR($s0) /* DLAB bit clear */
/* say hello */
lui $a0, %hi(szHello)
jal PutString
ori $a0, %lo(szHello)
you asked.
So basically you need to know what kind of UART it is, and register positions. How to do this with a laptop, I don't know, I got that from a SoC vendor manual.