CANopenNode
CANopen protocol stack
|
CANopen Network management and Heartbeat producer protocol. More...
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. | |
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.
Byte | Description |
---|---|
0 | CO_NMT_command_t |
1 | Node ID. If zero, command addresses all nodes. |
Byte | Description |
---|---|
0 | CO_NMT_internalState_t |
See Default CANopen identifiers for CAN identifiers.
Internal network state of the CANopen node.
enum CO_NMT_command_t |
Commands from NMT master.
enum CO_NMT_reset_cmd_t |
Return code from CO_NMT_process() that tells application code what to reset.
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.
NMT | This object will be initialized. | |
OD_1017_ProducerHbTime | OD entry for 0x1017 -"Producer heartbeat time", entry is required, IO extension is optional for runtime configuration. | |
em | Emergency object. | |
nodeId | CANopen Node ID of this device. | |
NMTcontrol | Control variable for calculation of NMT internal state, based on error register, startup and runtime behavior. | |
firstHBTime_ms | Time 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_CANdevRx | CAN device for NMT reception. | |
NMT_rxIdx | Index of receive buffer in above CAN device. | |
CANidRxNMT | CAN identifier for NMT receive message. | |
NMT_CANdevTx | CAN device for NMT master transmission. | |
NMT_txIdx | Index of transmit buffer in above CAN device. | |
CANidTxNMT | CAN identifier for NMT transmit message. | |
HB_CANdevTx | CAN device for HB transmission. | |
HB_txIdx | Index of transmit buffer in the above CAN device. | |
CANidTxHB | CAN identifier for HB message. | |
[out] | errInfo | Additional information in case of error, may be NULL. |
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.
NMT | This object. |
object | Pointer to object, which will be passed to pFunctSignal(). Can be NULL |
pFunctSignal | Pointer to the callback function. Not called if NULL. |
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.
NMT | This object. |
pFunctNMT | Pointer to the callback function. Not called if NULL. |
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.
NMT | This object. | |
[out] | NMTstate | If not NULL, CANopen NMT internal state is returned. |
timeDifference_us | Time difference from previous function call in microseconds. | |
[out] | timerNext_us | info to OS - see CO_process(). |
|
inlinestatic |
|
inlinestatic |
Send NMT command to self, without sending NMT message.
Internal NMT state will be verified and switched inside CO_NMT_process()
NMT | This object. |
command | NMT command |
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."
NMT | This object. |
command | NMT command from CO_NMT_command_t. |
nodeID | Node ID of the remote node. 0 for all nodes including self. |