/* * Function for accessing _RPDO mapping parameter_ (index 0x1600+) from SDO server. * * For more information see file CO_SDO.h. */ static CO_SDO_abortCode_t CO_ODF_RPDOmap(CO_ODF_arg_t *ODF_arg){ CO_RPDO_t *RPDO; RPDO = (CO_RPDO_t*) ODF_arg->object; /* Reading Object Dictionary variable */ if(ODF_arg->reading){ uint8_t *value = (uint8_t*) ODF_arg->data; if(ODF_arg->subIndex == 0){ /* If there is error in mapping, dataLength is 0, so numberOfMappedObjects is 0. */ if(!RPDO->dataLength) *value = 0; } return CO_SDO_AB_NONE; } /* Writing Object Dictionary variable */ if(RPDO->restrictionFlags & 0x08) return CO_SDO_AB_READONLY; /* Attempt to write a read only object. */ if(*RPDO->operatingState == CO_NMT_OPERATIONAL && (RPDO->restrictionFlags & 0x02)) return CO_SDO_AB_DATA_DEV_STATE; /* Data cannot be transferred or stored to the application because of the present device state. */ if(RPDO->valid) return CO_SDO_AB_INVALID_VALUE; /* Invalid value for parameter (download only). */ /* numberOfMappedObjects */ if(ODF_arg->subIndex == 0){ uint8_t *value = (uint8_t*) ODF_arg->data; if(*value > 8) return CO_SDO_AB_VALUE_HIGH; /* Value of parameter written too high. */ /* configure mapping */ return CO_RPDOconfigMap(RPDO, *value); } /* mappedObject */ else{ uint32_t *value = (uint32_t*) ODF_arg->data; uint8_t* pData; uint8_t length = 0; uint8_t dummy = 0; uint8_t MBvar; if(RPDO->dataLength) return CO_SDO_AB_INVALID_VALUE; /* Invalid value for parameter (download only). */ /* verify if mapping is correct */ return CO_PDOfindMap( RPDO->SDO, *value, 0, &pData, &length, &dummy, &MBvar); } return CO_SDO_AB_NONE; }
CO_ReturnError_t CO_RPDO_init( CO_RPDO_t *RPDO, CO_EM_t *em, CO_SDO_t *SDO, uint8_t *operatingState, uint8_t nodeId, uint16_t defaultCOB_ID, uint8_t restrictionFlags, const CO_RPDOCommPar_t *RPDOCommPar, const CO_RPDOMapPar_t *RPDOMapPar, uint16_t idx_RPDOCommPar, uint16_t idx_RPDOMapPar, CO_CANmodule_t *CANdevRx, uint16_t CANdevRxIdx) { /* verify arguments */ if(RPDO==NULL || em==NULL || SDO==NULL || operatingState==NULL || RPDOCommPar==NULL || RPDOMapPar==NULL || CANdevRx==NULL){ return CO_ERROR_ILLEGAL_ARGUMENT; } /* Configure object variables */ RPDO->em = em; RPDO->SDO = SDO; RPDO->RPDOCommPar = RPDOCommPar; RPDO->RPDOMapPar = RPDOMapPar; RPDO->operatingState = operatingState; RPDO->nodeId = nodeId; RPDO->defaultCOB_ID = defaultCOB_ID; RPDO->restrictionFlags = restrictionFlags; /* Configure Object dictionary entry at index 0x1400+ and 0x1600+ */ CO_OD_configure(SDO, idx_RPDOCommPar, CO_ODF_RPDOcom, (void*)RPDO, 0, 0); CO_OD_configure(SDO, idx_RPDOMapPar, CO_ODF_RPDOmap, (void*)RPDO, 0, 0); /* configure communication and mapping */ RPDO->CANrxNew = false; RPDO->CANdevRx = CANdevRx; RPDO->CANdevRxIdx = CANdevRxIdx; CO_RPDOconfigMap(RPDO, RPDOMapPar->numberOfMappedObjects); CO_RPDOconfigCom(RPDO, RPDOCommPar->COB_IDUsedByRPDO); return CO_ERROR_NO; }
int16_t CO_RPDO_init( CO_RPDO_t *RPDO, CO_EM_t *EM, CO_SDO_t *SDO, uint8_t *operatingState, uint8_t nodeId, uint16_t defaultCOB_ID, uint8_t restrictionFlags, const CO_RPDOCommPar_t *RPDOCommPar, const CO_RPDOMapPar_t *RPDOMapPar, uint16_t idx_RPDOCommPar, uint16_t idx_RPDOMapPar, CO_CANmodule_t *CANdevRx, uint16_t CANdevRxIdx) { /* Configure object variables */ RPDO->EM = EM; RPDO->SDO = SDO; RPDO->RPDOCommPar = RPDOCommPar; RPDO->RPDOMapPar = RPDOMapPar; RPDO->operatingState = operatingState; RPDO->nodeId = nodeId; RPDO->defaultCOB_ID = defaultCOB_ID; RPDO->restrictionFlags = restrictionFlags; /* Configure Object dictionary entry at index 0x1400+ and 0x1600+ */ CO_OD_configure(SDO, idx_RPDOCommPar, CO_ODF_RPDOcom, (void*)RPDO, 0, 0); CO_OD_configure(SDO, idx_RPDOMapPar, CO_ODF_RPDOmap, (void*)RPDO, 0, 0); /* configure communication and mapping */ RPDO->CANrxNew = 0; RPDO->CANdevRx = CANdevRx; RPDO->CANdevRxIdx = CANdevRxIdx; CO_RPDOconfigMap(RPDO, RPDOMapPar->numberOfMappedObjects); CO_RPDOconfigCom(RPDO, RPDOCommPar->COB_IDUsedByRPDO); return CO_ERROR_NO; }