Datasheet

224
7728G–AVR–06/10
ATtiny87/ATtiny167
ld r1, Y+
cpse r0, r1
rjmp Error
sbiw loophi:looplo, 1 ; use subi for PAGESIZEB<=256
brne Rdloop
; To ensure compatibility with devices supporting Read-While-Write
; Return to RWW section
; Verify that RWW section is safe to read
Return:
in temp1, SPMCSR
sbrs temp1, RWWSB ; If RWWSB is set, the RWW section is not ready
yet
ret
; Clear temporary page buffer
ldi spmcsrval, (1<<CPTB) | (1<<SELFPGEN)
call Do_spm
rjmp Return
Do_spm:
; Check for previous SPM complete
Wait_spm:
in temp1, SPMCSR
sbrc temp1, SELFPGEN
rjmp Wait_spm
; Input: spmcsrval determines SPM action
; Disable interrupts if enabled, store status
in temp2, SREG
cli
; Check that no EEPROM write access is present
Wait_ee:
sbic EECR, EEPE
rjmp Wait_ee
; SPM timed sequence
out SPMCSR, spmcsrval
spm
; Restore SREG (to enable interrupts if originally enabled)
out SREG, temp2
ret