//**************************************************************************** // @Function void CAN_vGetMsgObj(ubyte ubObjNr, stCAN_SWObj *pstObj) // //---------------------------------------------------------------------------- // @Description This function fills the forwarded SW message object with // the content of the chosen HW message object. // // The structure of the SW message object is defined in the // header file CAN.H (see stCAN_SWObj). // //---------------------------------------------------------------------------- // @Returnvalue None // //---------------------------------------------------------------------------- // @Parameters ubObjNr: // Number of the message object to be read (0-31) // @Parameters *pstObj: // Pointer on a message object to be filled by this function // //---------------------------------------------------------------------------- // @Date 11.05.2007 // //**************************************************************************** // USER CODE BEGIN (GetMsgObj,1) // USER CODE END void CAN_vGetMsgObj(ubyte ubObjNr, stCAN_SWObj *pstObj) { ubyte ubTemp; CAN_pushAMRegs(); // PUSH the CAN Access Mediator Register //----- get DLC ------------------------------------------------------- CAN_vWriteCANAddress(CAN_MOFCR(ubObjNr)); CAN_vReadEN(); // Readmode is Enabled pstObj->ubMOdlc = CAN_DATA3;//MOFCRn[31-24] DLC //----- get MODATAL --------------------------------------------------- CAN_vWriteCANAddress(CAN_MODATAL(ubObjNr)); CAN_vReadEN(); // Readmode is Enabled pstObj->ulDATAL.ubDB[3] = CAN_DATA0; // Read CAN Data Register 0 pstObj->ulDATAL.ubDB[2] = CAN_DATA1; // Read CAN Data Register 1 pstObj->ulDATAL.ubDB[1] = CAN_DATA2; // Read CAN Data Register 2 pstObj->ulDATAL.ubDB[0] = CAN_DATA3; // Read CAN Data Register 3 // CAN Address pointing to the CAN_MODATAH CAN_ADCON = ADR_INC; //----- get MODATAH --------------------------------------------------- CAN_vReadEN(); // Readmode is Enabled pstObj->ulDATAH.ubDB[3] = CAN_DATA0; // Read CAN Data Register 0 pstObj->ulDATAH.ubDB[2] = CAN_DATA1; // Read CAN Data Register 1 pstObj->ulDATAH.ubDB[1] = CAN_DATA2; // Read CAN Data Register 2 pstObj->ulDATAH.ubDB[0] = CAN_DATA3; // Read CAN Data Register 3 //----- get DIR ------------------------------------------------------- CAN_vWriteCANAddress(CAN_MOCTR(ubObjNr)); CAN_vReadEN(); // Readmode is Enabled if(CAN_DATA1 & 0x08) // if transmit object (MOSTAT_DIR) { pstObj->ubMOcfg = (pstObj->ubMOcfg | 0x08); // set DIR } //----- get XID - Extended Identifier --------------------------------- // CAN Address pointing to the CAN_MOARn CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1) CAN_vReadEN(); // ReadMode is Enabled if(CAN_DATA3 & 0x20) // if extended identifier { //----- get XID - Extended Identifier (MOARn) ------------------------ pstObj->ulID.ubDB[3] = CAN_DATA0; // MOARn[7-0] pstObj->ulID.ubDB[2] = CAN_DATA1; // MOARn[15-8] pstObj->ulID.ubDB[1] = CAN_DATA2; // MOARn[23-16] pstObj->ulID.ubDB[0] = (CAN_DATA3 & 0x1f); // MOARn[31-24] // CAN Address pointing to the CAN_MODATAH CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1) // CAN Address pointing to the CAN_MODATAL CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1) // CAN Address pointing to the CAN_MOAMR CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1) CAN_vReadEN(); // ReadMode is Enabled //----- get XID - Extended Acceptance Mask (MOAMRn) ----------------- pstObj->ulMask.ubDB[3] = CAN_DATA0; // MOAMRn[7-0] pstObj->ulMask.ubDB[2] = CAN_DATA1; // MOAMRn[15-8] pstObj->ulMask.ubDB[1] = CAN_DATA2; // MOAMRn[23-16] pstObj->ulMask.ubDB[0] = (CAN_DATA3 & 0x1f); // MOAMRn[31-24] pstObj->ubMOcfg = (pstObj->ubMOcfg | 0x04); // set IDE 29-bit } else // standard identifier { //----- get - ID - Standard Identifier (MOARn) --------------------- pstObj->ulID.ubDB[3] = (CAN_DATA2 & 0xFC) >> 2; // MOARn[23-16] pstObj->ulID.ubDB[2] = (CAN_DATA3 & 0x1f); // MOARn[31-24] pstObj->ulID.ubDB[1] = 0x00; // MOARn[15-8] pstObj->ulID.ubDB[0] = 0x00; // MOARn[15-8] ubTemp = 0; ubTemp = ((pstObj->ulID.ubDB[2]) & 0x03) << 6; pstObj->ulID.ubDB[2] = (pstObj->ulID.ubDB[2] >> 2); pstObj->ulID.ubDB[3] = (pstObj->ulID.ubDB[3] + ubTemp); // CAN Address pointing to the CAN_MODATAH CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1) // CAN Address pointing to the CAN_MODATAL CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1) // CAN Address pointing to the CAN_MOAMR CAN_ADCON = ADR_DEC; // Auto Decrement the current address(-1) CAN_vReadEN(); // ReadMode is Enabled //----- get - ID - Acceptance Mask (MOAMRn) ----------------------- pstObj->ulMask.ubDB[3] = (CAN_DATA2 & 0xFC) >> 2; // MOAMRn[23-16] pstObj->ulMask.ubDB[2] = (CAN_DATA3 & 0x1f); // MOAMRn[31-24] pstObj->ulMask.ubDB[1] = 0x00; // MOAMRn[15-8] pstObj->ulMask.ubDB[0] = 0x00; // MOAMRn[15-8] ubTemp = 0; ubTemp = ((pstObj->ulMask.ubDB[2]) & 0x03) << 6; pstObj->ulMask.ubDB[2] = (pstObj->ulMask.ubDB[2] >> 2); pstObj->ulMask.ubDB[3] = (pstObj->ulMask.ubDB[3] + ubTemp); } //----- get CFCVAL - CAN Frame Counter Value (MOIPRn) ----------------- CAN_vWriteCANAddress(CAN_MOIPR(ubObjNr)); CAN_vReadEN(); // Readmode is Enabled pstObj->uwCounter.ubDB[1] = CAN_DATA2; // MOIPRn[16-23] pstObj->uwCounter.ubDB[0] = CAN_DATA3; // MOIPRn[31-24] CAN_popAMRegs(); // POP the CAN Access Mediator Register } // End of function CAN_vGetMsgObj