4 basic code architecture, 1 initialization, Basic code architecture – Maxim Integrated 71M6521BE Energy Meter IC Family Software User Manual
Page 49: Initialization, Figure 5-5) routines. main_init() is used for

71M652X Software User’s Guide
Revision 1.7
TERIDIAN Proprietary
49 of 138
© Copyright 2005-2007 TERIDIAN Semiconductor Corporation
main_background()
main_run()
Process flag protocol (0)
yes
no
Run software timers
Neutralize potential flash
erase from EMI
Reset SW watchdog for
main loop
Run metering
Detect and manage battery
modes
Command pending?
Process command
Process flag protocol (1)
END
main_background()
END
Figure 5-5: main_run() Function
5.4 BASIC CODE ARCHITECTURE
The TERIDIAN 71M652X firmware can be divided into two code parts. One is the Background task that is executed
whenever there are no other higher priority exceptions such as the servicing of interrupts. The second part consists of
the interrupt-driven code (Foreground) tasks, such as the CE_BUSY Interrupt, Timer Interrupt, and other Interrupt
service routines. The background code takes care of the non time-critical functions starting with the system reset, and
this code is executed every time when there are CPU resources available after taking care of all interrupt-driven tasks.
The background of the 71M652X firmware is implemented as a very simple state machine. One state is serving the
command inputs and the other is idle/Display control.
5.4.1 Initialization
When the power applied for the first time or RESETZ is asserted, the 71M652X device executes the code pointed to by
the reset vector.