CANopenNode
CANopen protocol stack
Loading...
Searching...
No Matches
NMT and Heartbeat

CANopen Network management and Heartbeat producer protocol. More...

+ Collaboration diagram for NMT and Heartbeat:

Topics

 NMT control bitfield for NMT internal state.
 
 

Files

file  CO_NMT_Heartbeat.h
 CANopen Network management and Heartbeat producer protocol.
 

Data Structures

struct  CO_NMT_t
 NMT consumer and Heartbeat producer object. More...
 

Enumerations

enum  CO_NMT_internalState_t {
  CO_NMT_UNKNOWN = -1 , CO_NMT_INITIALIZING = 0 , CO_NMT_PRE_OPERATIONAL = 127 , CO_NMT_OPERATIONAL = 5 ,
  CO_NMT_STOPPED = 4
}
 Internal network state of the CANopen node. More...
 
enum  CO_NMT_command_t {
  CO_NMT_NO_COMMAND = 0 , CO_NMT_ENTER_OPERATIONAL = 1 , CO_NMT_ENTER_STOPPED = 2 , CO_NMT_ENTER_PRE_OPERATIONAL = 128 ,
  CO_NMT_RESET_NODE = 129 , CO_NMT_RESET_COMMUNICATION = 130
}
 Commands from NMT master. More...
 
enum  CO_NMT_reset_cmd_t { CO_RESET_NOT = 0 , CO_RESET_COMM = 1 , CO_RESET_APP = 2 , CO_RESET_QUIT = 3 }
 Return code from CO_NMT_process() that tells application code what to reset. More...
 

Functions

CO_ReturnError_t CO_NMT_init (CO_NMT_t *NMT, OD_entry_t *OD_1017_ProducerHbTime, CO_EM_t *em, uint8_t nodeId, uint16_t NMTcontrol, uint16_t firstHBTime_ms, CO_CANmodule_t *NMT_CANdevRx, uint16_t NMT_rxIdx, uint16_t CANidRxNMT, CO_CANmodule_t *NMT_CANdevTx, uint16_t NMT_txIdx, uint16_t CANidTxNMT, CO_CANmodule_t *HB_CANdevTx, uint16_t HB_txIdx, uint16_t CANidTxHB, uint32_t *errInfo)
 Initialize NMT and Heartbeat producer object.
 
void CO_NMT_initCallbackPre (CO_NMT_t *NMT, void *object, void(*pFunctSignal)(void *object))
 Initialize NMT callback function after message preprocessed.
 
void CO_NMT_initCallbackChanged (CO_NMT_t *NMT, void(*pFunctNMT)(CO_NMT_internalState_t state))
 Initialize NMT callback function.
 
CO_NMT_reset_cmd_t CO_NMT_process (CO_NMT_t *NMT, CO_NMT_internalState_t *NMTstate, uint32_t timeDifference_us, uint32_t *timerNext_us)
 Process received NMT and produce Heartbeat messages.
 
static CO_NMT_internalState_t CO_NMT_getInternalState (CO_NMT_t *NMT)
 Query current NMT state.
 
static void CO_NMT_sendInternalCommand (CO_NMT_t *NMT, CO_NMT_command_t command)
 Send NMT command to self, without sending NMT message.
 
CO_ReturnError_t CO_NMT_sendCommand (CO_NMT_t *NMT, CO_NMT_command_t command, uint8_t nodeID)
 Send NMT master command.
 

Detailed Description

CANopen Network management and Heartbeat producer protocol.

CANopen device can be in one of the CO_NMT_internalState_t

NMT master can change the internal state of the devices by sending CO_NMT_command_t.

NMT message contents:

Byte Description
0 CO_NMT_command_t
1 Node ID. If zero, command addresses all nodes.

Heartbeat message contents:

Byte Description
0 CO_NMT_internalState_t

See Default CANopen identifiers for CAN identifiers.

Enumeration Type Documentation

◆ CO_NMT_internalState_t

Internal network state of the CANopen node.

Enumerator
CO_NMT_UNKNOWN 

-1, Device state is unknown (for heartbeat consumer)

CO_NMT_INITIALIZING 

0, Device is initializing

CO_NMT_PRE_OPERATIONAL 

127, Device is in pre-operational state

CO_NMT_OPERATIONAL 

5, Device is in operational state

CO_NMT_STOPPED 

4, Device is stopped

◆ CO_NMT_command_t

Commands from NMT master.

Enumerator
CO_NMT_NO_COMMAND 

0, No command

CO_NMT_ENTER_OPERATIONAL 

1, Start device

CO_NMT_ENTER_STOPPED 

2, Stop device

CO_NMT_ENTER_PRE_OPERATIONAL 

128, Put device into pre-operational

CO_NMT_RESET_NODE 

129, Reset device

CO_NMT_RESET_COMMUNICATION 

130, Reset CANopen communication on device

◆ CO_NMT_reset_cmd_t

Return code from CO_NMT_process() that tells application code what to reset.

Enumerator
CO_RESET_NOT 

0, Normal return, no action

CO_RESET_COMM 

1, Application must provide communication reset.

CO_RESET_APP 

2, Application must provide complete device reset

CO_RESET_QUIT 

3, Application must quit, no reset of microcontroller (command is not requested by the stack.)

Function Documentation

◆ CO_NMT_init()

CO_ReturnError_t CO_NMT_init ( CO_NMT_t * NMT,
OD_entry_t * OD_1017_ProducerHbTime,
CO_EM_t * em,
uint8_t nodeId,
uint16_t NMTcontrol,
uint16_t firstHBTime_ms,
CO_CANmodule_t * NMT_CANdevRx,
uint16_t NMT_rxIdx,
uint16_t CANidRxNMT,
CO_CANmodule_t * NMT_CANdevTx,
uint16_t NMT_txIdx,
uint16_t CANidTxNMT,
CO_CANmodule_t * HB_CANdevTx,
uint16_t HB_txIdx,
uint16_t CANidTxHB,
uint32_t * errInfo )

Initialize NMT and Heartbeat producer object.

Function must be called in the communication reset section.

Parameters
NMTThis object will be initialized.
OD_1017_ProducerHbTimeOD entry for 0x1017 -"Producer heartbeat time", entry is required, IO extension is optional for runtime configuration.
emEmergency object.
nodeIdCANopen Node ID of this device.
NMTcontrolControl variable for calculation of NMT internal state, based on error register, startup and runtime behavior.
firstHBTime_msTime between bootup and first heartbeat message in milliseconds. If firstHBTime_ms is greater than "Producer Heartbeat time" (OD object 0x1017), latter is used instead. Entry is required, IO extension is optional.
NMT_CANdevRxCAN device for NMT reception.
NMT_rxIdxIndex of receive buffer in above CAN device.
CANidRxNMTCAN identifier for NMT receive message.
NMT_CANdevTxCAN device for NMT master transmission.
NMT_txIdxIndex of transmit buffer in above CAN device.
CANidTxNMTCAN identifier for NMT transmit message.
HB_CANdevTxCAN device for HB transmission.
HB_txIdxIndex of transmit buffer in the above CAN device.
CANidTxHBCAN identifier for HB message.
[out]errInfoAdditional information in case of error, may be NULL.
Returns
CO_ReturnError_t CO_ERROR_NO on success.

◆ CO_NMT_initCallbackPre()

void CO_NMT_initCallbackPre ( CO_NMT_t * NMT,
void * object,
void(* pFunctSignal )(void *object) )

Initialize NMT callback function after message preprocessed.

Function initializes optional callback function, which should immediately start processing of CO_NMT_process() function. Callback is called after NMT message is received from the CAN bus.

Parameters
NMTThis object.
objectPointer to object, which will be passed to pFunctSignal(). Can be NULL
pFunctSignalPointer to the callback function. Not called if NULL.

◆ CO_NMT_initCallbackChanged()

void CO_NMT_initCallbackChanged ( CO_NMT_t * NMT,
void(* pFunctNMT )(CO_NMT_internalState_t state) )

Initialize NMT callback function.

Function initializes optional callback function, which is called after NMT State change has occurred. Function may wake up external task which handles NMT events. The first call is made immediately to give the consumer the current NMT state.

Parameters
NMTThis object.
pFunctNMTPointer to the callback function. Not called if NULL.

◆ CO_NMT_process()

CO_NMT_reset_cmd_t CO_NMT_process ( CO_NMT_t * NMT,
CO_NMT_internalState_t * NMTstate,
uint32_t timeDifference_us,
uint32_t * timerNext_us )

Process received NMT and produce Heartbeat messages.

Function must be called cyclically.

Parameters
NMTThis object.
[out]NMTstateIf not NULL, CANopen NMT internal state is returned.
timeDifference_usTime difference from previous function call in microseconds.
[out]timerNext_usinfo to OS - see CO_process().
Returns
CO_NMT_reset_cmd_t

◆ CO_NMT_getInternalState()

static CO_NMT_internalState_t CO_NMT_getInternalState ( CO_NMT_t * NMT)
inlinestatic

Query current NMT state.

Parameters
NMTThis object.
Returns
CO_NMT_internalState_t

◆ CO_NMT_sendInternalCommand()

static void CO_NMT_sendInternalCommand ( CO_NMT_t * NMT,
CO_NMT_command_t command )
inlinestatic

Send NMT command to self, without sending NMT message.

Internal NMT state will be verified and switched inside CO_NMT_process()

Parameters
NMTThis object.
commandNMT command

◆ CO_NMT_sendCommand()

CO_ReturnError_t CO_NMT_sendCommand ( CO_NMT_t * NMT,
CO_NMT_command_t command,
uint8_t nodeID )

Send NMT master command.

This functionality may only be used from NMT master, as specified by standard CiA302-2. Standard provides one exception, where application from slave node may send NMT master command: "If CANopen object 0x1F80 has value of <strong>0x2</strong>, then NMT slave shall execute the NMT service start remote node (CO_NMT_ENTER_OPERATIONAL) with nodeID set to 0."

Parameters
NMTThis object.
commandNMT command from CO_NMT_command_t.
nodeIDNode ID of the remote node. 0 for all nodes including self.
Returns
CO_ERROR_NO on success or CO_ReturnError_t from CO_CANsend().