Hardware Reference
In-Depth Information
if (FSTAT & (ACCERR | PVIOL))
return 1;
/* error flag is set, command failed */
while(!(FSTAT & CCIF));
/* wait until command completion */
return 0;
}
}
Example 14.8
Write a function that programs a block of words to the flash memory. The number of words
to be programmed, the starting address of the flash memory to be programmed, and the starting
address of data are passed to this function in B, X, and Y, respectively.
Solution: The assembly function that performs the flash programming is as follows:
feProgBlok
tstb
; check word count
bne
doFLprog
; word count is valid
rts
; return if word count is zero
doFLprog
pshb
; save the word count in stack
fepwait1
brclr
FSTAT,CBEIF,fepwait1
; wait until command buffer is empty
movw
2,y 1 ,2,x 1
; write data word to flash address
movb
#Program,FCMD
; write program command
movb
#CBEIF,FSTAT
; launch the command
brclr
FSTAT,ACCERR 1 PVIOL,progK ; is there any error?
pulb
ldab
#1
; return error code 1
rts
progOK
dec
0,SP
; one word less to be programmed
bne
fepwait1
; more words to be programmed?
pulb
clrb
; return error code 0
rts
The C language version of the function is as follows:
int feProgBlok(char cnt, int *destptr, int *srcptr)
{
if(cnt 55 0)
return 0;
/* if word count is 0, do nothing */
while(cnt){
if(FSTAT & CBEIF){
// if command buffer is not empty, do nothing
*destptr 11 5 *srcptr 11 ; // write data word to flash location
FCMD 5 Program;
// write program command
FSTAT 5 CBEIF;
// launch program command
if(FSTAT & (ACCERR 1 PVIOL))
return 1;
// program error?
cnt 2 ;
}
}
Search WWH ::




Custom Search