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

Detailed Description

The CANopen Network Management (NMT) is used to change the state of a CANopen slave node. This module holds functions for the protocol stack to behave in both ways: as Master or as Slave. If the protocol stack is started in Slave mode (refer to the ComMgrInit() function), the protocol stack must react on NMT messages. If started in Master mode, the protocol stack holds the NMT resource and is allowed to send NMT messages.

The functionality includes also to act as heartbeat consumer for all possible slaves.

+ Include dependency graph for com_nmt.h:

Enumerations

enum  ComNmtState_e {
  eCOM_NMT_STATE_UNKNOWN = 0 ,
  eCOM_NMT_STATE_STOPPED ,
  eCOM_NMT_STATE_PREOPERATIONAL ,
  eCOM_NMT_STATE_OPERATIONAL ,
  eCOM_NMT_STATE_RESET_NODE ,
  eCOM_NMT_STATE_RESET_COM ,
  eCOM_NMT_STATE_BOOTUP ,
  eCOM_NMT_STATE_INIT
}
 

Functions

void ComNmtEventActiveMaster (uint8_t ubNetV, uint8_t ubPriorityV, uint8_t ubNodeIdV)
 
void ComNmtEventGuarding (uint8_t ubNetV, uint8_t ubNodeIdV, uint8_t ubReasonV)
 
void ComNmtEventHeartbeat (uint8_t ubNetV, uint8_t ubNodeIdV)
 
void ComNmtEventStateChange (uint8_t ubNetV, uint8_t ubNodeIdV, uint8_t ubNmtStateV)
 
void ComNmtEventIdCollision (uint8_t ubNetV)
 
void ComNmtEventMasterDetection (uint8_t ubNetV, uint8_t ubResultV)
 
void ComNmtEventResetNode (uint8_t ubNetV)
 
void ComNmtEventResetCommunication (uint8_t ubNetV)
 
ComStatus_tv ComNmtGetHbConsTime (uint8_t ubNetV, uint8_t ubNodeIdV, uint16_t *puwTimeV)
 
ComStatus_tv ComNmtGetHbProdTime (uint8_t ubNetV, uint16_t *puwTimeV)
 
ComStatus_tv ComNmtGetInhibit (uint8_t ubNetV, uint32_t *pulTimeV)
 
ComStatus_tv ComNmtGetNodeState (uint8_t ubNetV, uint8_t ubNodeIdV, uint8_t *pubStateV)
 
ComStatus_tv ComNmtIsMaster (uint8_t ubNetV)
 
ComStatus_tv ComNmtMasterDetection (uint8_t ubNetV, uint8_t ubBootupV)
 
ComStatus_tv ComNmtFlyingMaster (uint8_t ubNetV)
 
ComStatus_tv ComNmtSetGuardTime (uint8_t ubNetV, uint8_t ubNodeIdV, uint16_t uwGuardTimeV, uint8_t ubLifeTimeFactorV)
 
ComStatus_tv ComNmtSetHbConsTime (uint8_t ubNetV, uint8_t ubNodeIdV, uint16_t uwTimeV)
 
ComStatus_tv ComNmtSetHbProdTime (uint8_t ubNetV, uint16_t uwTimeV)
 
ComStatus_tv ComNmtSetInhibit (uint8_t ubNetV, uint32_t ulTimeV)
 
ComStatus_tv ComNmtSetNodeState (uint8_t ubNetV, uint8_t ubNodeIdV, uint8_t ubStateV)
 

Enumeration Type Documentation

◆ ComNmtState_e

NMT state codes.

The enumeration defines the values for setting the NMT state of a CANopen device via ComNmtSetNodeState() as well as for requesting the device state via ComNmtGetNodeState(). The values in this enumeration are not equal to the NMT command specifiers.

Enumerator
eCOM_NMT_STATE_UNKNOWN 

Unknown NMT state

eCOM_NMT_STATE_STOPPED 

NMT command / state "Stopped"

eCOM_NMT_STATE_PREOPERATIONAL 

NMT command / state "Pre-Operational"

eCOM_NMT_STATE_OPERATIONAL 

NMT command / state "Operational"

eCOM_NMT_STATE_RESET_NODE 

NMT command "Reset node"

eCOM_NMT_STATE_RESET_COM 

NMT command "Reset communication"

eCOM_NMT_STATE_BOOTUP 

Device has sent Bootup message

eCOM_NMT_STATE_INIT 

Device is in Initialisation state (Master only)

Function Documentation

◆ ComNmtEventActiveMaster()

void ComNmtEventActiveMaster ( uint8_t  ubNetV,
uint8_t  ubPriorityV,
uint8_t  ubNodeIdV 
)
Parameters
[in]ubNetVCANopen Network channel
ubPriorityV- NMT master priority
ubNodeIdV- Node-ID value

This function is called by the stack on a NMT active master indication.

The action on this function is application specific. The function body is placed inside the file com_user.c.

◆ ComNmtEventGuarding()

void ComNmtEventGuarding ( uint8_t  ubNetV,
uint8_t  ubNodeIdV,
uint8_t  ubReasonV 
)
Parameters
ubNetV- CANopen Network channel
ubNodeIdV- Node-ID value
ubReasonV- Reason for guarding event

This function is called by the stack on a NMT node guarding event (i.e. the node did not respond on a CAN remote frame within the configured guard time). The parameter ubReasonV defines the cause for the guarding event (see ComNmtGuard_e enumeration).

The action on this function is application specific. The function body is placed inside the file com_user.c.

◆ ComNmtEventHeartbeat()

void ComNmtEventHeartbeat ( uint8_t  ubNetV,
uint8_t  ubNodeIdV 
)
Parameters
[in]ubNetVCANopen Network channel
ubNodeIdV- Node-ID value

This function is called by the stack on a NMT heartbeat event.

The action on this function is application specific. The function body is placed inside the file com_user.c.

◆ ComNmtEventIdCollision()

void ComNmtEventIdCollision ( uint8_t  ubNetV)
Parameters
[in]ubNetVCANopen Network channel

This function is called by the stack on a NMT identifier collision.

The action on this function is application specific. The function body is placed inside the file com_user.c.

◆ ComNmtEventMasterDetection()

void ComNmtEventMasterDetection ( uint8_t  ubNetV,
uint8_t  ubResultV 
)

NMT master detection callback.

Parameters
[in]ubNetVCANopen Network channel
ubResultV- Result of NMT master detection
See also
ComNmtMasterDetection()

This function is called by the stack as result on a NMT master detection procedure. Possible values for the parameter ubResultV are

  • eCOM_NMT_DETECT_SUCCESS
  • eCOM_NMT_DETECT_TIMEOUT

The value eCOM_NMT_DETECT_SUCCESS means that a NMT master device is available in the network. The CANopen master stack shall not be used as NMT master in that case. The value eCOM_NMT_DETECT_TIMEOUT denotes that there was no response from another NMT master in the network and the CANopen master stack may be used as NMT master.

The action on this function is application specific. The function body is placed inside the file com_user.c.

◆ ComNmtEventResetCommunication()

void ComNmtEventResetCommunication ( uint8_t  ubNetV)
Parameters
[in]ubNetVCANopen Network channel

This function is called by the stack on a NMT reset communication command.

The action on this function is application specific. The function body is placed inside the file com_user.c.

◆ ComNmtEventResetNode()

void ComNmtEventResetNode ( uint8_t  ubNetV)

NMT reset event callback.

Parameters
ubNetV- CANopen Network channel

This function is called by the stack on a NMT reset remote node command.

The action on this function is application specific. The function body is placed inside the file com_user.c.

◆ ComNmtEventStateChange()

void ComNmtEventStateChange ( uint8_t  ubNetV,
uint8_t  ubNodeIdV,
uint8_t  ubNmtStateV 
)
Parameters
[in]ubNetVCANopen Network channel
ubNodeIdV- Node-ID value
ubNmtStateV- New NMT state

This function is called by the stack on a NMT state change event. Possible values for ubNmtStateV are listed in the ComNmtState_e enumeration.

The action on this function is application specific. The function body is placed inside the file com_user.c.

◆ ComNmtFlyingMaster()

ComStatus_tv ComNmtFlyingMaster ( uint8_t  ubNetV)

Start NMT Flying Master detection.

Parameters
ubNetV- CANopen Network channel
Returns
Value of enumeration ComErr_e

This function starts the NMT Flying Master process.

◆ ComNmtGetHbConsTime()

ComStatus_tv ComNmtGetHbConsTime ( uint8_t  ubNetV,
uint8_t  ubNodeIdV,
uint16_t *  puwTimeV 
)
Parameters
[in]ubNetVCANopen Network channel
ubNodeIdV- Node-ID value
puwTimeV- Pointer to heartbeat timer value
Returns
Value of enumeration ComErr_e
See also
ComNmtSetHbConsTime()

This function retrieves the heartbeat consumer time for the CANopen Master. The value passed to the pointer puwTimeV is given in multiples of 1 millisecond.

◆ ComNmtGetHbProdTime()

ComStatus_tv ComNmtGetHbProdTime ( uint8_t  ubNetV,
uint16_t *  puwTimeV 
)

Get producer heartbeat time.

Parameters
[in]ubNetVCANopen Network channel
[out]puwTimeVPointer to heartbeat timer value
Returns
Value of enumeration ComErr_e
See also
ComNmtSetHbProdTime()

This function retrieves the heartbeat producer time for the CANopen Master. The value passed to the pointer puwTimeV is given in multiples of 1 millisecond.

◆ ComNmtGetInhibit()

ComStatus_tv ComNmtGetInhibit ( uint8_t  ubNetV,
uint32_t *  pulTimeV 
)
Parameters
[in]ubNetVCANopen Network channel
[out]pulTimeVPointer to NMT inhibit time
Returns
Value of enumeration ComErr_e
See also
ComNmtSetInhibit()

This function retrieves the inhibit time between two subsequent NMT messages. The pointer pulTimeV points to a variable that holds the time value in multiples of one microsecond.

◆ ComNmtGetNodeState()

ComStatus_tv ComNmtGetNodeState ( uint8_t  ubNetV,
uint8_t  ubNodeIdV,
uint8_t *  pubStateV 
)
Parameters
[in]ubNetVCANopen Network channel
[in]ubNodeIdVNode-ID value
[out]pubStateVPointer to NMT state variable
Returns
Value of enumeration ComErr_e
See also
ComNmtSetNodeState()

This function retrieves the NMT state of the CANopen device with the Node-ID ubNodeIdV. Possible values for ubNodeIdV are 1 .. 127. The value passed to the pointer pubStateV is taken from the ComNmtState_e enumeration.

◆ ComNmtIsMaster()

ComStatus_tv ComNmtIsMaster ( uint8_t  ubNetV)

Check for NMT master.

Parameters
ubNetV- CANopen Network channel
Returns
1 if NMT master, 0 if NMT slave

This function checks if the device is the NMT master or not.

◆ ComNmtMasterDetection()

ComStatus_tv ComNmtMasterDetection ( uint8_t  ubNetV,
uint8_t  ubBootupV 
)

Start NMT master detection.

Parameters
[in]ubNetVCANopen Network channel
ubBootupV- set to 1 if run upon bootup
Returns
Value of enumeration ComErr_e
See also
ComNmtEventMasterDetection()

This function starts the NMT master detection.

◆ ComNmtSetGuardTime()

ComStatus_tv ComNmtSetGuardTime ( uint8_t  ubNetV,
uint8_t  ubNodeIdV,
uint16_t  uwGuardTimeV,
uint8_t  ubLifeTimeFactorV 
)
Parameters
ubNetV- CANopen Network channel
ubNodeIdV- Node-ID value
uwGuardTimeV- Node guard time value
ubLifeTimeFactorV- Life time factor
Returns
Value of enumeration ComErr_e

This function sets the node guard time for the CANopen device with the Node-ID ubNodeIdV. Possible values for ubNodeIdV are 1 .. 127. The value passed to uwGuardTimeV is given in multiples of 1 millisecond.

If the parameter ubNodeIdV is equal to the Node-ID of the CANopen FD Master, the function will return an error (eCOM_ERR_NODE_ID).

The node guard time can only be set if the heartbeat producer time for that node is set to 0 (both error protocols cannot be used at the same time). When node guarding is started for a CANopen node, the CANopen master stack will send RTR frames with the identifier 700h + ubNodeIdV and a cycle time of uwTimeV milliseconds.

◆ ComNmtSetHbConsTime()

ComStatus_tv ComNmtSetHbConsTime ( uint8_t  ubNetV,
uint8_t  ubNodeIdV,
uint16_t  uwTimeV 
)

Set consumer heartbeat time.

Parameters
ubNetV- CANopen Network channel
ubNodeIdV- Node-ID value
uwTimeV- Heartbeat timer value
Returns
Value of enumeration ComErr_e
See also
ComNmtGetHbProdTime()

This function sets the heartbeat consumer time for the CANopen device with the Node-ID ubNodeIdV. Possible values for ubNodeIdV are 1 .. 127. The value passed to uwTimeV is given in multiples of 1 millisecond.

If the parameter ubNodeIdV is equal to the Node-ID of the CANopen Master, the function will return an error (eCOM_ERR_NODE_ID).

◆ ComNmtSetHbProdTime()

ComStatus_tv ComNmtSetHbProdTime ( uint8_t  ubNetV,
uint16_t  uwTimeV 
)

Set producer heartbeat time.

Parameters
ubNetV- CANopen Network channel
uwTimeV- Heartbeat timer value
Returns
Value of enumeration ComErr_e
See also
ComNmtGetHbProdTime()

This function sets the heartbeat producer time for the CANopen Master. The value passed to uwTimeV is given in multiples of 1 millisecond.

◆ ComNmtSetInhibit()

ComStatus_tv ComNmtSetInhibit ( uint8_t  ubNetV,
uint32_t  ulTimeV 
)

Set NMT message inhibit time.

Parameters
ubNetV- CANopen Network channel
ulTimeV- NMT inhibit time
Returns
Value of enumeration ComErr_e
See also
ComNmtGetInhibit()

This function sets the inhibit time between two subsequent NMT messages. The parameter ulTimeV is given in multiples of 1 microsecond.

◆ ComNmtSetNodeState()

ComStatus_tv ComNmtSetNodeState ( uint8_t  ubNetV,
uint8_t  ubNodeIdV,
uint8_t  ubStateV 
)

Set NMT state of CANopen device.

Parameters
ubNetV- CANopen Network channel
ubNodeIdV- Node-ID value
ubStateV- New NMT state
Returns
Value of enumeration ComErr_e
See also
ComNmtGetNodeState()

This function changes the NMT state of the CANopen device with the Node-ID ubNodeIdV. Possible values for ubNodeIdV are 0 .. 127. A value of 0 addresses all devices in the network. Passing the address of the CANopen Master to ubNodeIdV will change the NMT state of the Master.

The value passed to ubStateV is taken from the ComNmtState_e enumeration.