Technical Support

C166: WRITING RELOCATABLE C FUNCTIONS FOR COPYING TO RAM


Information in this article applies to:

  • C166 Version 4.02

QUESTION

I have read application note 138, which describes how to copy assembler routines from Flash memory to RAM for execution. I want to copy C routines. Is this possible?

ANSWER

Yes. However, you must locate the C code in FAR memory (MEDIUM, LARGE, or HLARGE memory model) and you must use the RENAMECLASS directive to specify the correct name for the code class.

Write your C functions in a separate source file as functions. For example:

#pragma LARGE     // only required when you are using the SMALL memory model!
#pragma RENAMECLASS(FCODE=FLASH_CODE)

int PFlash_Erase (void huge *sector_adr)
{
sector_adr = sector_adr;   /* Avoid compiler warning */

return (0);
}

int PFlash_Write (void huge *target_adr, void huge *buffer)
{
target_adr = target_adr;   /* Avoid compiler warning */
buffer = buffer;           /* Avoid compiler warning */

return (0);
}

void PFlash_Reset (void)
{
}

Your C routines are then ready to use!

You will probably receive a linker warning similar to the following:

*** WARNING L14: INCOMPATIBLE MEMORY MODEL
    MODULE:  pflash.obj (PFLASH)
    MODEL:   LARGE

The warning is caused (in this instance) because the memory model of the program is SMALL while the memory model of the PFLASH module must be LARGE. It is safe to ignore this warning.

MORE INFORMATION

SEE ALSO

FORUM THREADS

The following Discussion Forum threads may provide information related to this topic.

Last Reviewed: Wednesday, June 01, 2005


Did this article provide the answer you needed?
 
Yes
No
Not Sure