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

View File

@@ -11,6 +11,12 @@
#define AQH_AVR_COMMON_EEPROM_W_H
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; Utils_WriteEepromIncr
;

View File

@@ -11,6 +11,12 @@
#define AQH_AVR_COMMON_EEPROM_TLV_H
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine EepromTlv_AddTlv @global
;
@@ -87,9 +93,9 @@ EepromTlv_FindFirst:
EepromTlv_Find:
mov r18, r16
EepromTlv_Find_loop:
rcall EepromTlv_ReadHeader
rcall EepromTlv_ReadHeader ; (none)
brcc EepromTlv_Find_notFound
cpi r16, r18 ; the one we wanted?
cp r16, r18 ; the one we wanted?
breq EepromTlv_Find_found
add xl, r17 ; skip TLV data
adc xh, r17
@@ -117,19 +123,20 @@ EepromTlv_Find_end:
; @clobbers none
EepromTlv_ReadHeader:
rcall Eeprom_ReadByteIncr ; read type
brcc EepromTlv_ReadHeader
rcall Eeprom_ReadByte ; read type
brcc EepromTlv_ReadHeader_ret
adiw xh:xl, 1
push r16
rcall Eeprom_ReadByteIncr ; read length
rcall Eeprom_ReadByte ; read length
mov r17, r16
pop r16
brcc EepromTlv_ReadHeader
brcc EepromTlv_ReadHeader_ret
adiw xh:xl, 1
sec
EepromTlv_ReadHeader:
EepromTlv_ReadHeader_ret:
ret
; @end
#endif