Add CO_errinfo() into CO_driver.h and driver_targets.
Add additional error info for 'CO_ERROR_OD_PARAMETERS'.
This commit is contained in:
parent
cf9fb2a547
commit
0e317dddf3
9 changed files with 54 additions and 7 deletions
|
|
@ -392,6 +392,7 @@ CO_ReturnError_t CO_EM_init(CO_EM_t *em,
|
|||
|
||||
/* get and verify "Error register" from Object Dictionary */
|
||||
if (OD_getPtr_u8(OD_1001_errReg, 0, &em->errorRegister) != ODR_OK) {
|
||||
CO_errinfo(CANdevTx, OD_getIndex(OD_1001_errReg));
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
*em->errorRegister = 0;
|
||||
|
|
@ -401,6 +402,7 @@ CO_ReturnError_t CO_EM_init(CO_EM_t *em,
|
|||
uint32_t COB_IDEmergency32;
|
||||
ODR_t odRet0 = OD_get_u32(OD_1014_cobIdEm, 0, &COB_IDEmergency32, true);
|
||||
if (odRet0 != ODR_OK || (COB_IDEmergency32 & 0x7FFFF800) != 0) {
|
||||
CO_errinfo(CANdevTx, OD_getIndex(OD_1014_cobIdEm));
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
|
||||
|
|
@ -412,6 +414,7 @@ CO_ReturnError_t CO_EM_init(CO_EM_t *em,
|
|||
(void *) em,
|
||||
OD_read_1014,
|
||||
OD_write_1014)) {
|
||||
CO_errinfo(CANdevTx, OD_getIndex(OD_1014_cobIdEm));
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
/* following two variables are used inside OD_read_1014 and OD_write_1014 */
|
||||
|
|
@ -428,6 +431,7 @@ CO_ReturnError_t CO_EM_init(CO_EM_t *em,
|
|||
(void *) em,
|
||||
OD_read_1014_default,
|
||||
OD_writeOriginal)) {
|
||||
CO_errinfo(CANdevTx, OD_getIndex(OD_1014_cobIdEm));
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@ CO_ReturnError_t CO_NMT_init(CO_NMT_t *NMT,
|
|||
/* get and verify required "Producer heartbeat time" from Object Dict. */
|
||||
uint16_t HBprodTime_ms;
|
||||
if (OD_get_u16(OD_1017_ProducerHbTime, 0, &HBprodTime_ms, true) != ODR_OK) {
|
||||
CO_errinfo(NMT_CANdevRx, OD_getIndex(OD_1017_ProducerHbTime));
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
NMT->HBproducerTime_us = (uint32_t)HBprodTime_ms * 1000;
|
||||
|
|
|
|||
|
|
@ -284,6 +284,7 @@ CO_ReturnError_t CO_SDOclient_init(CO_SDOclient_t *SDO_C,
|
|||
if (odRet0 != ODR_OK || maxSubIndex != 3
|
||||
|| odRet1 != ODR_OK || odRet2 != ODR_OK || odRet3 != ODR_OK
|
||||
) {
|
||||
CO_errinfo(CANdevTx, OD_getIndex(OD_1280_SDOcliPar));
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
|
||||
|
|
@ -292,6 +293,7 @@ CO_ReturnError_t CO_SDOclient_init(CO_SDOclient_t *SDO_C,
|
|||
(void *)SDO_C,
|
||||
OD_readOriginal,
|
||||
OD_write_1280)) {
|
||||
CO_errinfo(CANdevTx, OD_getIndex(OD_1280_SDOcliPar));
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -388,9 +388,11 @@ CO_ReturnError_t CO_SDOserver_init(CO_SDOserver_t *SDO,
|
|||
if (!OD_extensionIO_init(OD_1200_SDOsrvPar,
|
||||
(void *) SDO,
|
||||
OD_read_1200_default,
|
||||
NULL)) {
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
NULL)
|
||||
) {
|
||||
CO_errinfo(CANdevTx, OD_getIndex(OD_1200_SDOsrvPar));
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
}
|
||||
else if (OD_getIndex(OD_1200_SDOsrvPar) > OD_H1200_SDO_SERVER_1_PARAM
|
||||
&& OD_getIndex(OD_1200_SDOsrvPar) <= (OD_H1200_SDO_SERVER_1_PARAM+0x7F)
|
||||
|
|
@ -409,6 +411,7 @@ CO_ReturnError_t CO_SDOserver_init(CO_SDOserver_t *SDO,
|
|||
if (odRet0 != ODR_OK || (maxSubIndex != 2 && maxSubIndex != 3)
|
||||
|| odRet1 != ODR_OK || odRet2 != ODR_OK
|
||||
) {
|
||||
CO_errinfo(CANdevTx, OD_getIndex(OD_1200_SDOsrvPar));
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
|
||||
|
|
@ -422,9 +425,11 @@ CO_ReturnError_t CO_SDOserver_init(CO_SDOserver_t *SDO,
|
|||
if (!OD_extensionIO_init(OD_1200_SDOsrvPar,
|
||||
(void *) SDO,
|
||||
OD_readOriginal,
|
||||
OD_write_1201_additional)) {
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
OD_write_1201_additional)
|
||||
) {
|
||||
CO_errinfo(CANdevTx, OD_getIndex(OD_1200_SDOsrvPar));
|
||||
return CO_ERROR_OD_PARAMETERS;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -324,6 +324,7 @@ typedef struct {
|
|||
volatile uint16_t CANtxCount; /**< Number of messages in transmit
|
||||
buffer, which are waiting to be copied to the CAN module */
|
||||
uint32_t errOld; /**< Previous state of CAN errors */
|
||||
int32_t errinfo; /**< For use with @ref CO_errinfo() */
|
||||
} CO_CANmodule_t;
|
||||
|
||||
|
||||
|
|
@ -393,6 +394,24 @@ typedef struct {
|
|||
#endif /* CO_DOXYGEN */
|
||||
|
||||
|
||||
/** Macro for passing additional information about error.
|
||||
*
|
||||
* This macro is called from several CANopen init functions, which returns
|
||||
* @ref CO_ReturnError_t.
|
||||
*
|
||||
* CO_driver_target.h may implement this macro. Usually macro only sets
|
||||
* CANmodule->errinfo to err. Application may then use CANmodule->errinfo to
|
||||
* determine the reason of failure. errinfo must be type of int32_t. By default
|
||||
* macro does not record anything.
|
||||
*
|
||||
* CO_errinfo is called in following @ref CO_ReturnError_t reasons:
|
||||
* - 'CO_ERROR_OD_PARAMETERS' - Index of erroneous OD parameter.
|
||||
*/
|
||||
#ifndef CO_errinfo
|
||||
#define CO_errinfo(CANmodule, err)
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Default CANopen identifiers.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -182,6 +182,10 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
|
||||
/* Macro for passing additional information about error, see CO_driver.h. */
|
||||
#define CO_errinfo(CANmodule, err) CANmodule->errinfo = err
|
||||
|
||||
|
||||
/* Basic definitions. If big endian, CO_SWAP_xx macros must swap bytes. */
|
||||
#define CO_LITTLE_ENDIAN
|
||||
#define CO_SWAP_16(x) x
|
||||
|
|
@ -234,6 +238,7 @@ typedef struct {
|
|||
volatile bool_t firstCANtxMessage;
|
||||
volatile uint16_t CANtxCount;
|
||||
uint32_t errOld;
|
||||
int32_t errinfo;
|
||||
} CO_CANmodule_t;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -194,6 +194,9 @@ extern "C" {
|
|||
* Linux socketCAN specific @ref CO_driver definitions for CANopenNode.
|
||||
*/
|
||||
|
||||
/* Macro for passing additional information about error, see CO_driver.h. */
|
||||
#define CO_errinfo(CANmodule, err) CANmodule->errinfo = err
|
||||
|
||||
/**
|
||||
* Multi interface support
|
||||
*
|
||||
|
|
@ -347,6 +350,7 @@ typedef struct {
|
|||
CO_CANtx_t *txArray;
|
||||
uint16_t txSize;
|
||||
uint16_t CANerrorStatus;
|
||||
int32_t errinfo;
|
||||
volatile bool_t CANnormal;
|
||||
int epoll_fd; /* File descriptor for epoll, which waits for
|
||||
CAN receive event */
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ extern "C" {
|
|||
#define DBG_WRONG_PRIORITY "(%s) Wrong RT priority \"%d\"", __func__
|
||||
#define DBG_NO_CAN_DEVICE "(%s) Can't find CAN device \"%s\"", __func__
|
||||
#define DBG_OBJECT_DICTIONARY "(%s) Error in Object Dictionary \"%s\"", __func__
|
||||
#define DBG_OD_ENTRY "(%s) Error in Object Dictionary entry: 0x%X", __func__
|
||||
#define DBG_CAN_OPEN "(%s) CANopen error in %s, err=%d", __func__
|
||||
#define DBG_CAN_OPEN_INFO "CANopen device, Node ID = 0x%02X, %s"
|
||||
|
||||
|
|
|
|||
|
|
@ -500,7 +500,13 @@ int main (int argc, char *argv[]) {
|
|||
SDO_TIMEOUT_TIME, /* SDOtimeoutTime_ms */
|
||||
CO_activeNodeId);
|
||||
if(err != CO_ERROR_NO && err != CO_ERROR_NODE_ID_UNCONFIGURED_LSS) {
|
||||
log_printf(LOG_CRIT, DBG_CAN_OPEN, "CO_CANopenInit()", err);
|
||||
if (err == CO_ERROR_OD_PARAMETERS) {
|
||||
log_printf(LOG_CRIT, DBG_OD_ENTRY,
|
||||
(uint16_t)CO->CANmodule->errinfo);
|
||||
}
|
||||
else {
|
||||
log_printf(LOG_CRIT, DBG_CAN_OPEN, "CO_CANopenInit()", err);
|
||||
}
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue