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

📄 bbu_one_wire.s

📁 关于PXA310的最小系统的程序,初级学习阶段会有所帮助,汇编语言编写的
💻 S
📖 第 1 页 / 共 2 页
字号:
;*********************************************************************************
;
;     COPYRIGHT (C) 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_One_Wire.s
;                   One-Wire routines for Board Bring Up (BBU)
;
;
;       Addresses and offsets used in this module
;
BBU_W1_PHYSICAL_BASE    EQU     0x41B00000      ; 1-Wire Controller base address
BBU_W1CMDR_offset       EQU     0x00            ; 1-Wire Command Register
BBU_W1TRR_offset        EQU     0x04            ; 1-Wire Trans/Rec buffer
BBU_W1INTR_offset       EQU     0x08            ; 1-Wire Interrupt Register
BBU_W1IER_offset        EQU     0x0C            ; 1-Wire Interrupt Enable Register
BBU_W1CDR_offset        EQU     0x10            ; 1-Wire Clock Divisior Register
;
;       Bit definitions used in this file
;
BBU_1WR         EQU     0x01    ; 1-Wire Reset bit
BBU_PDR         EQU     0x02    ; Presence Detect Result
BBU_RBF         EQU     0x10    ; Receive buffer full
BBU_TBE         EQU     0x04    ; Transmit Buffer Empty
BBU_TEMT        EQU     0x08    ; Transmit Shift Register Empty

        GLOBAL  BBU_Fuel_Level  ; Read data from Fuel Gauge & return to user
        GLOBAL  BBU_1W_readReg  ; Read from a single register
        GLOBAL  BBU_1W_writeReg ; Write to a single register
        GLOBAL  BBU_1W_putchr   ; Write a byte to the one-wire interface
        GLOBAL  BBU_1W_getchr   ; Read a byte from the one-wire interface
        GLOBAL  BBU_1W_init     ; 1-Wire init subroutine
        GLOBAL  BBU_1W_BattInit ; Write battery parameters to fuel gauge

        EXTERN  BBU_msWait      ; Delay r0 milliseconds
        EXTERN  BBU_usWait      ; Delay r0 microseconds

        AREA  |text|,CODE,READONLY
;
;*********************************************************************************
;
;       ******************
;       *                * 
;       * BBU_Fuel_Level * Subroutine
;       *                *
;       ******************
;
;       This subroutine reads the "fuel level" data from the fuel gauge IC.
;       The One-Wire GPIO is assumed to have been previously configured.
;       Set up is simple - BBU just sets up the interface on every call.
;
; PARAMETERS:
;
;       INPUT: None
;
;       OUTPUT: 9 values are returned in 4 registers as follows:
;               Assume all values (except 8-bit % returns) are signed.
;
;       r0 (15:00) = Remaining Active Absolute Capacity in milli-amp-hours
;       r0 (31:16) = Remaining Standby Absolute Capacity in mili-amp-hours
;       r1 (07:01) = Remaining Active Relative Capacity in percent
;       r1 (15:08) = Remaining Standby Relative Capacity in percent
;       r1 (31:16) = Average Curent (over 28 sec) 78.13 uA per bit
;       r2 (15:00) = Battery Temperature as 0.0625 deg/C per bit (spec says 0.125 deg/C/bit)
;       r2 (31:16) = Battery Voltage as 4.88 mV per bit
;       r3 (15:00) = Battery Current as 78.13 uA per bit (Updated every 3.51 sec)
;       r3 (31:16) = Full Capacity of battery 
;
;
;
BBU_Fuel_Level  FUNCTION

        stmfd   sp!,    {r4-r5, lr}     ; Save used registers & link on stack
        mov     r0,     #2              ; Read from register #2
        bl      BBU_1W_readReg          ; Read from spcified register
        mov     r5,     r1,     LSL #8  ; Copy to r5 shifted left by 8 bits        
        bl      BBU_1W_getchr           ; Remaining Active Absolute capacity LSB
        orr     r5,     r5,     r0      ; OR in the 8 LSBs
        bl      BBU_1W_getchr           ; Remaining Standby Absolute capacity MSB
        mov     r0,     r0,     LSL #24 ; Shift to the 4th byte
        orr     r5,     r5,     r0      ; OR into r5
        bl      BBU_1W_getchr           ; Remaining Standby Absolute capacity LSB
        mov     r0,     r0,     LSL #16 ; Shift to the 3rd byte
        orr     r5,     r5,     r0      ; OR into r5
;
;       Assemble the data to be returned in r1
;
        bl      BBU_1W_getchr           ; Remaining Active Relative capacity
        mov     r1,     r0              ; Copy to r1
        bl      BBU_1W_getchr           ; Remaining Standby Relative capacity
        mov     r0,     r0,     LSL #8  ; Shift left by 8 bits
        orr     r1,     r1,     r0      ; OR in this data
        bl      BBU_1W_getchr           ; Average Current MSB
        mov     r0,     r0,     LSL #24 ; Shift left by 24 bits
        orr     r1,     r1,     r0      ; OR in this data        
        bl      BBU_1W_getchr           ; Average Current LSB
        mov     r0,     r0,     LSL #16 ; Shift left by 16 bits
        orr     r1,     r1,     r0      ; OR in this data
;
;       Assemble data to be returned in r2
;
        bl      BBU_1W_getchr           ; TEMP Register MSB
        mov     r2,     r0,     LSL #3  ; Copy data to r2 left shifted by 3 bits
        bl      BBU_1W_getchr           ; TEMP Register LSB
        mov     r0,     r0,     LSR #5  ; Right shift the data by 5 bits
        orr     r2,     r2,     r0      ; OR into the data alreay in r2
        bl      BBU_1W_getchr           ; Voltage Register MSB
        mov     r0,     r0,     LSL #19 ; Shift left by 19 bits
        orr     r2,     r2,     r0      ; OR in this data   
        bl      BBU_1W_getchr           ; Voltage Register LSB
        and     r0,     r0,     #0xE0   ; Save off the top 3 bits
        mov     r0,     r0,     LSL #11 ; Shift left by 11 bits
        orr     r2,     r2,     r0      ; OR in this data   
;
;       Assemble data to be returned in r3
;
        bl      BBU_1W_getchr           ; Current Register MSB
        mov     r3,     r0,     LSL #8  ; Copy to r3 left shifted by 8 bits
        bl      BBU_1W_getchr           ; Current Register LSB
        orr     r3,     r3,     r0      ; OR in the low byte of the data

;       More Code Goes Here            

        mov     r0,     r5              ; This data is to be returned in r0
        ldmfd   sp!,    {r4-r5, pc}     ; Return to caller

        ENDFUNC
;
;*********************************************************************************
;
;       ******************
;       *                * 
;       * BBU_1W_readReg * Subroutine
;       *                *
;       ******************
;
;       This subroutine performs a read from the specified register on the 1-wire
;       bus. Sucessive register reads may be performed by calling the BBU_1W_getchr
;       subroutine after this soubroutine has been called.
;
; PARAMETERS:
;
;       INPUT:
;
;          r0 = Register address to be read from (destoyed)
;
;       OUTPUT:
;
;          r0 = 0xFF if the device init failed - otherwise it's the register address
;          r1 = data from the specified register
;
BBU_1W_readReg  FUNCTION

        stmfd   sp!,    {r2, lr}        ; Save used registers & link on stack
        mov     r2,     r0              ; Save target register address in r2
        bl      BBU_1W_init             ; Init the bus for use
        cmp     r0,     #0              ; Any error detected?
        moveq   r0,     #0xFF           ; Yes - set error indication value...
        beq     %F10                    ; ... and exit
;
;       Set up to read data out of the Fuel Gauge
;
        mov     r0,     #0x69   ; Set the READ DATA command
        bl      BBU_1W_putchr   ; Send out the command
        mov     r0,     r2      ; Set the address to start reading from
        bl      BBU_1W_putchr   ; Send out the address
;
;       Now collect the data
;
        bl      BBU_1W_getchr           ; Dummy read - returns register read number
        bl      BBU_1W_getchr           ; Data returned by this read
        mov     r1,     r0              ; Copy data to r1
10      ldmfd   sp!,    {r2, pc}        ; Return to caller
        ENDFUNC
;
;*********************************************************************************
;
;       *******************
;       *                 * 
;       * BBU_1W_writeReg * Subroutine
;       *                 *
;       *******************
;
;       This subroutine writes to a single register on the 1-Wire bus
;
; PARAMETERS:
;
;       INPUT:
;
;          r0 = Register address to be written to (destroyed)
;          r1 = Data to be written to the specified register (preserved)
;
;       OUTPUT:
;
;          r0 = 0xFF if an error was detected.
;
BBU_1W_writeReg FUNCTION

        stmfd   sp!,    {r0-r2, lr}     ; Save used registers & link on stack
        mov     r2,     r0              ; Save target register address in r2
        bl      BBU_1W_init             ; Init the bus for use
        cmp     r0,     #0              ; Any error detected?
        moveq   r0,     #0xFF           ; Yes - set error indication value...
        beq     %F20                    ; ... and exit
;
;       Set up to write data to the specified register
;
        mov     r0,     #0x6C   ; Set the WRITE DATA command
        bl      BBU_1W_putchr   ; Send out the command
        mov     r0,     r2      ; Set the Address to write to
        bl      BBU_1W_putchr   ; Send out the address
        mov     r0,     r1      ; Set the data to be written
        bl      BBU_1W_putchr   ; Send out the data

;
20      ldmfd   sp!,    {r0-r2, pc}     ; Return to caller
        ENDFUNC
;
;*********************************************************************************

⌨️ 快捷键说明

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