2 compiler-specific information, Compiler-specific information – Maxim Integrated 71M6521BE Energy Meter IC Family Software User Manual
Page 40

71M652X Software User’s Guide
Revision 1.7
TERIDIAN Proprietary
40 of 138
© Copyright 2005-2007 TERIDIAN Semiconductor Corporation
Note: Throughout the Demo Code, an attempt has been made to put the most frequently used variables in the
fastest memory space.
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-2: Internal 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 71M652X 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.