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 #define AQH_AVR_COMMON_EEPROM_R_H
; ***************************************************************************
; code
.cseg
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; @routine Eeprom_ReadByte ; @routine Eeprom_ReadByte
@@ -20,37 +26,33 @@
; @param X EEPROM Address to read from ; @param X EEPROM Address to read from
; @return CFLAG set if address okay, cleared if out of range ; @return CFLAG set if address okay, cleared if out of range
; @return R16 byte read ; @return R16 byte read
; @return X EEPROM Address incremented
; @clobbers none ; @clobbers none
Eeprom_ReadByte: Eeprom_ReadByte:
rcall Eeprom_CheckAddr rcall Eeprom_CheckAddr ; (R16)
brcs Eeprom_ReadByte_addrOk brcc Eeprom_ReadByte_ret
ret
Eeprom_ReadByte_addrOk:
; call routine with IRQs disabled
push r15 push r15
inr r15, SREG inr r15, SREG
cli 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 outr SREG, r15
pop r15 pop r15
sec sec
ret Eeprom_ReadByte_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
ret ret
; @end ; @end

View File

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

View File

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