Performing neuron c functions from libraries – Echelon Neuron C User Manual

Page 237

Advertising
background image

Neuron C Programmer’s Guide

225

Use these include files in the library source files that define these

functions and data objects as well, so that the Neuron C compiler can
ensure that your extern declarations and prototypes match your actual

declarations and function definitions. You can follow a particular extern

declaration with the actual declaration, as long as the declarations
match.

This technique can help prevent calling a function with incorrect
parameters (due to an incorrect extern prototype, for example), which can

result in an overwritten data stack and thus could result in a device that

repeatedly experiences a watchdog timer reset, overwritten variables, or
similar software failures.

4

The NodeBuilder Project Make Utility advises the linker of all libraries

listed in the STDLIBS.LST file, but precedes this list by the list of user-
defined libraries that are specified through the NodeBuilder device

template. Therefore, to reduce the chances of a symbol conflict between

two or more libraries, use a naming convention to establish unique names
for library objects. Use the nlib -r command option (as described in

Appendix A,

Neuron C Tools Stand-Alone Use

, on page 211) to generate a

report listing the symbols that are defined in each existing library.

Performing Neuron C Functions from Libraries

The pure C code that is placed in a library cannot contain references to network

variables, messages, I/O, timers, or other Neuron C objects. However, the library

can be designed mainly for the purpose of performing Neuron C related tasks,
such as standard I/O device management, or message construction, or timer

manipulation.

You can access Neuron C objects from a library function by making it the

responsibility of the application program to actually perform the Neuron C

operation in an application function. The library can then call the application
function in the Neuron C application program, and effectively perform Neuron C

operations.
For example, consider a library that contains routines for management of a
standard LCD display device. This library would contain various routines for

formatting information and for managing the display in response to various

commands from the application program. It is desirable to have the library code
automatically perform the I/O operations to update the device. However, due to

the pure C restriction the required Neuron C code cannot be implemented as part
of the library.
For the I/O operations on the display, assume that the display has a Neurowire

device interface. The library could be accompanied with an include file for the
benefit of whatever Neuron C application program uses it. The include file can

contain the Neurowire I/O declarations and the function definitions necessary to

support the display’s I/O. Then, the library can access the functions as necessary
without further intervention from the application program, and without the

application program’s being responsible for passing some special parameters each

time it wants to interact with the library display management software.

As this discussion shows, it is possible to create utility functions that depend on

Neuron C features. By dividing the Neuron C code from the pure C code, and

Advertising