avr: cleanup, added labels to calculate module sizes.

This commit is contained in:
Martin Preuss
2023-04-08 18:18:19 +02:00
parent 4a915a3c85
commit 0f678d7d5a
21 changed files with 416 additions and 167 deletions

View File

@@ -67,7 +67,7 @@ CPRO_StartReclaimAddrProcedure:
ldi xh, HIGH(EEPROM_OFFS_COMADDR)
in r15, SREG
cli
rcall Utils_ReadEeprom ; (R16)
rcall Utils_ReadEepromIncr ; (R16)
tst r16
breq CPRO_StartReclaimAddrProcedure_l1
cpi r16, 0xff
@@ -179,7 +179,7 @@ cproHandle1sClaimingAddr3:
sts comAddress, r16 ; write address into eeprom
ldi xl, LOW(EEPROM_OFFS_COMADDR)
ldi xh, HIGH(EEPROM_OFFS_COMADDR)
rcall Utils_WriteEeprom ; write address to EEPROM
rcall Utils_WriteEepromIncr ; write address to EEPROM
ldi r16, CPRO_MODE_NORMAL ; set mode to "normal"
sts cproMode, r16
rcall CPRO_EnqueueHaveAddress
@@ -374,7 +374,7 @@ cproFindFreeAddr:
ldi xh, HIGH(cproUsedAddresses)
lds r16, cproAddrRangeBegin
dec r16
rcall Utils_GetPosAndMaskInBitField ; r1=bit pos, r2=mask (r1, r2, r17, Z)
rcall CPRO_GetPosAndMaskInBitField ; r1=bit pos, r2=mask (r1, r2, r17, Z)
clr r17
add xl, r1
adc xh, r17 ; X: pointer to byte
@@ -427,7 +427,7 @@ cproFindFreeAddr_allFull:
cproSetBitInBitfield:
; set bit corresponding to given address in bitfield of used addresses
rcall Utils_GetPosAndMaskInBitField ; get offset into R1, mask into R2 (r1, r2, r17, Z)
rcall CPRO_GetPosAndMaskInBitField ; get offset into R1, mask into R2 (r1, r2, r17, Z)
ldi xl, LOW(cproUsedAddresses)
ldi xh, HIGH(cproUsedAddresses)
clr r17
@@ -539,4 +539,34 @@ cproEnqueueAddressPacket_error:
; ---------------------------------------------------------------------------
; Get offset and mask for a given bit in a bitfield
; IN:
; - R16: bit to request position for
; OUT:
; - R1: offset into the bitfield to the byte containing the given bit
; - R2: mask for given id (apply to r1)
; USED REGISTERS: r1, r2, r17, Z
CPRO_GetPosAndMaskInBitField:
mov r1, r16 ; divide by 8 to get the offset to the byte containing the given module id
lsr r1
lsr r1
lsr r1 ; r1=offset of the byte holding the given bit
mov r2, r16 ; get bit mask for bit position in table byte
ldi r17, 7 ; keep lower 3 bits
and r2, r17
ldi zh, HIGH(cproModuleBitNumToMaskMap*2)
ldi zl, LOW(cproModuleBitNumToMaskMap*2)
add zl, r2
brcc CPRO_GetPosAndMaskInBitField_noOverflow
inc zh
CPRO_GetPosAndMaskInBitField_noOverflow:
lpm r2, z ; r2=mask for bit in byte from bitfield
ret
cproModuleBitNumToMaskMap:
.db 1, 2, 4, 8, 16, 32, 64, 128