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

📄 bbu_uart.s

📁 关于PXA310的最小系统的程序,初级学习阶段会有所帮助,汇编语言编写的
💻 S
📖 第 1 页 / 共 5 页
字号:
;
;*********************************************************************************
;
;     COPYRIGHT (C) 2006-2007 Marvell International Ltd. All Rights Reserved.
;
;   The information in this file is furnished for informational use only,
;   is subject to change without notice, and should not be construed as
;   a commitment by Marvell. Marvell assumes no responsibility or liability
;   for any errors or inaccuracies that may appear in this software or any
;   documenation that may be provided in association with this software.
;
;*********************************************************************************
;
;                                  bbu_UART.s
;  BBU Subroutines for working with UARTs when a stack pointer is available for use. 
;
; LIST OF SUBROUTINES IN THIS FILE:
; ---------------------------------
;
; BBU_UART_Init Initalize the selected UART
;
; BBU_putchr    Outputs character in r0 to the BBU UART
;
; BBU_BTputchr  Outputs character in r0 to the Bluetooth UART
;
; BBU_FFputchr  Outputs character in r0 to the Full Feature UART
;
; BBU_STputchr  Outputs character in r0 to the Standard UART
;
; BBU_putstr    Outputs a NULL terminated string pointed to in r0 to the BBU UART
;
; BBU_hexchr    Converts bits 3:0 in r0 to an ASCII hex value and sends it to the BBU UART
;
; BBU_puthexd   Converts the 32 bit value in r0 to hex and sends it to the BBU UART
;
; BBU_puthexw   Converts the 16 bit value in r0 to hex and sends it to the BBU UART
;
; BBU_puthexb   Converts the 8 bit value in r0 to hex and sends it to the BBU UART
;
; BBU_crlf      Sends a <return> and <line feed> to the BBU UART
;
; BBU_getchr    Fetch a byte from the BBU UART (if avaliable)
;
; BBU_BTgetchr  Fetch a byte from the Bluetooth UART (if avaliable)
;
; BBU_FFgetchr  Fetch a byte from the Full Feature UART (if avaliable)
;
; BBU_STgetchr  Fetch a byte from the Standard UART (if avaliable)
;
; BBU_getstr    Fetchs an ASCII input string from the BBU UART
;
; BBU_TXempty   Loops unill the BBU UART transmit FIFO is empty
;
; BBU_BT_TXempty   Loops unill the Bluetooth UART transmit FIFO is empty
;
; BBU_FF_TXempty   Loops unill the Full Feature UART transmit FIFO is empty
;
; BBU_ST_TXempty   Loops unill the Standard UART transmit FIFO is empty
;
; BBU_ASCII_value    Converts 32-bit value to ASCII text equivalent   
;
; BBU_UDecToAscii    Converts a 32-bit binary number to an ASCII decimal number.
;
; BBU_Enable_UART_Int  Enables UART interrupt.
;

        INCLUDE bbu_Monahans_defs.inc
        INCLUDE bbu_Littleton_defs.inc

        GLOBAL  BBU_UART_Init           ; Init the selected UART
        GLOBAL  BBU_putchr              ; Output character in r0 to BBU UART port
        GLOBAL  BBU_BTputchr            ; Output character in r0 to BlueTooth UART port
        GLOBAL  BBU_FFputchr            ; Output character in r0 to Full Feature UART port
        GLOBAL  BBU_STputchr            ; Output character in r0 to standard UART port
        GLOBAL  BBU_putstr              ; Output NULL terminated string pointed to in r0
        GLOBAL  BBU_puthexchr           ; Output hex byte in r0 (lowest 4 LSBs)
        GLOBAL  BBU_puthexd             ; Output doubleword hex value in r0 (32-bits)
        GLOBAL  BBU_puthexw             ; Output word hex value in r0 (16-bits)
        GLOBAL  BBU_puthexb             ; Output byte hex value in r0 (8-bits)
        GLOBAL  BBU_crlf                ; Output <cr><lf> pair to BBU UART port
        GLOBAL  BBU_getchr              ; Fectch a byte from the BBU UART port
        GLOBAL  BBU_BTgetchr            ; Fectch a byte from the Bluetooth UART port
        GLOBAL  BBU_FFgetchr            ; Fectch a byte from the Full Feature UART port
        GLOBAL  BBU_STgetchr            ; Fectch a byte from the Standard UART port
        GLOBAL  BBU_getstr              ; Fetch an input string from the user
        GLOBAL  BBU_TXempty             ; Stay in this routine until the BBU tx buffer is empty
        GLOBAL  BBU_BT_TXempty          ; Stay in this routine until the Bluetooth tx buffer is empty
        GLOBAL  BBU_FF_TXempty          ; Stay in this routine until the Full Feature tx buffer is empty
        GLOBAL  BBU_ST_TXempty          ; Stay in this routine until the Standard tx buffer is empty
        GLOBAL  BBU_ASCII_value         ; Converts 32-bit value to ASCII text
        GLOBAL  BBU_UDecToAscii         ;
        GLOBAL  BBU_Enable_UART_Int     ; Enable UART interrupt

        GLOBAL  BBU_ibuf                ; BBU input buffer

        EXTERN  BBU_U32Divide           ; BBU 32-bit Unsigned division routine
        EXTERN  BBU_MCR                 ; Entry point to BBU Monitor Console Routine
        EXTERN  BBU_msWait              ; BBU wait routine (Milliseconds)
        EXTERN  BBU_PROMPT_MSG          ; Location of BBU's prompt.
        EXTERN  bbu_stat_data           ; Location of BBU status word

        AREA  |text|,CODE,READONLY 

;*********************************************************************************
;       *****************
;       *               * 
;       * BBU_UART_Init * Subroutine
;       *               *
;       *****************
;
; This subroutine initalizes the UART who's base address is in r0.
;
; PARAMETER PASSING:
;
;       INPUTS:
;
;         r0 = base address of the UART control registers (value preserved)
;         r1 = the baud rate divisor
;
; NOTES:
;
;    1. The MFPRs must be properly set up before calling this subroutine
;
;    2. Sample baud rate divisor values (for r1) are as follows:
;
;       9600 baud   = 0x60
;       38400 baud  = 0x18
;       115200 baud = 0x08
;
;    3. Keep serial cable short (under 6 feet) especially at the higher baud rates.
;
;    4. The transmit FIFO is 64 8-bit bytes deep.
;

BBU_UART_Init  FUNCTION

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

        mov     r2,     #0x0                    ; Zero out a work register
        str     r2,     [r0, #bbu_UAIER_offset] ; Zero out Interrupt Enable Register
        str     r2,     [r0, #bbu_UAFCR_offset] ; Zero out FIFO Control Register
        str     r2,     [r0, #bbu_UALCR_offset] ; Zero out Line Control Register
        str     r2,     [r0, #bbu_UAMCR_offset] ; Zero out Modem Control Register
        str     r2,     [r0, #bbu_UAISR_offset] ; Zero out IR bit register
        ldr     r2,     [r0, #bbu_UAMSR_offset] ; Read MSR once to clear bits

        mov     r2,     #0x83           ; 8 bit character, no parity, 1 stop bit
        str     r2,     [r0,  #bbu_UALCR_offset]; Set DLAB bit

        str     r1,     [r0,  #bbu_UADLL_offset]; set baud rate
        ldr     r2,     =0x0                    ; Insure high baud rate byte is zero
        str     r2,     [r0,  #bbu_UADLH_offset]

        ldr     r2,     [r0,  #bbu_UALCR_offset]; Get LCR values
        bic     r2,     r2,   #bbu_DLAB         ; Clear DLAB bit
        str     r2,     [r0,  #bbu_UALCR_offset]; Write the value back out
        mov     r2,     #0x01                   ; This value will clear the TX and RX FIFOs
        str     r2,     [r0,  #bbu_UAFCR_offset]; ... and enabale the FIFOs for use.

        mov     r2,     #0x40                   ; set unit enable bit
        str     r2,     [r0,  #bbu_UAIER_offset]; enable the UART

        ldmfd   sp!,    {r2, pc}        ; Return to caller

        ENDFUNC
;
;*********************************************************************************
;
;       **************
;       *            * 
;       * BBU_purchr * Subroutine "BBU Put Character"
;       *            *
;       **************
;
; This subroutine outputs the character in r0 to the BBU UART port.
;
; 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_putchr      FUNCTION

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

        ldr     r1,     =bbu_stat_data          ; Get address where system status data stored
        ldr     r2,     [r1]                    ; Fetch BBU status word
        ldr     r1,     =bbu_BBUART_PHYSICAL_BASE
        ands    r2,     r2,     #BBU_STAT_IRDA  ; Test for IrDA port enable
        beq     %F10                            ; Skip the following if RS232 port is used
;
;       The following 2 lines of code set up the UART for IrDA transmit use
;
        mov     r2,     #0X15                   ; Set UART for IrDA transmit use
        str     r2,     [r1, #bbu_UAISR_offset] ; Set Infrared Select Register

10      ldr     r2,     [r1, #bbu_UALSR_offset] ; Get Line Status Register Data
        ands    r2,     r2,     #bbu_TDRQ       ; Is TDRQ (Transmit Data Request) bit set?
        beq     %B10                            ; 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_BTpurchr * Subroutine "BBU Put Character" to BlueTooth UART
;       *              *
;       ****************
;
; This subroutine outputs the character in r0 to the bluetooth 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_BTputchr    FUNCTION

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

        ldr     r1,     =bbu_BTUART_PHYSICAL_BASE
           IF :DEF: bbu_BT_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
12      ldr     r2,     [r1, #bbu_UALSR_offset] ; Get Line Status Register Data
        ands    r2,     r2,     #bbu_TDRQ       ; Is TDRQ (Transmit Data Request) bit set?
        beq     %B12                            ; 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_FFpurchr * Subroutine "BBU Put Character" to Full Feature UART
;       *              *
;       ****************
;
; This subroutine outputs the character in r0 to the bluetooth 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_FFputchr    FUNCTION

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

        ldr     r1,     =bbu_FFUART_PHYSICAL_BASE
           IF :DEF: bbu_FF_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
14      ldr     r2,     [r1, #bbu_UALSR_offset] ; Get Line Status Register Data
        ands    r2,     r2,     #bbu_TDRQ       ; Is TDRQ (Transmit Data Request) bit set?
        beq     %B14                            ; 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
;
;*********************************************************************************
;

⌨️ 快捷键说明

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