beautypg.com

4 economic usage of ram, 5 trading space for speed, 6 object-oriented design – Maxim Integrated 71M6534 Energy Meter IC Family Software User Manual

Page 78: Economic usage of ram, Trading space for speed, Object-oriented design

background image

71M653X Software User’s Guide

The Keil linker’s dependency command must be used to tell the linker about the caller of every routine called via a
function pointer. If this is not done, Keil’s address for the called routine is often in a bank, and the bank is rarely the
current bank. So, the caller goes to the called routine’s address, but in the wrong bank. This doesn’t work.

When the linker is told that a called routine is called from a caller, then it places a bank-switching stub for that routine in
the common bank, and the call via function pointer works splendidly.

The function pointer issue is a problem for the timer code, and the software timer code. These call an error function
when they get function pointer addresses greater than 0x7FFF.

5.14.1.4 Economic Usage of RAM

The IC has only 3K of RAM for use by the MPU. There are two main tricks to fit the data in:

• The main-loop organization lets Keil’s linker use overlays to maximum advantage, multiplying the utility of the

small amount of RAM.

• Also, the big pieces of stable data are global, and shared. Most of them are in Totals, a large C structure

defined in meter\meter.h. Totals contains all MPU calibration and register items. The CE interface is in CE, a
large C structure defined in meter\ce653x.h.

The largest unshared items are the serial buffers, defined in serial0cli.c and serial1cli.c. For most people, removing
serial1 has no effect at all on the usability of the debug interface, and it frees the port and RAM for use by an AMR
system.

5.14.1.5 Trading Space for Speed

The 8051 has seven types of memory space. If used correctly, they can help code run faster.

The Keil compiler provides memory type names like “data” “xdata” and “pdata” so that the programmer can place
particular data items in particular memory spaces. See the manual for more information.

Some memory areas are faster to access, because the code to access the memory is shorter. In decreasing order:

The code keeps a few critical high-speed bit-flags in BDATA, the fastest, rarest memory.

The code keeps a few high-speed counters in DATA, a fast data space. This is intentionally underutilized to make
room for customer data.

The code makes very little use of IDATA in order to conserve stack space.

The CE’s output registers are mapped to PDATA. This gives the math fast access to the CE output values.

XDATA is used for most variable data.

CODE is used for code, and a few large tables, like the CE’s code and initialization data.

5.14.1.6 Object-Oriented Design

First, is it worth it? An object-oriented design can use the same control code to run similar electronics or data. This
has several advantages. The big one for firmware is that the higher levels of the firmware can quickly change to use
other related devices with a minimum of introduced defects.

The trick in a small embedded system is to implement a base class (the “integration interface”) in a way that is efficient
and not too hard to understand.

In this design, a base class is an include file of macros (i.e. a “.h” file). Two schemes will be used.

When there are several devices or data structures and switching is not needed, each device will have its own .h file.
The macros and function prototypes will provide an interface that is the same for all callers. For example, instead of
including ser.h, and calling ser0_getc(), this scheme will have the caller include ser0.h, and then call ser_getc(). By
including ser1.h, the same calling code can be instantly ported to serial port 1.

If dynamic calling is needed, the .h file can conceal switching code that tests a bit and selects a daughter-class’s
methods. For example Cli\sercli.c conceals an interface that can write to either UART, based on a port parameter.

These schemes are efficient in the 8051, producing code as fast as individual calls for each daughter class.

v1.1v1.1

TERIDIAN Proprietary

78 of 116

© Copyright 2005-2008 TERIDIAN Semiconductor Corporation

This manual is related to the following products: