The eeprom_memcpy( ) function – Echelon Neuron C User Manual

Page 199

Advertising
background image

Neuron C Programmer’s Guide

187

The flash memory that is used for the EECODE data is erased once during the

application load process. If present, the alternate Neuron firmware image is not
erased during this step. Flash memories typically have an endurance rating of

10 000 erase/program cycles – this number translates directly to the number of

application load cycles.

The Series 5000 chip can operate at any system clock speed when using flash

memory.

The eeprom_memcpy( ) Function

You can write EEPROM memory, as well as flash memory, by direct assignment,
including structure-to-structure assignment. In these cases, the compiler

recognizes that the target variable is in EEPROM memory, and uses the
appropriate firmware function to write the memory properly, with the correct

delays, hardware interface sequences, and so on

.

However, when writing to EEPROM through a pointer, the compiler cannot track
what type of memory the pointer points to. Thus, addresses of EEPROM

variables are automatically typed by the compiler as 'const *', to prohibit use of

the pointer for writing:

eeprom int x;

void y() {
const int* pointer;
pointer = &x; // '&x' is 'const int *'
}

The compiler normally prevents removing the const attribute from any pointer so

typed. This is prevented for both implicit and explicit cast operations. An

implicit cast occurs when there is an assignment of a value to a variable of
different type, or when there is an actual parameter passed to a function whose

formal parameter is a different type, as illustrated in the following example:

eeprom int x;
int *p;
void f (int *p);

void y() {
p = &x; // implicit cast, compiler error
f(&x);

// another erroneous implicit cast

p = (int *)&x; // explicit cast, also error
}

This behavior of the Neuron C compiler is stricter than the behavior specified by

ANSI C. However, if you specify the #pragma relaxed_casting_on directive, the

compiler only generates a warning message for each such implicit or explicit cast.
You can use the #pragma warnings_off or #pragma disable_warning directive to

further suppress the warning messages. You can use the corresponding

warnings_on (or enable_warning) and relaxed_casting_off directives later in the
program to restore the default behavior of the compiler for the remainder of the

program.
Use of this feature is dangerous, because you can circumvent the compiler’s
checking and attempt a spurious write (that is, a write without knowledge of the

firmware) to EEPROM or flash memory. The eeprom_memcpy( ) function is

Advertising