掌機 - GKD Pixel - Assembly - UART



GKD Pixel是使用UART1做為除錯介面,腳位如下:


UART1 Clock


Baudrate計算方式

Baudrate = 24MHz / (16 * Divisor)

115200 = 24000000 / (16 * 13)

main.s

    .extern _start
    .set noreorder

    .equiv LED,     14
    .equiv DELAY,   0x100000

    .equiv CPM,     0xb0000000
    .equiv PA,      0xb0010000 
    .equiv PB,      0xb0011000 
    .equiv PC,      0xb0012000 
    .equiv PD,      0xb0013000
    .equiv UART1,   0xb0031000

    .equiv PXINT,   0x0010
    .equiv PXMSK,   0x0020
    .equiv PXPAT1,  0x0030
    .equiv PXPAT0,  0x0040

    .equiv URBR,    0x0000
    .equiv UTHR,    0x0000
    .equiv UDLLR,   0x0000
    .equiv UDLHR,   0x0004
    .equiv UIER,    0x0004
    .equiv UIIR,    0x0008
    .equiv UFCR,    0x0008
    .equiv ULCR,    0x000c
    .equiv UMCR,    0x0010
    .equiv ULSR,    0x0014
    .equiv UMSR,    0x0018
    .equiv USPR,    0x001c
    .equiv ISR,     0x0020
    .equiv UMR,     0x0024
    .equiv UACR,    0x0028
    .equiv URCR,    0x0040
    .equiv UTCR,    0x0044

    .equiv CLKGR0,  0x0020

    .text
    .ascii "LPSM"

    .rept 2044
    .byte 0
    .endr

_start:
    li $8, CPM + CLKGR0
    lw $9, 0($8)
    and $9, ~(1 << 15)
    sw $9, 0($8)

    li $9, ~((1 << 23) | (1 << 24))
    li $8, PB + PXMSK
    sw $9, 0($8)
    li $8, PB + PXPAT0
    sw $9, 0($8)

    li $9, (1 << 7) | 3
    li $8, UART1 + ULCR
    sw $9, 0($8)

    li $10, 0
    li $8, UART1 + UDLHR
    sw $10, 0($8)

    li $9, 13
    li $8, UART1 + UDLLR
    sw $9, 0($8)

    li $9, 3
    li $8, UART1 + ULCR
    sw $9, 0($8)

    li $9, (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0)
    li $8, UART1 + UFCR
    sw $9, 0($8)

    li $v0, '0
    bal send_byte
    li $v0, 'H'
    bal send_byte
    li $v0, 'e'
    bal send_byte
    li $v0, 'l'
    bal send_byte
    li $v0, 'l'
    bal send_byte
    li $v0, 'o'
    bal send_byte
    li $v0, ','
    bal send_byte
    li $v0, ' '
    bal send_byte
    li $v0, 'w'
    bal send_byte
    li $v0, 'o'
    bal send_byte
    li $v0, 'r'
    bal send_byte
    li $v0, 'l'
    bal send_byte
    li $v0, 'd'
    bal send_byte
    li $v0, '!'
    bal send_byte

main:
    b main
    nop

send_byte:
    li $8, UART1 + ULSR
0:
    lb $9, 0($8)
    and $9, (1 << 6)
    beq $9, $zero, 0b
    nop

    li $8, UART1 + UTHR
    sb $v0, 0($8)
    jr $ra
    nop

完成