;-----------------------------------------------------------------------!
; Erase Flash!
;-----------------------------------------------------------------------!
; r0 = start sector, r1 = sector count
fn FLZap
push{r7,lr};
ldrr7, =cmdBuff;
strr0, [r7, 1*4]; stash first sector
addsr0, r1; calc last sector
subsr0, 1; first+count-1
strr0, [r7, 2*4]; stash last sector
ldrr0, =clkKHz; get clock speed
strr0, [r7, 3*4]; stash clock speed
;---------------------------------------;
movsr0, 53; blank check
strr0, [r7];
movsr0, r7; 'in' parameters
addsr1, r7, 5*4; 'out' parameters
blGoIAP;
ldrr0, [r7, 5*4]; get status code
cbzr0, 9f; skip erase if blank
;---------------------------------------;
movsr0, 50; prepare
strr0, [r7];
movsr0, r7; 'in' parameters
addsr1, r7, 5*4; 'out' parameters
blGoIAP;
ldrr0, [r7, 5*4]; get status code
cbnzr0, 9f; OOPS -- IAP failed
movsr0, 52; erase
strr0, [r7];
movsr0, r7; 'in' parameters
addsr1, r7, 5*4; 'out' parameters
blGoIAP;
ldrr0, [r7, 5*4]; get status code
cmpr0, 11; is it lying about being 'busy'?
bne9f; nope
;---------------------------------------;
movsr0, 53; yup -- is it actually blank?
strr0, [r7];
movsr0, r7; 'in' parameters
addsr1, r7, 5*4; 'out' parameters
blGoIAP;
ldrr0, [r7, 5*4]; get status code
;cbnzr0, 9f; OOPS -- IAP failed
;---------------------------------------;
9:pop{r7,pc}; return (zero == success)
fe FLZap
;-----------------------------------------------------------------------!
; IAP Invoke Wrapper!
;-----------------------------------------------------------------------!
fn GoIAP
push{lr};
ldrr12, =IAP; get abs entry point
cpsidi; let's try disabling interrupts
blxr12; go IAP
cpsiei; and re-enable
pop{pc}; return
fe GoIAP
|