/** * Hardware error ISR for CAN * * @param unit CAN controller number( from 0 ) */ static void Can_ErrIsr( int unit ) { CAN_HW_t *canHw = GetController(unit); Can_UnitType *canUnit = CAN_GET_PRIVATE_DATA(unit); Can_Arc_ErrorType err; err.R = 0; // Check wake up if(SET == CAN_GetITStatus(canHw, CAN_IT_WKU)){ Can_WakeIsr(unit); CAN_ClearITPendingBit(canHw, CAN_IT_WKU); } if(SET == CAN_GetITStatus(canHw, CAN_IT_BOF)){ canUnit->stats.boffCnt++; CanIf_ControllerBusOff(unit); Can_SetControllerMode(unit, CAN_T_STOP); // CANIF272 Can_AbortTx( canHw, canUnit ); // CANIF273 // Clear int CAN_ClearITPendingBit(canHw, CAN_IT_BOF); } if (err.R != 0) { CanIf_Arc_Error( unit, err ); } }
/** * Hardware wake ISR for CAN * * @param unit CAN controller number( from 0 ) */ static void Can_WakeIsr( int unit ) { //CanIf_ControllerWakeup(unit); // 269,270,271 Can_SetControllerMode(unit, CAN_T_STOP); // TODO EcuM_CheckWakeup(); }
Std_ReturnType CanIf_SetControllerMode(uint8 Controller, CanIf_ControllerModeType ControllerMode) { // We call this a CanIf channel. Hopefully makes it easier to follow. CanIf_Arc_ChannelIdType channel = (CanIf_Arc_ChannelIdType) Controller; CanIf_ControllerModeType oldMode; VALIDATE( CanIf_Global.initRun, CANIF_SET_CONTROLLER_MODE_ID, CANIF_E_UNINIT ); VALIDATE( channel < CANIF_CHANNEL_CNT, CANIF_SET_CONTROLLER_MODE_ID, CANIF_E_PARAM_CONTROLLER ); oldMode = CanIf_Global.channelData[channel].ControllerMode; if (oldMode == CANIF_CS_UNINIT) { VALIDATE(FALSE, CANIF_SET_CONTROLLER_MODE_ID, CANIF_E_UNINIT); // See figure 32, 33 return E_NOT_OK; } CanControllerIdType canControllerId = ARC_GET_CHANNEL_CONTROLLER(Controller); switch (ControllerMode) { case CANIF_CS_STARTED: // Figure 32 { switch (oldMode) { case CANIF_CS_SLEEP: if (Can_SetControllerMode(canControllerId, CAN_T_STOP) == CAN_NOT_OK){ return E_NOT_OK; } CanIf_Global.channelData[channel].ControllerMode = CANIF_CS_STOPPED; break; default: // Just fall through break; } CanIf_SetPduMode(channel, CANIF_SET_ONLINE); if (Can_SetControllerMode(canControllerId, CAN_T_START) == CAN_NOT_OK){ return E_NOT_OK; } CanIf_Global.channelData[channel].ControllerMode = CANIF_CS_STARTED; } break; case CANIF_CS_SLEEP: // Figure 33 { switch (oldMode) { case CANIF_CS_STARTED: if (Can_SetControllerMode(canControllerId, CAN_T_STOP) == CAN_NOT_OK){ return E_NOT_OK; } CanIf_Global.channelData[channel].ControllerMode = CANIF_CS_STOPPED; break; default: // Just fall through for other cases break; } if (Can_SetControllerMode(canControllerId, CAN_T_SLEEP) == CAN_NOT_OK){ return E_NOT_OK; } CanIf_Global.channelData[channel].ControllerMode = CANIF_CS_SLEEP; break; } case CANIF_CS_STOPPED: { switch (oldMode) { case CANIF_CS_SLEEP: if (Can_SetControllerMode(canControllerId, CAN_T_WAKEUP) == CAN_NOT_OK){ return E_NOT_OK; } break; default: // Just fall through for other cases break; } CanIf_SetPduMode(channel, CANIF_SET_OFFLINE); if (Can_SetControllerMode(canControllerId, CAN_T_STOP) == CAN_NOT_OK){ return E_NOT_OK; } CanIf_Global.channelData[channel].ControllerMode = CANIF_CS_STOPPED; break; } case CANIF_CS_UNINIT: // Just fall through break; } return E_OK; }