; *************************************************************************** ; 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. * ; *************************************************************************** ; *************************************************************************** ; code .cseg FLASH_BEGIN: ; --------------------------------------------------------------------------- ; start flashing a page ; ; Interrupts must be disabled! ; ; IN: ; - Z: Address to work on (byte address as for LPM!) ; OUT: ; - nothing ; REGS: R16 (R0, R1, R16, R20, R24, R25) Flash_StartPage: push zh push zl ldi r16, ~((PAGESIZE*2)-1) and zl, r16 rcall Flash_ReadPageIntoPageBuffer ; (R0, R1, R16, R20, R24, R25, Z) pop zl pop zh ret ; --------------------------------------------------------------------------- ; finish flashing a page ; ; Interrupts must be disabled! ; ; IN: ; - Z: Address to work on (byte address as for LPM!) ; OUT: ; - nothing ; REGS: R16 (R15, R20) Flash_FinishPage: ldi r16, ~((PAGESIZE*2)-1) and zl, r16 rcall Flash_ErasePage ; (R15, R16, R20) rcall Flash_WritePage ; (R15, R16, R20) ret ; --------------------------------------------------------------------------- ; Flash_ReadPageIntoPageBuffer ; ; Interrupts must be disabled! ; ; IN: ; - Z: Address to read from (byte address as for LPM!) ; OUT: ; - nothing ; REGS: R0, R1, R16, R20, R24, R25, Z Flash_ReadPageIntoPageBuffer: ldi r24, LOW(PAGESIZE*2) ldi r25, HIGH(PAGESIZE*2) Flash_ReadPageIntoPageBuffer_loop: lpm r0, Z+ ; read source data from FLASH (low) lpm r1, Z ; read source data from FLASH (high) sbiw ZH:ZL, 1 ; rewind Z address for following SPM ldi r20, (1<