Compiler-specific information – Maxim Integrated 71M6513H Power Meter IC Family Software User Manual
Page 44

71M651x Software User’s Guide
Data Type
Notation
Bits
Bytes
Comments
Bit
Bbool
1
Unique to 8051
Sbit
1
Unique to 8051
SFR
8
1
Unique to 8051
SFR16
16
2
Unique to 8051
signed/unsigned char
U08
8
1
ANSI C
enum
enum
8 or 16
1 or 2
ANSI C
unsigned short
U16
16
2
ANSI C
signed short
S16
16
2
ANSI C
signed/unsigned int
U16
16
2
ANSI C
signed int
S16
16
2
ANSI C
unsigned long
U32
32
4
ANSI C
Float
F32
32
4
ANSI C
Table 5-1: Data Types
5.1.2. Compiler-Specific Information
The 8051 has 128 bytes of stack, and this motivates Keil C's unusual compiler design. By default, the Keil C compiler
does not generate reentrant code. The linker manages local variables of each type of memory as a series of overlays,
and uses a call-tree of the subroutines to arrange that the local variables of active subroutines do not overlap.
The overlay scheme can use memory very efficiently. This is useful because the 71M651X chips only have 2k of RAM,
and 256 bytes of internal memory.
The compiler treats uncalled subroutines as possible interrupt routines, and starts new hierarchies, which can rapidly
fragment each type of memory and interfere with its reuse.
To combat this, the following measures were taken when generating the Demo Code:
•
The code is organized as a control loop, keeping most code in a single hierarchy of subroutines,
•
The programmers eliminated unused subroutines by commenting them out when the linker complained
about them. Also, the Demo Code explicitly defines interrupt code and routines called from interrupt
code as "reentrant" so that the compiler keeps their variables on a stack.
•
When data has a stable existence, the Demo Code keeps a single copy in a shared static structure.
With these measures applied, the Demo Code uses memory efficiently, and normally no memory issues are en-
countered. The demo code does not have deep call trees from the interrupts, so "small reentrant" definitions can be
used, which keep the stack of reentrant variables in the fast (small) internal RAM.
The register sets are also in internal memory. The C compiler has special interrupt declaration syntax to use them.
The "noaregs" pragma around reentrant routines stops the compiler from accessing registers via the shorter absolute
memory references. This is because the demo code uses all four sets of registers for different high-speed interrupts.
Using "noaregs" lets any interrupt routine call any reentrant routine without overwriting a different interrupt's registers.
There is a known defect in version 7.50a of the Keil compiler:
Memory types must be explicitly defined in local variables. Using a predefined type is not
explicit enough, i.e. "char xdata c;" is ok. "typedef char int8_t; ... int8_t data c;" is ok, "typedef
char data int8d_t; ... int8d_t c;" is not ok.
Revision 2.4
TERIDIAN Proprietary
44 of 137
© Copyright 2005-2006 TERIDIAN Semiconductor Corporation