CANopenNode
CANopen protocol stack
Loading...
Searching...
No Matches
CANopen

Files

file  CANopen.h
 Main CANopenNode file.
 

Data Structures

struct  CO_config_t
 CANopen configuration, used with CO_new() More...
 
struct  CO_t
 CANopen object - collection of all CANopenNode objects. More...
 

Macros

#define CO_MULTIPLE_OD
 If macro is defined externally, then configuration with multiple object dictionaries will be possible.
 
#define CO_USE_GLOBALS
 If macro is defined externally, then global variables for CANopen objects will be used instead of heap.
 

Functions

CO_tCO_new (CO_config_t *config, uint32_t *heapMemoryUsed)
 Create new CANopen object.
 
void CO_delete (CO_t *co)
 Delete CANopen object and free memory.
 
bool_t CO_isLSSslaveEnabled (CO_t *co)
 Test if LSS slave is enabled.
 
CO_ReturnError_t CO_CANinit (CO_t *co, void *CANptr, uint16_t bitRate)
 Initialize CAN driver.
 
CO_ReturnError_t CO_LSSinit (CO_t *co, CO_LSS_address_t *lssAddress, uint8_t *pendingNodeID, uint16_t *pendingBitRate)
 Initialize CANopen LSS slave.
 
CO_ReturnError_t CO_CANopenInit (CO_t *co, CO_NMT_t *NMT, CO_EM_t *em, OD_t *od, OD_entry_t *OD_statusBits, uint16_t NMTcontrol, uint16_t firstHBTime_ms, uint16_t SDOserverTimeoutTime_ms, uint16_t SDOclientTimeoutTime_ms, bool_t SDOclientBlockTransfer, uint8_t nodeId, uint32_t *errInfo)
 Initialize CANopenNode except PDO objects.
 
CO_ReturnError_t CO_CANopenInitPDO (CO_t *co, CO_EM_t *em, OD_t *od, uint8_t nodeId, uint32_t *errInfo)
 Initialize CANopenNode PDO objects.
 
CO_ReturnError_t CO_CANopenInitSRDO (CO_t *co, CO_EM_t *em, OD_t *od, uint8_t nodeId, uint32_t *errInfo)
 Initialize Safety related Data Objects.
 
CO_NMT_reset_cmd_t CO_process (CO_t *co, bool_t enableGateway, uint32_t timeDifference_us, uint32_t *timerNext_us)
 Process CANopen objects.
 
bool_t CO_process_SYNC (CO_t *co, uint32_t timeDifference_us, uint32_t *timerNext_us)
 Process CANopen SYNC objects.
 
void CO_process_RPDO (CO_t *co, bool_t syncWas, uint32_t timeDifference_us, uint32_t *timerNext_us)
 Process CANopen RPDO objects.
 
void CO_process_TPDO (CO_t *co, bool_t syncWas, uint32_t timeDifference_us, uint32_t *timerNext_us)
 Process CANopen TPDO objects.
 
CO_SRDO_state_t CO_process_SRDO (CO_t *co, uint32_t timeDifference_us, uint32_t *timerNext_us)
 Process CANopen SRDO objects.
 

Detailed Description

CANopenNode is free and open source CANopen communication protocol stack.

CANopen is the internationally standardized (EN 50325-4) (CiA DS-301) CAN-based higher-layer protocol for embedded control system. For more information on CANopen see http://www.can-cia.org/

CANopenNode homepage is https://github.com/CANopenNode/CANopenNode

CANopen.h file combines all CANopenNode source files. Stack configuration is first defined in "CO_config.h" file. Number of different CANopenNode objects used is configured with CO_config_t structure or is read directly from "OD.h" file, if single object dictionary definition is used. "OD.h" and "OD.c" files defines CANopen Object Dictionary and are generated by external tool.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Macro Definition Documentation

◆ CO_MULTIPLE_OD

#define CO_MULTIPLE_OD

If macro is defined externally, then configuration with multiple object dictionaries will be possible.

If macro is not defined, default "OD.h" file with necessary definitions, such as OD_CNT_xxx, will be used, and also memory consumption and startup time will be lower.

◆ CO_USE_GLOBALS

#define CO_USE_GLOBALS

If macro is defined externally, then global variables for CANopen objects will be used instead of heap.

This is possible only if CO_MULTIPLE_OD is not defined.

Function Documentation

◆ CO_new()

CO_t * CO_new ( CO_config_t * config,
uint32_t * heapMemoryUsed )

Create new CANopen object.

If CO_USE_GLOBALS is defined, then function uses global static variables for all the CANopenNode objects. Otherwise it allocates all objects from heap.

Remarks
With some microcontrollers it is necessary to specify Heap size within linker configuration, if heap is used.
Parameters
configConfiguration structure, used if CO_MULTIPLE_OD is defined. It must stay in memory permanently. If CO_MULTIPLE_OD is not defined, config should be NULL and parameters are retrieved from default "OD.h" file.
[out]heapMemoryUsedInformation about heap memory used. Ignored if NULL.
Returns
Successfully allocated and configured CO_t object or NULL.

◆ CO_delete()

void CO_delete ( CO_t * co)

Delete CANopen object and free memory.

Must be called at program exit.

Parameters
coCANopen object.

◆ CO_isLSSslaveEnabled()

bool_t CO_isLSSslaveEnabled ( CO_t * co)

Test if LSS slave is enabled.

Parameters
coCANopen object.
Returns
True if enabled

◆ CO_CANinit()

CO_ReturnError_t CO_CANinit ( CO_t * co,
void * CANptr,
uint16_t bitRate )

Initialize CAN driver.

Function must be called in the communication reset section.

Parameters
coCANopen object.
CANptrPointer to the user-defined CAN base structure, passed to CO_CANmodule_init().
bitRateCAN bit rate.
Returns
CO_ERROR_NO in case of success.

◆ CO_LSSinit()

CO_ReturnError_t CO_LSSinit ( CO_t * co,
CO_LSS_address_t * lssAddress,
uint8_t * pendingNodeID,
uint16_t * pendingBitRate )

Initialize CANopen LSS slave.

Function must be called before CO_CANopenInit.

See CO_LSSslave_init() for description of parameters.

Parameters
coCANopen object.
lssAddressLSS slave address, from OD object 0x1018
[in,out]pendingNodeIDPending node ID or 0xFF (unconfigured)
[in,out]pendingBitRatePending bit rate of the CAN interface
Returns
CO_ERROR_NO in case of success.

◆ CO_CANopenInit()

CO_ReturnError_t CO_CANopenInit ( CO_t * co,
CO_NMT_t * NMT,
CO_EM_t * em,
OD_t * od,
OD_entry_t * OD_statusBits,
uint16_t NMTcontrol,
uint16_t firstHBTime_ms,
uint16_t SDOserverTimeoutTime_ms,
uint16_t SDOclientTimeoutTime_ms,
bool_t SDOclientBlockTransfer,
uint8_t nodeId,
uint32_t * errInfo )

Initialize CANopenNode except PDO objects.

Function must be called in the communication reset section.

Parameters
coCANopen object.
emEmergency object, which is used inside different CANopen objects, usually for error reporting. If NULL, then 'co->em' will be used. if NULL and 'co->CNT_EM' is 0, then function returns with error.
NMTIf 'co->CNT_NMT' is 0, this object must be specified, If 'co->CNT_NMT' is 1,then it is ignored and can be NULL. NMT object is used for retrieving NMT internal state inside CO_process().
odCANopen Object dictionary
OD_statusBitsArgument passed to CO_EM_init(). May be NULL.
NMTcontrolArgument passed to CO_NMT_init().
firstHBTime_msArgument passed to CO_NMT_init().
SDOserverTimeoutTime_msArgument passed to CO_SDOserver_init().
SDOclientTimeoutTime_msDefault timeout in milliseconds for SDO client, 500 typically. SDO client is configured from CO_GTWA_init().
SDOclientBlockTransferIf true, block transfer will be set in SDO client by default. SDO client is configured from by CO_GTWA_init().
nodeIdCANopen Node ID (1 ... 127) or 0xFF(unconfigured). In the CANopen initialization it is the same as pendingBitRate from CO_LSSinit(). If it is unconfigured, then some CANopen objects will not be initialized nor processed.
[out]errInfoAdditional information in case of error, may be NULL. errInfo can also be set in noncritical errors, where function returns CO_ERROR_NO. For example, if OD parameter contains wrong value.
Returns
CO_ERROR_NO in case of success.

◆ CO_CANopenInitPDO()

CO_ReturnError_t CO_CANopenInitPDO ( CO_t * co,
CO_EM_t * em,
OD_t * od,
uint8_t nodeId,
uint32_t * errInfo )

Initialize CANopenNode PDO objects.

Function must be called in the end of communication reset section after all CANopen and application initialization, otherwise some OD variables wont be mapped into PDO correctly.

Parameters
coCANopen object.
emEmergency object, which is used inside PDO objects for error reporting.
odCANopen Object dictionary
nodeIdCANopen Node ID (1 ... 127) or 0xFF(unconfigured). If unconfigured, then PDO will not be initialized nor processed.
[out]errInfoAdditional information in case of error, may be NULL.
Returns
CO_ERROR_NO in case of success.

◆ CO_CANopenInitSRDO()

CO_ReturnError_t CO_CANopenInitSRDO ( CO_t * co,
CO_EM_t * em,
OD_t * od,
uint8_t nodeId,
uint32_t * errInfo )

Initialize Safety related Data Objects.

Function must be called in the end of communication reset section after all CANopen and application initialization, otherwise some OD variables wont be mapped into SRDO correctly.

Parameters
coCANopen object.
emEmergency object, which is used inside PDO objects for error reporting.
odCANopen Object dictionary
nodeIdCANopen Node ID (1 ... 127) or 0xFF(unconfigured). If unconfigured, then PDO will not be initialized nor processed.
[out]errInfoAdditional information in case of error, may be NULL.
Returns
CO_ERROR_NO in case of success.

◆ CO_process()

CO_NMT_reset_cmd_t CO_process ( CO_t * co,
bool_t enableGateway,
uint32_t timeDifference_us,
uint32_t * timerNext_us )

Process CANopen objects.

Function must be called cyclically. It processes all "asynchronous" CANopen objects.

Parameters
coCANopen object.
enableGatewayIf true, gateway to external world will be enabled.
timeDifference_usTime difference from previous function call in microseconds.
[out]timerNext_usinfo to OS - maximum delay time after this function should be called next time in [microseconds]. Value can be used for OS sleep time. Initial value must be set to maximum interval time. Output will be equal or lower to initial value. Calculation is based on various timers which expire in known time. Parameter should be used in combination with callbacks configured with CO_***_initCallbackPre() functions. Those callbacks should also trigger calling of CO_process() function. Parameter is ignored if NULL. See also CO_CONFIG_FLAG_CALLBACK_PRE configuration macro.
Returns
Node or communication reset request, from CO_NMT_process().

◆ CO_process_SYNC()

bool_t CO_process_SYNC ( CO_t * co,
uint32_t timeDifference_us,
uint32_t * timerNext_us )

Process CANopen SYNC objects.

Function must be called cyclically. For time critical applications it may be called from real time thread with constant interval (1ms typically). It processes SYNC CANopen objects.

Parameters
coCANopen object.
timeDifference_usTime difference from previous function call in microseconds.
[out]timerNext_usinfo to OS - see CO_process().
Returns
True, if CANopen SYNC message was just received or transmitted.

◆ CO_process_RPDO()

void CO_process_RPDO ( CO_t * co,
bool_t syncWas,
uint32_t timeDifference_us,
uint32_t * timerNext_us )

Process CANopen RPDO objects.

Function must be called cyclically. For time critical applications it may be called from real time thread with constant interval (1ms typically). It processes receive PDO CANopen objects.

Parameters
coCANopen object.
syncWasTrue, if CANopen SYNC message was just received or transmitted.
timeDifference_usTime difference from previous function call in microseconds.
[out]timerNext_usinfo to OS - see CO_process().

◆ CO_process_TPDO()

void CO_process_TPDO ( CO_t * co,
bool_t syncWas,
uint32_t timeDifference_us,
uint32_t * timerNext_us )

Process CANopen TPDO objects.

Function must be called cyclically. For time critical applications it may be called from real time thread with constant interval (1ms typically). It processes transmit PDO CANopen objects.

Parameters
coCANopen object.
syncWasTrue, if CANopen SYNC message was just received or transmitted.
timeDifference_usTime difference from previous function call in microseconds.
[out]timerNext_usinfo to OS - see CO_process().

◆ CO_process_SRDO()

CO_SRDO_state_t CO_process_SRDO ( CO_t * co,
uint32_t timeDifference_us,
uint32_t * timerNext_us )

Process CANopen SRDO objects.

Function must be called cyclically. For time critical applications it may be called from real time thread with constant interval (1ms typically). It processes SRDO CANopen objects.

Parameters
coCANopen object.
timeDifference_usTime difference from previous function call in microseconds.
[out]timerNext_usinfo to OS - see CO_process().
Returns
CO_SRDO_state_t: lowest state of the SRDO objects.