master/slave.c
branchstable-1.2
changeset 1739 5fcbd29151d2
parent 1732 1cc865ba17c2
child 1744 7bc131b92039
equal deleted inserted replaced
1738:bc89e3fba1a5 1739:5fcbd29151d2
   110 
   110 
   111     slave->master = master;
   111     slave->master = master;
   112 
   112 
   113     slave->requested_state = EC_SLAVE_STATE_UNKNOWN;
   113     slave->requested_state = EC_SLAVE_STATE_UNKNOWN;
   114     slave->current_state = EC_SLAVE_STATE_UNKNOWN;
   114     slave->current_state = EC_SLAVE_STATE_UNKNOWN;
   115     slave->configured = 0;
   115     slave->self_configured = 0;
   116     slave->error_flag = 0;
   116     slave->error_flag = 0;
   117     slave->online = 1;
   117     slave->online = 1;
   118     slave->fmmu_count = 0;
   118     slave->fmmu_count = 0;
   119 
   119 
   120     slave->coupler_index = 0;
   120     slave->coupler_index = 0;
   143     slave->sii_mailbox_protocols = 0;
   143     slave->sii_mailbox_protocols = 0;
   144     slave->sii_group = NULL;
   144     slave->sii_group = NULL;
   145     slave->sii_image = NULL;
   145     slave->sii_image = NULL;
   146     slave->sii_order = NULL;
   146     slave->sii_order = NULL;
   147     slave->sii_name = NULL;
   147     slave->sii_name = NULL;
       
   148     slave->sii_current_on_ebus = 0;
   148 
   149 
   149     INIT_LIST_HEAD(&slave->sii_strings);
   150     INIT_LIST_HEAD(&slave->sii_strings);
   150     INIT_LIST_HEAD(&slave->sii_syncs);
   151     INIT_LIST_HEAD(&slave->sii_syncs);
   151     INIT_LIST_HEAD(&slave->sii_pdos);
   152     INIT_LIST_HEAD(&slave->sii_pdos);
   152     INIT_LIST_HEAD(&slave->sdo_dictionary);
   153     INIT_LIST_HEAD(&slave->sdo_dictionary);
   396     ec_slave_locate_string(slave, data[3], &slave->sii_name);
   397     ec_slave_locate_string(slave, data[3], &slave->sii_name);
   397 
   398 
   398     for (i = 0; i < 4; i++)
   399     for (i = 0; i < 4; i++)
   399         slave->sii_physical_layer[i] =
   400         slave->sii_physical_layer[i] =
   400             (data[4] & (0x03 << (i * 2))) >> (i * 2);
   401             (data[4] & (0x03 << (i * 2))) >> (i * 2);
       
   402 
       
   403     slave->sii_current_on_ebus = EC_READ_S16(data + 0x0C);
   401 }
   404 }
   402 
   405 
   403 /*****************************************************************************/
   406 /*****************************************************************************/
   404 
   407 
   405 /**
   408 /**
   627     off += sprintf(buffer + off, "Product code: 0x%08X\n\n",
   630     off += sprintf(buffer + off, "Product code: 0x%08X\n\n",
   628                    slave->sii_product_code);
   631                    slave->sii_product_code);
   629 
   632 
   630     off += sprintf(buffer + off, "State: ");
   633     off += sprintf(buffer + off, "State: ");
   631     off += ec_state_string(slave->current_state, buffer + off);
   634     off += ec_state_string(slave->current_state, buffer + off);
   632     off += sprintf(buffer + off, "\nFlags: %s, %s\n",
   635     off += sprintf(buffer + off, " (");
       
   636     off += ec_state_string(slave->requested_state, buffer + off);
       
   637     off += sprintf(buffer + off, ")\nFlags: %s, %s\n",
   633                    slave->online ? "online" : "OFFLINE",
   638                    slave->online ? "online" : "OFFLINE",
   634                    slave->error_flag ? "ERROR" : "ok");
   639                    slave->error_flag ? "ERROR" : "ok");
   635     off += sprintf(buffer + off, "Ring position: %i\n",
   640     off += sprintf(buffer + off, "Ring position: %i\n",
   636                    slave->ring_position);
   641                    slave->ring_position);
   637     off += sprintf(buffer + off, "Advanced position: %i:%i\n",
   642     off += sprintf(buffer + off, "Advanced position: %i:%i\n",
   638                    slave->coupler_index, slave->coupler_subindex);
   643                    slave->coupler_index, slave->coupler_subindex);
   639     off += sprintf(buffer + off, "Coupler: %s\n\n",
   644     off += sprintf(buffer + off, "Coupler: %s\n",
   640                    ec_slave_is_coupler(slave) ? "yes" : "no");
   645                    ec_slave_is_coupler(slave) ? "yes" : "no");
       
   646     off += sprintf(buffer + off, "Current consumption: %i mA\n\n",
       
   647                    slave->sii_current_on_ebus);
   641 
   648 
   642     off += sprintf(buffer + off, "Data link status:\n");
   649     off += sprintf(buffer + off, "Data link status:\n");
   643     for (i = 0; i < 4; i++) {
   650     for (i = 0; i < 4; i++) {
   644         off += sprintf(buffer + off, "  Port %i (", i);
   651         off += sprintf(buffer + off, "  Port %i (", i);
   645         switch (slave->sii_physical_layer[i]) {
   652         switch (slave->sii_physical_layer[i]) {
   967         byte_size = bit_size / 8 + 1;
   974         byte_size = bit_size / 8 + 1;
   968     else
   975     else
   969         byte_size = bit_size / 8;
   976         byte_size = bit_size / 8;
   970 
   977 
   971     return byte_size;
   978     return byte_size;
       
   979 }
       
   980 
       
   981 /*****************************************************************************/
       
   982 
       
   983 /**
       
   984    Initializes a sync manager configuration page with EEPROM data.
       
   985    The referenced memory (\a data) must be at least EC_SYNC_SIZE bytes.
       
   986 */
       
   987 
       
   988 void ec_slave_sync_config(const ec_slave_t *slave, /**< EtherCAT slave */
       
   989         const ec_sii_sync_t *sync, /**< sync manager */
       
   990         uint8_t *data /**> configuration memory */
       
   991         )
       
   992 {
       
   993     size_t sync_size;
       
   994 
       
   995     sync_size = ec_slave_calc_sync_size(slave, sync);
       
   996 
       
   997     if (slave->master->debug_level) {
       
   998         EC_DBG("Slave %3i, SM %i: Addr 0x%04X, Size %3i, Ctrl 0x%02X, En %i\n",
       
   999                slave->ring_position, sync->index, sync->physical_start_address,
       
  1000                sync_size, sync->control_register, sync->enable);
       
  1001     }
       
  1002 
       
  1003     EC_WRITE_U16(data,     sync->physical_start_address);
       
  1004     EC_WRITE_U16(data + 2, sync_size);
       
  1005     EC_WRITE_U8 (data + 4, sync->control_register);
       
  1006     EC_WRITE_U8 (data + 5, 0x00); // status byte (read only)
       
  1007     EC_WRITE_U16(data + 6, sync->enable ? 0x0001 : 0x0000); // enable
       
  1008 }
       
  1009 
       
  1010 /*****************************************************************************/
       
  1011 
       
  1012 /**
       
  1013    Initializes an FMMU configuration page.
       
  1014    The referenced memory (\a data) must be at least EC_FMMU_SIZE bytes.
       
  1015 */
       
  1016 
       
  1017 void ec_slave_fmmu_config(const ec_slave_t *slave, /**< EtherCAT slave */
       
  1018         const ec_fmmu_t *fmmu, /**< FMMU */
       
  1019         uint8_t *data /**> configuration memory */
       
  1020         )
       
  1021 {
       
  1022     size_t sync_size;
       
  1023 
       
  1024     sync_size = ec_slave_calc_sync_size(slave, fmmu->sync);
       
  1025 
       
  1026     if (slave->master->debug_level) {
       
  1027         EC_DBG("Slave %3i, FMMU %2i:"
       
  1028                " LogAddr 0x%08X, Size %3i, PhysAddr 0x%04X, Dir %s\n",
       
  1029                slave->ring_position, fmmu->index, fmmu->logical_start_address,
       
  1030                sync_size, fmmu->sync->physical_start_address,
       
  1031                ((fmmu->sync->control_register & 0x04) ? "out" : "in"));
       
  1032     }
       
  1033 
       
  1034     EC_WRITE_U32(data,      fmmu->logical_start_address);
       
  1035     EC_WRITE_U16(data + 4,  sync_size); // size of fmmu
       
  1036     EC_WRITE_U8 (data + 6,  0x00); // logical start bit
       
  1037     EC_WRITE_U8 (data + 7,  0x07); // logical end bit
       
  1038     EC_WRITE_U16(data + 8,  fmmu->sync->physical_start_address);
       
  1039     EC_WRITE_U8 (data + 10, 0x00); // physical start bit
       
  1040     EC_WRITE_U8 (data + 11, ((fmmu->sync->control_register & 0x04)
       
  1041                              ? 0x02 : 0x01));
       
  1042     EC_WRITE_U16(data + 12, 0x0001); // enable
       
  1043     EC_WRITE_U16(data + 14, 0x0000); // reserved
   972 }
  1044 }
   973 
  1045 
   974 /*****************************************************************************/
  1046 /*****************************************************************************/
   975 
  1047 
   976 /**
  1048 /**
  1211 #endif
  1283 #endif
  1212 }
  1284 }
  1213 
  1285 
  1214 /*****************************************************************************/
  1286 /*****************************************************************************/
  1215 
  1287 
  1216 /**< \cond */
  1288 /** \cond */
  1217 
  1289 
  1218 EXPORT_SYMBOL(ecrt_slave_conf_sdo8);
  1290 EXPORT_SYMBOL(ecrt_slave_conf_sdo8);
  1219 EXPORT_SYMBOL(ecrt_slave_conf_sdo16);
  1291 EXPORT_SYMBOL(ecrt_slave_conf_sdo16);
  1220 EXPORT_SYMBOL(ecrt_slave_conf_sdo32);
  1292 EXPORT_SYMBOL(ecrt_slave_conf_sdo32);
  1221 EXPORT_SYMBOL(ecrt_slave_pdo_size);
  1293 EXPORT_SYMBOL(ecrt_slave_pdo_size);
  1222 
  1294 
  1223 /**< \endcond */
  1295 /** \endcond */
  1224 
  1296 
  1225 /*****************************************************************************/
  1297 /*****************************************************************************/