ARM Technical Support Knowledge Articles

CALL C FUNCTIONS WITHIN STARTUP CODE

Applies to: C51 C Compiler

Answer


Information in this article applies to:


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

Article last edited on: 2004-05-03 18:52:47

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential