The USERCLASS directive assigns a user defined class name to a compiler generated segment. By default, the C51 Compiler uses the basic class name for segment definitions. The user class name may located at a specific address range by the extended LX51 Linker. This allows you to locate all segments with a class name such as XDATA_FLASH to a specific memory area. The USERCLASS directive renames the basic class name for an entire module. Overlayable segments (typically local variables in C functions) are not renamed. To rename a local variable, you must change its allocation type to static by including the static keyword in the variable definition. For example:
/* Rename XDATA class to XDATA_MyClass */
#pragma userclass (xdata = MyClass)
xdata int glob_var; /* Stored in XDATA_MyClass */
static xdata int static_var; /* Stored in XDATA_MyClass */
void func (void)
{
static xdata long func_var; /* Stored in XDATA_MyClass */
xdata long func_var2; /* Stored in XDATA */
func_var = 1;
func_var2 = 2;
}
void main (void)
{
static xdata long main_var; /* Stored in XDATA_MyClass */
xdata long main_var2; /* Stored in XDATA */
main_var = 1;
main_var2 = 2;
func ();
while (1);
}
Memory classes are only available when you use the OMF2 format and the extended LX51 Linker/Locater. |