URL
https://opencores.org/ocsvn/rf6809/rf6809/trunk
Subversion Repositories rf6809
[/] [rf6809/] [trunk/] [software/] [boot/] [rtc_driver.asm] - Rev 13
Compare with Previous | Blame | View Log
; ============================================================================; __; \\__/ o\ (C) 2022 Robert Finch, Waterloo; \ __ / All rights reserved.; \/_// robfinch<remove>@opencores.org; ||;;; BSD 3-Clause License; Redistribution and use in source and binary forms, with or without; modification, are permitted provided that the following conditions are met:;; 1. Redistributions of source code must retain the above copyright notice, this; list of conditions and the following disclaimer.;; 2. Redistributions in binary form must reproduce the above copyright notice,; this list of conditions and the following disclaimer in the documentation; and/or other materials provided with the distribution.;; 3. Neither the name of the copyright holder nor the names of its; contributors may be used to endorse or promote products derived from; this software without specific prior written permission.;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.;; ============================================================================;===============================================================================; Realtime clock routines;===============================================================================; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; Read the real-time-clock chip.;; The entire contents of the clock registers and sram are read into a buffer; in one-shot rather than reading the registers individually.;; Parameters: none; Returns: d = 0 on success, otherwise non-zero; Modifies: d and RTCBuf; Stack space: 6 words; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -rtc_read:ldx #RTCldy #RTCBufldb #$80stb I2C_CTRL,x ; enable I2Cldd #$900DE ; read address, write op, STA + wr bitbsr i2c_wr_cmdbitb #$80bne rtc_rxerrldd #$10000 ; address zero, wr bitbsr i2c_wr_cmdbitb #$80bne rtc_rxerrldd #$900DF ; read address, read op, STA + wr bitbsr i2c_wr_cmdbitb #$80bne rtc_rxerrclrbrtcr0001:lda #$20sta I2C_CMD,x ; rd bitbsr i2c_wait_tipbsr i2c_wait_rx_nacklda I2C_STAT,xbita #$80bne rtc_rxerrlda I2C_RXR,xsta b,yincbcmpb #$5Fblo rtcr0001lda #$68sta I2C_CMD,x ; STO, rd bit + nackbsr i2c_wait_tiplda I2C_STAT,xbita #$80bne rtc_rxerrlda I2C_RXR,xsta b,yclrd ; return 0rtc_rxerr:clr I2C_CTRL,x ; disable I2C and return statusclrarts; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; Write the real-time-clock chip.;; The entire contents of the clock registers and sram are written from a; buffer (RTCBuf) in one-shot rather than writing the registers individually.;; Parameters: none; Returns: r1 = 0 on success, otherwise non-zero; Modifies: r1 and RTCBuf; Stack space: 6 words; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -rtc_write:ldx #RTCldy #RTCBufldb #$80stb I2C_CTRL,x ; enable I2Cldd #$900DE ; read address, write op, STA + wr bitbsr i2c_wr_cmdbitb #$80bne rtc_rxerrldd #$10000 ; address zero, wr bitbsr i2c_wr_cmdbitb #$80bne rtc_rxerrldb #0rtcw0001:pshs bldb b,ylda #$10bsr i2c_wr_cmdbitb #$80puls bbne rtc_rxerrincbcmpb #$5Fblo rtcw0001ldb b,ylda #$50 ; STO, wr bitbsr i2c_wr_cmdbitb #$80bne rtc_rxerrclrd ; return 0clr I2C_CTRL,x ; disable I2C and return statusrts
