From faa59910243a2ae31a9068b9f385bfb58123c295 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Wed, 21 Jan 2026 22:46:18 +0100 Subject: [PATCH] avr: work on eeprom TLV code. --- avr/common/eeprom-r.asm | 46 ++++++++++++++++++++------------------- avr/common/eeprom-w.asm | 6 +++++ avr/common/eeprom_tlv.asm | 21 ++++++++++++------ 3 files changed, 44 insertions(+), 29 deletions(-) diff --git a/avr/common/eeprom-r.asm b/avr/common/eeprom-r.asm index 85447f6..464e6b3 100644 --- a/avr/common/eeprom-r.asm +++ b/avr/common/eeprom-r.asm @@ -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 diff --git a/avr/common/eeprom-w.asm b/avr/common/eeprom-w.asm index 02d87a2..602d03d 100644 --- a/avr/common/eeprom-w.asm +++ b/avr/common/eeprom-w.asm @@ -11,6 +11,12 @@ #define AQH_AVR_COMMON_EEPROM_W_H +; *************************************************************************** +; code + +.cseg + + ; --------------------------------------------------------------------------- ; Utils_WriteEepromIncr ; diff --git a/avr/common/eeprom_tlv.asm b/avr/common/eeprom_tlv.asm index 23a4709..906863b 100644 --- a/avr/common/eeprom_tlv.asm +++ b/avr/common/eeprom_tlv.asm @@ -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