master/slave.c
changeset 620 4f76acbf54a0
parent 619 15becb1879fd
child 624 11332ad89f47
equal deleted inserted replaced
619:15becb1879fd 620:4f76acbf54a0
   398 /**
   398 /**
   399    Fetches data from a STRING category.
   399    Fetches data from a STRING category.
   400    \return 0 in case of success, else < 0
   400    \return 0 in case of success, else < 0
   401 */
   401 */
   402 
   402 
   403 int ec_slave_fetch_strings(ec_slave_t *slave, /**< EtherCAT slave */
   403 int ec_slave_fetch_sii_strings(
   404                            const uint8_t *data /**< category data */
   404         ec_slave_t *slave, /**< EtherCAT slave */
   405                            )
   405         const uint8_t *data /**< category data */
       
   406         )
   406 {
   407 {
   407     unsigned int string_count, i;
   408     unsigned int string_count, i;
   408     size_t size;
   409     size_t size;
   409     off_t offset;
   410     off_t offset;
   410     ec_sii_string_t *string;
   411     ec_sii_string_t *string;
   436 /**
   437 /**
   437    Fetches data from a GENERAL category.
   438    Fetches data from a GENERAL category.
   438    \return 0 in case of success, else < 0
   439    \return 0 in case of success, else < 0
   439 */
   440 */
   440 
   441 
   441 void ec_slave_fetch_general(ec_slave_t *slave, /**< EtherCAT slave */
   442 void ec_slave_fetch_sii_general(
   442                             const uint8_t *data /**< category data */
   443         ec_slave_t *slave, /**< EtherCAT slave */
   443                             )
   444         const uint8_t *data /**< category data */
       
   445         )
   444 {
   446 {
   445     unsigned int i;
   447     unsigned int i;
   446 
   448 
   447     ec_slave_locate_string(slave, data[0], &slave->sii_group);
   449     ec_slave_locate_sii_string(slave, data[0], &slave->sii_group);
   448     ec_slave_locate_string(slave, data[1], &slave->sii_image);
   450     ec_slave_locate_sii_string(slave, data[1], &slave->sii_image);
   449     ec_slave_locate_string(slave, data[2], &slave->sii_order);
   451     ec_slave_locate_sii_string(slave, data[2], &slave->sii_order);
   450     ec_slave_locate_string(slave, data[3], &slave->sii_name);
   452     ec_slave_locate_sii_string(slave, data[3], &slave->sii_name);
   451 
   453 
   452     for (i = 0; i < 4; i++)
   454     for (i = 0; i < 4; i++)
   453         slave->sii_physical_layer[i] =
   455         slave->sii_physical_layer[i] =
   454             (data[4] & (0x03 << (i * 2))) >> (i * 2);
   456             (data[4] & (0x03 << (i * 2))) >> (i * 2);
   455 
   457 
   461 /**
   463 /**
   462    Fetches data from a SYNC MANAGER category.
   464    Fetches data from a SYNC MANAGER category.
   463    \return 0 in case of success, else < 0
   465    \return 0 in case of success, else < 0
   464 */
   466 */
   465 
   467 
   466 int ec_slave_fetch_sync(ec_slave_t *slave, /**< EtherCAT slave */
   468 int ec_slave_fetch_sii_syncs(
   467                         const uint8_t *data, /**< category data */
   469         ec_slave_t *slave, /**< EtherCAT slave */
   468                         size_t word_count /**< number of words */
   470         const uint8_t *data, /**< category data */
   469                         )
   471         size_t word_count /**< number of words */
       
   472         )
   470 {
   473 {
   471     unsigned int i;
   474     unsigned int i;
   472     ec_sii_sync_t *sync;
   475     ec_sii_sync_t *sync;
   473 
   476 
   474     // sync manager struct is 4 words long
   477     // sync manager struct is 4 words long
   500 /**
   503 /**
   501    Fetches data from a [RT]XPDO category.
   504    Fetches data from a [RT]XPDO category.
   502    \return 0 in case of success, else < 0
   505    \return 0 in case of success, else < 0
   503 */
   506 */
   504 
   507 
   505 int ec_slave_fetch_pdo(ec_slave_t *slave, /**< EtherCAT slave */
   508 int ec_slave_fetch_sii_pdos(
   506                        const uint8_t *data, /**< category data */
   509         ec_slave_t *slave, /**< EtherCAT slave */
   507                        size_t word_count, /**< number of words */
   510         const uint8_t *data, /**< category data */
   508                        ec_sii_pdo_type_t pdo_type /**< PDO type */
   511         size_t word_count, /**< number of words */
   509                        )
   512         ec_sii_pdo_type_t pdo_type /**< PDO type */
       
   513         )
   510 {
   514 {
   511     ec_sii_pdo_t *pdo;
   515     ec_sii_pdo_t *pdo;
   512     ec_sii_pdo_entry_t *entry;
   516     ec_sii_pdo_entry_t *entry;
   513     unsigned int entry_count, i;
   517     unsigned int entry_count, i;
   514 
   518 
   524 
   528 
   525         pdo->index = EC_READ_U16(data);
   529         pdo->index = EC_READ_U16(data);
   526         entry_count = EC_READ_U8(data + 2);
   530         entry_count = EC_READ_U8(data + 2);
   527         pdo->sync_index = EC_READ_U8(data + 3);
   531         pdo->sync_index = EC_READ_U8(data + 3);
   528         pdo->name = NULL;
   532         pdo->name = NULL;
   529         ec_slave_locate_string(slave, EC_READ_U8(data + 5), &pdo->name);
   533         ec_slave_locate_sii_string(slave, EC_READ_U8(data + 5), &pdo->name);
   530 
   534 
   531         list_add_tail(&pdo->list, &slave->sii_pdos);
   535         list_add_tail(&pdo->list, &slave->sii_pdos);
   532 
   536 
   533         word_count -= 4;
   537         word_count -= 4;
   534         data += 8;
   538         data += 8;
   541             }
   545             }
   542 
   546 
   543             entry->index = EC_READ_U16(data);
   547             entry->index = EC_READ_U16(data);
   544             entry->subindex = EC_READ_U8(data + 2);
   548             entry->subindex = EC_READ_U8(data + 2);
   545             entry->name = NULL;
   549             entry->name = NULL;
   546             ec_slave_locate_string(slave, EC_READ_U8(data + 3), &entry->name);
   550             ec_slave_locate_sii_string(
       
   551                     slave, EC_READ_U8(data + 3), &entry->name);
   547             entry->bit_length = EC_READ_U8(data + 5);
   552             entry->bit_length = EC_READ_U8(data + 5);
   548 
   553 
   549             list_add_tail(&entry->list, &pdo->entries);
   554             list_add_tail(&entry->list, &pdo->entries);
   550 
   555 
   551             word_count -= 4;
   556             word_count -= 4;
   562    Searches the string list for an index and allocates a new string.
   567    Searches the string list for an index and allocates a new string.
   563    \return 0 in case of success, else < 0
   568    \return 0 in case of success, else < 0
   564    \todo documentation
   569    \todo documentation
   565 */
   570 */
   566 
   571 
   567 int ec_slave_locate_string(ec_slave_t *slave, /**< EtherCAT slave */
   572 int ec_slave_locate_sii_string(
   568                            unsigned int index, /**< string index */
   573         ec_slave_t *slave, /**< EtherCAT slave */
   569                            char **ptr /**< Address of the string pointer */
   574         unsigned int index, /**< string index */
   570                            )
   575         char **ptr /**< Address of the string pointer */
       
   576         )
   571 {
   577 {
   572     ec_sii_string_t *string;
   578     ec_sii_string_t *string;
   573     char *err_string;
   579     char *err_string;
   574 
   580 
   575     // Erst alten Speicher freigeben
   581     // Erst alten Speicher freigeben