CO_ReturnError_t CO_TPDO_init( CO_TPDO_t *TPDO, CO_EM_t *em, CO_SDO_t *SDO, uint8_t *operatingState, uint8_t nodeId, uint16_t defaultCOB_ID, uint8_t restrictionFlags, const CO_TPDOCommPar_t *TPDOCommPar, const CO_TPDOMapPar_t *TPDOMapPar, uint16_t idx_TPDOCommPar, uint16_t idx_TPDOMapPar, CO_CANmodule_t *CANdevTx, uint16_t CANdevTxIdx) { /* verify arguments */ if(TPDO==NULL || em==NULL || SDO==NULL || operatingState==NULL || TPDOCommPar==NULL || TPDOMapPar==NULL || CANdevTx==NULL){ return CO_ERROR_ILLEGAL_ARGUMENT; } /* Configure object variables */ TPDO->em = em; TPDO->SDO = SDO; TPDO->TPDOCommPar = TPDOCommPar; TPDO->TPDOMapPar = TPDOMapPar; TPDO->operatingState = operatingState; TPDO->nodeId = nodeId; TPDO->defaultCOB_ID = defaultCOB_ID; TPDO->restrictionFlags = restrictionFlags; /* Configure Object dictionary entry at index 0x1800+ and 0x1A00+ */ CO_OD_configure(SDO, idx_TPDOCommPar, CO_ODF_TPDOcom, (void*)TPDO, 0, 0); CO_OD_configure(SDO, idx_TPDOMapPar, CO_ODF_TPDOmap, (void*)TPDO, 0, 0); /* configure communication and mapping */ TPDO->CANdevTx = CANdevTx; TPDO->CANdevTxIdx = CANdevTxIdx; TPDO->syncCounter = 255; TPDO->inhibitTimer = 0; TPDO->eventTimer = ((uint32_t) TPDOCommPar->eventTimer) * 1000; if(TPDOCommPar->transmissionType>=254) TPDO->sendRequest = 1; CO_TPDOconfigMap(TPDO, TPDOMapPar->numberOfMappedObjects); CO_TPDOconfigCom(TPDO, TPDOCommPar->COB_IDUsedByTPDO, ((TPDOCommPar->transmissionType<=240) ? 1 : 0)); if((TPDOCommPar->transmissionType>240 && TPDOCommPar->transmissionType<254) || TPDOCommPar->SYNCStartValue>240){ TPDO->valid = false; } return CO_ERROR_NO; }
int16_t CO_TPDO_init( CO_TPDO_t *TPDO, CO_EM_t *EM, CO_SDO_t *SDO, uint8_t *operatingState, uint8_t nodeId, uint16_t defaultCOB_ID, uint8_t restrictionFlags, const CO_TPDOCommPar_t *TPDOCommPar, const CO_TPDOMapPar_t *TPDOMapPar, uint16_t idx_TPDOCommPar, uint16_t idx_TPDOMapPar, CO_CANmodule_t *CANdevTx, uint16_t CANdevTxIdx) { /* Configure object variables */ TPDO->EM = EM; TPDO->SDO = SDO; TPDO->TPDOCommPar = TPDOCommPar; TPDO->TPDOMapPar = TPDOMapPar; TPDO->operatingState = operatingState; TPDO->nodeId = nodeId; TPDO->defaultCOB_ID = defaultCOB_ID; TPDO->restrictionFlags = restrictionFlags; /* Configure Object dictionary entry at index 0x1800+ and 0x1A00+ */ CO_OD_configure(SDO, idx_TPDOCommPar, CO_ODF_TPDOcom, (void*)TPDO, 0, 0); CO_OD_configure(SDO, idx_TPDOMapPar, CO_ODF_TPDOmap, (void*)TPDO, 0, 0); /* configure communication and mapping */ TPDO->CANdevTx = CANdevTx; TPDO->CANdevTxIdx = CANdevTxIdx; TPDO->syncCounter = 255; TPDO->inhibitTimer = 0; TPDO->eventTimer = TPDOCommPar->eventTimer; TPDO->SYNCtimerPrevious = 0; if(TPDOCommPar->transmissionType>=254) TPDO->sendRequest = 1; CO_TPDOconfigMap(TPDO, TPDOMapPar->numberOfMappedObjects); CO_TPDOconfigCom(TPDO, TPDOCommPar->COB_IDUsedByTPDO, ((TPDOCommPar->transmissionType<=240) ? 1 : 0)); if((TPDOCommPar->transmissionType>240 && TPDOCommPar->transmissionType<254) || TPDOCommPar->SYNCStartValue>240){ TPDO->valid = 0; } return CO_ERROR_NO; }
/* * Function for accessing _TPDO communication parameter_ (index 0x1800+) from SDO server. * * For more information see file CO_SDO.h. */ static CO_SDO_abortCode_t CO_ODF_TPDOcom(CO_ODF_arg_t *ODF_arg){ CO_TPDO_t *TPDO; TPDO = (CO_TPDO_t*) ODF_arg->object; if(ODF_arg->subIndex == 4) return CO_SDO_AB_SUB_UNKNOWN; /* Sub-index does not exist. */ /* Reading Object Dictionary variable */ if(ODF_arg->reading){ if(ODF_arg->subIndex == 1){ /* COB_ID */ uint32_t *value = (uint32_t*) ODF_arg->data; /* if default COB ID is used, write default value here */ if(((*value)&0xFFFF) == TPDO->defaultCOB_ID && TPDO->defaultCOB_ID) *value += TPDO->nodeId; /* If PDO is not valid, set bit 31 */ if(!TPDO->valid) *value |= 0x80000000L; } return CO_SDO_AB_NONE; } /* Writing Object Dictionary variable */ if(TPDO->restrictionFlags & 0x04) return CO_SDO_AB_READONLY; /* Attempt to write a read only object. */ if(*TPDO->operatingState == CO_NMT_OPERATIONAL && (TPDO->restrictionFlags & 0x01)) return CO_SDO_AB_DATA_DEV_STATE; /* Data cannot be transferred or stored to the application because of the present device state. */ if(ODF_arg->subIndex == 1){ /* COB_ID */ uint32_t *value = (uint32_t*) ODF_arg->data; /* bits 11...29 must be zero */ if(*value & 0x3FFF8000L) return CO_SDO_AB_INVALID_VALUE; /* Invalid value for parameter (download only). */ /* if default COB-ID is being written, write defaultCOB_ID without nodeId */ if(((*value)&0xFFFF) == (TPDO->defaultCOB_ID + TPDO->nodeId)){ *value &= 0xC0000000L; *value += TPDO->defaultCOB_ID; } /* if PDO is valid, bits 0..29 can not be changed */ if(TPDO->valid && ((*value ^ TPDO->TPDOCommPar->COB_IDUsedByTPDO) & 0x3FFFFFFFL)) return CO_SDO_AB_INVALID_VALUE; /* Invalid value for parameter (download only). */ /* configure TPDO */ CO_TPDOconfigCom(TPDO, *value, TPDO->CANtxBuff->syncFlag); TPDO->syncCounter = 255; } else if(ODF_arg->subIndex == 2){ /* Transmission_type */ uint8_t *value = (uint8_t*) ODF_arg->data; /* values from 241...253 are not valid */ if(*value >= 241 && *value <= 253) return CO_SDO_AB_INVALID_VALUE; /* Invalid value for parameter (download only). */ TPDO->CANtxBuff->syncFlag = (*value <= 240) ? 1 : 0; TPDO->syncCounter = 255; } else if(ODF_arg->subIndex == 3){ /* Inhibit_Time */ /* if PDO is valid, value can not be changed */ if(TPDO->valid) return CO_SDO_AB_INVALID_VALUE; /* Invalid value for parameter (download only). */ TPDO->inhibitTimer = 0; } else if(ODF_arg->subIndex == 5){ /* Event_Timer */ uint16_t *value = (uint16_t*) ODF_arg->data; TPDO->eventTimer = *value; } else if(ODF_arg->subIndex == 6){ /* SYNC start value */ uint8_t *value = (uint8_t*) ODF_arg->data; /* if PDO is valid, value can not be changed */ if(TPDO->valid) return CO_SDO_AB_INVALID_VALUE; /* Invalid value for parameter (download only). */ /* values from 240...255 are not valid */ if(*value > 240) return CO_SDO_AB_INVALID_VALUE; /* Invalid value for parameter (download only). */ } return CO_SDO_AB_NONE; }