CANopenNode
CO_NMT_Heartbeat.h
Go to the documentation of this file.
1 
26 #ifndef CO_NMT_HEARTBEAT_H
27 #define CO_NMT_HEARTBEAT_H
28 
29 #include "301/CO_driver.h"
30 #include "301/CO_ODinterface.h"
31 #include "301/CO_Emergency.h"
32 
33 /* default configuration, see CO_config.h */
34 #ifndef CO_CONFIG_NMT
35 #define CO_CONFIG_NMT (0)
36 #endif
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
77 typedef enum {
89 
90 
94 typedef enum {
106 
107 
112 typedef enum {
123 
124 
135 typedef enum {
157 
158 
162 typedef struct {
180 #if ((CO_CONFIG_NMT) & CO_CONFIG_NMT_MASTER) || defined CO_DOXYGEN
181 
185 #endif
186 
190 #if ((CO_CONFIG_NMT) & CO_CONFIG_FLAG_CALLBACK_PRE) || defined CO_DOXYGEN
191 
192  void (*pFunctSignalPre)(void *object);
195 #endif
196 #if ((CO_CONFIG_NMT) & CO_CONFIG_NMT_CALLBACK_CHANGE) || defined CO_DOXYGEN
197 
198  void (*pFunctNMT)(CO_NMT_internalState_t state);
199 #endif
200 } CO_NMT_t;
201 
202 
232  const OD_entry_t *OD_1017_ProducerHbTime,
233  CO_EM_t *em,
234  uint8_t nodeId,
235  CO_NMT_control_t NMTcontrol,
236  uint16_t firstHBTime_ms,
237  CO_CANmodule_t *NMT_CANdevRx,
238  uint16_t NMT_rxIdx,
239  uint16_t CANidRxNMT,
240 #if ((CO_CONFIG_NMT) & CO_CONFIG_NMT_MASTER) || defined CO_DOXYGEN
241  CO_CANmodule_t *NMT_CANdevTx,
242  uint16_t NMT_txIdx,
243  uint16_t CANidTxNMT,
244 #endif
245  CO_CANmodule_t *HB_CANdevTx,
246  uint16_t HB_txIdx,
247  uint16_t CANidTxHB);
248 
249 
250 #if ((CO_CONFIG_NMT) & CO_CONFIG_FLAG_CALLBACK_PRE) || defined CO_DOXYGEN
251 
264  void *object,
265  void (*pFunctSignal)(void *object));
266 #endif
267 
268 
269 #if ((CO_CONFIG_NMT) & CO_CONFIG_NMT_CALLBACK_CHANGE) || defined CO_DOXYGEN
270 
282  void (*pFunctNMT)(CO_NMT_internalState_t state));
283 #endif
284 
285 
300  CO_NMT_internalState_t *NMTstate,
301  uint32_t timeDifference_us,
302  uint32_t *timerNext_us);
303 
304 
313  return (NMT == NULL) ? CO_NMT_INITIALIZING : NMT->operatingState;
314 }
315 
316 
326 static inline void CO_NMT_setInternalState(CO_NMT_t *NMT,
328 {
329  if (NMT != NULL) NMT->operatingState = state;
330 }
331 
332 
333 #if ((CO_CONFIG_NMT) & CO_CONFIG_NMT_MASTER) || defined CO_DOXYGEN
334 
350  CO_NMT_command_t command,
351  uint8_t nodeID);
352 
353 #endif /* (CO_CONFIG_NMT) & CO_CONFIG_NMT_MASTER */
354  /* CO_NMT_Heartbeat */
356 
357 #ifdef __cplusplus
358 }
359 #endif /*__cplusplus*/
360 
361 #endif /* CO_NMT_HEARTBEAT_H */
CO_RESET_APP
@ CO_RESET_APP
2, Application must provide complete device reset
Definition: CO_NMT_Heartbeat.h:118
CO_NMT_PRE_OPERATIONAL
@ CO_NMT_PRE_OPERATIONAL
127, Device is in pre-operational state
Definition: CO_NMT_Heartbeat.h:83
uint32_t
unsigned long int uint32_t
UNSIGNED32 in CANopen (0007h), 32-bit unsigned integer.
Definition: CO_driver.h:155
CO_driver.h
Interface between CAN hardware and CANopenNode.
CO_NMT_t::functSignalObjectPre
void * functSignalObjectPre
From CO_NMT_initCallbackPre() or NULL.
Definition: CO_NMT_Heartbeat.h:194
CO_NMT_t::HBproducerTime_us
uint32_t HBproducerTime_us
Producer heartbeat time, calculated from OD 0x1017.
Definition: CO_NMT_Heartbeat.h:175
CO_NMT_init
CO_ReturnError_t CO_NMT_init(CO_NMT_t *NMT, const OD_entry_t *OD_1017_ProducerHbTime, CO_EM_t *em, uint8_t nodeId, CO_NMT_control_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)
Initialize NMT and Heartbeat producer object.
CO_CONFIG_NMT
#define CO_CONFIG_NMT
Configuration of NMT and Heartbeat.
Definition: CO_config.h:123
CO_NMT_setInternalState
static void CO_NMT_setInternalState(CO_NMT_t *NMT, CO_NMT_internalState_t state)
Set internal NMT state.
Definition: CO_NMT_Heartbeat.h:326
CO_RESET_QUIT
@ CO_RESET_QUIT
3, Application must quit, no reset of microcontroller (command is not requested by the stack....
Definition: CO_NMT_Heartbeat.h:121
CO_NMT_INITIALIZING
@ CO_NMT_INITIALIZING
0, Device is initializing
Definition: CO_NMT_Heartbeat.h:81
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.
uint16_t
unsigned int uint16_t
UNSIGNED16 in CANopen (0006h), 16-bit unsigned integer.
Definition: CO_driver.h:153
CO_NMT_RESET_NODE
@ CO_NMT_RESET_NODE
129, Reset device
Definition: CO_NMT_Heartbeat.h:102
CO_ReturnError_t
CO_ReturnError_t
Return values of some CANopen functions.
Definition: CO_driver.h:488
CO_NMT_getInternalState
static CO_NMT_internalState_t CO_NMT_getInternalState(CO_NMT_t *NMT)
Query current NMT state.
Definition: CO_NMT_Heartbeat.h:312
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.
Definition: CO_NMT_Heartbeat.c:222
CO_NMT_t::HBproducerTimer
uint32_t HBproducerTimer
Internal timer for HB producer.
Definition: CO_NMT_Heartbeat.h:177
CO_NMT_reset_cmd_t
CO_NMT_reset_cmd_t
Return code from CO_NMT_process() that tells application code what to reset.
Definition: CO_NMT_Heartbeat.h:112
CO_NMT_t::internalCommand
uint8_t internalCommand
NMT internal command from CO_NMT_receive() or CO_NMT_sendCommand(), processed in CO_NMT_process().
Definition: CO_NMT_Heartbeat.h:169
CO_NMT_STARTUP_TO_OPERATIONAL
@ CO_NMT_STARTUP_TO_OPERATIONAL
If bit is set, then device enters NMT operational state after the initialization phase,...
Definition: CO_NMT_Heartbeat.h:141
CO_NMT_initCallbackPre
void CO_NMT_initCallbackPre(CO_NMT_t *NMT, void *object, void(*pFunctSignal)(void *object))
Initialize NMT callback function after message preprocessed.
CO_NMT_ERR_TO_STOPPED
@ CO_NMT_ERR_TO_STOPPED
If bit is set and CO_NMT_ERR_ON_xx condition is met, then device will enter NMT stopped state,...
Definition: CO_NMT_Heartbeat.h:152
CO_NMT_t
NMT consumer and Heartbeat producer object.
Definition: CO_NMT_Heartbeat.h:162
CO_NMT_t::HB_TXbuff
CO_CANtx_t * HB_TXbuff
CAN transmit buffer for heartbeat message.
Definition: CO_NMT_Heartbeat.h:189
CO_NMT_ERR_FREE_TO_OPERATIONAL
@ CO_NMT_ERR_FREE_TO_OPERATIONAL
If bit is set and device is pre-operational, it enters NMT operational state automatically,...
Definition: CO_NMT_Heartbeat.h:155
CO_NMT_t::NMT_TXbuff
CO_CANtx_t * NMT_TXbuff
CAN transmit buffer for NMT master message.
Definition: CO_NMT_Heartbeat.h:184
CO_RESET_COMM
@ CO_RESET_COMM
1, Application must provide communication reset.
Definition: CO_NMT_Heartbeat.h:116
CO_NMT_ERR_REG_MASK
@ CO_NMT_ERR_REG_MASK
First 8 bits can be used to specify bitmask for the CO_errorRegister_t, to get relevant bits for the ...
Definition: CO_NMT_Heartbeat.h:138
CO_NMT_t::HB_CANdevTx
CO_CANmodule_t * HB_CANdevTx
From CO_NMT_init()
Definition: CO_NMT_Heartbeat.h:187
CO_NMT_ENTER_STOPPED
@ CO_NMT_ENTER_STOPPED
2, Stop device
Definition: CO_NMT_Heartbeat.h:98
CO_NMT_t::em
CO_EM_t * em
From CO_NMT_init()
Definition: CO_NMT_Heartbeat.h:179
CO_NMT_OPERATIONAL
@ CO_NMT_OPERATIONAL
5, Device is in operational state
Definition: CO_NMT_Heartbeat.h:85
CO_NMT_t::operatingStatePrev
uint8_t operatingStatePrev
Previous NMT operating state.
Definition: CO_NMT_Heartbeat.h:166
CO_NMT_command_t
CO_NMT_command_t
Commands from NMT master.
Definition: CO_NMT_Heartbeat.h:94
CO_NMT_UNKNOWN
@ CO_NMT_UNKNOWN
-1, Device state is unknown (for heartbeat consumer)
Definition: CO_NMT_Heartbeat.h:79
CO_NMT_ERR_ON_ERR_REG
@ CO_NMT_ERR_ON_ERR_REG
If bit is set and device is operational, it enters NMT pre-operational or stopped state,...
Definition: CO_NMT_Heartbeat.h:149
CO_RESET_NOT
@ CO_RESET_NOT
0, Normal return, no action
Definition: CO_NMT_Heartbeat.h:114
CO_NMT_t::NMT_CANdevTx
CO_CANmodule_t * NMT_CANdevTx
From CO_NMT_init()
Definition: CO_NMT_Heartbeat.h:182
CO_EM_t
Emergency object.
Definition: CO_Emergency.h:369
CO_NMT_internalState_t
CO_NMT_internalState_t
Internal network state of the CANopen node.
Definition: CO_NMT_Heartbeat.h:77
CO_ODinterface.h
CANopen Object Dictionary interface.
CO_NMT_initCallbackChanged
void CO_NMT_initCallbackChanged(CO_NMT_t *NMT, void(*pFunctNMT)(CO_NMT_internalState_t state))
Initialize NMT callback function.
CO_NMT_STOPPED
@ CO_NMT_STOPPED
4, Device is stopped
Definition: CO_NMT_Heartbeat.h:87
CO_Emergency.h
CANopen Emergency protocol.
CO_NMT_t::operatingState
uint8_t operatingState
Current NMT operating state.
Definition: CO_NMT_Heartbeat.h:164
NULL
#define NULL
NULL, for general usage.
Definition: CO_driver.h:135
CO_CANmodule_t
Complete CAN module object.
Definition: CO_driver.h:319
CO_NMT_ENTER_PRE_OPERATIONAL
@ CO_NMT_ENTER_PRE_OPERATIONAL
128, Put device into pre-operational
Definition: CO_NMT_Heartbeat.h:100
CO_NMT_t::NMTcontrol
CO_NMT_control_t NMTcontrol
From CO_NMT_init()
Definition: CO_NMT_Heartbeat.h:173
CO_NMT_ENTER_OPERATIONAL
@ CO_NMT_ENTER_OPERATIONAL
1, Start device
Definition: CO_NMT_Heartbeat.h:96
OD_entry_t
Object Dictionary entry for one OD object.
Definition: CO_ODinterface.h:336
CO_NMT_control_t
CO_NMT_control_t
NMT control bitfield for NMT internal state.
Definition: CO_NMT_Heartbeat.h:135
CO_NMT_t::nodeId
uint8_t nodeId
From CO_NMT_init()
Definition: CO_NMT_Heartbeat.h:171
CO_NMT_ERR_ON_BUSOFF_HB
@ CO_NMT_ERR_ON_BUSOFF_HB
If bit is set and device is operational, it enters NMT pre-operational or stopped state,...
Definition: CO_NMT_Heartbeat.h:145
CO_NMT_RESET_COMMUNICATION
@ CO_NMT_RESET_COMMUNICATION
130, Reset CANopen communication on device
Definition: CO_NMT_Heartbeat.h:104
CO_CANtx_t
Configuration object for CAN transmit message for specific CANopenNode Object.
Definition: CO_driver.h:299
uint8_t
unsigned char uint8_t
UNSIGNED8 in CANopen (0005h), 8-bit unsigned integer.
Definition: CO_driver.h:151