avr: cleanup, added labels to calculate module sizes.
This commit is contained in:
@@ -80,14 +80,6 @@
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; EEPROM positions
|
||||
|
||||
|
||||
.equ EEPROM_OFFS_UUID = 0 ; 4 bytes (occupy total of 8 bytes for extensibility)
|
||||
.equ EEPROM_OFFS_COMADDR = 8 ; 1 byte
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; COM module
|
||||
|
||||
|
||||
@@ -101,14 +101,6 @@
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; EEPROM positions
|
||||
|
||||
|
||||
.equ EEPROM_OFFS_UUID = 0 ; 4 bytes (occupy total of 8 bytes for extensibility)
|
||||
.equ EEPROM_OFFS_COMADDR = 8 ; 1 byte
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; COM module
|
||||
|
||||
@@ -239,7 +231,7 @@
|
||||
;.include "comproto_debug.asm"
|
||||
;.include "comproto_twi.asm"
|
||||
.include "twimaster.asm"
|
||||
.include "lcd.asm"
|
||||
;.include "lcd.asm"
|
||||
.include "si7021.asm"
|
||||
|
||||
|
||||
@@ -249,8 +241,6 @@
|
||||
|
||||
.dseg
|
||||
|
||||
ledA3Sram: .byte LED_SRAM_SIZE
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
34
avr/com.asm
34
avr/com.asm
@@ -12,7 +12,7 @@
|
||||
; ***************************************************************************
|
||||
; defines
|
||||
|
||||
.equ COM_MAXWAIT = 200 ; maximum loop count when waiting for rising/falling clock (TODO: Make frequency-dependant)
|
||||
.equ COM_MAXWAIT_US = 100 ; maximum wait time in microseconds when waiting for rising/falling clock
|
||||
|
||||
.equ COM_MAINTENANCE_ADDR = 0xf1
|
||||
|
||||
@@ -94,6 +94,8 @@ comDataEnd:
|
||||
|
||||
.cseg
|
||||
|
||||
COM_BEGIN:
|
||||
|
||||
|
||||
comIsrPcint0:
|
||||
push r15
|
||||
@@ -213,33 +215,6 @@ COM_EnqueuePacket:
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; COM_AllocBufferAndGetXY
|
||||
;
|
||||
; IN:
|
||||
; - nothing
|
||||
; OUT:
|
||||
; - CFLAG: set if okay, clear otherwise
|
||||
; - Y: pointer to buffer
|
||||
; - X: pointer to data portion of the buffer
|
||||
; MODIFIED REGS: R16, R17 (R21)
|
||||
|
||||
COM_AllocBufferAndGetXY:
|
||||
rcall COM_BufferAlloc ; (r16, r17, r21)
|
||||
brcc COM_AllocBufferAndGetXY_error
|
||||
mov xl, yl
|
||||
mov xh, yh
|
||||
adiw xh:xl, COM_BUFFER_OFFS_DATA
|
||||
sec
|
||||
ret
|
||||
COM_AllocBufferAndGetXY_error:
|
||||
ldi xl, LOW(comStatsSendNoBuffer)
|
||||
ldi xh, HIGH(comStatsSendNoBuffer)
|
||||
clc
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; comHandleNextPacketInQueue
|
||||
;
|
||||
@@ -325,3 +300,6 @@ comHandleReceivedPacket_l2:
|
||||
|
||||
|
||||
|
||||
COM_END:
|
||||
.equ MODULE_SIZE_COM = COM_END-COM_BEGIN
|
||||
|
||||
|
||||
@@ -15,6 +15,35 @@
|
||||
|
||||
.cseg
|
||||
|
||||
COM_BUFFER_BEGIN:
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; COM_AllocBufferAndGetXY
|
||||
;
|
||||
; IN:
|
||||
; - nothing
|
||||
; OUT:
|
||||
; - CFLAG: set if okay, clear otherwise
|
||||
; - Y: pointer to buffer
|
||||
; - X: pointer to data portion of the buffer
|
||||
; MODIFIED REGS: R16, R17 (R21)
|
||||
|
||||
COM_AllocBufferAndGetXY:
|
||||
rcall COM_BufferAlloc ; (r16, r17, r21)
|
||||
brcc COM_AllocBufferAndGetXY_error
|
||||
mov xl, yl
|
||||
mov xh, yh
|
||||
adiw xh:xl, COM_BUFFER_OFFS_DATA
|
||||
sec
|
||||
ret
|
||||
COM_AllocBufferAndGetXY_error:
|
||||
ldi xl, LOW(comStatsSendNoBuffer)
|
||||
ldi xh, HIGH(comStatsSendNoBuffer)
|
||||
clc
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; COM_BufferAlloc
|
||||
@@ -170,5 +199,8 @@ COM_BufferPosToY:
|
||||
ret
|
||||
|
||||
|
||||
COM_BUFFER_END:
|
||||
.equ MODULE_SIZE_COM_BUFFER = COM_BUFFER_END-COM_BUFFER_BEGIN
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
.cseg
|
||||
|
||||
|
||||
COM_CRC_BEGIN:
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
@@ -135,3 +137,7 @@ cproCalcCrc8_l1:
|
||||
ret
|
||||
|
||||
|
||||
COM_CRC_END:
|
||||
.equ MODULE_SIZE_COM_CRC = COM_CRC_END-COM_CRC_BEGIN
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
.cseg
|
||||
|
||||
|
||||
COM_LOWLEVEL_BEGIN:
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; comSendByte
|
||||
@@ -114,19 +116,19 @@ comReceiveByte_error:
|
||||
; ---------------------------------------------------------------------------
|
||||
; comWaitForDataLow
|
||||
;
|
||||
; Waits up to COM_MAXWAIT loops for low data line
|
||||
; Waits up to COM_MAXWAIT_US loops for low data line
|
||||
; IN:
|
||||
; OUT:
|
||||
; - CFLAG: set if okay, clear otherwise
|
||||
; MODIFIED REGISTERS: r17, r22
|
||||
|
||||
comWaitForDataLow:
|
||||
ldi r17, COM_MAXWAIT
|
||||
ldi r17, COM_MAXWAIT_US
|
||||
|
||||
comWaitForDataLow_loop:
|
||||
sbis COM_PIN_DATA, COM_PINNUM_DATA
|
||||
rjmp comWaitForDataLow_done
|
||||
Utils_WaitNanoSecs 100, 0, r22 ; wait for 100 nanosecs
|
||||
rcall comWaitFor1000ns
|
||||
dec r17
|
||||
brne comWaitForDataLow_loop
|
||||
clc ; timeout
|
||||
@@ -141,19 +143,19 @@ comWaitForDataLow_done:
|
||||
; ---------------------------------------------------------------------------
|
||||
; comWaitForDataHigh
|
||||
;
|
||||
; Waits up to COM_MAXWAIT loops for high data line
|
||||
; Waits up to COM_MAXWAIT_US loops for high data line
|
||||
; IN:
|
||||
; OUT:
|
||||
; - CFLAG: set if okay, clear otherwise
|
||||
; MODIFIED REGISTERS: r17, r22, X
|
||||
|
||||
comWaitForDataHigh:
|
||||
ldi r17, COM_MAXWAIT
|
||||
ldi r17, COM_MAXWAIT_US
|
||||
|
||||
comWaitForDataHigh_loop:
|
||||
sbic COM_PIN_DATA, COM_PINNUM_DATA
|
||||
rjmp comWaitForDataHigh_done
|
||||
Utils_WaitNanoSecs 100, 0, r22 ; wait for 100 nanosecs
|
||||
rcall comWaitFor1000ns
|
||||
dec r17
|
||||
brne comWaitForDataHigh_loop
|
||||
clc ; timeout
|
||||
@@ -168,19 +170,19 @@ comWaitForDataHigh_done:
|
||||
; ---------------------------------------------------------------------------
|
||||
; comWaitForAttnHigh
|
||||
;
|
||||
; Waits up to COM_MAXWAIT loops for high ATTN line
|
||||
; Waits up to COM_MAXWAIT_US loops for high ATTN line
|
||||
; IN:
|
||||
; OUT:
|
||||
; - CFLAG: set if okay, clear otherwise
|
||||
; MODIFIED REGISTERS: r17, r22, X
|
||||
|
||||
comWaitForAttnHigh:
|
||||
ldi r17, COM_MAXWAIT
|
||||
ldi r17, COM_MAXWAIT_US
|
||||
|
||||
comWaitForAttnHigh_loop:
|
||||
sbic COM_PIN_ATTN, COM_PINNUM_ATTN
|
||||
rjmp comWaitForAttnHigh_done
|
||||
Utils_WaitNanoSecs 100, 0, r22 ; wait for 100 nanosecs
|
||||
rcall comWaitFor1000ns
|
||||
dec r17
|
||||
brne comWaitForAttnHigh_loop
|
||||
clc ; timeout
|
||||
@@ -192,3 +194,22 @@ comWaitForAttnHigh_done:
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; comWaitFor100ns
|
||||
;
|
||||
; Waits for 100 nanoseconds.
|
||||
; IN:
|
||||
; OUT:
|
||||
; - CFLAG: set if okay, clear otherwise
|
||||
; MODIFIED REGISTERS: r17, r22, X
|
||||
|
||||
comWaitFor1000ns:
|
||||
Utils_WaitNanoSecs 1000, 7, r22 ; wait for 100 nanosecs (minus 3 cycles for rcall, 4 for ret)
|
||||
ret
|
||||
|
||||
|
||||
COM_LOWLEVEL_END:
|
||||
.equ MODULE_SIZE_COM_LOWLEVEL = COM_LOWLEVEL_END-COM_LOWLEVEL_BEGIN
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
.cseg
|
||||
|
||||
COM_RECV_BEGIN:
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
@@ -154,5 +155,7 @@ comReceivePacketToSram_error:
|
||||
ret
|
||||
|
||||
|
||||
COM_RECV_END:
|
||||
.equ MODULE_SIZE_COM_RECV = COM_RECV_END-COM_RECV_BEGIN
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
|
||||
.cseg
|
||||
|
||||
COM_SEND_BEGIN:
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; comSendPacketHandleRepeat
|
||||
@@ -205,4 +208,7 @@ comDeallocReadBufAndIncrCounter:
|
||||
|
||||
|
||||
|
||||
COM_SEND_END:
|
||||
.equ MODULE_SIZE_COM_SEND = COM_SEND_END-COM_SEND_BEGIN
|
||||
|
||||
|
||||
|
||||
@@ -95,6 +95,8 @@ cproDataEnd:
|
||||
.cseg
|
||||
|
||||
|
||||
CPRO_BEGIN:
|
||||
|
||||
|
||||
CPRO_Init:
|
||||
; preset SRAM data area
|
||||
@@ -347,6 +349,8 @@ cproCalcPayloadSize_l2:
|
||||
ret
|
||||
|
||||
|
||||
CPRO_END:
|
||||
.equ MODULE_SIZE_CPRO = CPRO_END-CPRO_BEGIN
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -29,3 +29,12 @@
|
||||
.equ AQHOME_FW_START_ADDRESS_MAIN = 0x0500
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; EEPROM positions
|
||||
|
||||
|
||||
.equ EEPROM_OFFS_UUID = 0 ; 4 bytes (occupy total of 8 bytes for extensibility)
|
||||
.equ EEPROM_OFFS_COMADDR = 8 ; 1 byte
|
||||
.equ EEPROM_OFFS_SEED = 10 ; 2 bytes
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
.cseg
|
||||
|
||||
|
||||
FLASH_BEGIN:
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; start flashing a page
|
||||
;
|
||||
@@ -169,3 +172,10 @@ wait: ; wait for possibly previous SPM to complete
|
||||
out SPMCSR, r20
|
||||
spm
|
||||
ret
|
||||
|
||||
|
||||
FLASH_END:
|
||||
.equ MODULE_SIZE_FLASH = FLASH_END-FLASH_BEGIN
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@ lcdDataEnd:
|
||||
.cseg
|
||||
|
||||
|
||||
LCD_BEGIN:
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
@@ -812,4 +814,6 @@ lcdFont6x8:
|
||||
#endif
|
||||
|
||||
|
||||
LCD_END:
|
||||
.equ MODULE_SIZE_LCD = LCD_END-LCD_BEGIN
|
||||
|
||||
|
||||
17
avr/led.asm
17
avr/led.asm
@@ -1,3 +1,14 @@
|
||||
; ***************************************************************************
|
||||
; copyright : (C) 2023 by Martin Preuss
|
||||
; email : martin@libchipcard.de
|
||||
;
|
||||
; ***************************************************************************
|
||||
; * This file is part of the project "AqHome". *
|
||||
; * Please see toplevel file COPYING of that project for license details. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; defs
|
||||
@@ -23,6 +34,8 @@
|
||||
.cseg
|
||||
|
||||
|
||||
LED_BEGIN:
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Led_Init
|
||||
@@ -304,4 +317,8 @@ ledOn_end:
|
||||
|
||||
|
||||
|
||||
LED_END:
|
||||
.equ MODULE_SIZE_LED = LED_END-LED_BEGIN
|
||||
|
||||
|
||||
|
||||
|
||||
20
avr/main.asm
20
avr/main.asm
@@ -8,10 +8,30 @@
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; data in SRAM
|
||||
|
||||
.dseg
|
||||
|
||||
|
||||
#ifdef MODULES_LED
|
||||
ledA3Sram: .byte LED_SRAM_SIZE
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; main
|
||||
;
|
||||
|
||||
main:
|
||||
; setup stack
|
||||
.ifdef SPH ; if SPH is defined
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
.cseg
|
||||
|
||||
|
||||
RINGBUFFER_BEGIN:
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
@@ -247,5 +249,7 @@ RingBuffer_Read_end:
|
||||
|
||||
|
||||
|
||||
RINGBUFFER_END:
|
||||
.equ MODULE_SIZE_RINGBUFFER = RINGBUFFER_END-RINGBUFFER_BEGIN
|
||||
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ si7021DataEnd:
|
||||
.cseg
|
||||
|
||||
|
||||
SI7021_BEGIN:
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
@@ -439,6 +441,7 @@ si7021Muls16x16_32_done:
|
||||
; ret
|
||||
|
||||
|
||||
|
||||
SI7021_END:
|
||||
.equ MODULE_SIZE_SI7021 = SI7021_END-SI7021_BEGIN
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ timerModuleData_end:
|
||||
|
||||
.cseg
|
||||
|
||||
TIMER_BEGIN:
|
||||
|
||||
|
||||
; number of entries here must be equal to bytes in timerModuleDerivedCounters!
|
||||
timerTable:
|
||||
@@ -319,6 +321,8 @@ timerIrq2_l2:
|
||||
|
||||
|
||||
|
||||
TIMER_END:
|
||||
.equ MODULE_SIZE_TIMER = TIMER_END-TIMER_BEGIN
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ twiMasterDataEnd:
|
||||
|
||||
.cseg
|
||||
|
||||
TWIMASTER_BEGIN:
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
@@ -435,4 +436,6 @@ TWI_Master_ScanNext_end:
|
||||
|
||||
|
||||
|
||||
TWIMASTER_END:
|
||||
.equ MODULE_SIZE_TWIMASTER = TWIMASTER_END-TWIMASTER_BEGIN
|
||||
|
||||
|
||||
325
avr/utils.asm
325
avr/utils.asm
@@ -75,6 +75,9 @@ utilsDataEnd:
|
||||
|
||||
.cseg
|
||||
|
||||
UTILS_BEGIN:
|
||||
|
||||
|
||||
utilsDateString: .db "%YEAR%-%MONTH%-%DAY%-%HOUR%:%MINUTE%", 0, 0
|
||||
|
||||
|
||||
@@ -86,50 +89,17 @@ utilsDateString: .db "%YEAR%-%MONTH%-%DAY%-%HOUR%:%MINUTE%", 0, 0
|
||||
; IN:
|
||||
; OUT:
|
||||
; - CFLAG: set if okay, clear on error
|
||||
; USED: R16, R17, R18, R24, R25, X, Y
|
||||
; USED: R16, R17, R18, R19, X, (R20, R21, R24, R25, X, Z)
|
||||
|
||||
Utils_Init:
|
||||
; preset initial seed from compile date string
|
||||
ldi zl, LOW(utilsDateString*2)
|
||||
ldi zh, HIGH(utilsDateString*2)
|
||||
ldi r18, 0xe1
|
||||
ldi r19, 0xac
|
||||
Utils_Init_l1:
|
||||
lpm r16, Z+
|
||||
tst r16
|
||||
breq Utils_Init_l2
|
||||
eor r18, r16
|
||||
|
||||
clc
|
||||
sbrc r19, 7
|
||||
sec ; only executed if bit 7 is set in r19
|
||||
rol r18
|
||||
rol r19
|
||||
rjmp Utils_Init_l1
|
||||
Utils_Init_l2:
|
||||
|
||||
; build initial SRAM content into intial seed
|
||||
ldi xl, LOW(SRAM_START)
|
||||
ldi xh, HIGH(SRAM_START)
|
||||
ldi r24, LOW(RAMEND-SRAM_START)
|
||||
ldi r25, HIGH(RAMEND-SRAM_START)
|
||||
Utils_Init_l3:
|
||||
ld r16, X+
|
||||
eor r18, r16
|
||||
clc
|
||||
sbrc r19, 7
|
||||
sec ; only executed if bit 7 is set in r19
|
||||
rol r18
|
||||
rol r19
|
||||
sbiw r25:r24, 1
|
||||
brne Utils_Init_l3
|
||||
rcall utilsSetupSeed ; (R16, R18, R19, R20, R21, R24, R25, X, Z)
|
||||
|
||||
; preset SRAM data area
|
||||
ldi xh, HIGH(utilsDataBegin)
|
||||
ldi xl, LOW(utilsDataBegin)
|
||||
clr r16
|
||||
ldi r17, (utilsDataEnd-utilsDataBegin)
|
||||
rcall Utils_FillSram
|
||||
rcall Utils_FillSram ; (r17, x)
|
||||
|
||||
sts utilsSeed, r18
|
||||
sts utilsSeed+1, r19
|
||||
@@ -139,6 +109,112 @@ Utils_Init_l3:
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; setup seed
|
||||
;
|
||||
; IN:
|
||||
; OUT:
|
||||
; REGS: R16, R18, R19, R20, R21, R24, R25, X, Z
|
||||
|
||||
utilsSetupSeed:
|
||||
rcall Utils_ReadSeed
|
||||
mov r20, r18
|
||||
mov r21, r19
|
||||
|
||||
; default initial seed
|
||||
ldi r18, 0xe1
|
||||
ldi r19, 0xac
|
||||
|
||||
; work stored seed into it
|
||||
mov r16, r20
|
||||
rcall utilsWorkByteIntoSeed
|
||||
mov r16, r21
|
||||
rcall utilsWorkByteIntoSeed
|
||||
|
||||
; work date string into seed
|
||||
ldi zl, LOW(utilsDateString*2)
|
||||
ldi zh, HIGH(utilsDateString*2)
|
||||
rcall utilsWorkProgStringIntoSeed ; (R16, Z)
|
||||
|
||||
; work sram content into seed
|
||||
rcall utilsWorkSramContentIntoSeed ; (R16, R24, R25, X)
|
||||
|
||||
; store seed in EEPROM
|
||||
rcall Utils_WriteSeed ; (R16, R17, X)
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; utilsWorkProgStringIntoSeed
|
||||
;
|
||||
; IN:
|
||||
; - Z : pointer to string to work into seed
|
||||
; - R18: low byte of current seed
|
||||
; - R19: high byte of current seed
|
||||
; OUT:
|
||||
; - R18: low byte of updated seed
|
||||
; - R19: high byte of updated seed
|
||||
; USED: R16, Z
|
||||
|
||||
utilsWorkProgStringIntoSeed:
|
||||
lpm r16, Z+
|
||||
tst r16
|
||||
breq utilsWorkProgStringIntoSeed_done
|
||||
rcall utilsWorkByteIntoSeed
|
||||
rjmp utilsWorkProgStringIntoSeed
|
||||
utilsWorkProgStringIntoSeed_done:
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; utilsWorkSramContentIntoSeed
|
||||
; IN:
|
||||
; - Z : pointer to string to work into seed
|
||||
; - R18: low byte of current seed
|
||||
; - R19: high byte of current seed
|
||||
; OUT:
|
||||
; - R18: low byte of updated seed
|
||||
; - R19: high byte of updated seed
|
||||
; USED: R16, R24, R25, X
|
||||
|
||||
utilsWorkSramContentIntoSeed:
|
||||
ldi xl, LOW(SRAM_START)
|
||||
ldi xh, HIGH(SRAM_START)
|
||||
ldi r24, LOW(RAMEND-SRAM_START)
|
||||
ldi r25, HIGH(RAMEND-SRAM_START)
|
||||
utilsWorkSramContentIntoSeed_loop:
|
||||
ld r16, X+
|
||||
rcall utilsWorkByteIntoSeed
|
||||
sbiw r25:r24, 1
|
||||
brne utilsWorkSramContentIntoSeed_loop
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; utilsWorkByteIntoSeed
|
||||
;
|
||||
; IN:
|
||||
; - R16: byte to work into the seed
|
||||
; - R18: low byte of current seed
|
||||
; - R19: high byte of current seed
|
||||
; OUT:
|
||||
; - R18: low byte of updated seed
|
||||
; - R19: high byte of updated seed
|
||||
; USED:
|
||||
|
||||
utilsWorkByteIntoSeed:
|
||||
eor r18, r16
|
||||
clc
|
||||
sbrc r19, 7
|
||||
sec ; only executed if bit 7 is set in r19
|
||||
rol r18
|
||||
rol r19
|
||||
ret
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Utils_Fini
|
||||
;
|
||||
@@ -230,7 +306,7 @@ Utils_IncrementCounter16:
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Utils_ReadEeprom
|
||||
; Utils_ReadEepromIncr
|
||||
;
|
||||
; Read a byte from EEPROM (see example in ATtiny24/44/84 manual p.19).
|
||||
;
|
||||
@@ -238,34 +314,36 @@ Utils_IncrementCounter16:
|
||||
; - X: EEPROM Address to read from
|
||||
; OUT:
|
||||
; - R16: byte read
|
||||
; - X: EEPROM Address incremented
|
||||
; MODIFIED REGISTERS: R16
|
||||
|
||||
Utils_ReadEeprom:
|
||||
Utils_ReadEepromIncr:
|
||||
sbic EECR, EEPE ; wait for previous write to complete (if any)
|
||||
rjmp Utils_ReadEeprom
|
||||
rjmp Utils_ReadEepromIncr
|
||||
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
|
||||
adiw xh:xl, 1
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Utils_WriteEeprom
|
||||
; Utils_WriteEepromIncr
|
||||
;
|
||||
; Write a byte to EEPROM (see example in ATtiny24/44/84 manual p.18).
|
||||
;
|
||||
; IN:
|
||||
; - R16: byte to write
|
||||
; - X: EEPROM Address to read from
|
||||
; - X: EEPROM Address to write to
|
||||
; OUT:
|
||||
; - nothing
|
||||
; - X: EEPROM Address incremented
|
||||
; MODIFIED REGISTERS: R17
|
||||
|
||||
Utils_WriteEeprom:
|
||||
Utils_WriteEepromIncr:
|
||||
sbic EECR, EEPE ; wait for previous write to complete (if any)
|
||||
rjmp Utils_WriteEeprom
|
||||
rjmp Utils_WriteEepromIncr
|
||||
ldi r17, (0<<EEPM1) | (0<<EEPM0) ; set programming mode
|
||||
out EECR, r17
|
||||
out EEARH, xh ; set EEPROM address
|
||||
@@ -273,6 +351,7 @@ Utils_WriteEeprom:
|
||||
out EEDR, r16 ; write data to data register
|
||||
sbi EECR, EEMPE ; write logical one to EEMPE
|
||||
sbi EECR, EEPE ; start EEPROM write by setting EEPE
|
||||
adiw xh:xl, 1
|
||||
ret
|
||||
|
||||
|
||||
@@ -294,12 +373,12 @@ Utils_PseudoRandom:
|
||||
ldi r18, 0x9c
|
||||
ldi r19, 8
|
||||
Utils_PseudoRandom_step:
|
||||
lsr r17
|
||||
ror r16
|
||||
brcc Utils_PseudoRandom_nomask
|
||||
eor r17, r18
|
||||
lsr r17
|
||||
ror r16
|
||||
brcc Utils_PseudoRandom_nomask
|
||||
eor r17, r18
|
||||
Utils_PseudoRandom_nomask:
|
||||
dec r19
|
||||
dec r19
|
||||
brne Utils_PseudoRandom_step
|
||||
sts utilsSeed, r16
|
||||
sts utilsSeed+1, r17
|
||||
@@ -307,6 +386,21 @@ Utils_PseudoRandom_nomask:
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Update seed in EEPROM.
|
||||
;
|
||||
; IN:
|
||||
; OUT:
|
||||
; REGS: R18, R19, (R16, R17, X)
|
||||
|
||||
Utils_UpdateSeedInEeprom:
|
||||
lds r18, utilsSeed
|
||||
lds r19, utilsSeed+1
|
||||
rcall Utils_WriteSeed ; (R16, R17, X)
|
||||
ret
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Utils_ReadUid
|
||||
;
|
||||
@@ -323,16 +417,13 @@ Utils_ReadUid:
|
||||
cli
|
||||
ldi xl, LOW(EEPROM_OFFS_UUID)
|
||||
ldi xh, HIGH(EEPROM_OFFS_UUID)
|
||||
rcall Utils_ReadEeprom ; (R16)
|
||||
rcall Utils_ReadEepromIncr ; (R16)
|
||||
mov r18, r16
|
||||
adiw xh:xl, 1
|
||||
rcall Utils_ReadEeprom ; (R16)
|
||||
rcall Utils_ReadEepromIncr ; (R16)
|
||||
mov r19, r16
|
||||
adiw xh:xl, 1
|
||||
rcall Utils_ReadEeprom ; (R16)
|
||||
rcall Utils_ReadEepromIncr ; (R16)
|
||||
mov r20, r16
|
||||
adiw xh:xl, 1
|
||||
rcall Utils_ReadEeprom ; (R16)
|
||||
rcall Utils_ReadEepromIncr ; (R16)
|
||||
mov r21, r16
|
||||
pop r15
|
||||
out SREG, r15
|
||||
@@ -348,42 +439,41 @@ Utils_ReadUid:
|
||||
; IN:
|
||||
; OUT:
|
||||
; - CFLAG set if new generated, cleared if there already was one.
|
||||
; REGS: R15, R16, R18, R19, R20, R21, X
|
||||
; REGS: R15, R16, R18, R19, R20, R21, X (R17)
|
||||
|
||||
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
|
||||
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)
|
||||
ldi xh, HIGH(EEPROM_OFFS_UUID)
|
||||
rcall Utils_PseudoRandom ; byte 0 (R16, R17, R18, R19)
|
||||
inc r16
|
||||
rcall Utils_WriteEeprom ; (R17)
|
||||
adiw xh:xl, 1
|
||||
rcall Utils_PseudoRandom ; byte 1
|
||||
rcall Utils_WriteEeprom
|
||||
adiw xh:xl, 1
|
||||
rcall Utils_PseudoRandom ; byte 2
|
||||
rcall Utils_WriteEeprom
|
||||
adiw xh:xl, 1
|
||||
rcall Utils_PseudoRandom ; byte 3
|
||||
rcall Utils_WriteEeprom
|
||||
adiw xh:xl, 1
|
||||
ldi xl, LOW(EEPROM_OFFS_UUID)
|
||||
ldi xh, HIGH(EEPROM_OFFS_UUID)
|
||||
rcall Utils_PseudoRandom ; byte 0 (R16, R17, R18, R19)
|
||||
inc r16
|
||||
rcall Utils_WriteEepromIncr ; (R17)
|
||||
rcall Utils_PseudoRandom ; byte 1
|
||||
rcall Utils_WriteEepromIncr
|
||||
rcall Utils_PseudoRandom ; byte 2
|
||||
rcall Utils_WriteEepromIncr
|
||||
rcall Utils_PseudoRandom ; byte 3
|
||||
rcall Utils_WriteEepromIncr
|
||||
|
||||
rcall Utils_UpdateSeedInEeprom ; (R16, R17, R18, R19, X)
|
||||
|
||||
out SREG, r15
|
||||
sec
|
||||
ret
|
||||
@@ -391,33 +481,56 @@ Utils_SetupUid_generate:
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Get offset and mask for a given bit in a bitfield
|
||||
; Utils_ReadSeed
|
||||
;
|
||||
; Read seed from EEPROM.
|
||||
;
|
||||
; 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
|
||||
; - R18:R19: seed read
|
||||
; REGS: R16, X
|
||||
|
||||
Utils_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(utilsModuleBitNumToMaskMap*2)
|
||||
ldi zl, LOW(utilsModuleBitNumToMaskMap*2)
|
||||
add zl, r2
|
||||
brcc Utils_GetPosAndMaskInBitField_noOverflow
|
||||
inc zh
|
||||
Utils_GetPosAndMaskInBitField_noOverflow:
|
||||
lpm r2, z ; r2=mask for bit in byte from bitfield
|
||||
Utils_ReadSeed:
|
||||
push r15
|
||||
in r15, SREG
|
||||
cli
|
||||
ldi xl, LOW(EEPROM_OFFS_SEED)
|
||||
ldi xh, HIGH(EEPROM_OFFS_SEED)
|
||||
rcall Utils_ReadEepromIncr ; (R16)
|
||||
mov r18, r16
|
||||
rcall Utils_ReadEepromIncr ; (R16)
|
||||
mov r19, r16
|
||||
pop r15
|
||||
out SREG, r15
|
||||
ret
|
||||
|
||||
|
||||
utilsModuleBitNumToMaskMap:
|
||||
.db 1, 2, 4, 8, 16, 32, 64, 128
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Utils_WriteSeed
|
||||
;
|
||||
; Read seed from EEPROM.
|
||||
;
|
||||
; IN:
|
||||
; - R18:R19: seed to write
|
||||
; OUT:
|
||||
; REGS: R16, X, (R17)
|
||||
Utils_WriteSeed:
|
||||
push r15
|
||||
in r15, SREG
|
||||
cli
|
||||
ldi xl, LOW(EEPROM_OFFS_SEED)
|
||||
ldi xh, HIGH(EEPROM_OFFS_SEED)
|
||||
mov r16, r18
|
||||
rcall Utils_WriteEepromIncr ; (R17)
|
||||
mov r16, r19
|
||||
rcall Utils_WriteEepromIncr ; (R17)
|
||||
pop r15
|
||||
out SREG, r15
|
||||
ret
|
||||
|
||||
|
||||
|
||||
UTILS_END:
|
||||
.equ MODULE_SIZE_UTILS = UTILS_END-UTILS_BEGIN
|
||||
|
||||
|
||||
Reference in New Issue
Block a user