Keil Logo

C51: CALL C FUNCTIONS WITHIN STARTUP CODE


Information in this article applies to:

  • C51 All Versions

QUESTION

I 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?

ANSWER

Yes, 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 ALSO

FORUM THREADS

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

Last Reviewed: Monday, May 3, 2004


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.