CANopen API Description

This section explains the application programming interface of the CANopen stack in detail. Before explaining the API functions in detail, the overall philosophy of the CANopen implementation may help to understand the naming conventions and data to function relationship.

The CANopen stack is implemented in an object oriented way:

  1. The data is strictly separated from the function. The data of a module is collected within a C structure and is called: class.
  2. The CANopen stack allocates no memory. The memory must be allocated within the device configuration or within the application. The allocated memory of a class is called: object
  3. The function of a class needs at least the reference to an object of that class type. As a convention, the functions expects this reference as first parameter. This reference is in most object oriented literature the this-pointer. Within the CANopen stack the name of this reference is an abbreviation of the class to highlight the membership of the function.

The following example source explains the principle implementation of a hypothetical module in this object oriented philosophy.


                                 >>> module.h <<<
 
typedef struct MOD_T {           /* definition of class 'module'       */
    CPU_INT32U  Data;            /* object member data                 */
} MOD;
                                 /* declaration of member function     */
void ModSetData (MOD *mod, CPU_INT32U value);
 
                                 >>> module.c <<<
#include "module.h"
                                 /* implementation of member function  */
void ModSetData (MOD *mod, CPU_INT32U value)
{
    mod->Data = value;           /* set member data in given instance  */
}
 
                                 >>> app.c <<<
#include "module.h"
 
void main (void)
{
    MOD  ma;                     /* allocate memory for module object  */
 
    ModSetData(&ma, 0L);         /* call member function of module     */
}