This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Create standalone function to be loaded into Code memory

I have an application, for an 8051 device, that accepts commands, acts on them, and provides a reply.  I want to implement a command that will load code (for an new function) into a reserved section of Code memory so that the code will run when a different command jumps to it.  I'm having trouble getting the standalone function, which needs to access data arrays and other functions in the main application, to link (BL51 linker) without warnings.  My test function is:

void Cipher (unsigned char *in, unsigned char *out);

extern unsigned char xdata Data_Bffer[];
extern unsigned char xdata PlainTxt[];

void User1(void)
{
	PlainTxt[0] = 0x06;		//ASCII "ACK"
	PlainTxt[1] = 0xAA;
	PlainTxt[2] = 0x55;
	PlainTxt[3] = 0xAA;
	PlainTxt[4] = 0x55;
	PlainTxt[5] = 0xAA;
	PlainTxt[6] = 0x55;
	PlainTxt[7] = 0xAA;
	PlainTxt[8] = 0x55;
	PlainTxt[9] = 0xAA;
	PlainTxt[10] = 0x55;
	PlainTxt[11] = 0xAA;
	PlainTxt[12] = 0x55;
	PlainTxt[13] = 0xAA;
	PlainTxt[14] = 0x55;
	PlainTxt[15] = 0xAA;

	Cipher(&PlainTxt[0], &Data_Bffer[0]);
	return;
}

and the project also contains the following assembly code file:

$NOMOD51

PUBLIC   Data_Bffer
PUBLIC   PlainTxt
PUBLIC   Cipher

Data_Bffer   EQU   0DE0h
PlainTxt   EQU   0FF0h
Cipher	EQU	2104h

END

where the addresses for the data arrays and the function Cipher are taken from the .M51 file of the main application.  I'm getting warnings like the following from the linker:

*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  _CIPHER
    MODULE:  C:\Users\R\UserFunctions.obj (USERFUNCTIONS)

>>
*** WARNING L1: UNRESOLVED EXTERNAL SYMBOL
    SYMBOL:  ?_CIPHER?BYTE
    MODULE:  C:\Users\R\UserFunctions.obj (USERFUNCTIONS)

My Assembler, Compiler, and Linker command lines are unaltered from the defaults (in the Silicon Labs IDE); e.g. linker command line is:

RS(256) PL(68) PW(78)

If I change "Cipher" to "_Cipher" in the Assembly file, then the first warning goes away.  But I don't know what to do about "?_CIPHER?BYTE".  Anyone tried something like this before and know the fix?

Parents
  • Sorry, I did not understand what you meant by "define" - from your correction of my example code I now see what you meant.  Unfortunately, ?_Cipher?BYTE does not appear in the .M51 file from my main program so I can not get the address - this is why I did not have it on a line with an EQU.  Both "in" and "out" appear in the .M51 file, perhaps I could use them instead?

    I'm going to try your suggestion of redefining the prototype for Cipher to specify xdata, that sounds like a straight forward fix, and I don't see any reason not to (this was a function I obtained from somewhere else, and had left the way it was).  And I will use the NOOVERLAY directive.

Reply
  • Sorry, I did not understand what you meant by "define" - from your correction of my example code I now see what you meant.  Unfortunately, ?_Cipher?BYTE does not appear in the .M51 file from my main program so I can not get the address - this is why I did not have it on a line with an EQU.  Both "in" and "out" appear in the .M51 file, perhaps I could use them instead?

    I'm going to try your suggestion of redefining the prototype for Cipher to specify xdata, that sounds like a straight forward fix, and I don't see any reason not to (this was a function I obtained from somewhere else, and had left the way it was).  And I will use the NOOVERLAY directive.

Children