| ||||||||
Technical Support Support Resources Product Information | C51: CALL C FUNCTIONS WITHIN STARTUP CODEInformation in this article applies to:
QUESTIONI am using a 80C51RD with on-chip Flash and XRAM. In addition, I have an 32KByte external XDATA RAM. The external XDATA RAM is connected to an FPGA which requires programming before I can access it. This FPGA programming routine is part of the initialization code that I do in the beginning of the C main function. However, I am now facing a problem: the initializations of xdata variables in this external XDATA RAM is performed within the INIT.A51 file, and since it is called before main from the STARTUP.A51 code, my initialization fails. Since I would prefer to stay in C with the FPGA initialization, I have a question: is it possible to call a C function within the STARTUP code before the INIT.A51 gets executed? ANSWERYes, you can basically call a C function after you have set the stack pointer (done in STARTUP.A51 with the instruction MOV SP,#?STACK). Change the STARTUP.A51 file as follows and add it to your project.
.
.
.
; function name of FPGA init function written in C.
EXTRN CODE (FPGA_init)
RSEG ?C_C51STARTUP
STARTUP1:
; insert at the STARTUP1 label the following code:
MOV SP,#?STACK-1 ; set stack pointer
CALL FPGA_init
; rest of the STARTUP file.
.
.
.
Note: You may remove the stack pointer initialization at the end of the STARTUP file since it is moved to the beginning of the startup code. SEE ALSOFORUM THREADSThe following Discussion Forum threads may provide information related to this topic. Last Reviewed: Monday, May 03, 2004 | |||||||
| ||||||||