avr: started working on base system vs. main system.
base system will be a base system which can be used to flash and start the main system.
This commit is contained in:
101
avr/utils.asm
101
avr/utils.asm
@@ -146,6 +146,7 @@ Utils_FillSram_end:
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
; ---------------------------------------------------------------------------
|
||||
; Increment a 32 bit counter at the address given by X.
|
||||
; IN:
|
||||
@@ -170,6 +171,7 @@ Utils_IncrementCounter32:
|
||||
st -x, r19
|
||||
st -x, r18
|
||||
ret
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -243,105 +245,6 @@ 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
|
||||
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; Utils_PseudoRandom
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user