master/slave_config.c
changeset 1609 94010c6d8198
parent 1543 373cd456dc26
child 1798 e7733f825982
equal deleted inserted replaced
1608:004a8b91e927 1609:94010c6d8198
   416         ec_direction_t dir, ec_watchdog_mode_t watchdog_mode)
   416         ec_direction_t dir, ec_watchdog_mode_t watchdog_mode)
   417 {
   417 {
   418     ec_sync_config_t *sync_config;
   418     ec_sync_config_t *sync_config;
   419     
   419     
   420     if (sc->master->debug_level)
   420     if (sc->master->debug_level)
   421         EC_DBG("ecrt_slave_config_sync_manager(sc = 0x%x, sync_index = %u, "
   421         EC_DBG("ecrt_slave_config_sync_manager(sc = 0x%p, sync_index = %u, "
   422                 "dir = %i, watchdog_mode = %i)\n",
   422                 "dir = %i, watchdog_mode = %i)\n",
   423                 (u32) sc, sync_index, dir, watchdog_mode);
   423                  sc, sync_index, dir, watchdog_mode);
   424 
   424 
   425     if (sync_index >= EC_MAX_SYNC_MANAGERS) {
   425     if (sync_index >= EC_MAX_SYNC_MANAGERS) {
   426         EC_ERR("Invalid sync manager index %u!\n", sync_index);
   426         EC_ERR("Invalid sync manager index %u!\n", sync_index);
   427         return -ENOENT;
   427         return -ENOENT;
   428     }
   428     }
   442 
   442 
   443 void ecrt_slave_config_watchdog(ec_slave_config_t *sc,
   443 void ecrt_slave_config_watchdog(ec_slave_config_t *sc,
   444         uint16_t divider, uint16_t intervals)
   444         uint16_t divider, uint16_t intervals)
   445 {
   445 {
   446     if (sc->master->debug_level)
   446     if (sc->master->debug_level)
   447         EC_DBG("%s(sc = 0x%x, divider = %u, intervals = %u)\n",
   447         EC_DBG("%s(sc = 0x%p, divider = %u, intervals = %u)\n",
   448                 __func__, (u32) sc, divider, intervals);
   448                 __func__, sc, divider, intervals);
   449 
   449 
   450     sc->watchdog_divider = divider;
   450     sc->watchdog_divider = divider;
   451     sc->watchdog_intervals = intervals;
   451     sc->watchdog_intervals = intervals;
   452 }
   452 }
   453 
   453 
   457         uint8_t sync_index, uint16_t pdo_index)
   457         uint8_t sync_index, uint16_t pdo_index)
   458 {
   458 {
   459     ec_pdo_t *pdo;
   459     ec_pdo_t *pdo;
   460 
   460 
   461     if (sc->master->debug_level)
   461     if (sc->master->debug_level)
   462         EC_DBG("ecrt_slave_config_pdo_assign_add(sc = 0x%x, sync_index = %u, "
   462         EC_DBG("ecrt_slave_config_pdo_assign_add(sc = 0x%p, sync_index = %u, "
   463                 "pdo_index = 0x%04X)\n", (u32) sc, sync_index, pdo_index);
   463                 "pdo_index = 0x%04X)\n", sc, sync_index, pdo_index);
   464 
   464 
   465     if (sync_index >= EC_MAX_SYNC_MANAGERS) {
   465     if (sync_index >= EC_MAX_SYNC_MANAGERS) {
   466         EC_ERR("Invalid sync manager index %u!\n", sync_index);
   466         EC_ERR("Invalid sync manager index %u!\n", sync_index);
   467         return -EINVAL;
   467         return -EINVAL;
   468     }
   468     }
   486 
   486 
   487 void ecrt_slave_config_pdo_assign_clear(ec_slave_config_t *sc,
   487 void ecrt_slave_config_pdo_assign_clear(ec_slave_config_t *sc,
   488         uint8_t sync_index)
   488         uint8_t sync_index)
   489 {
   489 {
   490     if (sc->master->debug_level)
   490     if (sc->master->debug_level)
   491         EC_DBG("ecrt_slave_config_pdo_assign_clear(sc = 0x%x, "
   491         EC_DBG("ecrt_slave_config_pdo_assign_clear(sc = 0x%p, "
   492                 "sync_index = %u)\n", (u32) sc, sync_index);
   492                 "sync_index = %u)\n", sc, sync_index);
   493 
   493 
   494     if (sync_index >= EC_MAX_SYNC_MANAGERS) {
   494     if (sync_index >= EC_MAX_SYNC_MANAGERS) {
   495         EC_ERR("Invalid sync manager index %u!\n", sync_index);
   495         EC_ERR("Invalid sync manager index %u!\n", sync_index);
   496         return;
   496         return;
   497     }
   497     }
   511     ec_pdo_t *pdo = NULL;
   511     ec_pdo_t *pdo = NULL;
   512     ec_pdo_entry_t *entry;
   512     ec_pdo_entry_t *entry;
   513     int retval = 0;
   513     int retval = 0;
   514     
   514     
   515     if (sc->master->debug_level)
   515     if (sc->master->debug_level)
   516         EC_DBG("ecrt_slave_config_pdo_mapping_add(sc = 0x%x, "
   516         EC_DBG("ecrt_slave_config_pdo_mapping_add(sc = 0x%p, "
   517                 "pdo_index = 0x%04X, entry_index = 0x%04X, "
   517                 "pdo_index = 0x%04X, entry_index = 0x%04X, "
   518                 "entry_subindex = 0x%02X, entry_bit_length = %u)\n",
   518                 "entry_subindex = 0x%02X, entry_bit_length = %u)\n",
   519                 (u32) sc, pdo_index, entry_index, entry_subindex,
   519                 sc, pdo_index, entry_index, entry_subindex,
   520                 entry_bit_length);
   520                 entry_bit_length);
   521 
   521 
   522     for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++)
   522     for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++)
   523         if ((pdo = ec_pdo_list_find_pdo(
   523         if ((pdo = ec_pdo_list_find_pdo(
   524                         &sc->sync_configs[sync_index].pdos, pdo_index)))
   524                         &sc->sync_configs[sync_index].pdos, pdo_index)))
   547 {
   547 {
   548     uint8_t sync_index;
   548     uint8_t sync_index;
   549     ec_pdo_t *pdo = NULL;
   549     ec_pdo_t *pdo = NULL;
   550     
   550     
   551     if (sc->master->debug_level)
   551     if (sc->master->debug_level)
   552         EC_DBG("ecrt_slave_config_pdo_mapping_clear(sc = 0x%x, "
   552         EC_DBG("ecrt_slave_config_pdo_mapping_clear(sc = 0x%p, "
   553                 "pdo_index = 0x%04X)\n", (u32) sc, pdo_index);
   553                 "pdo_index = 0x%04X)\n", sc, pdo_index);
   554 
   554 
   555     for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++)
   555     for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++)
   556         if ((pdo = ec_pdo_list_find_pdo(
   556         if ((pdo = ec_pdo_list_find_pdo(
   557                         &sc->sync_configs[sync_index].pdos, pdo_index)))
   557                         &sc->sync_configs[sync_index].pdos, pdo_index)))
   558             break;
   558             break;
   577     const ec_sync_info_t *sync_info;
   577     const ec_sync_info_t *sync_info;
   578     const ec_pdo_info_t *pdo_info;
   578     const ec_pdo_info_t *pdo_info;
   579     const ec_pdo_entry_info_t *entry_info;
   579     const ec_pdo_entry_info_t *entry_info;
   580 
   580 
   581     if (sc->master->debug_level)
   581     if (sc->master->debug_level)
   582         EC_DBG("ecrt_slave_config_pdos(sc = 0x%x, n_syncs = %u, "
   582         EC_DBG("ecrt_slave_config_pdos(sc = 0x%p, n_syncs = %u, "
   583                 "syncs = 0x%x)\n", (u32) sc, n_syncs, (u32) syncs);
   583                 "syncs = 0x%p)\n", sc, n_syncs, syncs);
   584 
   584 
   585     if (!syncs)
   585     if (!syncs)
   586         return 0;
   586         return 0;
   587 
   587 
   588     for (i = 0; i < n_syncs; i++) {
   588     for (i = 0; i < n_syncs; i++) {
   649     ec_pdo_t *pdo;
   649     ec_pdo_t *pdo;
   650     ec_pdo_entry_t *entry;
   650     ec_pdo_entry_t *entry;
   651     int sync_offset;
   651     int sync_offset;
   652 
   652 
   653     if (sc->master->debug_level)
   653     if (sc->master->debug_level)
   654         EC_DBG("ecrt_slave_config_reg_pdo_entry(sc = 0x%x, index = 0x%04X, "
   654         EC_DBG("ecrt_slave_config_reg_pdo_entry(sc = 0x%p, index = 0x%04X, "
   655                 "subindex = 0x%02X, domain = 0x%x, bit_position = 0x%x)\n",
   655                 "subindex = 0x%02X, domain = 0x%p, bit_position = 0x%p)\n",
   656                 (u32) sc, index, subindex, (u32) domain, (u32) bit_position);
   656                 sc, index, subindex, domain, bit_position);
   657 
   657 
   658     for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++) {
   658     for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++) {
   659         sync_config = &sc->sync_configs[sync_index];
   659         sync_config = &sc->sync_configs[sync_index];
   660         bit_offset = 0;
   660         bit_offset = 0;
   661 
   661 
   711     ec_slave_t *slave = sc->slave;
   711     ec_slave_t *slave = sc->slave;
   712     ec_sdo_request_t *req;
   712     ec_sdo_request_t *req;
   713     int ret;
   713     int ret;
   714 
   714 
   715     if (sc->master->debug_level)
   715     if (sc->master->debug_level)
   716         EC_DBG("ecrt_slave_config_sdo(sc = 0x%x, index = 0x%04X, "
   716         EC_DBG("ecrt_slave_config_sdo(sc = 0x%p, index = 0x%04X, "
   717                 "subindex = 0x%02X, data = 0x%x, size = %u)\n", (u32) sc,
   717                 "subindex = 0x%02X, data = 0x%p, size = %zu)\n", sc,
   718                 index, subindex, (u32) data, size);
   718                 index, subindex, data, size);
   719 
   719 
   720     if (slave && !(slave->sii.mailbox_protocols & EC_MBOX_COE)) {
   720     if (slave && !(slave->sii.mailbox_protocols & EC_MBOX_COE)) {
   721         EC_ERR("Slave %u does not support CoE!\n", slave->ring_position);
   721         EC_ERR("Slave %u does not support CoE!\n", slave->ring_position);
   722         return -EPROTONOSUPPORT; // protocol not supported
   722         return -EPROTONOSUPPORT; // protocol not supported
   723     }
   723     }
   750         uint8_t subindex, uint8_t value)
   750         uint8_t subindex, uint8_t value)
   751 {
   751 {
   752     uint8_t data[1];
   752     uint8_t data[1];
   753 
   753 
   754     if (sc->master->debug_level)
   754     if (sc->master->debug_level)
   755         EC_DBG("ecrt_slave_config_sdo8(sc = 0x%x, index = 0x%04X, "
   755         EC_DBG("ecrt_slave_config_sdo8(sc = 0x%p, index = 0x%04X, "
   756                 "subindex = 0x%02X, value = %u)\n", (u32) sc,
   756                 "subindex = 0x%02X, value = %u)\n", sc,
   757                 index, subindex, (u32) value);
   757                 index, subindex, (u32) value);
   758 
   758 
   759     EC_WRITE_U8(data, value);
   759     EC_WRITE_U8(data, value);
   760     return ecrt_slave_config_sdo(sc, index, subindex, data, 1);
   760     return ecrt_slave_config_sdo(sc, index, subindex, data, 1);
   761 }
   761 }
   766         uint8_t subindex, uint16_t value)
   766         uint8_t subindex, uint16_t value)
   767 {
   767 {
   768     uint8_t data[2];
   768     uint8_t data[2];
   769 
   769 
   770     if (sc->master->debug_level)
   770     if (sc->master->debug_level)
   771         EC_DBG("ecrt_slave_config_sdo16(sc = 0x%x, index = 0x%04X, "
   771         EC_DBG("ecrt_slave_config_sdo16(sc = 0x%p, index = 0x%04X, "
   772                 "subindex = 0x%02X, value = %u)\n", (u32) sc,
   772                 "subindex = 0x%02X, value = %u)\n", sc,
   773                 index, subindex, value);
   773                 index, subindex, value);
   774 
   774 
   775     EC_WRITE_U16(data, value);
   775     EC_WRITE_U16(data, value);
   776     return ecrt_slave_config_sdo(sc, index, subindex, data, 2);
   776     return ecrt_slave_config_sdo(sc, index, subindex, data, 2);
   777 }
   777 }
   782         uint8_t subindex, uint32_t value)
   782         uint8_t subindex, uint32_t value)
   783 {
   783 {
   784     uint8_t data[4];
   784     uint8_t data[4];
   785 
   785 
   786     if (sc->master->debug_level)
   786     if (sc->master->debug_level)
   787         EC_DBG("ecrt_slave_config_sdo32(sc = 0x%x, index = 0x%04X, "
   787         EC_DBG("ecrt_slave_config_sdo32(sc = 0x%p, index = 0x%04X, "
   788                 "subindex = 0x%02X, value = %u)\n", (u32) sc,
   788                 "subindex = 0x%02X, value = %u)\n", sc,
   789                 index, subindex, value);
   789                 index, subindex, value);
   790 
   790 
   791     EC_WRITE_U32(data, value);
   791     EC_WRITE_U32(data, value);
   792     return ecrt_slave_config_sdo(sc, index, subindex, data, 4);
   792     return ecrt_slave_config_sdo(sc, index, subindex, data, 4);
   793 }
   793 }
   800     ec_slave_t *slave = sc->slave;
   800     ec_slave_t *slave = sc->slave;
   801     ec_sdo_request_t *req;
   801     ec_sdo_request_t *req;
   802     int ret;
   802     int ret;
   803 
   803 
   804     if (sc->master->debug_level)
   804     if (sc->master->debug_level)
   805         EC_DBG("ecrt_slave_config_complete_sdo(sc = 0x%x, index = 0x%04X, "
   805         EC_DBG("ecrt_slave_config_complete_sdo(sc = 0x%p, index = 0x%04X, "
   806                 "data = 0x%x, size = %u)\n", (u32) sc,
   806                 "data = 0x%p, size = %zu)\n", sc, index, data, size);
   807                 index, (u32) data, size);
       
   808 
   807 
   809     if (slave && !(slave->sii.mailbox_protocols & EC_MBOX_COE)) {
   808     if (slave && !(slave->sii.mailbox_protocols & EC_MBOX_COE)) {
   810         EC_ERR("Slave %u does not support CoE!\n", slave->ring_position);
   809         EC_ERR("Slave %u does not support CoE!\n", slave->ring_position);
   811         return -EPROTONOSUPPORT; // protocol not supported
   810         return -EPROTONOSUPPORT; // protocol not supported
   812     }
   811     }
   844 {
   843 {
   845     ec_sdo_request_t *req;
   844     ec_sdo_request_t *req;
   846     int ret;
   845     int ret;
   847 
   846 
   848     if (sc->master->debug_level)
   847     if (sc->master->debug_level)
   849         EC_DBG("ecrt_slave_config_create_sdo_request(sc = 0x%x, "
   848         EC_DBG("ecrt_slave_config_create_sdo_request(sc = 0x%p, "
   850                 "index = 0x%04X, subindex = 0x%02X, size = %u)\n", (u32) sc,
   849                 "index = 0x%04X, subindex = 0x%02X, size = %zu)\n", sc,
   851                 index, subindex, size);
   850                 index, subindex, size);
   852 
   851 
   853     if (!(req = (ec_sdo_request_t *)
   852     if (!(req = (ec_sdo_request_t *)
   854                 kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
   853                 kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
   855         EC_ERR("Failed to allocate SDO request memory!\n");
   854         EC_ERR("Failed to allocate SDO request memory!\n");
   897 {
   896 {
   898     ec_voe_handler_t *voe;
   897     ec_voe_handler_t *voe;
   899     int ret;
   898     int ret;
   900 
   899 
   901     if (sc->master->debug_level)
   900     if (sc->master->debug_level)
   902         EC_DBG("ecrt_slave_config_create_voe_handler(sc = 0x%x, size = %u)\n",
   901         EC_DBG("ecrt_slave_config_create_voe_handler(sc = 0x%p, size = %zu)\n",
   903                 (u32) sc, size);
   902                 sc, size);
   904 
   903 
   905     if (!(voe = (ec_voe_handler_t *)
   904     if (!(voe = (ec_voe_handler_t *)
   906                 kmalloc(sizeof(ec_voe_handler_t), GFP_KERNEL))) {
   905                 kmalloc(sizeof(ec_voe_handler_t), GFP_KERNEL))) {
   907         EC_ERR("Failed to allocate VoE request memory!\n");
   906         EC_ERR("Failed to allocate VoE request memory!\n");
   908         return ERR_PTR(-ENOMEM);
   907         return ERR_PTR(-ENOMEM);