avr: generate new uid if the current one consists of 4 equal bytes.

This commit is contained in:
Martin Preuss
2025-05-01 00:55:33 +02:00
parent 5981ec44e4
commit 614a30fd4e

View File

@@ -397,35 +397,27 @@ Utils_SetupUid:
in r15, SREG
cli
rcall Utils_ReadUid ; (R16, X)
mov r16, r18 ; all 0x00?
or r16, r19
or r16, r20
or r16, r21
breq Utils_SetupUid_generate ; yep, go generate one
mov r16, r18 ; all 0xff?
and r16, r19
and r16, r20
and r16, r21
inc r16
breq Utils_SetupUid_generate ; yep, go generate one
out SREG, r15
clc
ret
Utils_SetupUid_generate:
ldi xl, LOW(EEPROM_OFFS_UUID)
cp r18, r19 ; all the same?
brne Utils_SetupUid_uidOkay ; different, jmp
cp r18, r20
brne Utils_SetupUid_uidOkay ; different, jmp
cp r18, r21
brne Utils_SetupUid_uidOkay ; different, jmp
ldi xl, LOW(EEPROM_OFFS_UUID) ; all the same, generate new uid
ldi xh, HIGH(EEPROM_OFFS_UUID)
rcall Utils_PseudoRandom ; byte 0 (R16, R17, R18, R19)
inc r16
rcall Utils_WriteEepromIncr ; (R17)
rcall Utils_WriteEepromIncr ; (R17)
rcall Utils_PseudoRandom ; byte 1
rcall Utils_WriteEepromIncr
rcall Utils_WriteEepromIncr ; (R17)
rcall Utils_PseudoRandom ; byte 2
rcall Utils_WriteEepromIncr
rcall Utils_WriteEepromIncr ; (R17)
rcall Utils_PseudoRandom ; byte 3
rcall Utils_WriteEepromIncr
rcall Utils_WriteEepromIncr ; (R17)
rcall Utils_UpdateSeedInEeprom ; (R16, R17, R18, R19, X)
Utils_SetupUid_uidOkay:
out SREG, r15
sec
ret