![]() |
CANopen Slave Protocol Stack
Version 7.08.00
|
The CANopen Network Management (NMT) is used to change the state of a CANopen device (see CANopen Terms and Definitions). In addition, the network state can be monitored via the Network Management Error Control (NMT-EC) service. This module provides the following functionality:
A CANopen device moves through four states. The current state can be queried with CosNmtGetNodeState(); the possible return values are defined in NMT node state.
| State | NODE_STATE value | Description |
|---|---|---|
| Initialization | NODE_STATE_BOOTUP | Device starts here after power-on or reset. SDO, PDO, and SYNC communication is not yet active. |
| Pre-Operational | NODE_STATE_PREOPERATIONAL | Entered automatically after initialization completes. SDO communication is active; PDO communication is inhibited. |
| Operational | NODE_STATE_OPERATIONAL | PDO communication is active. Normal device operation. |
| Stopped | NODE_STATE_STOPPED | All communication except NMT and heartbeat is inhibited. |
NMT state transitions are triggered by NMT commands received on CAN-ID 0 from the NMT master. The following table maps each transition to the NMT command code and to the application callback that fires:
| Transition | NMT command | Callback |
|---|---|---|
| Initialization → Pre-Operational | (automatic after boot-up) | CosMgrOnStart() then CosMgrOnBootUp() |
| Pre-Operational → Operational | Start Remote Node (01h) | CosNmtServiceOnStart() |
| Operational → Pre-Operational | Enter Pre-Operational (80h) | CosNmtServiceOnPreOperational() |
| Operational → Stopped | Stop Remote Node (02h) | CosNmtServiceOnStop() |
| Stopped → Pre-Operational | Enter Pre-Operational (80h) | CosNmtServiceOnPreOperational() |
| Stopped → Operational | Start Remote Node (01h) | CosNmtServiceOnStart() |
| Pre-Operational → Stopped | Stop Remote Node (02h) | CosNmtServiceOnStop() |
| Any → Initialization | Reset Node (81h) / Reset Communication (82h) | — |
Additional event callbacks are triggered by NMT error control:
All callback implementations reside in cos_user.c and must be supplied by the integrator.
Macros | |
| #define | NODE_STATE_BOOTUP ((uint8_t)(0x00)) |
| #define | NODE_STATE_STOPPED ((uint8_t)(0x04)) |
| #define | NODE_STATE_OPERATIONAL ((uint8_t)(0x05)) |
| #define | NODE_STATE_PREOPERATIONAL ((uint8_t)(0x7F)) |
| #define | NODE_STATE_BUS_OFF ((uint8_t)(0xFF)) |
Functions | |
| void | CosNmtChangeNodeState (uint8_t ubFailureV) |
| uint8_t | CosNmtCheckNodeReset (void) |
| uint8_t | CosNmtGetNodeState (void) |
| void | CosNmtServiceOnError (void) |
| void | CosNmtServiceOnGuardingEvent (void) |
| void | CosNmtServiceOnHeartbeatEvent (void) |
| void | CosNmtServiceOnPreOperational (void) |
| void | CosNmtServiceOnStart (void) |
| void | CosNmtServiceOnStop (void) |
| uint8_t | CosNmtSetHeartbeatCons (uint8_t ubEntryV, uint8_t ubNodeIdV, uint16_t uwTimeV) |
| void | CosNmtSetHeartbeatProd (uint16_t uwTimeV) |
| void CosNmtChangeNodeState | ( | uint8_t | ubFailureV | ) |
| [in] | ubFailureV | Error reason |
This function changes the NMT state of the device depending on the contents of object 1029h (error behaviour). The parameter ubFailureV defines the reason for the failure:
The maximum value for ubFailureV is defined by the symbol COS_DICT_OBJ_1029. For the failure type 'communication error' the function is called by the stack.
| uint8_t CosNmtCheckNodeReset | ( | void | ) |
This function returns the node reset state (NODE_RESET_XXX).
| uint8_t CosNmtGetNodeState | ( | void | ) |
This function returns the current NMT state of the node. Possible return values are defined by NMT node state.
| void CosNmtServiceOnError | ( | void | ) |
cos_user.c provides an example and has to be adopted to the application.This function is called when the NMT state machine receives an unknown NMT command, i.e. a frame on CAN-ID 0 with a DLC that does not match or data that does not match any defined command code. The reaction on this event is application specific; it may be ignored or logged.
| void CosNmtServiceOnGuardingEvent | ( | void | ) |
cos_user.c provides an example and has to be adopted to the application.This function is called when a node-guarding life-time event occurs, i.e. the NMT master did not send the RTR guard frame within the guard time × life-time factor window (objects 100Ch and 100Dh). The typical reaction is to report an emergency via CosEmcyErrorSet() with error code eEMCY_301_CAN_LIFEGUARD.
| void CosNmtServiceOnHeartbeatEvent | ( | void | ) |
cos_user.c provides an example and has to be adopted to the application.This function is called when a heartbeat consumer timeout fires, i.e. a monitored node did not transmit its heartbeat within the expected cycle window (object 1016h). The typical reaction is to report an emergency via CosEmcyErrorSet() with error code eEMCY_301_CAN_LIFEGUARD.
| void CosNmtServiceOnPreOperational | ( | void | ) |
cos_user.c provides an example and has to be adopted to the application.This function is called when the NMT state machine enters NODE_STATE_PREOPERATIONAL, triggered by the NMT command Enter Pre-Operational (80h). PDO communication is suspended at this point; SDO communication remains active. Use this callback to disable application outputs or enter a safe state.
| void CosNmtServiceOnStart | ( | void | ) |
cos_user.c provides an example and has to be adopted to the application.This function is called when the NMT state machine enters NODE_STATE_OPERATIONAL, triggered by the NMT command Start Remote Node (01h). PDO communication becomes active at this point. Use this callback to enable application outputs and trigger an initial PDO transmission via CosPdoSend().
| void CosNmtServiceOnStop | ( | void | ) |
cos_user.c provides an example and has to be adopted to the application.This function is called when the NMT state machine enters NODE_STATE_STOPPED, triggered by the NMT command Stop Remote Node (02h). All communication except NMT and heartbeat is suspended. Use this callback to set outputs to a defined safe state.
| uint8_t CosNmtSetHeartbeatCons | ( | uint8_t | ubEntryV, |
| uint8_t | ubNodeIdV, | ||
| uint16_t | uwTimeV ) |
| [in] | ubEntryV | heartbeat consumer entry (0 .. N) |
| [in] | ubNodeIdV | node-ID to monitor |
| [in] | uwTimeV | expected heartbeat cycle time |
This function sets the heartbeat consumer time for the entry ubEntryV. The maximum number of entries is defined via the symbol COS_DICT_OBJ_1016. The parameter uwTimeV denotes the time in milli-seconds. If the heartbeat consumer time is setup for the own node-ID or the supplied node-ID is already in use, the function will return the value 1. On success, the value 0 is returned.
| void CosNmtSetHeartbeatProd | ( | uint16_t | uwTimeV | ) |
| [in] | uwTimeV | heartbeat cycle time |
This function sets the heartbeat producer time. The parameter uwTimeV denotes the time in milli-seconds. By default, the heartbeat producer time is set to 0 during initialization.