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

📄 bbu_uart.s

📁 关于PXA310的最小系统的程序,初级学习阶段会有所帮助,汇编语言编写的
💻 S
📖 第 1 页 / 共 5 页
字号:
;       ****************
;       *              * 
;       * BBU_STpurchr * Subroutine "BBU Put Character" to standard UART
;       *              *
;       ****************
;
; This subroutine outputs the character in r0 to the standard UART.
;
; PARAMETER PASSING:
;
;       r0 contains the byte of data that will be sent out on the port (preserved)
;
; 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 character has been
; sent to the output FIFO buffer.
;

BBU_STputchr    FUNCTION

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

        ldr     r1,     =bbu_STUART_PHYSICAL_BASE
           IF :DEF: bbu_ST_IRDA                 ; This code is for IRDA use only!
        mov     r2,     #0X15                   ; Set UART for IRDA transmit use
        str     r2,     [r1, #bbu_UAISR_offset] ; Set Infrared Select Register
           ENDIF
16      ldr     r2,     [r1, #bbu_UALSR_offset] ; Get Line Status Register Data
        ands    r2,     r2,     #bbu_TDRQ       ; Is TDRQ (Transmit Data Request) bit set?
        beq     %B16                            ; No - loop until it is
        strb    r0,     [r1, #bbu_UATHR_offset] ; It's ready! - output byte to buffer	
        ldmfd   sp!,    {r1, r2, pc}            ; Restore r1, r2 and return to caller

        ENDFUNC
;
;*********************************************************************************
;
;       **************
;       *            * 
;       * BBU_putstr * Subroutine "BBU Put String"
;       *            *
;       **************
;
; This subroutine outputs the string pointed to by r0 to the selected UART.
;
; PARAMETER PASSING:
;
;       r0 contains the address of NULL terminated ASCII string that will be sent to the
;          BBU UART (destroyed) 
;
; NOTES:
;
;    1. The selected UART port must be initalized first - otherwise this will hang the system!
;
; Control is passed back to the caller after the last character has been
; sent to the UART transmit buffer.
;

BBU_putstr      FUNCTION

        stmfd   sp!,    {r1, lr}        ; Save r1 and link register on the stack
        mov     r1,     r0              ; Copy string address to r1
20      ldrb    r0,     [r1],   #1      ; copy a byte into r0
        cmp     r0,     #0              ; See if byte is null
        beq     %F25                    ; Yes - take exit path
        bl      BBU_putchr              ; No - output character to UART
        b       %B20                    ; Get another byte
25      ldmfd   sp!,    {r1, pc}        ; Restore r1 and return to caller

        ENDFUNC
;
;*********************************************************************************
;
;       *****************
;       *               * 
;       * BBU_puthexchr * Subroutine "BBU Put Hex Character"
;       *               *
;       *****************
;
; This subroutine takes the 4 LS bits in r0, converts it to an ASCII value from 0-F and sends
; it out to the BBU UART.
;
; PARAMETER PASSING:
;
;       r0 contains the 4-bit value to be converted (destroyed)
;
; NOTES:
;
;    1. The UART port must be initalized first - otherwise this code will hang the system!
;
; Control is passed back to the caller only after the character has been
; sent to the UART FIFO buffer.
;
BBU_puthexchr   FUNCTION

        stmfd   sp!,    {lr}            ; Save r1 and link register on the stack
        and     r0,     r0,     #0xF    ; save the lowest 4 bits of r0
        add     r0,     r0,     #0x30   ; Add ASCII 0 (zero) to the data
        cmp     r0,     #0x39           ; Compare to ASCII "9" 
        addgt   r0,     r0,     #0x7    ; If .GT. 9 add 0x7 to get to letter value
        bl      BBU_putchr              ; Output to UART
        ldmfd   sp!,    {pc}            ; return to caller

        ENDFUNC
;
;*********************************************************************************
;
;       ***************
;       *             * 
;       * BBU_puthexd * Subroutine "BBU Put Hex Doubleword"
;       *             *
;       ***************
;
; This subroutine takes the 32 bit value in r0, converts it to an ASCII hex value in
; the format "0xHHHHHHHH" (where ecah "H" represents the hex value 0-F). The output
; is sent to the BBU UART.
;
;
; PARAMETER PASSING:
;
;       r0 contains the data to be converted and displayed
;       r1 If = 1, will not display the leading "0x" (otherwise ignored)
;
; NOTES:
;
;    1. The selected UART port must be initalized first - otherwise this will hang!
;
; Control is passed back to the caller only after the hex value has been
; sent to the output FIFO buffer.
;

BBU_puthexd     FUNCTION

        stmfd   sp!,    {r0-r2, lr}     ; Save registers and link on the stack
        mov     r2,     r0              ; Save value in r2
        cmp     r1,     #1              ; Supress leading 0x?
        beq     %F3                     ; Yes - skip the following
        ldr     r0,     ='0'            ; Send out "0x" prefix
        bl      BBU_putchr              ; Output byte to UART
        ldr     r0,     ='x'
        bl      BBU_putchr
;
;       Output 32 bit hex value
;
3       mov     r0,     r2,     LSR #28 ; Copy & shift 1st digit value into r0
        bl      BBU_puthexchr           ; Output hex byte 
        mov     r0,     r2,     LSR #24 ; Copy & shift 2nd digit value into r0
        bl      BBU_puthexchr           ; Output hex byte 
        mov     r0,     r2,     LSR #20 ; Copy & shift 3rd digit value into r0
        bl      BBU_puthexchr           ; Output hex byte 
        mov     r0,     r2,     LSR #16 ; Copy & shift 4th digit value into r0
        bl      BBU_puthexchr           ; Output hex byte 
        mov     r0,     r2,     LSR #12 ; Copy & shift 5th digit value into r0
        bl      BBU_puthexchr           ; Output hex byte 
        mov     r0,     r2,     LSR #8  ; Copy & shift 6th digit value into r0
        bl      BBU_puthexchr           ; Output hex byte 
        mov     r0,     r2,     LSR #4  ; Copy & shift 7th digit value into r0
        bl      BBU_puthexchr           ; Output hex byte 
        mov     r0,     r2              ; Copy 8th digit value into r0
        bl      BBU_puthexchr           ; Output hex byte  
        ldmfd   sp!,    {r0-r2, pc}    ; Restore r0, r1 and return to caller

        ENDFUNC
;
;*********************************************************************************
;
;       ***************
;       *             * 
;       * BBU_puthexw * Subroutine "BBU Put Hex Word"
;       *             *
;       ***************
;
; This subroutine takes the 16 bit value in r0, converts it to an ASCII hex value in
; the format "0xHHHH" (where ecah "H" represents the hex value 0-F). The output
; is sent to the BBU UART.
;
;
; PARAMETER PASSING:
;
;       r0 contains the data to be converted and displayed
;       r1 If = 1, will not display the leading "0x" (otherwise ignored)
;
; NOTES:
;
;    1. The selected UART port must be initalized first - otherwise this will hang!
;
; Control is passed back to the caller only after the hex value has been
; sent to the output FIFO buffer.
;

BBU_puthexw     FUNCTION

        stmfd   sp!,    {r0-r2, lr}     ; Save registersw and link on the stack
        mov     r2,     r0              ; Save value in r2
        cmp     r1,     #1              ; Supress 0x prefix?
        beq     %F4                     ; Yes - skip the following
        ldr     r0,     ='0'            ; Send out "0x" prefix
        bl      BBU_putchr              ; Output byte to UART
        ldr     r0,     ='x'
        bl      BBU_putchr
;
;       Output 16 bit hex value
; 
4       mov     r0,     r2,     LSR #12 ; Copy & shift 1st digit value into r0
        bl      BBU_puthexchr           ; Output hex byte 
        mov     r0,     r2,     LSR #8  ; Copy & shift 2nd digit value into r0
        bl      BBU_puthexchr           ; Output hex byte 
        mov     r0,     r2,     LSR #4  ; Copy & shift 3rd digit value into r0
        bl      BBU_puthexchr           ; Output hex byte 
        mov     r0,     r2              ; Copy 4th digit value into r0
        bl      BBU_puthexchr           ; Output hex byte  
        ldmfd   sp!,    {r0-r2, pc}     ; Restore registers and return to caller

        ENDFUNC
;
;*******************************************************************************
;
;       ***************
;       *             * 
;       * BBU_puthexb * Subroutine "BBU Put Hex Byte"
;       *             *
;       ***************
;
; This subroutine takes the 8 bit value in r0, converts it to an ASCII hex value in
; the format "0xHHHH" (where ecah "H" represents the hex value 0-F). The output
; is sent to the BBU UART.
;
;
; PARAMETER PASSING:
;
;       r0 contains the data to be converted and displayed
;       r1 If = 1, will not display the leading "0x" (otherwise ignored)
;
; NOTES:
;
; Control is passed back to the caller only after the hex value has been
; sent to the output FIFO buffer.
;

BBU_puthexb     FUNCTION

        stmfd   sp!,    {r0-r2, lr}     ; Save r0-r2 and link register on the stack
        mov     r2,     r0              ; Save value in r2
        cmp     r1,     #1              ; is r1 equal to 1?
        beq     %F5                     ; Yes - skip "0x" prefix
        ldr     r0,     ='0'            ; Send out "0x" prefix
        bl      BBU_putchr              ; Output byte to UART
        ldr     r0,     ='x'
        bl      BBU_putchr
;
;       Output 8 bit hex value
;  
5       mov     r0,     r2,     LSR #4  ; Copy & shift 1st digit value into r0
        bl      BBU_puthexchr           ; Output hex byte 
        mov     r0,     r2              ; Copy 2nd digit value into r0
        bl      BBU_puthexchr           ; Output hex byte  
        ldmfd   sp!,    {r0- r2, pc}    ; Restore r0-r2 and return to caller

        ENDFUNC
;
;*********************************************************************************
;
;       ************
;       *          * 
;       * BBU_crlf * Subroutine "BBU carrage return, line feed"
;       *          *
;       ************
;
; This subroutine sends a <return> and <line feed> character to the BBU UART
;
;
; PARAMETER PASSING:
;
;       No parameters
;
; NOTES:
;
;    1. The selected UART port must be initalized first - otherwise this will hang!
;
; Control is passed back to the caller only after the <return> and <line feed>
; have been sent to the BBU UART
;

BBU_crlf        FUNCTION

        stmfd   sp!,    {r0, lr}; Save r0 & link register on the stack
        ldr     r0,     =0xD    ; r0 = <return>
        bl      BBU_putchr      ; Output byte to UART
        ldr     r0,     =0xA    ; r0 = <line feed>

⌨️ 快捷键说明

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