Use efficient constant values, Use neuron c utility functions effectively – Echelon Neuron C User Manual

Page 214

Advertising
background image

202 Memory

Management

Use Efficient Constant Values

In the Neuron Chip and Smart Transceiver CPU architecture, constants in the

range of 0 to 7 can be used more efficiently than larger 8-bit constants.
Instructions that use these constant values are smaller and faster. Therefore,

when choosing a sequence of constant values, normalize the sequence to begin

with 0. An enumerated type (an enum) is, by default, normalized with zero in
this manner.
Also, because the Neuron firmware initializes RAM to zero automatically when

the application is reset, a constant sequence should be designed with zero as its
initial value. The following section,

Take Advantage of Neuron Firmware

Default Initialization Actions

, describes how you can use this fact to your

advantage.
Another consideration is a comparison, especially when used in a loop control

expression, such as in a while statement. The most efficient comparison of an
expression with a constant is when the constant is zero. If you cannot arrange to

have your loop test compare with zero, then try to arrange to have your loop test

compare with one. Equality comparisons with one are not as efficient as
comparisons with zero, but they are more efficient than comparisons with other

constants.

Take Advantage of Neuron Firmware Default
Initialization Actions

The Neuron firmware automatically sets all RAM variables to zero each time the
chip resets, and also when the Neuron C application_restart( ) function is called.

After this action, the Neuron C application program is started. The first action of

a Neuron C application program is to execute code to initialize any RAM
variables to non-zero values. Then, if a task associated with the when(reset)

clause exists, it is called.

Therefore, use of compile-time initializers to set RAM variables to zero is free.

Eliminate any code in the when(reset) clause’s task which is used to set RAM

variables to zero, because it is unnecessary.

Also, compile-time initializers of I/O output objects are free. They are free

regardless of initializer value. The use of compile-time initializers for I/O uses

less code space than corresponding calls to io_out( ) in the when(reset) clause’s
task.
Finally, during reset, the Neuron C application timers are all turned off

automatically. Eliminate any code in the when(reset) clause’s task that explicitly
turns off application timers.

Use Neuron C Utility Functions Effectively

There are several Neuron C utility functions that can be used to reduce code

requirements. For example, there are min( ), max( ), and abs( ) functions, as well
as other utility functions which can be used for common operations. Using these

functions is generally more code-space efficient than coding the operations in-line

using C operators.

Advertising