/*! Sets a new error with code errCode. Also sets corresponding bits in Error register (1001h)
**
**
** @param d
** @param errCode Code of the error
** @param errRegMask
** @param addInfo
** @return 1 if error, 0 if successful
*/
UNS8 EMCY_setError(CO_Data* d, UNS16 errCode, UNS8 errRegMask, UNS16 addInfo)
{
UNS8 index;
UNS8 errRegister_tmp;
for (index = 0; index < EMCY_MAX_ERRORS; ++index)
{
if (d->error_data[index].errCode == errCode) /* error already registered */
{
if (d->error_data[index].active)
{
MSG_WAR(0x3052, "EMCY message already sent", 0);
return 0;
} else d->error_data[index].active = 1; /* set as active error */
break;
}
}
if (index == EMCY_MAX_ERRORS) /* if errCode not already registered */
for (index = 0; index < EMCY_MAX_ERRORS; ++index) if (d->error_data[index].active == 0) break; /* find first inactive error */
if (index == EMCY_MAX_ERRORS) /* error_data full */
{
MSG_ERR(0x3053, "error_data full", 0);
return 1;
}
d->error_data[index].errCode = errCode;
d->error_data[index].errRegMask = errRegMask;
d->error_data[index].active = 1;
/* set the new state in the error state machine */
d->error_state = Error_occurred;
/* set Error Register (1001h) */
for (index = 0, errRegister_tmp = 0; index < EMCY_MAX_ERRORS; ++index)
if (d->error_data[index].active == 1) errRegister_tmp |= d->error_data[index].errRegMask;
*d->error_register = errRegister_tmp;
/* set Pre-defined Error Field (1003h) */
for (index = d->error_history_size - 1; index > 0; --index)
*(d->error_first_element + index) = *(d->error_first_element + index - 1);
*(d->error_first_element) = errCode | ((UNS32)addInfo << 16);
if(*d->error_number < d->error_history_size) ++(*d->error_number);
/* send EMCY message */
if (d->CurrentCommunicationState.csEmergency)
return sendEMCY(d, errCode, *d->error_register, NULL);
else return 1;
}对这个canfestival的源码有点疑惑,有没有做过工程用过这个传递紧急报文的,想让大神给我解惑解惑。
|