Texas Instruments TMS320F20x/F24x DSP Computer Drive User Manual


 
Sample C Code to Erase and Reprogram the TMS320F206
PRELIMINARY
A-37
Assembly Source Listings and Program Examples
PRELIMINARY
A.4 Sample C Code to Erase and Reprogram the TMS320F206
Because the algorithm implementations do not follow the C-calling convention
of the ’C2000 C environment, they cannot be used directly from C. The assem-
bly code of section A.2,
C-Callable Interface to Flash Algorithms
, is provided
as a C-callable interface to the programming algorithms. The following C
source file and linker command file provide a working example for the ’F206. In
this example, the algorithms reside in the on-chip SARAM, and either flash0 or
flash1 can be reprogrammed. The code can be relocated anywhere in pro-
gram space, with the exceptions described in section A.3,
Using the Algo-
rithms With Assembly Code
.
A.4.1 C Code That Calls the Interface to Flash Algorithms for TMS320F206
/***************************************************/
/* Filename: sample.c */
/* Description: This is an example of how to */
/* program the ’F2XX flash from C code. */
/* The C–callable interface for the standard */
/* flash algorithms is used. This interface is */
/* defined in the file <flash.asm>, as two */
/* C–callable functions: erase(), and program() */
/* At link time, this example must be combined */
/* with the code in <flash.asm> as well as with */
/* the object modules for the standard algos. */
/***************************************************/
/* This example is set up for the TMS320F206, */
/* and uses the SARAM as a buffer for programming */
/* data. The code first erases module1, */
/* then programs the first three locations. */
/***************************************************/
/* Rev1.0 10/97 RDP */
/***************************************************/
extern int erase(); /* Declare external func for flash erase. */
extern int program(); /* Declare external func for flash programming. */
main()
{
int *a;
if (erase(0xff00,0x4000,0x7fff))
{ /*Flash is erased, now let’s program it.*/
/* Init program buffer. */
a=(int *)0xC00; /*Use last 3K of SARAM for data buffer*/
a[0]=0x7A80;
a[1]=0x0FDF;
a[2]=0x7A80;
/*Program the flash from the buffer*/
if (program(0xff00,0xc00,0x4000,0x3))
{ /*Flash programmed ok.*/
while(1){} /*Spin here forever*/
}
else