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

📄 bbu_codec.s

📁 关于PXA310的最小系统的程序,初级学习阶段会有所帮助,汇编语言编写的
💻 S
📖 第 1 页 / 共 4 页
字号:
;
;       Check for user input
;
363     mov     r0,     #2      ; Do not echo input character
        bl      BBU_getchr      ; Check the keyboard for input
        beq     %B631           ; Nothing came in - do another loop
        b       %F639           ; Exit path
;
;       Read Error Exit
;
634     ldr     r0,     =BBU_TPAN_RERR  ; Error message
        bl      BBU_putstr              ; Output string
;
;       Exit path
;
639     ldmfd   sp!,    {r0-r5,pc} ; Return to caller
        ENDFUNC       
;
;       TPAN Messaqges
;
BBU_TPAN_INS    DCB     "tpan--> Press any key to stop the readings.",0xD,0xA,0
BBU_TPAN_MSGXU  DCB     "tpan--> Pen UP  , X value = ",0
BBU_TPAN_MSGXD  DCB     "tpan--> Pen DOWN, X value = ",0
BBU_TPAN_MSGY   DCB     ", Y value = ",0
BBU_TPAN_RERR   DCB     "tpan--> I2C timeout - command terminated.",0xD,0xA,0xA,0
        ALIGN   4
;
;*********************************************************************************
;
;       ****************
;       *              * 
;       * BBU_SPKR_VOL * Subroutine
;       *              *
;       ****************
;
;       This subroutine sets the speaker volume
;
; PARAMETER PASSING:
;
;       INPUT:
;
;         r0 = Speaker volume level (0-63)
;
BBU_SPKR_VOL    FUNCTION
        stmfd   sp!,    {r0-r3,lr}      ; Save used registers
;
;       Modify user data into the format needed by the codec
;
        mvn     r2,     r0              ; Invert the data
        and     r2,     r2,     #0x3F   ; Mask out all unused bits
        orr     r3,     r2,     #0x40   ; Enable Mono amp with soft start up
;
;       Set the I2C address for the DA9034 audio codec
;
        mov     r1,  #0x68                      ; I2C address for PMIC
        ldr     r0,  =bbu_FFUART_PHYSICAL_BASE  ; Fetch base address of FFUART
        str     r1,  [r0, #bbu_UASPR_offset]    ; Store I2C address in the scratch pad register
;
;       Set up the BEAR amp (This amp must be enabled to get output from the speaker)
;
        mov     r0,     #0x7A           ; Register 0x79 (BEAR_VOL) This amp must be enabled
        bl      BBU_getI2C              ; Read the data
        orr     r1,     r1,     #0x40   ; OR in the enable bit
        bl      BBU_putI2C              ; Write back out to I2C bus 
;
;       Set the speaker volume
;
        mov     r0,     #0x79   ; Register 0x79 (MONO_VOL)
        mov     r1,     r3      ; Copy the user data to r1
        bl      BBU_putI2C      ; Write out to I2C bus
;
;       Exit path
;
        ldmfd   sp!,    {r0-r3,pc} ; Return to caller
        ENDFUNC
;
;*********************************************************************************
;
;       ***************
;       *             * 
;       * BBU_EAR_VOL * Subroutine
;       *             *
;       ***************
;
;       This subroutine sets the ear speaker volume
;
; PARAMETER PASSING:
;
;       INPUT:
;
;         r0 = Speaker volume level (0-63)
;
BBU_EAR_VOL     FUNCTION
        stmfd   sp!,    {r0-r2,lr}      ; Save used registers
;
;       Modify user data into the format needed by the codec
;
        mvn     r2,     r0              ; Invert the data
        and     r2,     r2,     #0x3F   ; Mask out all unused bits
        orr     r2,     r2,     #0x40   ; Enable Mono amp with soft start up
;
;       Set the I2C address for the DA9034 audio codec
;
        mov     r1,  #0x68                      ; I2C address for PMIC
        ldr     r0,  =bbu_FFUART_PHYSICAL_BASE  ; Fetch base address of FFUART
        str     r1,  [r0, #bbu_UASPR_offset]    ; Store I2C address in the scratch pad register
;
;       Set up the BEAR volume
;
        mov     r0,     #0x7A   ; Register 0x70 (BEAR_VOL)
        mov     r1,     r2      ; Copy volume to r1
        bl      BBU_putI2C      ; Write out to I2C bus 
;
;       The MONO amp must also be enabled to get audio out of the BEAR amplifier
;
        mov     r0,     #0x79           ; Register 0x79 (MONO_VOL) This amp must be enabled
        bl      BBU_getI2C              ; Read the data
        orr     r1,     r1,     #0x40   ; OR in the enable bit
        bl      BBU_putI2C              ; Write back out to I2C bus
;
;       Exit path
;
        ldmfd   sp!,    {r0-r2,pc} ; Return to caller
        ENDFUNC
;
;*********************************************************************************
;
;       ******************
;       *                * 
;       * BBU_CODEC_TONE * Subroutine
;       *                *
;       ******************
;
;       This subroutine sends tones to the codec
;
; PARAMETER PASSING:
;
;       INPUT:
;
;         This code will fetch the arguments directly from the decoded command
;         string arrays (BBU_CMD_SW and BBU_CMD_ARG)
;
;       OUTPUT:
;
;         r0 = 0 if tone is sent on I2S bus
;         r0 = 'P' if tone is sent on PCM bus
;
BBU_CODEC_TONE  FUNCTION
        stmfd   sp!,    {r1-r10,lr}      ; Save used registers
;
;       Kill any DMA TONE code that may be running
;
        ldr     r5,     =bbu_DMA_PHYSICAL_BASE          ; Get physical base of DMA controller
        ldr     r6,     =0x0                            ; Kill any DMA on this channel
        str     r6,     [r5, #bbu_DMA_DCSR6_offset]     ; Control/Status for DMA channel 6
;
;       Prepare to assemble the requested tone data into the TONE_D array
;
393     ldr     r4,     =BBU_CMD_SW     ; Command switches are located here
        ldr     r5,     =BBU_CMD_ARG    ; Command arguments are located here
        ldr     r7,     [r5]            ; Fetch 1st argument
        cmp     r7,     #0              ; Is it zero?
        beq     %F399                   ; Yes - just exit
;
;       See if the user specified the PCM bus and store the result in r10 for later reference
;
        mov     r10,    #0      ; Clear r10
        ldrb    r6,     [r4]    ; Fetch the 1st parameter
        cmp     r6,     #'P'    ; Is switch #1 = 'P'?
        moveq   r10,    r6      ; YES copy r6 to r10

        ldr     r6,     =TONE_D ; Tone Data goes here
        mov     r7,     #96     ; Size of the array
        mov     r0,     #0      ; Data to be loaded
;
;       Clear out the array
;
394     str     r0,     [r6],   #4      ; Reset this location
        subs    r7,     r7,     #1      ; Decrement count
        bne     %B394                   ; Loop until clear
;
;       Brach to code depending on if the user specified I2S data (default)
;       or PCM data (by using the /P switch on the command line)
;
        cmp     r10,    #'P'    ; Did the use specifiey PCM mode?
        beq     PCM_T           ; Yes - branch to code
;
;       *********************************************
;       ********** I2S BUS TONE DATA SETUP **********
;       *********************************************
;
;       Process the 1st parameter
;
        ldr     r6,     =TONE_D         ; Reset base address of data array
        ldr     r8,     =T_DATA         ; Pointer to tone data
        ldrb    r0,     [r4],   #1      ; Get switch value
        cmp     r0,     #'R'            ; Right channel? (otherwise do left channel)
        addeq   r6,     r6,     #4      ; YES - Add offset to right channel data
        cmp     r2,     #2              ; Insert 2KHz Tone?
        beq     K2HZA                   ; Yes, skip to code
        cmp     r2,     #4              ; Insert 4KHz Tone?
        beq     K4HZA                   ; Yes, skip to code
;
;       Load 1KHz tone into selected channel
;
K1HZA   mov     r7,     #48             ; Size of the array/2
K1HZA1  ldr     r0,     [r8],   #4      ; Get data
        str     r0,     [r6],   #8      ; Load data and skip to next entry
        subs    r7,     r7,     #1      ; Decrement count
        bne     K1HZA1                  ; Loop until done
        b       TONE2                   ; Process 2nd parameter
;
;       Load 2KHz tone into selected channel
;
K2HZA   mov     r7,     #24             ; Size of the array/4
        mov     r9,     #2              ; Loop count for 2 KHz
K2HZA1  ldr     r0,     [r8],   #8      ; Get data & increment pointer
        str     r0,     [r6],   #8      ; Load data and skip to next entry
        subs    r7,     r7,     #1      ; Decrement count
        bne     K2HZA1                  ; Loop until done
        ldr     r8,     =T_DATA         ; Pointer to tone data
        mov     r7,     #24             ; Size of the array/4
        subs    r9,     r9,     #1      ; Decrement outer loop count
        bne     K2HZA1                  ; Keep looping if not zero
        b       TONE2                   ; Process 2nd parameter
;
;       Load 4KHz tone into selected channel
;
K4HZA   mov     r7,     #12             ; Size of the array/8
        mov     r9,     #4              ; Loop count for 4 KHz
K4HZA1  ldr     r0,     [r8],   #16     ; Get data & increment pointer
        str     r0,     [r6],   #8      ; Load data and skip to next entry
        subs    r7,     r7,     #1      ; Decrement count
        bne     K4HZA1                  ; Loop until done
        ldr     r8,     =T_DATA         ; Pointer to tone data
        mov     r7,     #12             ; Size of the array/8
        subs    r9,     r9,     #1      ; Decrement outer loop count
        bne     K4HZA1                  ; Keep looping if not zero
;
;       Process the 2nd parameter
;
TONE2   cmp     r1,     #1              ; Only 1 parameter?
        beq     %F397                   ; Yes - start DMA
        ldr     r6,     =TONE_D         ; Reset base address of data array
        ldr     r8,     =T_DATA         ; Pointer to tone data
        ldrb    r0,     [r4],   #1      ; Get switch value
        cmp     r0,     #'R'            ; Right channel? (otherwise do left channel)
        addeq   r6,     r6,     #4      ; YES - Add offset to right channel data
        cmp     r3,     #2              ; Insert 2KHz Tone?
        beq     K2HZB                   ; Yes, skip to 2KHz code
        cmp     r3,     #4              ; Insert 4KHz Tone?
        beq     K4HZB                   ; Yes, skip to 4KHz code
;
;       Load 1KHz tone into selected channel
;
K1HZB   mov     r7,     #48             ; Size of the array/2
K1HZB1  ldr     r0,     [r8],   #4      ; Get data
        str     r0,     [r6],   #8      ; Load data and skip to next entry
        subs    r7,     r7,     #1      ; Decrement count
        bne     K1HZB1                  ; Loop until done
        b       %F397                   ; Set up DMA
;
;       Load 2KHz tone into selected channel
;
K2HZB   mov     r7,     #24             ; Size of the array/4
        mov     r9,     #2              ; Loop count for 2 KHz
K2HZB1  ldr     r0,     [r8],   #8      ; Get data & increment pointer
        str     r0,     [r6],   #8      ; Load data and skip to next entry
        subs    r7,     r7,     #1      ; Decrement count
        bne     K2HZB1                  ; Loop until done
        ldr     r8,     =T_DATA         ; Pointer to tone data
        mov     r7,     #24             ; Size of the array/4
        subs    r9,     r9,     #1      ; Decrement outer loop count
        bne     K2HZB1                  ; Keep looping if not zero
        b       %F397                   ; Set up DMA
        ;
;       Load 4KHz tone into selected channel
;
K4HZB   mov     r7,     #12             ; Size of the array/8
        mov     r9,     #4              ; Loop count for 4 KHz
K4HZB1  ldr     r0,     [r8],   #16     ; Get data & increment pointer
        str     r0,     [r6],   #8      ; Load data and skip to next entry
        subs    r7,     r7,     #1      ; Decrement count
        bne     K4HZB1                  ; Loop until done
        ldr     r8,     =T_DATA         ; Pointer to tone data
        mov     r7,     #12             ; Size of the array/8
        subs    r9,     r9,     #1      ; Decrement outer loop count
        bne     K4HZB1                  ; Keep looping if not zero
        b       %F397                   ; Set up DMA
;
;       *********************************************
;       ********** PCM BUS TONE DATA SETUP **********
;       *********************************************
;
;       Process the 1st parameter
;
PCM_T   ldr     r6,     =TONE_D         ; Reset base address of data array
        ldr     r8,     =T_DATA         ; Pointer to tone data
        ldr     r5,     =BBU_CMD_ARG    ; Command arguments are located here
        ldr     r2,     [r5]            ; Get 1st parameter value
        cmp     r2,     #2              ; Insert 667 Hz Tone?
        beq     PK2HZA                  ; Yes, skip to code
        cmp     r2,     #4              ; Insert 1.3 KHz Tone?
        beq     PK4HZA                  ; Yes, skip to code
        cmp     r2,     #6              ; Insert 2.0 KHz Tone?
        beq     PK6HZA                  ; Yes, skip to code
;
;       Load 333 Hz tone into selected channel
;
PK1HZA  mov     r7,     #48             ; Size of the array
        mov     r9,     #2              ; Loop count for 333 Hz
PK1HZA1 ldr     r0,     [r8],   #4      ; Get data
        mov     r0,     r0,     LSR #16 ; move to lower word
        str     r0,     [r6],   #4      ; Load data & increment pointer
        subs    r7,     r7,     #1      ; Decrement count
        bne     PK1HZA1                 ; Loop until done
        ldr     r8,     =T_DATA         ; Pointer to tone data
        mov     r7,     #48             ; Size of the data array
        subs    r9,     r9,     #1      ; Decrement outer loop count
        bne     PK1HZA1                 ; Keep looping if not zero
        b       %F397                   ; Set up the DMA
;
;       Load 667 Hz tone into selected channel
;
PK2HZA  mov     r7,     #24             ; Size of the array/2
        mov     r9,     #4              ; Loop count for 667 Hz
PK2HZA1 ldr     r0,     [r8],   #8      ; Get data & increment pointer
        mov     r0,     r0,     LSR #16 ; move to lower word
        str     r0,     [r6],   #4      ; Load data & increment pointer
        subs    r7,     r7,     #1      ; Decrement count
        bne     PK2HZA1                 ; Loop until done
        ldr     r8,     =T_DATA         ; Pointer to tone data
        mov     r7,     #24             ; Size of the array/4
        subs    r9,     r9,     #1      ; Decrement outer loop count
        bne     PK2HZA1                 ; Keep looping if not zero
        b       %F397                   ; Set up the DMA
;
;       Load 1.3 KHz tone into selected channel

⌨️ 快捷键说明

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