CANopenNode
CANopen protocol stack
Loading...
Searching...
No Matches
CO_Emergency.h
Go to the documentation of this file.
1
21#ifndef CO_EMERGENCY_H
22#define CO_EMERGENCY_H
23
24#include "301/CO_driver.h"
25#include "301/CO_ODinterface.h"
26
27/* default configuration, see CO_config.h */
28#ifndef CO_CONFIG_EM
29#define CO_CONFIG_EM \
30 (CO_CONFIG_EM_PRODUCER | CO_CONFIG_EM_HISTORY | CO_CONFIG_GLOBAL_FLAG_CALLBACK_PRE \
31 | CO_CONFIG_GLOBAL_FLAG_TIMERNEXT)
32#endif
33#ifndef CO_CONFIG_EM_ERR_STATUS_BITS_COUNT
34#define CO_CONFIG_EM_ERR_STATUS_BITS_COUNT (10U * 8U)
35#endif
36#ifndef CO_CONFIG_ERR_CONDITION_GENERIC
37#define CO_CONFIG_ERR_CONDITION_GENERIC (em->errorStatusBits[5] != 0U)
38#endif
39#ifndef CO_CONFIG_ERR_CONDITION_COMMUNICATION
40#define CO_CONFIG_ERR_CONDITION_COMMUNICATION ((em->errorStatusBits[2] != 0U) || (em->errorStatusBits[3] != 0U))
41#endif
42#ifndef CO_CONFIG_ERR_CONDITION_MANUFACTURER
43#define CO_CONFIG_ERR_CONDITION_MANUFACTURER ((em->errorStatusBits[8] != 0U) || (em->errorStatusBits[9] != 0U))
44#endif
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
101#define CO_ERR_REG_GENERIC_ERR 0x01U
102#define CO_ERR_REG_CURRENT 0x02U
103#define CO_ERR_REG_VOLTAGE 0x04U
104#define CO_ERR_REG_TEMPERATURE 0x08U
105#define CO_ERR_REG_COMMUNICATION 0x10U
106#define CO_ERR_REG_DEV_PROFILE 0x20U
107#define CO_ERR_REG_RESERVED 0x40U
108#define CO_ERR_REG_MANUFACTURER 0x80U
110 /* CO_errorRegister_t */
111
118#define CO_EMC_NO_ERROR 0x0000U
119#define CO_EMC_GENERIC 0x1000U
120#define CO_EMC_CURRENT 0x2000U
121#define CO_EMC_CURRENT_INPUT 0x2100U
122#define CO_EMC_CURRENT_INSIDE 0x2200U
123#define CO_EMC_CURRENT_OUTPUT 0x2300U
124#define CO_EMC_VOLTAGE 0x3000U
125#define CO_EMC_VOLTAGE_MAINS 0x3100U
126#define CO_EMC_VOLTAGE_INSIDE 0x3200U
127#define CO_EMC_VOLTAGE_OUTPUT 0x3300U
128#define CO_EMC_TEMPERATURE 0x4000U
129#define CO_EMC_TEMP_AMBIENT 0x4100U
130#define CO_EMC_TEMP_DEVICE 0x4200U
131#define CO_EMC_HARDWARE 0x5000U
132#define CO_EMC_SOFTWARE_DEVICE 0x6000U
133#define CO_EMC_SOFTWARE_INTERNAL 0x6100U
134#define CO_EMC_SOFTWARE_USER 0x6200U
135#define CO_EMC_DATA_SET 0x6300U
136#define CO_EMC_ADDITIONAL_MODUL 0x7000U
137#define CO_EMC_MONITORING 0x8000U
138#define CO_EMC_COMMUNICATION 0x8100U
139#define CO_EMC_CAN_OVERRUN 0x8110U
140#define CO_EMC_CAN_PASSIVE 0x8120U
141#define CO_EMC_HEARTBEAT 0x8130U
142#define CO_EMC_BUS_OFF_RECOVERED 0x8140U
143#define CO_EMC_CAN_ID_COLLISION 0x8150U
144#define CO_EMC_PROTOCOL_ERROR 0x8200U
145#define CO_EMC_PDO_LENGTH 0x8210U
146#define CO_EMC_PDO_LENGTH_EXC 0x8220U
147#define CO_EMC_DAM_MPDO 0x8230U
148#define CO_EMC_SYNC_DATA_LENGTH 0x8240U
149#define CO_EMC_RPDO_TIMEOUT 0x8250U
150#define CO_EMC_EXTERNAL_ERROR 0x9000U
151#define CO_EMC_ADDITIONAL_FUNC 0xF000U
152#define CO_EMC_DEVICE_SPECIFIC 0xFF00U
154#define CO_EMC401_OUT_CUR_HI 0x2310U
155#define CO_EMC401_OUT_SHORTED 0x2320U
156#define CO_EMC401_OUT_LOAD_DUMP 0x2330U
157#define CO_EMC401_IN_VOLT_HI 0x3110U
158#define CO_EMC401_IN_VOLT_LOW 0x3120U
159#define CO_EMC401_INTERN_VOLT_HI 0x3210U
160#define CO_EMC401_INTERN_VOLT_LO 0x3220U
161#define CO_EMC401_OUT_VOLT_HIGH 0x3310U
162#define CO_EMC401_OUT_VOLT_LOW 0x3320U
164 /* CO_EM_errorCode_t */
165
181#define CO_EM_NO_ERROR 0x00U
182#define CO_EM_CAN_BUS_WARNING 0x01U
183#define CO_EM_RXMSG_WRONG_LENGTH 0x02U
184#define CO_EM_RXMSG_OVERFLOW 0x03U
185#define CO_EM_RPDO_WRONG_LENGTH 0x04U
186#define CO_EM_RPDO_OVERFLOW 0x05U
187#define CO_EM_CAN_RX_BUS_PASSIVE 0x06U
188#define CO_EM_CAN_TX_BUS_PASSIVE 0x07U
189#define CO_EM_NMT_WRONG_COMMAND 0x08U
190#define CO_EM_TIME_TIMEOUT 0x09U
191#define CO_EM_0A_unused 0x0AU
192#define CO_EM_0B_unused 0x0BU
193#define CO_EM_0C_unused 0x0CU
194#define CO_EM_0D_unused 0x0DU
195#define CO_EM_0E_unused 0x0EU
196#define CO_EM_0F_unused 0x0FU
198#define CO_EM_10_unused 0x10U
199#define CO_EM_11_unused 0x11U
200#define CO_EM_CAN_TX_BUS_OFF 0x12U
201#define CO_EM_CAN_RXB_OVERFLOW 0x13U
202#define CO_EM_CAN_TX_OVERFLOW 0x14U
203#define CO_EM_TPDO_OUTSIDE_WINDOW 0x15U
204#define CO_EM_16_unused 0x16U
205#define CO_EM_RPDO_TIME_OUT 0x17U
206#define CO_EM_SYNC_TIME_OUT 0x18U
207#define CO_EM_SYNC_LENGTH 0x19U
208#define CO_EM_PDO_WRONG_MAPPING 0x1AU
209#define CO_EM_HEARTBEAT_CONSUMER 0x1BU
210#define CO_EM_HB_CONSUMER_REMOTE_RESET 0x1CU
211#define CO_EM_SRDO_CONFIGURATION 0x1DU
212#define CO_EM_1E_unused 0x1EU
213#define CO_EM_1F_unused 0x1FU
215#define CO_EM_EMERGENCY_BUFFER_FULL 0x20U
216#define CO_EM_21_unused 0x21U
217#define CO_EM_MICROCONTROLLER_RESET 0x22U
218#define CO_EM_23_unused 0x23U
219#define CO_EM_24_unused 0x24U
220#define CO_EM_25_unused 0x25U
221#define CO_EM_26_unused 0x26U
222#define CO_EM_NON_VOLATILE_AUTO_SAVE 0x27U
224#define CO_EM_WRONG_ERROR_REPORT 0x28U
225#define CO_EM_ISR_TIMER_OVERFLOW 0x29U
226#define CO_EM_MEMORY_ALLOCATION_ERROR 0x2AU
227#define CO_EM_GENERIC_ERROR 0x2BU
228#define CO_EM_GENERIC_SOFTWARE_ERROR 0x2CU
229#define CO_EM_INCONSISTENT_OBJECT_DICT 0x2DU
230#define CO_EM_CALCULATION_OF_PARAMETERS 0x2EU
231#define CO_EM_NON_VOLATILE_MEMORY 0x2FU
238#define CO_EM_MANUFACTURER_START 0x30U
240#define CO_EM_MANUFACTURER_END (CO_CONFIG_EM_ERR_STATUS_BITS_COUNT - 1U)
241
242 /* CO_EM_errorStatusBits_t */
243
244#if (((CO_CONFIG_EM) & (CO_CONFIG_EM_PRODUCER | CO_CONFIG_EM_HISTORY)) != 0) || defined CO_DOXYGEN
248typedef struct {
249 uint32_t msg;
250#if (((CO_CONFIG_EM)&CO_CONFIG_EM_PRODUCER) != 0) || defined CO_DOXYGEN
251 uint32_t info;
252#endif
254#endif
255
259typedef struct {
266#if (((CO_CONFIG_EM) & (CO_CONFIG_EM_PRODUCER | CO_CONFIG_EM_HISTORY)) != 0) || defined CO_DOXYGEN
279#endif /* (CO_CONFIG_EM) & (CO_CONFIG_EM_PRODUCER | CO_CONFIG_EM_HISTORY) */
280
281#if (((CO_CONFIG_EM)&CO_CONFIG_EM_PRODUCER) != 0) || defined CO_DOXYGEN
286#if (((CO_CONFIG_EM)&CO_CONFIG_EM_PROD_CONFIGURABLE) != 0) || defined CO_DOXYGEN
289#endif
290#if (((CO_CONFIG_EM)&CO_CONFIG_EM_PROD_INHIBIT) != 0) || defined CO_DOXYGEN
294#endif
295#endif /* (CO_CONFIG_EM) & CO_CONFIG_EM_PRODUCER */
296
297#if (((CO_CONFIG_EM)&CO_CONFIG_EM_HISTORY) != 0) || defined CO_DOXYGEN
299#endif
300
301#if (((CO_CONFIG_EM)&CO_CONFIG_EM_STATUS_BITS) != 0) || defined CO_DOXYGEN
303#endif
304
305#if (((CO_CONFIG_EM)&CO_CONFIG_EM_CONSUMER) != 0) || defined CO_DOXYGEN
306 void (*pFunctSignalRx)(const uint16_t ident, const uint16_t errorCode, const uint8_t errorRegister,
307 const uint8_t errorBit, const uint32_t infoCode);
308#endif
309
310#if (((CO_CONFIG_EM)&CO_CONFIG_FLAG_CALLBACK_PRE) != 0) || defined CO_DOXYGEN
311 void (*pFunctSignalPre)(void* object);
313#endif
314} CO_EM_t;
315
345CO_ReturnError_t CO_EM_init(CO_EM_t* em, CO_CANmodule_t* CANdevTx, const OD_entry_t* OD_1001_errReg,
346#if (((CO_CONFIG_EM) & (CO_CONFIG_EM_PRODUCER | CO_CONFIG_EM_HISTORY)) != 0) || defined CO_DOXYGEN
347 CO_EM_fifo_t* fifo, uint8_t fifoSize,
348#endif
349#if (((CO_CONFIG_EM)&CO_CONFIG_EM_PRODUCER) != 0) || defined CO_DOXYGEN
350 OD_entry_t* OD_1014_cobIdEm, uint16_t CANdevTxIdx,
351#if (((CO_CONFIG_EM)&CO_CONFIG_EM_PROD_INHIBIT) != 0) || defined CO_DOXYGEN
352 OD_entry_t* OD_1015_InhTime,
353#endif
354#endif
355#if (((CO_CONFIG_EM)&CO_CONFIG_EM_HISTORY) != 0) || defined CO_DOXYGEN
356 OD_entry_t* OD_1003_preDefErr,
357#endif
358#if (((CO_CONFIG_EM)&CO_CONFIG_EM_STATUS_BITS) != 0) || defined CO_DOXYGEN
359 OD_entry_t* OD_statusBits,
360#endif
361#if (((CO_CONFIG_EM)&CO_CONFIG_EM_CONSUMER) != 0) || defined CO_DOXYGEN
362 CO_CANmodule_t* CANdevRx, uint16_t CANdevRxIdx,
363#endif
364 const uint8_t nodeId, uint32_t* errInfo);
365
366#if (((CO_CONFIG_EM)&CO_CONFIG_FLAG_CALLBACK_PRE) != 0) || defined CO_DOXYGEN
378void CO_EM_initCallbackPre(CO_EM_t* em, void* object, void (*pFunctSignal)(void* object));
379#endif
380
381#if (((CO_CONFIG_EM)&CO_CONFIG_EM_CONSUMER) != 0) || defined CO_DOXYGEN
396void CO_EM_initCallbackRx(CO_EM_t* em, void (*pFunctSignalRx)(const uint16_t ident, const uint16_t errorCode,
397 const uint8_t errorRegister, const uint8_t errorBit,
398 const uint32_t infoCode));
399#endif
400
412void CO_EM_process(CO_EM_t* em, bool_t NMTisPreOrOperational, uint32_t timeDifference_us, uint32_t* timerNext_us);
413
431void CO_error(CO_EM_t* em, bool_t setError, const uint8_t errorBit, uint16_t errorCode, uint32_t infoCode);
432
436#define CO_errorReport(em, errorBit, errorCode, infoCode) CO_error(em, true, errorBit, errorCode, infoCode)
437
441#define CO_errorReset(em, errorBit, infoCode) CO_error(em, false, errorBit, CO_EMC_NO_ERROR, infoCode)
442
453static inline bool_t
454CO_isError(CO_EM_t* em, const uint8_t errorBit) {
455 uint8_t index = errorBit >> 3;
456 uint8_t bitmask = 1 << (errorBit & 0x7);
457
458 return (em == NULL || index >= (CO_CONFIG_EM_ERR_STATUS_BITS_COUNT / 8U)
459 || (em->errorStatusBits[index] & bitmask) != 0)
460 ? true
461 : false;
462}
463
471static inline uint8_t
473 return (em == NULL || em->errorRegister == NULL) ? 0 : *em->errorRegister;
474}
475
476 /* CO_Emergency */
477
478#ifdef __cplusplus
479}
480#endif /* __cplusplus */
481
482#endif /* CO_EMERGENCY_H */
CANopen Object Dictionary interface.
Interface between CAN hardware and CANopenNode.
void CO_EM_initCallbackRx(CO_EM_t *em, void(*pFunctSignalRx)(const uint16_t ident, const uint16_t errorCode, const uint8_t errorRegister, const uint8_t errorBit, const uint32_t infoCode))
Initialize Emergency received callback function.
static bool_t CO_isError(CO_EM_t *em, const uint8_t errorBit)
Check specific error condition.
Definition CO_Emergency.h:454
void CO_error(CO_EM_t *em, bool_t setError, const uint8_t errorBit, uint16_t errorCode, uint32_t infoCode)
Set or reset error condition.
Definition CO_Emergency.c:639
void CO_EM_process(CO_EM_t *em, bool_t NMTisPreOrOperational, uint32_t timeDifference_us, uint32_t *timerNext_us)
Process Error control and Emergency object.
Definition CO_Emergency.c:487
void CO_EM_initCallbackPre(CO_EM_t *em, void *object, void(*pFunctSignal)(void *object))
Initialize Emergency callback function.
CO_ReturnError_t CO_EM_init(CO_EM_t *em, CO_CANmodule_t *CANdevTx, const OD_entry_t *OD_1001_errReg, CO_EM_fifo_t *fifo, uint8_t fifoSize, OD_entry_t *OD_1014_cobIdEm, uint16_t CANdevTxIdx, OD_entry_t *OD_1015_InhTime, OD_entry_t *OD_1003_preDefErr, OD_entry_t *OD_statusBits, CO_CANmodule_t *CANdevRx, uint16_t CANdevRxIdx, const uint8_t nodeId, uint32_t *errInfo)
Initialize Emergency object.
Definition CO_Emergency.c:300
static uint8_t CO_getErrorRegister(CO_EM_t *em)
Get error register.
Definition CO_Emergency.h:472
#define CO_CONFIG_EM_ERR_STATUS_BITS_COUNT
Maximum number of Error status bits.
Definition CO_config.h:255
#define NULL
NULL, for general usage.
Definition CO_driver.h:123
unsigned int uint16_t
UNSIGNED16 in CANopen (0006h), 16-bit unsigned integer.
Definition CO_driver.h:132
unsigned long int uint32_t
UNSIGNED32 in CANopen (0007h), 32-bit unsigned integer.
Definition CO_driver.h:133
#define true
Logical true, for general use.
Definition CO_driver.h:124
uint_fast8_t bool_t
Boolean data type for general use.
Definition CO_driver.h:126
unsigned char uint8_t
UNSIGNED8 in CANopen (0005h), 8-bit unsigned integer.
Definition CO_driver.h:131
CO_ReturnError_t
Return values of some CANopen functions.
Definition CO_driver.h:449
Complete CAN module object.
Definition CO_driver.h:268
Configuration object for CAN transmit message for specific CANopenNode Object.
Definition CO_driver.h:250
Fifo buffer for emergency producer and error history.
Definition CO_Emergency.h:248
Emergency object.
Definition CO_Emergency.h:259
OD_extension_t OD_1003_extension
Extension for OD object.
Definition CO_Emergency.h:298
OD_extension_t OD_statusBits_extension
Extension for OD object.
Definition CO_Emergency.h:302
OD_extension_t OD_1014_extension
Extension for OD object.
Definition CO_Emergency.h:285
uint8_t errorStatusBits[CO_CONFIG_EM_ERR_STATUS_BITS_COUNT/8U]
Bitfield for the internal indication of the error condition.
Definition CO_Emergency.h:260
uint8_t fifoPpPtr
Pointer for the fifo, where next emergency message has to be post-processed by CO_EM_process() functi...
Definition CO_Emergency.h:275
uint16_t CANerrorStatusOld
Old CAN error status bitfield.
Definition CO_Emergency.h:263
uint8_t fifoSize
Size of the above buffer, specified by CO_EM_init().
Definition CO_Emergency.h:272
uint16_t producerCanId
COB ID of emergency message, from Object dictionary.
Definition CO_Emergency.h:287
uint8_t fifoOverflow
Indication of overflow - messages in buffer are not post-processed.
Definition CO_Emergency.h:277
CO_CANmodule_t * CANdevTx
From CO_EM_init()
Definition CO_Emergency.h:264
uint32_t inhibitEmTimer
Internal timer for inhibit time.
Definition CO_Emergency.h:292
CO_CANtx_t * CANtxBuff
CAN transmit buffer.
Definition CO_Emergency.h:284
uint32_t inhibitEmTime_us
Inhibit time for emergency message, from Object dictionary.
Definition CO_Emergency.h:291
uint8_t fifoCount
Count of emergency messages in fifo, used for OD object 0x1003.
Definition CO_Emergency.h:278
uint16_t CANdevTxIdx
From CO_EM_init()
Definition CO_Emergency.h:288
uint8_t fifoWrPtr
Pointer for the fifo buffer, where next emergency message will be written by CO_error() function.
Definition CO_Emergency.h:273
void * functSignalObjectPre
From CO_EM_initCallbackPre() or NULL.
Definition CO_Emergency.h:312
uint8_t nodeId
Copy of CANopen node ID, from CO_EM_init()
Definition CO_Emergency.h:283
bool_t producerEnabled
True, if emergency producer is enabled, from Object dictionary.
Definition CO_Emergency.h:282
uint8_t * errorRegister
Pointer to error register in object dictionary at 0x1001,00.
Definition CO_Emergency.h:262
OD_extension_t OD_1015_extension
Extension for OD object.
Definition CO_Emergency.h:293
CO_EM_fifo_t * fifo
Internal circular FIFO buffer for storing pre-processed emergency messages.
Definition CO_Emergency.h:268
Object Dictionary entry for one OD object.
Definition CO_ODinterface.h:272
Extension of OD object, which can optionally be specified by application in initialization phase with...
Definition CO_ODinterface.h:245