CANopenNode is free and open source implementation of CANopen communication protocol. More...
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. More... | |
#define | CO_USE_GLOBALS |
If macro is defined externally, then global variables for CANopen objects will be used instead of heap. More... | |
Functions | |
CO_t * | CO_new (CO_config_t *config, uint32_t *heapMemoryUsed) |
Create new CANopen object. More... | |
void | CO_delete (CO_t *co) |
Delete CANopen object and free memory. More... | |
bool_t | CO_isLSSslaveEnabled (CO_t *co) |
Test if LSS slave is enabled. More... | |
CO_ReturnError_t | CO_CANinit (CO_t *co, void *CANptr, uint16_t bitRate) |
Initialize CAN driver. More... | |
CO_ReturnError_t | CO_LSSinit (CO_t *co, CO_LSS_address_t *lssAddress, uint8_t *pendingNodeID, uint16_t *pendingBitRate) |
Initialize CANopen LSS slave. More... | |
CO_ReturnError_t | CO_CANopenInit (CO_t *co, CO_NMT_t *NMT, CO_EM_t *em, const OD_t *od, const OD_entry_t *OD_statusBits, CO_NMT_control_t NMTcontrol, uint16_t firstHBTime_ms, uint16_t SDOserverTimeoutTime_ms, uint16_t SDOclientTimeoutTime_ms, bool_t SDOclientBlockTransfer, uint8_t nodeId) |
Initialize CANopenNode. More... | |
CO_NMT_reset_cmd_t | CO_process (CO_t *co, bool_t enableGateway, uint32_t timeDifference_us, uint32_t *timerNext_us) |
Process CANopen objects. More... | |
bool_t | CO_process_SYNC (CO_t *co, uint32_t timeDifference_us, uint32_t *timerNext_us) |
Process CANopen SYNC objects. More... | |
void | CO_process_RPDO (CO_t *co, bool_t syncWas) |
Process CANopen RPDO objects. More... | |
void | CO_process_TPDO (CO_t *co, bool_t syncWas, uint32_t timeDifference_us, uint32_t *timerNext_us) |
Process CANopen TPDO objects. More... | |
void | CO_process_SRDO (CO_t *co, uint32_t timeDifference_us, uint32_t *timerNext_us) |
Process CANopen SRDO objects. More... | |
CANopenNode is free and open source implementation of CANopen communication protocol.
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.
#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.
#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.
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.
config | Configuration 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] | heapMemoryUsed | Information about heap memory used. Ignored if NULL. |
void CO_delete | ( | CO_t * | co | ) |
Delete CANopen object and free memory.
Must be called at program exit.
co | CANopen object. |
Test if LSS slave is enabled.
co | CANopen object. |
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.
co | CANopen object. |
CANptr | Pointer to the user-defined CAN base structure, passed to CO_CANmodule_init(). |
bitRate | CAN bit rate. |
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.
co | CANopen object. | |
lssAddress | LSS slave address, from OD object 0x1018 | |
[in,out] | pendingNodeID | Pending node ID or 0xFF (unconfigured) |
[in,out] | pendingBitRate | Pending bit rate of the CAN interface |
CO_ReturnError_t CO_CANopenInit | ( | CO_t * | co, |
CO_NMT_t * | NMT, | ||
CO_EM_t * | em, | ||
const OD_t * | od, | ||
const OD_entry_t * | OD_statusBits, | ||
CO_NMT_control_t | NMTcontrol, | ||
uint16_t | firstHBTime_ms, | ||
uint16_t | SDOserverTimeoutTime_ms, | ||
uint16_t | SDOclientTimeoutTime_ms, | ||
bool_t | SDOclientBlockTransfer, | ||
uint8_t | nodeId | ||
) |
Initialize CANopenNode.
Function must be called in the communication reset section.
co | CANopen object. |
em | Emergency 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. |
NMT | If '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(). |
od | CANopen Object dictionary |
OD_statusBits | Argument passed to CO_EM_init(). May be NULL. |
NMTcontrol | Argument passed to CO_NMT_init(). |
firstHBTime_ms | Argument passed to CO_NMT_init(). |
SDOserverTimeoutTime_ms | Argument passed to CO_SDOserver_init(). |
SDOclientTimeoutTime_ms | Default timeout in milliseconds for SDO client, 500 typically. SDO client is configured from CO_GTWA_init(). |
SDOclientBlockTransfer | If true, block transfer will be set in SDO client by default. SDO client is configured from by CO_GTWA_init(). |
nodeId | CANopen 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. |
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.
co | CANopen object. | |
enableGateway | If true, gateway to external world will be enabled. | |
timeDifference_us | Time difference from previous function call in microseconds. | |
[out] | timerNext_us | info 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. |
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.
co | CANopen object. | |
timeDifference_us | Time difference from previous function call in microseconds. | |
[out] | timerNext_us | info to OS - see CO_process(). |
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.
co | CANopen object. |
syncWas | True, if CANopen SYNC message was just received or transmitted. |
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.
co | CANopen object. | |
syncWas | True, if CANopen SYNC message was just received or transmitted. | |
timeDifference_us | Time difference from previous function call in microseconds. | |
[out] | timerNext_us | info to OS - see CO_process(). |
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.
co | CANopen object. | |
timeDifference_us | Time difference from previous function call in microseconds. | |
[out] | timerNext_us | info to OS - see CO_process(). |