CO_NMT_Heartbeat.h
Go to the documentation of this file.
#ifndef CO_NMT_HEARTBEAT_H
#define CO_NMT_HEARTBEAT_H
#include "301/CO_driver.h"
#include "301/CO_ODinterface.h"
#include "301/CO_Emergency.h"
/* default configuration, see CO_config.h */
#ifndef CO_CONFIG_NMT
#define CO_CONFIG_NMT (0)
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
CO_NMT_UNKNOWN = -1,
CO_NMT_INITIALIZING = 0,
CO_NMT_PRE_OPERATIONAL = 127,
CO_NMT_OPERATIONAL = 5,
CO_NMT_STOPPED = 4
} CO_NMT_internalState_t;
typedef enum {
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
} CO_NMT_command_t;
typedef enum {
CO_RESET_NOT = 0,
CO_RESET_COMM = 1,
CO_RESET_APP = 2,
CO_RESET_QUIT = 3
} CO_NMT_reset_cmd_t;
typedef enum {
CO_NMT_ERR_REG_MASK = 0x00FFU,
CO_NMT_STARTUP_TO_OPERATIONAL = 0x0100U,
CO_NMT_ERR_ON_BUSOFF_HB = 0x1000U,
CO_NMT_ERR_ON_ERR_REG = 0x2000U,
CO_NMT_ERR_TO_STOPPED = 0x4000U,
CO_NMT_ERR_FREE_TO_OPERATIONAL = 0x8000U
} CO_NMT_control_t;
typedef struct {
uint8_t operatingState;
uint8_t operatingStatePrev;
uint8_t internalCommand;
uint8_t nodeId;
CO_NMT_control_t NMTcontrol;
uint32_t HBproducerTime_us;
uint32_t HBproducerTimer;
CO_EM_t *em;
#if ((CO_CONFIG_NMT) & CO_CONFIG_NMT_MASTER) || defined CO_DOXYGEN
CO_CANmodule_t *NMT_CANdevTx;
CO_CANtx_t *NMT_TXbuff;
#endif
CO_CANmodule_t *HB_CANdevTx;
CO_CANtx_t *HB_TXbuff;
#if ((CO_CONFIG_NMT) & CO_CONFIG_FLAG_CALLBACK_PRE) || defined CO_DOXYGEN
void (*pFunctSignalPre)(void *object);
void *functSignalObjectPre;
#endif
#if ((CO_CONFIG_NMT) & CO_CONFIG_NMT_CALLBACK_CHANGE) || defined CO_DOXYGEN
void (*pFunctNMT)(CO_NMT_internalState_t state);
#endif
} CO_NMT_t;
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,
#if ((CO_CONFIG_NMT) & CO_CONFIG_NMT_MASTER) || defined CO_DOXYGEN
CO_CANmodule_t *NMT_CANdevTx,
uint16_t NMT_txIdx,
uint16_t CANidTxNMT,
#endif
CO_CANmodule_t *HB_CANdevTx,
uint16_t HB_txIdx,
uint16_t CANidTxHB);
#if ((CO_CONFIG_NMT) & CO_CONFIG_FLAG_CALLBACK_PRE) || defined CO_DOXYGEN
void CO_NMT_initCallbackPre(CO_NMT_t *NMT,
void *object,
void (*pFunctSignal)(void *object));
#endif
#if ((CO_CONFIG_NMT) & CO_CONFIG_NMT_CALLBACK_CHANGE) || defined CO_DOXYGEN
void CO_NMT_initCallbackChanged(CO_NMT_t *NMT,
void (*pFunctNMT)(CO_NMT_internalState_t state));
#endif
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);
static inline CO_NMT_internalState_t CO_NMT_getInternalState(CO_NMT_t *NMT) {
return (NMT == NULL) ? CO_NMT_INITIALIZING : NMT->operatingState;
}
static inline void CO_NMT_setInternalState(CO_NMT_t *NMT,
CO_NMT_internalState_t state)
{
if (NMT != NULL) NMT->operatingState = state;
}
#if ((CO_CONFIG_NMT) & CO_CONFIG_NMT_MASTER) || defined CO_DOXYGEN
CO_ReturnError_t CO_NMT_sendCommand(CO_NMT_t *NMT,
CO_NMT_command_t command,
uint8_t nodeID);
#endif /* (CO_CONFIG_NMT) & CO_CONFIG_NMT_MASTER */
/* CO_NMT_Heartbeat */
#ifdef __cplusplus
}
#endif /*__cplusplus*/
#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