⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bbu_uart.s

📁 关于PXA310的最小系统的程序,初级学习阶段会有所帮助,汇编语言编写的
💻 S
📖 第 1 页 / 共 5 页
字号:
;       No parameters required
;
; NOTES: 
;
;    1. The selected UART port must be initalized first - otherwise this will hang the system!
;
; Control is passed back to the caller only after the transmitter buffer has been emptied of
; all characters on the FIFO buffer.
;

BBU_FF_TXempty  FUNCTION

        stmfd   sp!,    {r0, r1, lr}            ; Save r0, r1 and link register on the stack

        ldr     r1,     =bbu_FFUART_PHYSICAL_BASE
102     ldr     r0,     [r1, #bbu_UALSR_offset] ; Get Line Status Register Data
        ands    r0,     r0,     #bbu_TEMT       ; Is TDRQ (Transmit Data Request) bit set?
        beq     %B102                           ; No - loop until it is	
        ldmfd   sp!,    {r0, r1, pc}            ; Restore r0, r1 and return to caller

        ENDFUNC
;
;*********************************************************************************
;
;       ******************
;       *                * 
;       * BBU_ST_TXempty * Subroutine
;       *                *
;       ******************
;
; This subroutine does not return to the caller until the Standard UART 
; transmitter buffer is empty
;
; PARAMETER PASSING:
;
;       No parameters required
;
; NOTES: 
;
;    1. The selected UART port must be initalized first - otherwise this will hang the system!
;
; Control is passed back to the caller only after the transmitter buffer has been emptied of
; all characters on the FIFO buffer.
;

BBU_ST_TXempty  FUNCTION

        stmfd   sp!,    {r0, r1, lr}            ; Save r0, r1 and link register on the stack

        ldr     r1,     =bbu_STUART_PHYSICAL_BASE
102     ldr     r0,     [r1, #bbu_UALSR_offset] ; Get Line Status Register Data
        ands    r0,     r0,     #bbu_TEMT       ; Is TDRQ (Transmit Data Request) bit set?
        beq     %B102                           ; No - loop until it is	
        ldmfd   sp!,    {r0, r1, pc}            ; Restore r0, r1 and return to caller

        ENDFUNC
;*********************************************************************************
;
;       *******************
;       *                 * 
;       * BBU_ASCII_value * Converts 32-bit value into ASCII
;       *                 *
;       *******************
;
; This subroutine takes the 32 bit value in r0, converts it to four ASCII characters
; and outputs the data to the UART.
;
; PARAMETER PASSING:
;
; r0 contains the 32 bit value to be converted into ASCII text
;
; NOTES:
;
;    1. The selected UART port must be initalized first - otherwise this will hang!
;

BBU_ASCII_value    FUNCTION

        stmfd   sp!,    {r1, lr}        ; Save r1 and link register on the stack
        mov     r1,     r0              ; Copy value to r2
        and     r0,     r1,     #0xFF   ; Get the first byte
        cmp     r0,     #0X20           ; Check for low end of valid range
        movlt   r0,     #'.'            ; If .LT. above value, replace with period
        cmp     r0,     #0X7E           ; Check for high end of valid range
        movgt   r0,     #'.'            ; If .GT. abive value, replace with period
        bl      BBU_putchr              ; Output character

        and     r0,     r1,     #0xFF00 ; Get the second byte
        mov     r0,     r0,     LSR #8  ; and move to lowest 8 bits
        cmp     r0,     #0X20           ; Check for low end of valid range
        movlt   r0,     #'.'            ; If .LT. above value, replace with period
        cmp     r0,     #0X7E           ; Check for high end of valid range
        movgt   r0,     #'.'            ; If .GT. abive value, replace with period
        bl      BBU_putchr              ; Output character

        and     r0,     r1,     #0xFF0000       ; Get the third byte
        mov     r0,     r0,     LSR #16         ; and move to lowest 8 bits
        cmp     r0,     #0X20           ; Check for low end of valid range
        movlt   r0,     #'.'            ; If .LT. above value, replace with period
        cmp     r0,     #0X7E           ; Check for high end of valid range
        movgt   r0,     #'.'            ; If .GT. abive value, replace with period
        bl      BBU_putchr              ; Output character

        and     r0,     r1,     #0xFF000000     ; Get the fourth byte
        mov     r0,     r0,     LSR #24         ; and move to lowest 8 bits
        cmp     r0,     #0X20           ; Check for low end of valid range
        movlt   r0,     #'.'            ; If .LT. above value, replace with period
        cmp     r0,     #0X7E           ; Check for high end of valid range
        movgt   r0,     #'.'            ; If .GT. abive value, replace with period
        bl      BBU_putchr              ; Output character

        ldmfd   sp!,    {r1, pc}        ; Restore r1 and return to caller		
        ENDFUNC
;*********************************************************************************
;
;       *******************
;       *                 * 
;       * BBU_UDecToAscii * Subroutine
;       *                 *
;       *******************
;
; This subroutine converts an unsigned 32 bit number to decimal ASCII
;
; PARAMETER PASSING:
;
;       INPUTS
;
;         r0 = contains the number to be converted
;         r1 = format of output as follows for the possible 10 digit output:
;            bit    6 = 0 to send output to UART, 1 to send output to buffer in r2
;            bit    5 = 0 for no comma delimeters, 1 = comma delimeters
;            bit    4 = 0 for no leading spaces before 1st digit, 1 = use spaces
;            bits 3:0 = number of digits to force in output (LS digit is ALWAYS displayed)
;         r2 = address of internal buffer (ignored if bit 6 of r1 = 0)
;
;       OUTPUTS:
;
;         r2 = updated pointer (if used on input)
;
BBU_UDecToAscii   FUNCTION
;
        stmfd   sp!,    {r0, r1, r3-r7, lr}     ; Save used registers
;
;       Check for x,000,000,000 digit
;
        mov     r5,     r1              ; Copy output format to r5
        mov     r6,     r2              ; Copy buffer address (if present) to r6
        and     r4,     r5,     #0xF    ; Put number of forced digits in r4
        ldr     r1,     =1000000000     ; Set up divisor
        bl      BBU_U32Divide           ; Divide
        orr    r0,      r2,     #0x30   ; Convert result to ASCII digit
        cmp    r0,      #0x30           ; Is it an ASCII zero?
        bne    %F20                     ; Nope - force printing of digit
        cmp    r4,      #10             ; Print leading zero?
        blt    %F22                     ; No - skip the following
20      ands    r7,     r5,     #0x40   ; UART or buffer output?
        strneb  r0,     [r6],   #1      ; Save byte in buffer
        bleq    BBU_putchr              ; Send byte to UART
        mov    r4,      #10             ; Force sucesive zeros to be printed 
        ands    r0,     r5,     #0x20   ; Print a comma?
        beq     %F25                    ; No - process next digit
        mov     r0,     #','            ; <comma>
        ands    r7,     r5,     #0x40   ; UART or buffer output?
        strneb  r0,     [r6],   #1      ; Save byte in buffer
        bleq    BBU_putchr              ; Send byte to UART
        b       %F25                    ; Process next digit
22      ands    r0,     r5,     #0x10   ; Output leading space?
        beq     %F25                    ; No - process next digit
        mov     r0,     #' '            ; <space>
        ands    r7,     r5,     #0x40   ; UART or buffer output?
        strneb  r0,     [r6],   #1      ; Save byte in buffer
        bleq    BBU_putchr              ; Send byte to UART
        ands    r0,     r5,     #0x20   ; Output <space> to allow for commas?
        beq     %F25                    ; No - process next digit
        mov     r0,     #' '            ; Yes - load a space
        ands    r7,     r5,     #0x40   ; UART or buffer output?
        strneb  r0,     [r6],   #1      ; Save byte in buffer
        bleq    BBU_putchr              ; Send byte to UART
;
;       Check for x00,000,000 digit
;

25      mov     r0,     r3              ; Copy remainder to dividend
        ldr     r1,     =100000000      ; Set up divisor
        bl      BBU_U32Divide           ; Divide 
        orr     r0,     r2,  #0x30      ; Convert to ASCII digit
        cmp     r0,     #0x30           ; Is it an ASCII zero?
        bne     %F30                    ; Nope - force printing of digit
        cmp     r4,     #9              ; Print leading zero?
        blt     %F32                    ; No - skip the following
30      ands    r7,     r5,     #0x40   ; UART or buffer output?
        strneb  r0,     [r6],   #1      ; Save byte in buffer
        bleq    BBU_putchr              ; Send byte to UART
        mov     r4,     #10             ; Force sucesive zeros to be printed
        b       %F35                    ; Process next digit
32      ands    r0,     r5,     #0x10   ; Output leading space?
        beq     %F35                    ; No - process next digit
        mov     r0,     #' '            ; <space>
        ands    r7,     r5,     #0x40   ; UART or buffer output?
        strneb  r0,     [r6],   #1      ; Save byte in buffer
        bleq    BBU_putchr              ; Send byte to UART                     
;
;       Check for x0,000,000 digit
;
35      mov     r0,     r3              ; Copy remainder to dividend
        ldr     r1,     =10000000       ; Set up divisor
        bl      BBU_U32Divide           ; Divide 
        orr     r0,     r2,     #0x30   ; Convert to ASCII digit
        cmp     r0,     #0x30           ; Is it an ASCII zero?
        bne     %F40                    ; Nope - force printing of digit
        cmp     r4,     #8              ; Print leading zero?
        blt     %F42                    ; No - skip the following
40      ands    r7,     r5,     #0x40   ; UART or buffer output?
        strneb  r0,     [r6],   #1      ; Save byte in buffer
        bleq    BBU_putchr              ; Send byte to UART
        mov     r4,     #10             ; Force sucesive zeros to be printed
        b       %F45                    ; Process next digit
42      ands    r0,     r5,     #0x10   ; Output leading space?
        beq     %F45                    ; No - process next digit
        mov     r0,     #' '    ; <space>
        ands    r7,     r5,     #0x40   ; UART or buffer output?
        strneb  r0,     [r6],   #1      ; Save byte in buffer
        bleq    BBU_putchr              ; Send byte to UART                     
;
;       Check for x,000,000 digit
;
45      mov     r0,     r3              ; Copy remainder to dividend
        ldr     r1,     =1000000        ; Set up divisor
        bl      BBU_U32Divide           ; Divide 
        orr     r0,     r2,     #0x30   ; Convert to ASCII digit
        cmp     r0,     #0x30           ; Is it an ASCII zero?
        bne     %F50                    ; Nope - force printing of digit
        cmp     r4,     #7              ; Print leading zero?
        blt     %F52                    ; No - skip the following
50      ands    r7,     r5,     #0x40   ; UART or buffer output?
        strneb  r0,     [r6],   #1      ; Save byte in buffer
        bleq    BBU_putchr              ; Send byte to UART
        mov     r4,     #10             ; Force sucesive zeros to be printed
        ands    r0,     r5,     #0x20   ; Print a comma?
        beq     %F55                    ; No - process next digit
        mov     r0,     #','            ; <comma>
        ands    r7,     r5,     #0x40   ; UART or buffer output?
        strneb  r0,     [r6],   #1      ; Save byte in buffer
        bleq    BBU_putchr              ; Send byte to UART
        b       %F55                    ; Process next digit
52      ands    r0,     r5,     #0x10   ; Output leading space?
        beq     %F55                    ; No - process next digit
        mov     r0,     #' '            ; <space>
        ands    r7,     r5,     #0x40   ; UART or buffer output?
        strneb  r0,     [r6],   #1      ; Save byte in buffer
        bleq    BBU_putchr              ; Send byte to UART
        ands    r0,     r5,     #0x20   ; Output <space> to allow for commas?
        beq     %F55                    ; No - process next digit
        mov     r0,     #' '            ; Yes - load a space
        ands    r7,     r5,     #0x40   ; UART or buffer output?
        strneb  r0,     [r6],   #1      ; Save byte in buffer
        bleq    BBU_putchr              ; Send byte to UART                    
;
;       Check for x00,000 digit
;
55      mov     r0,     r3              ; Copy remainder to dividend
        ldr     r1,     =100000         ; Set up divisor
        bl      BBU_U32Divide           ; Divide 
        orr     r0,     r2,     #0x30   ; Convert to ASCII digit
        cmp     r0,     #0x30           ; Is it an ASCII zero?
        bne     %F60                    ; Nope - force printing of digit
        cmp     r4,     #6              ; Print leading zero?
        blt     %F62                    ; No - skip the following
60      ands    r7,     r5,     #0x40   ; UART or buffer output?
        strneb  r0,     [r6],   #1      ; Save byte in buffer
        bleq    BBU_putchr              ; Send byte to UART
        mov     r4,     #10             ; Force sucesive zeros to be printed 
        b       %F65                    ; Process next digit
62      ands    r0,     r5,     #0x10   ; Output leading space?
        beq     %F65                    ; No - process next digit
        mov     r0,     #' '            ; <space>
        ands    r7,     r5,     #0x40   ; UART or buffer output?
        strneb  r0,     [r6],   #1      ; Save byte in buffer
        bleq    BBU_putchr              ; Send byte to UART                    
;
;       Check for x0,000 digit
;
65      mov     r0,     r3              ; Copy remainder to dividend
        ldr     r1,     =10000          ; Set up divisor
        bl      BBU_U32Divide           ; Divide 
        orr     r0,     r2,     #0x30   ; Convert to ASCII digit
        cmp     r0,     #0x30           ; Is it an ASCII zero?
        bne     %F70                    ; Nope - force printing of digit
        cmp     r4,     #5              ; Print leading zero?
        blt     %F72                    ; No - skip the following
70      ands    r7,     r5,     #0x40   ; UART or

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -