CANopen Master Documentation
Version 6.06.04
Loading...
Searching...
No Matches
com_mgr.h File Reference

Detailed Description

This module holds all functions for the initialisation and control of the CANopen Master. Some functions of this module need to be adopted to the target platform. These functions are located inside the com_user.c file.

+ Include dependency graph for com_mgr.h:

Data Structures

struct  ComMgrIdentity_s
 

Typedefs

typedef struct ComMgrIdentity_s ComMgrIdentity_ts
 

Enumerations

enum  ComVersion_e {
  eCOM_VERSION_STACK = 1 ,
  eCOM_VERSION_COMPILER ,
  eCOM_VERSION_SYSTEM
}
 
enum  ComMode_e {
  eCOM_MODE_NMT_SLAVE = 0x0000 ,
  eCOM_MODE_NMT_MASTER = 0x0001 ,
  eCOM_MODE_NMT_START_ALL = 0x0002 ,
  eCOM_MODE_NMT_PREOPERATIONAL = 0x0004 ,
  eCOM_MODE_NMT_APP_START_NODE = 0x0008 ,
  eCOM_MODE_NMT_RESET_ALL = 0x0010 ,
  eCOM_MODE_NMT_FLYING_MASTER = 0x0020 ,
  eCOM_MODE_NMT_STOP_ALL = 0x0040 ,
  eCOM_MODE_NMT_MASTER_DETECT = 0x0100 ,
  eCOM_MODE_FD = 0x0200 ,
  eCOM_MODE_CAN_RAW = 0x1000 ,
  eCOM_MODE_J1939 = 0x2000
}
 

Functions

CpState_tsComMgrBusState (uint8_t ubNetV)
 
void ComMgrEventBus (uint8_t ubNetV, CpState_ts *ptsBusStateV)
 
int32_t ComMgrGetDataBitrate (uint8_t ubNetV)
 
const char * ComMgrGetVersionString (uint8_t ubTypeV)
 
const char * ComMgrGetConfiguration (void)
 
ComStatus_tv ComMgrInit (uint8_t ubCanIfV, uint8_t ubNetV, uint8_t ubBitrateNomSelV, uint8_t ubNodeIdV, uint32_t ulModeV)
 
void ComMgrNetTimerEvent (uint8_t ubNetV)
 
ComStatus_tv ComMgrNodeAdd (uint8_t ubNetV, uint8_t ubNodeIdV, ComNode_ts *ptsNodeV)
 
ComStatus_tv ComMgrNodeDelete (uint8_t ubNetV, uint8_t ubNodeIdV)
 
ComStatus_tv ComMgrProcess (uint8_t ubNetV)
 
ComStatus_tv ComMgrRelease (uint8_t ubNetV)
 
ComStatus_tv ComMgrSetErrorRegister (uint8_t ubNetV, uint8_t ubSetErrorV, uint8_t ubResetErrorV)
 
ComStatus_tv ComMgrSetIdentity (uint8_t ubNetV, ComMgrIdentity_ts *ptsIdentityV)
 
ComStatus_tv ComMgrStart (uint8_t ubNetV)
 
ComStatus_tv ComMgrStop (uint8_t ubNetV)
 
void ComMgrTimerEvent (void)
 
ComStatus_tv ComMgrUserInit (uint8_t ubNetV)
 

Typedef Documentation

◆ ComMgrIdentity_ts

CANopen Master - device identity.

The structure ComMgrIdentity_s allows access to the device identity object. It is used by the functions ComMgrGetIdentity() and ComMgrSetIdentity().

Enumeration Type Documentation

◆ ComMode_e

enum ComMode_e

NMT startup mode.

The enumeration defines the values for starting the CANopen Master supplied to ComMgrInit(). The CANopen NMT configuration is reflected by object 1F80h (least significant 8 bits).

Enumerator
eCOM_MODE_NMT_SLAVE 

Device is NMT slave

eCOM_MODE_NMT_MASTER 

Device is the NMT master

eCOM_MODE_NMT_START_ALL 

NMT service start remote node with Node-ID = 0

eCOM_MODE_NMT_PREOPERATIONAL 

Device does not switch into Operational by itself

eCOM_MODE_NMT_APP_START_NODE 

Application shall start the nodes

eCOM_MODE_NMT_RESET_ALL 

In case of an error event the NMT service "reset all nodes" shall be executed.

eCOM_MODE_NMT_FLYING_MASTER 

CANopen device shall participate the NMT flying master negotiation.

eCOM_MODE_NMT_STOP_ALL 

In case of an error event the NMT service "stop remote node" shall be executed.

eCOM_MODE_NMT_MASTER_DETECT 

Device shall execute the NMT master detection protocol

eCOM_MODE_FD 

Device shall start in CAN FD mode

eCOM_MODE_CAN_RAW 

Device shall start in CAN-Raw mode, no CANopen services (SDO, NMT, etc.) are executed. CAN messages are received and send via the PDO module. This is a mutually exclusive mode of operation.

eCOM_MODE_J1939 

Device shall start in SAE J1939 mode

◆ ComVersion_e

Retrieve stack information.

The enumeration defines possible values for the parameter value ComMgrGetVersionString().

Enumerator
eCOM_VERSION_STACK 

Return version information of CANopen Master protocol stack

eCOM_VERSION_COMPILER 

Return version information of used compiler

eCOM_VERSION_SYSTEM 

Return version information of operating system

Function Documentation

◆ ComMgrBusState()

CpState_ts * ComMgrBusState ( uint8_t  ubNetV)
Parameters
[in]ubNetVCANopen Network channel
Returns
Pointer to CpState_ts structure of corresponding network

This function returns a pointer to the CpState_ts structure of the corresponding network.

◆ ComMgrEventBus()

void ComMgrEventBus ( uint8_t  ubNetV,
CpState_ts ptsBusStateV 
)
Parameters
[in]ubNetVCANopen Network channel
[out]ptsBusStateVPointer to CpState_ts value of bus

This function is called by the stack on a CAN bus state change. The action on this function is application specific. The function body is placed in the file com_user.c.

◆ ComMgrGetConfiguration()

const char * ComMgrGetConfiguration ( void  )
Returns
Pointer to a Null terminated configuration string

This function returns a configuration string of the CANopen FD Master.

◆ ComMgrGetDataBitrate()

int32_t ComMgrGetDataBitrate ( uint8_t  ubNetV)
Parameters
[in]ubNetVCANopen Network channel
Returns
Bit-rate value selection for CAN FD data phase

This function is called by ComMgrInit() if the symbol COM_FD_SUPPORT is set to 1 and the CAN FD mode is enabled by eCOM_MODE_FD. In case no bit-rate switching is desired, the function shall return eCP_BITRATE_NONE. The function body is placed in the file com_user.c.

◆ ComMgrGetVersionString()

const char * ComMgrGetVersionString ( uint8_t  ubTypeV)
Parameters
[in]ubTypeV- Information type
Returns
Pointer to a Null terminated character string

This function returns a version string of the CANopen FD Master. The parameter ubTypeV defines the requested information, possible values are defined by the enumeration ComVersion_e.

◆ ComMgrInit()

ComStatus_tv ComMgrInit ( uint8_t  ubCanIfV,
uint8_t  ubNetV,
uint8_t  ubBitrateNomSelV,
uint8_t  ubNodeIdV,
uint32_t  ulModeV 
)
Parameters
[in]ubCanIfVPhysical CAN interface
[in]ubNetVCANopen Network channel
[in]ubBitrateNomSelVNominal bit-rate selection
[in]ubNodeIdVNode-ID value
[in]ulModeVMode selection
Returns
Value of enumeration ComErr_e
See also
ComMgrRelease()

This function must be called before any other function of the CANopen FD Master stack. It is responsible for the initialisation of all services (NMT, SYNC, SDO, PDO, etc).

The function assigns the logical CANopen network number ubNetV to the CAN interface given by ubCanIfV. The value for ubNetV can be taken from the ComNet_e enumeration. The maximum value is given by the symbol COM_NET_MAX.

The parameter ulModeV selects the mode of the protocol stack, possible values are defined by the enumeration ComMode_e.

//------------------------------------------------------
// Initialise the CANopen Master stack with address 1, bit-rate 500 kBit/s
//
@ eCP_BITRATE_500K
Definition canpie.h:677
@ eCP_CHANNEL_1
Definition canpie.h:732
@ eCOM_NET_1
Definition com_defs.h:723
@ eCOM_MODE_NMT_MASTER
Definition com_mgr.h:94
ComStatus_tv ComMgrInit(uint8_t ubCanIfV, uint8_t ubNetV, uint8_t ubBitrateNomSelV, uint8_t ubNodeIdV, uint32_t ulModeV)

◆ ComMgrNetTimerEvent()

void ComMgrNetTimerEvent ( uint8_t  ubNetV)

Execute Timer-based Services.

Parameters
ubNetV- CANopen Network channel
See also
ComMgrTimerEvent()

This routine must be called by a timer resource of the target system. It is responsible to call services that depend on a timer (e.g. Heartbeat). The period of the timer is defined via the COM_TIMER_PERIOD constant. The function calls the services for the CANopen network defined by ubNetV. Execution of timer-based services for all CANopen networks is possible via ComMgrTimerEvent().

Example

//-------------------------------------------------------------//
// Timer interrupt service routine //
// //
//-------------------------------------------------------------//
void MyTimerInterrupt(void)
{
//... timer services of application ...
//--- call CANopen stack timer function -------------
//... retrigger the timer
}
void ComMgrNetTimerEvent(uint8_t ubNetV)
Execute Timer-based Services.

◆ ComMgrNodeAdd()

ComStatus_tv ComMgrNodeAdd ( uint8_t  ubNetV,
uint8_t  ubNodeIdV,
ComNode_ts ptsNodeV 
)
Parameters
ubNetV- CANopen Network channel
ubNodeIdV- Node-ID value
ptsNodeV- Pointer to CANopen node
Returns
Value of enumeration ComErr_e
See also
ComMgrNodeDelete()

This function adds a new CANopen node (device) to the CANopen Master on address ubNodeIdV.

◆ ComMgrNodeDelete()

ComStatus_tv ComMgrNodeDelete ( uint8_t  ubNetV,
uint8_t  ubNodeIdV 
)

Remove CANopen device.

Parameters
ubNetV- CANopen Network channel
ubNodeIdV- Node-ID value
Returns
Value of enumeration ComErr_e
See also
ComMgrNodeAdd()

This function removes a CANopen node (device) from the CANopen Master on address ubNodeIdV.

◆ ComMgrProcess()

ComStatus_tv ComMgrProcess ( uint8_t  ubNetV)
Parameters
[in]ubNetV- CANopen Network channel
Returns
Value of enumeration ComErr_e

This function is responsible for processing of CAN messages if the symbol COM_MGR_INT is set to 0.

◆ ComMgrRelease()

ComStatus_tv ComMgrRelease ( uint8_t  ubNetV)

Shutdown the CANopen Master.

Parameters
[in]ubNetV- CANopen Network channel
Returns
Value of enumeration ComErr_e
See also
ComMgrInit()

This function performs a shutdown of the CANopen Master.

◆ ComMgrSetErrorRegister()

ComStatus_tv ComMgrSetErrorRegister ( uint8_t  ubNetV,
uint8_t  ubSetErrorV,
uint8_t  ubResetErrorV 
)

Set error register.

Parameters
ubNetV- CANopen Network channel
ubSetErrorV- Set new new error state
ubResetErrorV- Clear error state
Returns
Value of enumeration ComErr_e

This function sets and clears bit-masked error states of the error register.

◆ ComMgrSetIdentity()

ComStatus_tv ComMgrSetIdentity ( uint8_t  ubNetV,
ComMgrIdentity_ts ptsIdentityV 
)

Set CANopen master identity values.

Parameters
[in]ubNetVCANopen Network channel
[in]ptsIdentityVIdentity structure
Returns
Value of enumeration ComErr_e

This function sets the values for object 1000h (device type) and object 1018h (identity). The new value must be different from 0, otherwise the default value is not modified. The value of object 1018h, sub-index 3 (software revision) allows only the modification of the lower 16 bits (minor revision number).

◆ ComMgrStart()

ComStatus_tv ComMgrStart ( uint8_t  ubNetV)

Start the CANopen Master.

Parameters
[in]ubNetVCANopen Network channel
Returns
Value of enumeration ComErr_e
See also
ComMgrStop()

◆ ComMgrStop()

ComStatus_tv ComMgrStop ( uint8_t  ubNetV)

Stop the CANopen Master.

Parameters
[in]ubNetVCANopen Network channel
Returns
Value of enumeration ComErr_e
See also
ComMgrStart()

◆ ComMgrTimerEvent()

void ComMgrTimerEvent ( void  )

Execute Timer-based Services.

See also
ComMgrNetTimerEvent()

This routine must be called by a timer resource of the target system. It is responsible to call services that depend on a timer (e.g. Heartbeat). The period of the timer is defined via the COM_TIMER_PERIOD constant. The function calls the services for all available networks. Execution of timer-based services for an individual network is possible via ComMgrNetTimerEvent().

Example

//-------------------------------------------------------------//
// Timer interrupt service routine //
// //
//-------------------------------------------------------------//
void MyTimerInterrupt(void)
{
//... timer services of application ...
//--- call CANopen stack timer function -------------
//... retrigger the timer
}
void ComMgrTimerEvent(void)
Execute Timer-based Services.

◆ ComMgrUserInit()

ComStatus_tv ComMgrUserInit ( uint8_t  ubNetV)

Change CANopen Master settings.

Parameters
ubNetV- CANopen Network channel
Returns
Value of enumeration ComErr_e

This function is called by ComMgrInit() during the initialisation phase. It can be used to change internal values of the Master (e.g. the vendor-ID or product code). The behavior of this function is application specific. The function body is placed in the file com_user.c.