Changed for two callbacks, as one is called inside ISR context. This also keeps backward compatibility for current useres that don't need RX EMCY events
This commit is contained in:
parent
fa5f81e0a9
commit
e336b3ad26
2 changed files with 56 additions and 23 deletions
|
|
@ -64,14 +64,14 @@ static void CO_EM_receive(void *object, const CO_CANrxMsg_t *msg){
|
|||
|
||||
em = (CO_EM_t*)object;
|
||||
|
||||
if(em->pFunctSignal != NULL){
|
||||
if(em!=NULL && em->pFunctSignalRx!=NULL){
|
||||
CO_memcpySwap2(&errorCode, &msg->data[0]);
|
||||
CO_memcpySwap4(&infoCode, &msg->data[4]);
|
||||
em->pFunctSignal(msg->ident & 0x07FFU,
|
||||
errorCode,
|
||||
msg->data[2],
|
||||
msg->data[3],
|
||||
infoCode);
|
||||
em->pFunctSignalRx(msg->ident & 0x07FFU,
|
||||
errorCode,
|
||||
msg->data[2],
|
||||
msg->data[3],
|
||||
infoCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -178,6 +178,7 @@ CO_ReturnError_t CO_EM_init(
|
|||
em->bufFull = 0U;
|
||||
em->wrongErrorReport = 0U;
|
||||
em->pFunctSignal = NULL;
|
||||
em->pFunctSignalRx = NULL;
|
||||
emPr->em = em;
|
||||
emPr->errorRegister = errorRegister;
|
||||
emPr->preDefErr = preDefErr;
|
||||
|
|
@ -222,11 +223,7 @@ CO_ReturnError_t CO_EM_init(
|
|||
/******************************************************************************/
|
||||
void CO_EM_initCallback(
|
||||
CO_EM_t *em,
|
||||
void (*pFunctSignal)(const uint16_t ident,
|
||||
const uint16_t errorCode,
|
||||
const uint8_t errorRegister,
|
||||
const uint8_t errorBit,
|
||||
const uint32_t infoCode))
|
||||
void (*pFunctSignal)(void))
|
||||
{
|
||||
if(em != NULL){
|
||||
em->pFunctSignal = pFunctSignal;
|
||||
|
|
@ -234,6 +231,21 @@ void CO_EM_initCallback(
|
|||
}
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
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))
|
||||
{
|
||||
if(em != NULL){
|
||||
em->pFunctSignalRx = pFunctSignalRx;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
void CO_EM_process(
|
||||
CO_EMpr_t *emPr,
|
||||
|
|
@ -395,7 +407,7 @@ void CO_errorReport(CO_EM_t *em, const uint8_t errorBit, const uint16_t errorCod
|
|||
|
||||
/* Optional signal to RTOS, which can resume task, which handles CO_EM_process */
|
||||
if(em->pFunctSignal != NULL) {
|
||||
em->pFunctSignal(0, errorCode, 0, errorBit, infoCode);
|
||||
em->pFunctSignal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -454,7 +466,7 @@ void CO_errorReset(CO_EM_t *em, const uint8_t errorBit, const uint32_t infoCode)
|
|||
|
||||
/* Optional signal to RTOS, which can resume task, which handles CO_EM_process */
|
||||
if(em->pFunctSignal != NULL) {
|
||||
em->pFunctSignal(0, 0, 0, errorBit, infoCode);
|
||||
em->pFunctSignal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -283,11 +283,13 @@ typedef struct{
|
|||
uint8_t wrongErrorReport; /**< Error in arguments to CO_errorReport() */
|
||||
|
||||
/** From CO_EM_initCallback() or NULL */
|
||||
void (*pFunctSignal)(const uint16_t ident,
|
||||
const uint16_t errorCode,
|
||||
const uint8_t errorRegister,
|
||||
const uint8_t errorBit,
|
||||
const uint32_t infoCode);
|
||||
void (*pFunctSignal)(void);
|
||||
/** From CO_EM_initCallbackRx() or NULL */
|
||||
void (*pFunctSignalRx)(const uint16_t ident,
|
||||
const uint16_t errorCode,
|
||||
const uint8_t errorRegister,
|
||||
const uint8_t errorBit,
|
||||
const uint32_t infoCode);
|
||||
}CO_EM_t;
|
||||
|
||||
|
||||
|
|
@ -414,12 +416,31 @@ CO_ReturnError_t CO_EM_init(
|
|||
* @param pFunctSignal Pointer to the callback function. Not called if NULL.
|
||||
*/
|
||||
void CO_EM_initCallback(
|
||||
CO_EM_t *em,
|
||||
void (*pFunctSignal)(void));
|
||||
|
||||
|
||||
/**
|
||||
* Initialize Emergency received callback function.
|
||||
*
|
||||
* Function initializes optional callback function, which executes after
|
||||
* error condition is received. Function may wake up external task,
|
||||
* which processes mainline CANopen functions.
|
||||
*
|
||||
* @remark Depending on the CAN driver implementation, this function is called
|
||||
* inside an ISR
|
||||
*
|
||||
* @param em This object.
|
||||
* @param pFunctSignal Pointer to the callback function. Not called if NULL.
|
||||
*/
|
||||
void CO_EM_initCallbackRx(
|
||||
CO_EM_t *em,
|
||||
void (*pFunctSignal)(const uint16_t ident,
|
||||
const uint16_t errorCode,
|
||||
const uint8_t errorRegister,
|
||||
const uint8_t errorBit,
|
||||
const uint32_t infoCode));
|
||||
void (*pFunctSignalRx)(const uint16_t ident,
|
||||
const uint16_t errorCode,
|
||||
const uint8_t errorRegister,
|
||||
const uint8_t errorBit,
|
||||
const uint32_t infoCode));
|
||||
|
||||
|
||||
/**
|
||||
* Process Error control and Emergency object.
|
||||
|
|
|
|||
Loading…
Reference in a new issue