Application note 0564-02: no global variables

The CANopen Library from port provides the possibility to convert the global object dictionary and internal global variables into C structures. The user application can create locally variables of these structure data types.

 

In order to use the conversion to no global variables the following conditions have to be complied:

·         The CANopen Library is only used in the single-line configuration.

·         The CANopen Driver Package (DP) supports no global variables.

·         The license “no global variables” for the CANopen Design Tool (CDT) is available, order number: 0640/99.

 

 

Configuration about the CDT

 

The creation of the C structures is activated in the CDT about:

·         General Settings / Tab Mask / Object dictionary without global variables: on

 

Because the variable for the object dictionary is created by the application during run-time, the variable is located in RAM. That is why the property “Store Object Dictionary Structure in ROM” has to be switched off.

·         Line x / Standard Settings / Tab Mask / Store Object Dictionary Structure in ROM: off

 

 

Creation of an application with no global variables

 

The CANopen Library and the DP need the following variables:

·         variable of data type CANOPEN_OBJ_DIR_T for the object dictionary inclusive the object description, the C structure is generated by the CDT

·         variable of data type CANOPEN_DATA_T for internal controlling of the CANopen Library, the C structure is generated during compilation depending on the selected CANopen services

·         variable of data type DRIVER_DATA_T for internal controlling of the CANopen DP, the C structure is generated during compilation

 

These variables have to be declared in the user application. In order to initialize these variables the user application shall call the following functions:

·         void init_ObjectDictionary (CANOPEN_OBJ_DIR_T *pObjectDictionary, CANOPEN_DATA_T *pLibVars)

·         void init_canDriverPtr((UNSIGNED8*) drvVars, CANOPEN_DATA_T *pLibVars)

 

All CANopen Library and DP functions need the link to these variables. The address of the variables is added to the function calls, e.g.:

·         UNSIGNED8 initCan(UNSIGNED16 baud, CANOPEN_DATA_T *pLibVars)

·         RET_T init_Library(CANOPEN_DATA_T *pLibVars)

·         void FlushMbox(CANOPEN_DATA_T *pLibVars)

 

The CANopen Library example s21 shows the implementation for a simple NMT slave device.

 

 

Compilation

 

The C modules of the CANopen Library globvars.[h,c]c has to be added to the compiler project.

 

After compilation the executable program shall work with no global variables.