Emergency
CANopen_301

## 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.

## Enumerations

enum | CO_errorRegister_t { CO_ERR_REG_GENERIC_ERR = 0x01U, CO_ERR_REG_CURRENT = 0x02U, CO_ERR_REG_VOLTAGE = 0x04U, CO_ERR_REG_TEMPERATURE = 0x08U, CO_ERR_REG_COMMUNICATION = 0x10U, CO_ERR_REG_DEV_PROFILE = 0x20U, CO_ERR_REG_RESERVED = 0x40U, CO_ERR_REG_MANUFACTURER = 0x80U }
| CANopen Error register. More...

enum

CO_EM_errorCode_t {
CO_EMC_NO_ERROR = 0x0000U, CO_EMC_GENERIC = 0x1000U, CO_EMC_CURRENT = 0x2000U, CO_EMC_CURRENT_INPUT = 0x2100U,
CO_EMC_CURRENT_INSIDE = 0x2200U, CO_EMC_CURRENT_OUTPUT = 0x2300U, CO_EMC_VOLTAGE = 0x3000U, CO_EMC_VOLTAGE_MAINS = 0x3100U,
CO_EMC_VOLTAGE_INSIDE = 0x3200U, CO_EMC_VOLTAGE_OUTPUT = 0x3300U, CO_EMC_TEMPERATURE = 0x4000U, CO_EMC_TEMP_AMBIENT = 0x4100U,
CO_EMC_TEMP_DEVICE = 0x4200U, CO_EMC_HARDWARE = 0x5000U, CO_EMC_SOFTWARE_DEVICE = 0x6000U, CO_EMC_SOFTWARE_INTERNAL = 0x6100U,
CO_EMC_SOFTWARE_USER = 0x6200U, CO_EMC_DATA_SET = 0x6300U, CO_EMC_ADDITIONAL_MODUL = 0x7000U, CO_EMC_MONITORING = 0x8000U,
CO_EMC_COMMUNICATION = 0x8100U, CO_EMC_CAN_OVERRUN = 0x8110U, CO_EMC_CAN_PASSIVE = 0x8120U, CO_EMC_HEARTBEAT = 0x8130U,
CO_EMC_BUS_OFF_RECOVERED = 0x8140U, CO_EMC_CAN_ID_COLLISION = 0x8150U, CO_EMC_PROTOCOL_ERROR = 0x8200U, CO_EMC_PDO_LENGTH = 0x8210U,
CO_EMC_PDO_LENGTH_EXC = 0x8220U, CO_EMC_DAM_MPDO = 0x8230U, CO_EMC_SYNC_DATA_LENGTH = 0x8240U, CO_EMC_RPDO_TIMEOUT = 0x8250U,
CO_EMC_TIME_DATA_LENGTH = 0x8260U, CO_EMC_EXTERNAL_ERROR = 0x9000U, CO_EMC_ADDITIONAL_FUNC = 0xF000U, CO_EMC_DEVICE_SPECIFIC = 0xFF00U,
CO_EMC401_OUT_CUR_HI = 0x2310U, CO_EMC401_OUT_SHORTED = 0x2320U, CO_EMC401_OUT_LOAD_DUMP = 0x2330U, CO_EMC401_IN_VOLT_HI = 0x3110U,
CO_EMC401_IN_VOLT_LOW = 0x3120U, CO_EMC401_INTERN_VOLT_HI = 0x3210U, CO_EMC401_INTERN_VOLT_LO = 0x3220U, CO_EMC401_OUT_VOLT_HIGH = 0x3310U,
CO_EMC401_OUT_VOLT_LOW = 0x3320U
}

| CANopen Error code. More...

enum

CO_EM_errorStatusBits_t {
CO_EM_NO_ERROR = 0x00U, CO_EM_CAN_BUS_WARNING = 0x01U, CO_EM_RXMSG_WRONG_LENGTH = 0x02U, CO_EM_RXMSG_OVERFLOW = 0x03U,
CO_EM_RPDO_WRONG_LENGTH = 0x04U, CO_EM_RPDO_OVERFLOW = 0x05U, CO_EM_CAN_RX_BUS_PASSIVE = 0x06U, CO_EM_CAN_TX_BUS_PASSIVE = 0x07U,
CO_EM_NMT_WRONG_COMMAND = 0x08U, CO_EM_TIME_TIMEOUT = 0x09U, CO_EM_TIME_LENGTH = 0x0AU, CO_EM_0B_unused = 0x0BU,
CO_EM_0C_unused = 0x0CU, CO_EM_0D_unused = 0x0DU, CO_EM_0E_unused = 0x0EU, CO_EM_0F_unused = 0x0FU,
CO_EM_10_unused = 0x10U, CO_EM_11_unused = 0x11U, CO_EM_CAN_TX_BUS_OFF = 0x12U, CO_EM_CAN_RXB_OVERFLOW = 0x13U,
CO_EM_CAN_TX_OVERFLOW = 0x14U, CO_EM_TPDO_OUTSIDE_WINDOW = 0x15U, CO_EM_16_unused = 0x16U, CO_EM_17_unused = 0x17U,
CO_EM_SYNC_TIME_OUT = 0x18U, CO_EM_SYNC_LENGTH = 0x19U, CO_EM_PDO_WRONG_MAPPING = 0x1AU, CO_EM_HEARTBEAT_CONSUMER = 0x1BU,
CO_EM_HB_CONSUMER_REMOTE_RESET = 0x1CU, CO_EM_1D_unused = 0x1DU, CO_EM_1E_unused = 0x1EU, CO_EM_1F_unused = 0x1FU,
CO_EM_EMERGENCY_BUFFER_FULL = 0x20U, CO_EM_21_unused = 0x21U, CO_EM_MICROCONTROLLER_RESET = 0x22U, CO_EM_23_unused = 0x23U,
CO_EM_24_unused = 0x24U, CO_EM_25_unused = 0x25U, CO_EM_26_unused = 0x26U, CO_EM_27_unused = 0x27U,
CO_EM_WRONG_ERROR_REPORT = 0x28U, CO_EM_ISR_TIMER_OVERFLOW = 0x29U, CO_EM_MEMORY_ALLOCATION_ERROR = 0x2AU, CO_EM_GENERIC_ERROR = 0x2BU,
CO_EM_GENERIC_SOFTWARE_ERROR = 0x2CU, CO_EM_INCONSISTENT_OBJECT_DICT = 0x2DU, CO_EM_CALCULATION_OF_PARAMETERS = 0x2EU, CO_EM_NON_VOLATILE_MEMORY = 0x2FU,
CO_EM_MANUFACTURER_START = 0x30U, CO_EM_MANUFACTURER_END = CO_CONFIG_EM_ERR_STATUS_BITS_COUNT - 1
}

| Error status bits. More...

## 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...

## Detailed Description

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.

### Emergency producer

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.

### Error history

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.

### Emergency consumer

If CO_CONFIG_EM has CO_CONFIG_EM_CONSUMER enabled, then callback can be registered by CO_EM_initCallbackRx() function.

## Enumeration Type Documentation

## CO_errorRegister_t

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.

Enumerator
CO_ERR_REG_GENERIC_ERR | bit 0, generic error
CO_ERR_REG_CURRENT | bit 1, current
CO_ERR_REG_VOLTAGE | bit 2, voltage
CO_ERR_REG_TEMPERATURE | bit 3, temperature
CO_ERR_REG_COMMUNICATION | bit 4, communication error
CO_ERR_REG_DEV_PROFILE | bit 5, device profile specific
CO_ERR_REG_RESERVED | bit 6, reserved (always 0)
CO_ERR_REG_MANUFACTURER | bit 7, manufacturer specific

## CO_EM_errorCode_t

enum CO_EM_errorCode_t

CANopen Error code.

Standard error codes according to CiA DS-301 and DS-401.

Enumerator
CO_EMC_NO_ERROR | 0x00xx, error Reset or No Error
CO_EMC_GENERIC | 0x10xx, Generic Error
CO_EMC_CURRENT | 0x20xx, Current
CO_EMC_CURRENT_INPUT | 0x21xx, Current, device input side
CO_EMC_CURRENT_INSIDE | 0x22xx, Current inside the device
CO_EMC_CURRENT_OUTPUT | 0x23xx, Current, device output side
CO_EMC_VOLTAGE | 0x30xx, Voltage
CO_EMC_VOLTAGE_MAINS | 0x31xx, Mains Voltage
CO_EMC_VOLTAGE_INSIDE | 0x32xx, Voltage inside the device
CO_EMC_VOLTAGE_OUTPUT | 0x33xx, Output Voltage
CO_EMC_TEMPERATURE | 0x40xx, Temperature
CO_EMC_TEMP_AMBIENT | 0x41xx, Ambient Temperature
CO_EMC_TEMP_DEVICE | 0x42xx, Device Temperature
CO_EMC_HARDWARE | 0x50xx, Device Hardware
CO_EMC_SOFTWARE_DEVICE | 0x60xx, Device Software
CO_EMC_SOFTWARE_INTERNAL | 0x61xx, Internal Software
CO_EMC_SOFTWARE_USER | 0x62xx, User Software
CO_EMC_DATA_SET | 0x63xx, Data Set
CO_EMC_ADDITIONAL_MODUL | 0x70xx, Additional Modules
CO_EMC_MONITORING | 0x80xx, Monitoring
CO_EMC_COMMUNICATION | 0x81xx, Communication
CO_EMC_CAN_OVERRUN | 0x8110, CAN Overrun (Objects lost)
CO_EMC_CAN_PASSIVE | 0x8120, CAN in Error Passive Mode
CO_EMC_HEARTBEAT | 0x8130, Life Guard Error or Heartbeat Error
CO_EMC_BUS_OFF_RECOVERED | 0x8140, recovered from bus off
CO_EMC_CAN_ID_COLLISION | 0x8150, CAN-ID collision
CO_EMC_PROTOCOL_ERROR | 0x82xx, Protocol Error
CO_EMC_PDO_LENGTH | 0x8210, PDO not processed due to length error
CO_EMC_PDO_LENGTH_EXC | 0x8220, PDO length exceeded
CO_EMC_DAM_MPDO | 0x8230, DAM MPDO not processed, destination object not available
CO_EMC_SYNC_DATA_LENGTH | 0x8240, Unexpected SYNC data length
CO_EMC_RPDO_TIMEOUT | 0x8250, RPDO timeout
CO_EMC_TIME_DATA_LENGTH | 0x8260, Unexpected TIME data length
CO_EMC_EXTERNAL_ERROR | 0x90xx, External Error
CO_EMC_ADDITIONAL_FUNC | 0xF0xx, Additional Functions
CO_EMC_DEVICE_SPECIFIC | 0xFFxx, Device specific
CO_EMC401_OUT_CUR_HI | 0x2310, DS401, Current at outputs too high (overload)
CO_EMC401_OUT_SHORTED | 0x2320, DS401, Short circuit at outputs
CO_EMC401_OUT_LOAD_DUMP | 0x2330, DS401, Load dump at outputs
CO_EMC401_IN_VOLT_HI | 0x3110, DS401, Input voltage too high
CO_EMC401_IN_VOLT_LOW | 0x3120, DS401, Input voltage too low
CO_EMC401_INTERN_VOLT_HI | 0x3210, DS401, Internal voltage too high
CO_EMC401_INTERN_VOLT_LO | 0x3220, DS401, Internal voltage too low
CO_EMC401_OUT_VOLT_HIGH | 0x3310, DS401, Output voltage too high
CO_EMC401_OUT_VOLT_LOW | 0x3320, DS401, Output voltage too low

## CO_EM_errorStatusBits_t

enum CO_EM_errorStatusBits_t

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.

## Function Documentation

## CO_EM_init()

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.

Parameters

  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)

Returns
  CO_ReturnError_t CO_ERROR_NO in case of success.

## CO_EM_initCallbackPre()

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.

Parameters

  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.

## CO_EM_initCallbackRx()

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.

Remarks
  Depending on the CAN driver implementation, this function is called inside an ISR or inside a mainline. Must be thread safe.

Parameters

  em | This object.
  pFunctSignalRx | Pointer to the callback function. Not called if NULL.

## CO_EM_process()

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.

Parameters

  | 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().

## CO_error()

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.

Parameters

  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.

## CO_isError()

static bool_t CO_isError | ( | CO_EM_t * | em,
|  | const uint8_t | errorBit
| ) |  |

inlinestatic

Check specific error condition.

Function returns true, if specific internal error is present.

Parameters

  em | Emergency object.
  errorBit | from CO_EM_errorStatusBits_t.

Returns
  true if Error is present.

## CO_getErrorRegister()

static uint8_t CO_getErrorRegister | ( | CO_EM_t * | em | ) |

inlinestatic

Get error register.

Parameters

  em | Emergency object.

Returns
  Error register or 0 if doesn't exist.