CANopen Slave Documentation
Version 6.16.04
Loading...
Searching...
No Matches
cos_mgr.h File Reference

Detailed Description

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.

+ Include dependency graph for cos_mgr.h:

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)
 

Functions

uint8_t CosMgrGetBitrate (void)
 
uint8_t CosMgrGetNodeId (void)
 
uint32_t CosMgrGetProductCode (void)
 
uint32_t CosMgrGetSerialNumber (void)
 
uint8_t CosMgrInit (uint8_t ubCanIfV, uint16_t uwConfigV)
 
void CosMgrOnBootUp (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)
 

Macro Definition Documentation

◆ COS_CONF_AUTOSTART

#define COS_CONF_AUTOSTART   ((uint16_t) 0x0002)

After transmission of the boot-up message, make an automatic transition of the NMT state machine to the Operational state.

◆ COS_CONF_FD

#define COS_CONF_FD   ((uint16_t) 0x0004)

Start CANopen slave in ISO CAN FD mode (CANopen FD).

◆ COS_CONF_MASTER

#define COS_CONF_MASTER   ((uint16_t) 0x0001)

Use the CANopen FD Slave protocol stack as NMT master and LSS master. This option is only possible in conjunction with the mini-master add-on. It is advised to use the CANopen FD Master protocol stack in order to achieve full support of all CANopen master features.

◆ COS_CONF_SLAVE

#define COS_CONF_SLAVE   ((uint16_t) 0x0000)

This the the default configuration: CANopen slave.

Function Documentation

◆ CosMgrGetBitrate()

uint8_t CosMgrGetBitrate ( void  )

Get module bit-rate.

Returns
Constant value for bit-rate
Todo:
This function has to be adopted to the application (cos_user.c)

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.

◆ CosMgrGetNodeId()

uint8_t CosMgrGetNodeId ( void  )
Returns
node-ID
Todo:
This function has to be adopted to the application (cos_user.c)

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.

◆ CosMgrGetProductCode()

uint32_t CosMgrGetProductCode ( void  )
Returns
Product Code
Todo:
This function has to be adopted to the application (cos_user.c)

This routine returns the Product Code of the module. The Product Number is used within in Identity Object (index 1018:02h).

◆ CosMgrGetSerialNumber()

uint32_t CosMgrGetSerialNumber ( void  )
Returns
Serial Number
Todo:
This function has to be adopted to the application (cos_user.c)

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).

◆ CosMgrInit()

uint8_t CosMgrInit ( uint8_t  ubCanIfV,
uint16_t  uwConfigV 
)

Initialise the CANopen Slave.

Parameters
ubCanIfV- Physical CAN interface
uwConfigV- Initial configuration
Returns
Error Code

The function returns eCOS_ERR_NONE on success. It is responsible for the following tasks:

  • Initialise the CANopen state machine
  • Initialise LED management

Possible values for uwConfigV are:

◆ CosMgrOnBootUp()

void CosMgrOnBootUp ( void  )

This event is called after successful transmission of the Boot-up message.

◆ CosMgrOnStart()

void CosMgrOnStart ( uint8_t  ubCallerResultV)
Parameters
[in]ubCallerResultVResult of CANopen service initialization

This event is called during the initialization of CANopen services (refer to CosMgrStart()). 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.

void CosMgrOnStart(uint8_t ubCallerResultV)
{
//---------------------------------------------------------------------------------------------------
// Device Profile : CiA 401
//
Cos301_SetDeviceType(1, 0x000F0191);
//---------------------------------------------------------------------------------------------------
// Register possible EMCY codes
//
//---------------------------------------------------------------------------------------------------
// Check status of initialization
//
switch (ubCallerResultV)
{
// no error
break;
// failed to initialise CAN interface
break;
// node-ID not valid
break;
// could not load parameters from NVM
break;
default:
break;
}
//---------------------------------------------------------------------------------------------------
// Set SYNC producer to 2 sec
//
//---------------------------------------------------------------------------------------------------
// Set heartbeat producer to 1 sec
//
}
@ eCoErrReg_VOLTAGE
Definition canopen.h:734
@ eCoErrReg_TEMPERATURE
Definition canopen.h:737
void Cos301_SetDeviceType(uint8_t ubLogicalDeviceV, uint32_t ulDeviceTypeV)
@ eCOS_ERR_NONE
Definition cos_defs.h:504
@ eCOS_ERR_PARM_LOAD
Definition cos_defs.h:537
@ eCOS_ERR_VALUE_NODE_ID
Definition cos_defs.h:519
@ eCOS_ERR_CAN_INIT
Definition cos_defs.h:507
@ eEMCY_301_DEVICE_TEMPERATURE
Definition cos_emcy.h:392
@ eEMCY_301_MAINS_VOLTAGE
Definition cos_emcy.h:389
Status_tv CosEmcyErrorRegister(uint8_t ubErrConditionV, uint16_t uwErrCodeV, uint8_t ubErrRegisterV, uint8_t ubErrCompareV)
void CosMgrOnStart(uint8_t ubCallerResultV)
void CosNmtSetHeartbeatProd(uint16_t uwTimeV)
void CosSyncSetProducer(uint16_t uwTimeV)
#define EMCY_ERR_TEMP_DEVICE
Definition cos_emcy.h:172

◆ CosMgrProcess()

uint8_t CosMgrProcess ( void  )

Process CANopen message queue.

Returns
Status of CANopen Slave Protocol stack

This function has to called within the main loop of the application. It is responsible to handle NVM operations and to check the requested NMT state. Possible return values are:

◆ CosMgrProfileUpdate()

void CosMgrProfileUpdate ( uint16_t  uwIndexV,
uint8_t  ubSubIndexV 
)

Update parameter of device profile.

Parameters
uwIndexVparameter index
ubSubIndexVparameter 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.

◆ CosMgrRelease()

uint8_t CosMgrRelease ( void  )

Release the CANopen Slave protocol stack.

Returns
Error Code

This routine stops the CANopen protocol stack. The function returns CosErr_OK on success.

◆ CosMgrStart()

uint8_t CosMgrStart ( uint8_t  ubNodeIdV,
int32_t  slBitrateNomSelV,
int32_t  slBitrateDatSelV 
)
Parameters
ubNodeIdV- Device node-ID (NID)
slBitrateNomSelV- Nominal bit rate value
slBitrateDatSelV- Data bit rate value
Returns
Error Code
See also
CosMgrOnBootUp(), CosMgrOnStart()

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.

Attention
The number and position of parameters has been changed with major version 6 (CANopen FD) of the protocol stack.