avr: work on eeprom TLV code.

This commit is contained in:
Martin Preuss
2026-01-21 22:46:18 +01:00
parent dbe42c5bcb
commit faa5991024
3 changed files with 44 additions and 29 deletions

View File

@@ -11,6 +11,12 @@
#define AQH_AVR_COMMON_EEPROM_R_H
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine Eeprom_ReadByte
@@ -20,37 +26,33 @@
; @param X EEPROM Address to read from
; @return CFLAG set if address okay, cleared if out of range
; @return R16 byte read
; @return X EEPROM Address incremented
; @clobbers none
Eeprom_ReadByte:
rcall Eeprom_CheckAddr
brcs Eeprom_ReadByte_addrOk
ret
Eeprom_ReadByte_addrOk:
; call routine with IRQs disabled
rcall Eeprom_CheckAddr ; (R16)
brcc Eeprom_ReadByte_ret
push r15
inr r15, SREG
cli
rcall Eeprom_ReadByte_noirq
; wait until EEPROM ready
Eeprom_ReadByte_waitLoop:
.ifdef EEPE
sbic EECR, EEPE ; wait for previous write to complete (if any)
.else
sbic EECR, EEWE ; wait for previous write to complete (if any)
.endif
rjmp Eeprom_ReadByte_waitLoop
; read from EEPROM
out EEARH, xh ; set EEPROM address
out EEARL, xl
sbi EECR, EERE ; start EEPROM read by writing EERE
in r16, EEDR ; read data from data register
Eeprom_ReadByte_done:
outr SREG, r15
pop r15
sec
ret
Eeprom_ReadByte_noirq:
; wait until EEPROM ready
Eeprom_ReadByte_waitLoop:
.ifdef EEPE
sbic EECR, EEPE ; wait for previous write to complete (if any)
.else
sbic EECR, EEWE ; wait for previous write to complete (if any)
.endif
rjmp Eeprom_ReadByte_waitLoop
; read from EEPROM
out EEARH, xh ; set EEPROM address
out EEARL, xl
sbi EECR, EERE ; start EEPROM read by writing EERE
in r16, EEDR ; read data from data register
Eeprom_ReadByte_ret:
ret
; @end