![]() |
CANopen Slave Protocol Stack
Version 7.08.00
|
This module holds all functions for the initialization and control of the CANopen slave. Some functions of this module need to be adopted to the target application:
These functions are located in the cos_user.c file. Please refer to Initialization Process for details about the CosMgrInit() function and also check the Complete Startup Process for reference.
Macros | |
| #define | COS_CONF_SLAVE ((uint16_t) 0x0000) |
| #define | COS_CONF_MASTER ((uint16_t) 0x0001) |
| #define | COS_CONF_AUTOSTART ((uint16_t) 0x0002) |
| #define | COS_CONF_FD ((uint16_t) 0x0004) |
| #define | COS_CONF_J1939 ((uint16_t) 0x0010) |
Functions | |
| uint8_t | CosMgrGetBitrate (void) |
| uint16_t | CosMgrGetConfiguration (void) |
| int32_t | CosMgrGetDataBitrate (void) |
| uint8_t | CosMgrGetFrameFormat (void) |
| uint8_t | CosMgrGetNodeId (void) |
| int32_t | CosMgrGetNominalBitrate (void) |
| uint32_t | CosMgrGetProductCode (void) |
| uint32_t | CosMgrGetSerialNumber (void) |
| uint8_t | CosMgrInit (uint8_t ubCanIfV, uint16_t uwConfigV) |
| void | CosMgrOnBootUp (void) |
| void | CosMgrOnBusOff (void) |
| void | CosMgrOnStart (uint8_t ubCallerResultV) |
| uint8_t | CosMgrProcess (void) |
| void | CosMgrProfileUpdate (uint16_t uwIndexV, uint8_t ubSubIndexV) |
| uint8_t | CosMgrRelease (void) |
| uint8_t | CosMgrStart (uint8_t ubNodeIdV, int32_t slBitrateNomSelV, int32_t slBitrateDatSelV) |
| uint8_t CosMgrGetBitrate | ( | void | ) |
cos_user.c provides an example and has to be adopted to the application.This routine checks for the bit-rate. The code of this routine has to be adopted to the specific target. The function returns a constant for the bit-rate that is specified in the canpie.h file.
| uint16_t CosMgrGetConfiguration | ( | void | ) |
This function returns the protocol stack configuration, i.e. the bit-masked values defined by COS_CONF.
| int32_t CosMgrGetDataBitrate | ( | void | ) |
cos_user.c provides an example and has to be adopted to the application.This routine checks for the data bit rate. The code of this routine has to be adopted to the specific target. The function returns a constant for the bit rate that is specified in the canpie.h file. If CAN FD is not supported, the function shall return eCP_BITRATE_NONE.
| uint8_t CosMgrGetFrameFormat | ( | void | ) |
This function returns the CAN message frame format that shall be used for message buffer configuration. The value depends on the the stack configuration as shown in the table:
| CosMgrInit() - uwConfigV | data bit rate | Frame Format |
|---|---|---|
| COS_CONF_FD not set | not evaluated | CP_MSG_FORMAT_CBFF |
| COS_CONF_FD set | eCP_BITRATE_NONE | CP_MSG_FORMAT_FBFF |
| COS_CONF_FD set | valid bit-rate | CP_MSG_FORMAT_FBFF | CP_MSG_CTRL_BRS_BIT |
| uint8_t CosMgrGetNodeId | ( | void | ) |
cos_user.c provides an example and has to be adopted to the application.This routine checks for the node-ID. The code of this routine has to be adopted to the specific target. The function returns a value in the range from 1 to 127.
| int32_t CosMgrGetNominalBitrate | ( | void | ) |
cos_user.c provides an example and has to be adopted to the application.This routine checks for the nominal bit rate. The code of this routine has to be adopted to the specific target. The function returns a constant for the bit rate that is specified in the canpie.h file.
| uint32_t CosMgrGetProductCode | ( | void | ) |
cos_user.c provides an example and has to be adopted to the application.This routine returns the Product Code of the module. The Product Number is used within in Identity Object (index 1018:02h).
| uint32_t CosMgrGetSerialNumber | ( | void | ) |
cos_user.c provides an example and has to be adopted to the application.This routine returns the Serial Number of the module, which must be a unique value for a product family. The Serial Number is used within the Identity Object (index 1018:04h).
| uint8_t CosMgrInit | ( | uint8_t | ubCanIfV, |
| uint16_t | uwConfigV ) |
| ubCanIfV | - Physical CAN interface |
| uwConfigV | - Initial configuration |
The function returns eCOS_ERR_NONE on success. It is responsible for the following tasks:
Possible values for uwConfigV are:
| void CosMgrOnBootUp | ( | void | ) |
This callback is invoked from the CAN transmit handler the moment the Boot-up message has physically left the bus. At this point the device is visible to the network in NMT Pre-Operational state.
Use this callback for application startup tasks that must happen after the device has announced itself on the bus, e.g. enabling hardware outputs or driving safe initial values.
| void CosMgrOnBusOff | ( | void | ) |
This callback is invoked when the CAN controller has entered the Bus-Off state. All CAN communication is suspended by the stack automatically.
Typical response in this callback:
Bus-Off recovery is managed by the stack. Once the controller has recovered, CosMgrProcess() returns eCOS_ERR_NODE_RESET. The application should then call CosMgrStart() from the main loop to restart the CANopen stack.
| void CosMgrOnStart | ( | uint8_t | ubCallerResultV | ) |
| [in] | ubCallerResultV | Result of CANopen service initialization |
This event is called inside CosMgrStart() before the Boot-up message is queued for transmission. Use it to configure stack settings such as heartbeat producer time, SYNC period, device type, and EMCY code registration. The device is not yet visible on the network at this point.
The parameter ubCallerResultV holds the state of the initialization process. Possible values are defined by the CosErr_e enumeration. On successful initialization the value for ubCallerResultV is eCOS_ERR_NONE.
The following example shows how to change default settings for the heartbeat and the SYNC producer, as well as registration of EMCY codes.
| uint8_t CosMgrProcess | ( | void | ) |
This function must be called repeatedly from the application main loop. It performs all background processing required by the CANopen stack:
Possible return values and the expected application response:
| Return value | Meaning | Application action |
|---|---|---|
| eCOS_ERR_NONE | Normal operation | Call again on next cycle |
| eCOS_ERR_NODE_RESET | NMT reset command received, or Bus-Off / Stop state | Call CosMgrStart() to restart |
| eCOS_ERR_NODE_INIT | CosMgrStart() has not been called yet | Call CosMgrStart() first |
| void CosMgrProfileUpdate | ( | uint16_t | uwIndexV, |
| uint8_t | ubSubIndexV ) |
| uwIndexV | parameter index |
| ubSubIndexV | parameter sub-index |
This function is called by the stack when a parameter of a device profile is modified. It can be used to control the interaction between the CANopen slave stack and the application. The implementation of this function depends on the application.
| uint8_t CosMgrRelease | ( | void | ) |
This routine stops the CANopen protocol stack. The function returns eCOS_ERR_NONE on success.
| uint8_t CosMgrStart | ( | uint8_t | ubNodeIdV, |
| int32_t | slBitrateNomSelV, | ||
| int32_t | slBitrateDatSelV ) |
| ubNodeIdV | - Device node-ID (NID) |
| slBitrateNomSelV | - Nominal bit rate value |
| slBitrateDatSelV | - Data bit rate value |
This routine starts the CANopen protocol stack on the given node-ID and bit rate. The initialization routines from other CANopen services are called and the Boot-up message is sent. The function returns eCOS_ERR_NONE on success.
In case the device shall be started in classical CANopen mode the parameter slBitrateDatSelV must be set to eCP_BITRATE_NONE.
slBitrateDatSelV was added in major version 6 for CANopen FD support. When migrating from an earlier version, add eCP_BITRATE_NONE as the third argument to retain classical CANopen behaviour.