;-----------------------------------------------------------------------! ; Constants and Equates ! ;-----------------------------------------------------------------------! IAP = 0x1FFF1FF1 ; ROM Boot IAP dispatch address clkKHz = 120000 ; system clock in KHz cmdSz = 32 ; codeSz = 4096 ; ;-----------------------------------------------------------------------! ; Private Data ! ;-----------------------------------------------------------------------! .section .sbss, "aw", %nobits ; private sram bss area .align 2,0 .type cmdBuff, %object .size cmdBuff, cmdSz cmdBuff: .space cmdSz .type codeBuff, %object .size codeBuff, codeSz codeBuff: .space codeSz ;-----------------------------------------------------------------------! ; Erase Flash ! ;-----------------------------------------------------------------------! ; r0 = start sector, r1 = sector count fn FLZap push {r7,lr} ; ldr r7, =cmdBuff ; str r0, [r7, 1*4] ; stash first sector adds r0, r1 ; calc last sector subs r0, 1 ; first+count-1 str r0, [r7, 2*4] ; stash last sector ldr r0, =clkKHz ; get clock speed str r0, [r7, 3*4] ; stash clock speed ;---------------------------------------; movs r0, 53 ; blank check str r0, [r7] ; movs r0, r7 ; 'in' parameters adds r1, r7, 5*4 ; 'out' parameters bl GoIAP ; ldr r0, [r7, 5*4] ; get status code cbz r0, 9f ; skip erase if blank ;---------------------------------------; movs r0, 50 ; prepare str r0, [r7] ; movs r0, r7 ; 'in' parameters adds r1, r7, 5*4 ; 'out' parameters bl GoIAP ; ldr r0, [r7, 5*4] ; get status code cbnz r0, 9f ; OOPS -- IAP failed movs r0, 52 ; erase str r0, [r7] ; movs r0, r7 ; 'in' parameters adds r1, r7, 5*4 ; 'out' parameters bl GoIAP ; ldr r0, [r7, 5*4] ; get status code ;cbnz r0, 9f ; OOPS -- IAP failed ;---------------------------------------; 9: pop {r7,pc} ; return (zero == success) fe FLZap ;-----------------------------------------------------------------------! ; IAP Invoke Wrapper ! ;-----------------------------------------------------------------------! fn GoIAP push {lr} ; ldr r12, =IAP ; get abs entry point blx r12 ; go IAP pop {pc} ; return fe GoIAP |