Files | |
file | CO_Emergency.h |
CANopen Emergency protocol. | |
Data Structures | |
struct | CO_EM_t |
Emergency object. More... | |
Macros | |
#define | CO_errorReport(em, errorBit, errorCode, infoCode) CO_error(em, true, errorBit, errorCode, infoCode) |
Report error condition, for description of parameters see CO_error. | |
#define | CO_errorReset(em, errorBit, infoCode) CO_error(em, false, errorBit, CO_EMC_NO_ERROR, infoCode) |
Reset error condition, for description of parameters see CO_error. | |
Functions | |
CO_ReturnError_t | CO_EM_init (CO_EM_t *em, const OD_entry_t *OD_1001_errReg, const OD_entry_t *OD_1014_cobIdEm, CO_CANmodule_t *CANdevTx, uint16_t CANdevTxIdx, const OD_entry_t *OD_1015_InhTime, const OD_entry_t *OD_1003_preDefErr, const OD_entry_t *OD_statusBits, CO_CANmodule_t *CANdevRx, uint16_t CANdevRxIdx, const uint8_t nodeId) |
Initialize Emergency object. More... | |
void | CO_EM_initCallbackPre (CO_EM_t *em, void *object, void(*pFunctSignal)(void *object)) |
Initialize Emergency callback function. More... | |
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. More... | |
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. More... | |
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. More... | |
static bool_t | CO_isError (CO_EM_t *em, const uint8_t errorBit) |
Check specific error condition. More... | |
static uint8_t | CO_getErrorRegister (CO_EM_t *em) |
Get error register. More... | |
CANopen Emergency protocol.
Error control and Emergency is used for control internal error state and for sending a CANopen Emergency message.
In case of error condition stack or application calls CO_errorReport() function with indication of the error. Specific error condition is reported (with CANopen Emergency message) only the first time after it occurs. Internal state of specific error condition is indicated by internal bitfield variable, with space for maximum CO_CONFIG_EM_ERR_STATUS_BITS_COUNT bits. Meaning for each bit is described by CO_EM_errorStatusBits_t. Specific error condition can be reset by CO_errorReset() function. In that case Emergency message is sent with CO_EM_NO_ERROR indication.
Some error conditions are informative and some are critical. Critical error conditions set the corresponding bit in CO_errorRegister_t. Critical error conditions for generic error are specified by CO_CONFIG_ERR_CONDITION_GENERIC macro. Similar macros are defined for other error bits in in CO_errorRegister_t.
If CO_CONFIG_EM has CO_CONFIG_EM_PRODUCER enabled, then CANopen Emergency message will be sent on each change of any error condition. Emergency message contents are:
Byte | Description |
---|---|
0..1 | CO_EM_errorCode_t |
2 | CO_errorRegister_t |
3 | Index of error condition (see CO_EM_errorStatusBits_t). |
4..7 | Additional informative argument to CO_errorReport() function. |
If CO_CONFIG_EM has CO_CONFIG_EM_HISTORY enabled, then latest errors can be read from Pre Defined Error Field (object dictionary, index 0x1003). Contents corresponds to bytes 0..3 from the Emergency message.
If CO_CONFIG_EM has CO_CONFIG_EM_CONSUMER enabled, then callback can be registered by CO_EM_initCallbackRx() function.
enum CO_errorRegister_t |
CANopen Error register.
Mandatory for CANopen, resides in object dictionary, index 0x1001.
Error register is calculated from internal bitfield variable, critical bits. See CO_EM_errorStatusBits_t and Emergency producer/consumer for error condition macros.
Internal errors may prevent device to stay in NMT Operational state and changes may switch between the states. See CO_NMT_control_t for details.
enum CO_EM_errorCode_t |
CANopen Error code.
Standard error codes according to CiA DS-301 and DS-401.
Error status bits.
Bits for internal indication of the error condition. Each error condition is specified by unique index from 0x00 up to 0xFF.
If specific error occurs in the stack or in the application, CO_errorReport() sets specific bit in the errorStatusBit variable from CO_EM_t. If bit was already set, function returns without any action. Otherwise it prepares emergency message.
Maximum size (in bits) of the errorStatusBit variable is specified by CO_CONFIG_EM_ERR_STATUS_BITS_COUNT (set to 10*8 bits by default). Stack uses first 6 bytes. Additional 4 bytes are pre-defined for manufacturer or device specific error indications, by default.
Enumerator | |
---|---|
CO_EM_NO_ERROR | 0x00, Error Reset or No Error |
CO_EM_CAN_BUS_WARNING | 0x01, communication, info, CAN bus warning limit reached |
CO_EM_RXMSG_WRONG_LENGTH | 0x02, communication, info, Wrong data length of the received CAN message |
CO_EM_RXMSG_OVERFLOW | 0x03, communication, info, Previous received CAN message wasn't processed yet |
CO_EM_RPDO_WRONG_LENGTH | 0x04, communication, info, Wrong data length of received PDO |
CO_EM_RPDO_OVERFLOW | 0x05, communication, info, Previous received PDO wasn't processed yet |
CO_EM_CAN_RX_BUS_PASSIVE | 0x06, communication, info, CAN receive bus is passive |
CO_EM_CAN_TX_BUS_PASSIVE | 0x07, communication, info, CAN transmit bus is passive |
CO_EM_NMT_WRONG_COMMAND | 0x08, communication, info, Wrong NMT command received |
CO_EM_TIME_TIMEOUT | 0x09, communication, info, TIME message timeout |
CO_EM_TIME_LENGTH | 0x0A, communication, info, Unexpected TIME data length |
CO_EM_0B_unused | 0x0B, communication, info, (unused) |
CO_EM_0C_unused | 0x0C, communication, info, (unused) |
CO_EM_0D_unused | 0x0D, communication, info, (unused) |
CO_EM_0E_unused | 0x0E, communication, info, (unused) |
CO_EM_0F_unused | 0x0F, communication, info, (unused) |
CO_EM_10_unused | 0x10, communication, critical, (unused) |
CO_EM_11_unused | 0x11, communication, critical, (unused) |
CO_EM_CAN_TX_BUS_OFF | 0x12, communication, critical, CAN transmit bus is off |
CO_EM_CAN_RXB_OVERFLOW | 0x13, communication, critical, CAN module receive buffer has overflowed |
CO_EM_CAN_TX_OVERFLOW | 0x14, communication, critical, CAN transmit buffer has overflowed |
CO_EM_TPDO_OUTSIDE_WINDOW | 0x15, communication, critical, TPDO is outside SYNC window |
CO_EM_16_unused | 0x16, communication, critical, (unused) |
CO_EM_17_unused | 0x17, communication, critical, (unused) |
CO_EM_SYNC_TIME_OUT | 0x18, communication, critical, SYNC message timeout |
CO_EM_SYNC_LENGTH | 0x19, communication, critical, Unexpected SYNC data length |
CO_EM_PDO_WRONG_MAPPING | 0x1A, communication, critical, Error with PDO mapping |
CO_EM_HEARTBEAT_CONSUMER | 0x1B, communication, critical, Heartbeat consumer timeout |
CO_EM_HB_CONSUMER_REMOTE_RESET | 0x1C, communication, critical, Heartbeat consumer detected remote node reset |
CO_EM_1D_unused | 0x1D, communication, critical, (unused) |
CO_EM_1E_unused | 0x1E, communication, critical, (unused) |
CO_EM_1F_unused | 0x1F, communication, critical, (unused) |
CO_EM_EMERGENCY_BUFFER_FULL | 0x20, generic, info, Emergency buffer is full, Emergency message wasn't sent |
CO_EM_21_unused | 0x21, generic, info, (unused) |
CO_EM_MICROCONTROLLER_RESET | 0x22, generic, info, Microcontroller has just started |
CO_EM_23_unused | 0x23, generic, info, (unused) |
CO_EM_24_unused | 0x24, generic, info, (unused) |
CO_EM_25_unused | 0x25, generic, info, (unused) |
CO_EM_26_unused | 0x26, generic, info, (unused) |
CO_EM_27_unused | 0x27, generic, info, (unused) |
CO_EM_WRONG_ERROR_REPORT | 0x28, generic, critical, Wrong parameters to CO_errorReport() function |
CO_EM_ISR_TIMER_OVERFLOW | 0x29, generic, critical, Timer task has overflowed |
CO_EM_MEMORY_ALLOCATION_ERROR | 0x2A, generic, critical, Unable to allocate memory for objects |
CO_EM_GENERIC_ERROR | 0x2B, generic, critical, Generic error, test usage |
CO_EM_GENERIC_SOFTWARE_ERROR | 0x2C, generic, critical, Software error |
CO_EM_INCONSISTENT_OBJECT_DICT | 0x2D, generic, critical, Object dictionary does not match the software |
CO_EM_CALCULATION_OF_PARAMETERS | 0x2E, generic, critical, Error in calculation of device parameters |
CO_EM_NON_VOLATILE_MEMORY | 0x2F, generic, critical, Error with access to non volatile device memory |
CO_EM_MANUFACTURER_START | 0x30+, manufacturer, info or critical, Error status buts, free to use by manufacturer. By default bits 0x30..0x3F are set as informational and bits 0x40..0x4F are set as critical. Manufacturer critical bits sets the error register, as specified by CO_CONFIG_ERR_CONDITION_MANUFACTURER |
CO_EM_MANUFACTURER_END | (CO_CONFIG_EM_ERR_STATUS_BITS_COUNT - 1), largest value of the Error status bit. |
CO_ReturnError_t CO_EM_init | ( | CO_EM_t * | em, |
const OD_entry_t * | OD_1001_errReg, | ||
const OD_entry_t * | OD_1014_cobIdEm, | ||
CO_CANmodule_t * | CANdevTx, | ||
uint16_t | CANdevTxIdx, | ||
const OD_entry_t * | OD_1015_InhTime, | ||
const OD_entry_t * | OD_1003_preDefErr, | ||
const OD_entry_t * | OD_statusBits, | ||
CO_CANmodule_t * | CANdevRx, | ||
uint16_t | CANdevRxIdx, | ||
const uint8_t | nodeId | ||
) |
Initialize Emergency object.
Function must be called in the communication reset section.
em | This object will be initialized. |
OD_1001_errReg | OD entry for 0x1001 - "Error register", entry is required, without IO extension. |
OD_1014_cobIdEm | OD entry for 0x1014 - "COB-ID EMCY", entry is required, IO extension is required. |
CANdevTx | CAN device for Emergency transmission. |
CANdevTxIdx | Index of transmit buffer in the above CAN device. |
OD_1015_InhTime | OD entry for 0x1015 - "Inhibit time EMCY", entry is optional (can be NULL), IO extension is optional for runtime configuration. |
OD_1003_preDefErr | OD entry for 0x1003 - "Pre-defined error field". Emergency object has own memory buffer for this entry. Entry is optional, IO extension is required. |
OD_statusBits | Custom OD entry for accessing errorStatusBits from CO_EM_t. Entry must have variable of size (CO_CONFIG_EM_ERR_STATUS_BITS_COUNT/8) bytes available for read/write access on subindex 0. Emergency object has own memory buffer for this entry. Entry is optional, IO extension is required. |
CANdevRx | CAN device for Emergency consumer reception. |
CANdevRxIdx | Index of receive buffer in the above CAN device. |
nodeId | CANopen node ID of this device (for default emergency producer) |
void CO_EM_initCallbackPre | ( | CO_EM_t * | em, |
void * | object, | ||
void(*)(void *object) | pFunctSignal | ||
) |
Initialize Emergency callback function.
Function initializes optional callback function, which should immediately start processing of CO_EM_process() function. Callback is called from CO_errorReport() or CO_errorReset() function. Those functions are fast and may be called from any thread. Callback should immediately start mainline thread, which calls CO_EM_process() function.
em | 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_EM_initCallbackRx | ( | CO_EM_t * | em, |
void(*)(const uint16_t ident, const uint16_t errorCode, const uint8_t errorRegister, const uint8_t errorBit, const uint32_t infoCode) | pFunctSignalRx | ||
) |
Initialize Emergency received callback function.
Function initializes optional callback function, which executes after error condition is received.
ident argument from callback contains CAN-ID of the emergency message. If ident == 0, then emergency message was sent from this device.
em | This object. |
pFunctSignalRx | Pointer to the callback function. Not called if NULL. |
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.
Function must be called cyclically. It verifies some communication errors, calculates OD object 0x1001 - "Error register" and sends emergency message if necessary.
em | This object. | |
NMTisPreOrOperational | True if this node is NMT_PRE_OPERATIONAL or NMT_OPERATIONAL state. | |
timeDifference_us | Time difference from previous function call in [microseconds]. | |
[out] | timerNext_us | info to OS - see CO_process(). |
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.
Function can be called on any error condition inside CANopen stack or application. Function first checks change of error condition (setError is true and error bit wasn't set or setError is false and error bit was set before). If changed, then Emergency message is prepared and record in history is added. Emergency message is later sent by CO_EM_process() function.
Function is short and thread safe.
em | Emergency object. |
setError | True if error occurred or false if error resolved. |
errorBit | from CO_EM_errorStatusBits_t. |
errorCode | from CO_EM_errorCode_t. |
infoCode | 32 bit value is passed to bytes 4...7 of the Emergency message. It contains optional additional information. |
Check specific error condition.
Function returns true, if specific internal error is present.
em | Emergency object. |
errorBit | from CO_EM_errorStatusBits_t. |