Utils: added code to write FLASH (bot tested, yet).
This commit is contained in:
107
avr/utils.asm
107
avr/utils.asm
@@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
; Utils_WaitNanoSecs waittime_in_ns , cyles_already_used , waitcount_register
|
; Utils_WaitNanoSecs waittime_in_ns , cyles_already_used , waitcount_register
|
||||||
;
|
;
|
||||||
; cycles already used will be subtracted from the delay
|
; cycles already used will be subtracted from the delay
|
||||||
@@ -42,7 +43,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
; ---------------------------------------------------------------------------
|
||||||
; Utils_FillSram
|
; Utils_FillSram
|
||||||
;
|
;
|
||||||
; IN:
|
; IN:
|
||||||
@@ -66,7 +67,7 @@ Utils_FillSram_end:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
; ---------------------------------------------------------------------------
|
||||||
; Increment a 32 bit counter at the address given by X.
|
; Increment a 32 bit counter at the address given by X.
|
||||||
; IN:
|
; IN:
|
||||||
; - X: Address of the 4 byte counter (1. byte is LSB)
|
; - X: Address of the 4 byte counter (1. byte is LSB)
|
||||||
@@ -93,7 +94,7 @@ Utils_IncrementCounter32:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
; ---------------------------------------------------------------------------
|
||||||
; Increment a 16 bit counter at the address given by X.
|
; Increment a 16 bit counter at the address given by X.
|
||||||
; IN:
|
; IN:
|
||||||
; - X: Address of the 2 byte counter (1. byte is LSB)
|
; - X: Address of the 2 byte counter (1. byte is LSB)
|
||||||
@@ -115,7 +116,7 @@ Utils_IncrementCounter16:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
; ---------------------------------------------------------------------------
|
||||||
; Utils_ReadEeprom
|
; Utils_ReadEeprom
|
||||||
;
|
;
|
||||||
; Read a byte from EEPROM (see example in ATtiny24/44/84 manual p.19).
|
; Read a byte from EEPROM (see example in ATtiny24/44/84 manual p.19).
|
||||||
@@ -137,7 +138,7 @@ Utils_ReadEeprom:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
; ---------------------------------------------------------------------------
|
||||||
; Utils_WriteEeprom
|
; Utils_WriteEeprom
|
||||||
;
|
;
|
||||||
; Write a byte to EEPROM (see example in ATtiny24/44/84 manual p.18).
|
; Write a byte to EEPROM (see example in ATtiny24/44/84 manual p.18).
|
||||||
@@ -166,3 +167,99 @@ Utils_WriteEeprom:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Utils_ReadFlashPageIntoPageBuffer
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; IN:
|
||||||
|
; - Z: Address to read from (byte address as for LPM!)
|
||||||
|
; OUT:
|
||||||
|
; - nothing
|
||||||
|
; MODIFIED REGISTERS: R0, R1, R15, R16, R20, R24, R25, Z
|
||||||
|
|
||||||
|
Utils_ReadFlashPageIntoPageBuffer:
|
||||||
|
in r15, SREG
|
||||||
|
cli
|
||||||
|
ldi r24, LOW(PAGESIZE*2)
|
||||||
|
ldi r25, HIGH(PAGESIZE*2)
|
||||||
|
Utils_ReadFlashPageIntoPageBuffer_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<<SPMEN) ; enable next SPM, write into temp page buffer
|
||||||
|
rcall utilsDoSpm ; (R16)
|
||||||
|
adiw ZH:ZL, 2
|
||||||
|
sbiw r25:r24, 2 ;use subi for PAGESIZEB<=256
|
||||||
|
brne Utils_ReadFlashPageIntoPageBuffer_loop
|
||||||
|
out SREG, r15
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Utils_EraseFlashPage
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; IN:
|
||||||
|
; - Z: Address of the page to erase.
|
||||||
|
; OUT:
|
||||||
|
; - nothing
|
||||||
|
; MODIFIED REGISTERS: R0, R1, R15, R16, R18, R19, R20
|
||||||
|
|
||||||
|
Utils_EraseFlashPage:
|
||||||
|
in r15, SREG
|
||||||
|
cli
|
||||||
|
ldi r20, (1<<PGERS) + (1<<SPMEN) ; enable next SPM, erase page (R1/R0 ignored)
|
||||||
|
rcall utilsDoSpm ; (R16)
|
||||||
|
out SREG, r15
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; Utils_WriteFlashPage
|
||||||
|
;
|
||||||
|
;
|
||||||
|
; IN:
|
||||||
|
; - Z: Address of the page to erase.
|
||||||
|
; OUT:
|
||||||
|
; - nothing
|
||||||
|
; MODIFIED REGISTERS: R0, R1, R15, R16, R18, R19, R20
|
||||||
|
|
||||||
|
Utils_WriteFlashPage:
|
||||||
|
in r15, SREG
|
||||||
|
cli
|
||||||
|
ldi r20, (1<<PGWRT) + (1<<SPMEN) ; enable next SPM, erase page (R1/R0 ignored)
|
||||||
|
rcall utilsDoSpm ; (R16)
|
||||||
|
out SREG, r15
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; utilsDoSpm
|
||||||
|
;
|
||||||
|
; wait until possible previous SPM finished and then issue another SPM.
|
||||||
|
;
|
||||||
|
; IN:
|
||||||
|
; - R20: value for register SPMCR
|
||||||
|
; - R0: low value for SPM
|
||||||
|
; - R1: high value for SPM
|
||||||
|
; - Z : address for SPM (byte address!)
|
||||||
|
; OUT:
|
||||||
|
; - nothing
|
||||||
|
; REGS: R16
|
||||||
|
|
||||||
|
utilsDoSpm:
|
||||||
|
wait: ; wait for possibly previous SPM to complete
|
||||||
|
in r16, SPMCSR
|
||||||
|
sbrc r16, SPMEN
|
||||||
|
rjmp wait
|
||||||
|
; SPM timed sequence
|
||||||
|
out SPMCSR, r20
|
||||||
|
spm
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user