master/slave_config.c
changeset 807 f8bca95ab75d
parent 797 1c2726f9c81b
child 814 a51f857b1b2d
equal deleted inserted replaced
806:ab8daaabbe48 807:f8bca95ab75d
   215     }
   215     }
   216 
   216 
   217     fmmu = &sc->fmmu_configs[sc->used_fmmus++];
   217     fmmu = &sc->fmmu_configs[sc->used_fmmus++];
   218     ec_fmmu_config_init(fmmu, sc, domain, dir);
   218     ec_fmmu_config_init(fmmu, sc, domain, dir);
   219     return fmmu->logical_start_address;
   219     return fmmu->logical_start_address;
   220 }
       
   221 
       
   222 /*****************************************************************************/
       
   223 
       
   224 /** Registers a Pdo entry.
       
   225  *
       
   226  * Searches the mapping and the Pdo configurations for the given Pdo entry. If
       
   227  * found, the curresponding sync manager/FMMU is added to the domain and the
       
   228  * offset of the Pdo entry's data in the domain process data is returned.
       
   229  *
       
   230  * \retval >=0 Offset of the Pdo entry's process data.
       
   231  * \retval -1  Pdo entry not found.
       
   232  * \retval -2  Failed to register Pdo entry.
       
   233  */
       
   234 int ec_slave_config_reg_pdo_entry(
       
   235         ec_slave_config_t *sc, /**< Slave configuration. */
       
   236         ec_domain_t *domain, /**< Domain. */
       
   237         uint16_t index, /**< Index of Pdo entry to register. */
       
   238         uint8_t subindex /**< Subindex of Pdo entry to register. */
       
   239         )
       
   240 {
       
   241     ec_direction_t dir;
       
   242     ec_pdo_mapping_t *map;
       
   243     unsigned int bit_offset, byte_offset;
       
   244     ec_pdo_t *pdo;
       
   245     ec_pdo_entry_t *entry;
       
   246     int ret;
       
   247 
       
   248     for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++) {
       
   249         map = &sc->mapping[dir];
       
   250         bit_offset = 0;
       
   251         list_for_each_entry(pdo, &map->pdos, list) {
       
   252             list_for_each_entry(entry, &pdo->entries, list) {
       
   253                 if (entry->index != index || entry->subindex != subindex) {
       
   254                     bit_offset += entry->bit_length;
       
   255                 } else {
       
   256                     goto found;
       
   257                 }
       
   258             }
       
   259         }
       
   260     }
       
   261 
       
   262     EC_ERR("PDO entry 0x%04X:%u is not mapped in slave config %u:%u.\n",
       
   263            index, subindex, sc->alias, sc->position);
       
   264     return -1;
       
   265 
       
   266 found:
       
   267     byte_offset = bit_offset / 8;
       
   268     if ((ret = ec_slave_config_prepare_fmmu(sc, domain, dir)) < 0)
       
   269         return -2;
       
   270     return ret + byte_offset;
       
   271 }
   220 }
   272 
   221 
   273 /*****************************************************************************/
   222 /*****************************************************************************/
   274 
   223 
   275 /** Outputs all information about a certain slave configuration.
   224 /** Outputs all information about a certain slave configuration.
   502     return 0;
   451     return 0;
   503 }
   452 }
   504 
   453 
   505 /*****************************************************************************/
   454 /*****************************************************************************/
   506 
   455 
       
   456 int ecrt_slave_config_reg_pdo_entry(
       
   457         ec_slave_config_t *sc, /**< Slave configuration. */
       
   458         uint16_t index, /**< Index of Pdo entry to register. */
       
   459         uint8_t subindex, /**< Subindex of Pdo entry to register. */
       
   460         ec_domain_t *domain /**< Domain. */
       
   461         )
       
   462 {
       
   463     ec_direction_t dir;
       
   464     ec_pdo_mapping_t *map;
       
   465     unsigned int bit_offset, byte_offset;
       
   466     ec_pdo_t *pdo;
       
   467     ec_pdo_entry_t *entry;
       
   468     int ret;
       
   469 
       
   470     for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++) {
       
   471         map = &sc->mapping[dir];
       
   472         bit_offset = 0;
       
   473         list_for_each_entry(pdo, &map->pdos, list) {
       
   474             list_for_each_entry(entry, &pdo->entries, list) {
       
   475                 if (entry->index != index || entry->subindex != subindex) {
       
   476                     bit_offset += entry->bit_length;
       
   477                 } else {
       
   478                     goto found;
       
   479                 }
       
   480             }
       
   481         }
       
   482     }
       
   483 
       
   484     EC_ERR("PDO entry 0x%04X:%u is not mapped in slave config %u:%u.\n",
       
   485            index, subindex, sc->alias, sc->position);
       
   486     return -1;
       
   487 
       
   488 found:
       
   489     byte_offset = bit_offset / 8;
       
   490     if ((ret = ec_slave_config_prepare_fmmu(sc, domain, dir)) < 0)
       
   491         return -2;
       
   492     return ret + byte_offset;
       
   493 }
       
   494 
       
   495 /*****************************************************************************/
       
   496 
   507 int ecrt_slave_config_sdo8(ec_slave_config_t *slave, uint16_t index,
   497 int ecrt_slave_config_sdo8(ec_slave_config_t *slave, uint16_t index,
   508         uint8_t subindex, uint8_t value)
   498         uint8_t subindex, uint8_t value)
   509 {
   499 {
   510     uint8_t data[1];
   500     uint8_t data[1];
   511     EC_WRITE_U8(data, value);
   501     EC_WRITE_U8(data, value);
   535 /*****************************************************************************/
   525 /*****************************************************************************/
   536 
   526 
   537 /** \cond */
   527 /** \cond */
   538 
   528 
   539 EXPORT_SYMBOL(ecrt_slave_config_mapping);
   529 EXPORT_SYMBOL(ecrt_slave_config_mapping);
       
   530 EXPORT_SYMBOL(ecrt_slave_config_reg_pdo_entry);
   540 EXPORT_SYMBOL(ecrt_slave_config_sdo8);
   531 EXPORT_SYMBOL(ecrt_slave_config_sdo8);
   541 EXPORT_SYMBOL(ecrt_slave_config_sdo16);
   532 EXPORT_SYMBOL(ecrt_slave_config_sdo16);
   542 EXPORT_SYMBOL(ecrt_slave_config_sdo32);
   533 EXPORT_SYMBOL(ecrt_slave_config_sdo32);
   543 
   534 
   544 /** \endcond */
   535 /** \endcond */