RTE-V831-PC
USER’S MANUAL (Rev. 2.00)
29
11.4.
FLASH ROM PROGRAMMING
A sample program for writing data into a flash ROM mounted on the board is indicated below. For
writing to a flash ROM, data is written on a byte-by-byte basis in the uncacheable area. For detailed
information about the programming algorithm, refer to the data sheet for the flash ROM.
/ *
Flash ROM write sample
* /
# d e f i n e F L C M D
_
E R A S E
0 x 8 0
/ *
Erase
* /
# d e f i n e F L C M D
_
W R I T E
0 x A 0
/ *
Write
* /
# d e f i n e F L C M D
_
R E A D
0 x F 0
/ *
Read
* /
# d e f i n e B I T
_
D Q ( n )
( 1 < < ( n ) )
/ *
Bit macro
* /
/ * F l a s h - R O M L i b r a r y * /
s t a t i c F l a s h C o m m a n d ( i n t a d d r , i n t c m d )
/ *
C o m m a n d
* /
{
i n t a d d r 2 ;
a d d r 2 = a d d r & ~ ( 0 x 7 F F < < 2 ) ;
/ *
Address 11 bit 0 clear
* /
* ( c h a r * ) ( a d d r 2 + ( 0 x 5 5 5 < < 2 ) ) = 0 x A A ;
* ( c h a r * ) ( a d d r 2 + ( 0 x 2 A A < < 2 ) ) = 0 x 5 5 ;
* ( c h a r * ) ( a d d r 2 + ( 0 x 5 5 5 < < 2 ) ) = c m d ;
r e t u r n 0 ;
}
s t a t i c F l a s h D a t a P o l l ( i n t a d d r , i n t d a t a )
/ *
Busy check
* /
{
i n t r d a t a ;
d a t a & = 0 x f f ;
/ *
Byte
* /
d o {
r d a t a = * ( c h a r * ) a d d r & 0 x f f ;
i f ( ( ( d a t a ^ r d a t a ) & B I T
_
D Q ( 7 ) ) = = 0 ) {
b r e a k ;
}
} w h i l e ( ( r d a t a & B I T
_
D Q ( 5 ) ) = = 0 ) ;
r d a t a = * ( c h a r * ) a d d r & 0 x f f ;
r e t u r n ( ( ( d a t a ^ r d a t a ) & B I T
_
D Q ( 7 ) ) = = 0 ) ? 0 : - 1 ;
}
F l a s h E r a s e ( i n t a d d r , i n t a l l )
/ *
Erase (whole/sector)
* /
{
F l a s h C o m m a n d ( a d d r , F L C M D
_
E R A S E ) ;
F l a s h C o m m a n d ( a d d r , ( a l l ) ? 0 x 1 0 : 0 x 3 0 ) ;
/ *
Whole/sector
* /
r e t u r n F l a s h D a t a P o l l ( a d d r , 0 x f f ) ;
}
F l a s h W r i t e ( i n t a d d r , i n t d a t a )
/ *
Write
* /
{
F l a s h C o m m a n d ( a d d r , F L C M D
_
W R I T E ) ;
d a t a & = 0 x F F ;
* ( c h a r * ) a d d r = d a t a ;
r e t u r n F l a s h D a t a P o l l ( a d d r , d a t a ) ;
}
F l a s h R e a d ( i n t a d d r )
/ *
Read (reset)
* /
{
i n t d a t a ;
F l a s h C o m m a n d ( a d d r , F L C M D
_
R E A D ) ;
d a t a = * ( c h a r * ) a d d r & 0 x F F ;
r e t u r n d a t a ;
}
/ *
Copy monitor to flash ROM
* /
# d e f i n e S R C
_
A D D R
0 x F F F F 0 0 0 0
/ *
E P R O M
* /
# d e f i n e D S T
_
A D D R
0 x 4 2 7 F 0 0 0 0
/ *
F L A S H R O M
* /
# d e f i n e D A T A
_
S I Z E
0 x 1 0 0 0 0
/ *
64 KB
* /
m a i n ( )
{
i n t d a d d r , s a d d r , d a t a ;
i n t i , e r r ;