Variable initialization, Neuron c declarations – Echelon Mini EVK User Manual

Page 45

Advertising
background image

Variable Initialization

Initialization of variables occurs at different times for different classes. The
const variables, except for network variables, must be initialized.
Initialization of const variables occurs when the application image is first

loaded into the Neuron Chip or Smart Transceiver. The const ram variables
are placed in off-chip RAM that must be non-volatile. The eeprom and config

variables are also initialized at load time, except when the uninit class
modifier is included in these variable definitions.
Automatic variables cannot be declared const because Neuron C does not

implement initializers in declarations of automatic variables.

Global RAM variables are initialized at reset (that is, when the device is reset

or powered up). By default, all global RAM variables (including static

variables) are initialized to zero at this time. Initialization to zero costs no
extra code space, as it is a firmware feature.
Initialization of I/O objects, input network variables (except for eeprom,
config, config_prop, or const network variables), and timers also occurs at

reset. Zero is the default initial value for network variables and timers.
Local variables (except static ones) are not automatically initialized, nor are
their values preserved when the program execution leaves the local scope.

Neuron C Declarations

Both ANSI C and Neuron C support declarations of the following:

Declaration Example
•Simple data items

int a, b, c;

•Data types

typedef unsigned long ULONG;

•Enumerations

enum hue {RED, GREEN, BLUE};

•Pointers

char *p;

•Functions

int f(int a, int b);

•Arrays

int a[4];

•Structures and unions

struct s {
int field1;

unsigned field2 : 3;

unsigned field3 : 4;

};

In addition, Neuron C Version 2.1 supports declarations of the following:
Declaration For

Example:

•I/O objects

IO_0 output oneshot relay_trigger;

•Timers

mtimer led_on_timer;

•Network variables

network input SNVT_temp nviTemperature;

Mini EVK User’s Guide

39

Advertising