master/master.c
changeset 136 a03a684cac89
parent 135 80d493917205
child 138 7e743a61a991
equal deleted inserted replaced
135:80d493917205 136:a03a684cac89
   660 }
   660 }
   661 
   661 
   662 /*****************************************************************************/
   662 /*****************************************************************************/
   663 
   663 
   664 /**
   664 /**
       
   665    Initialisiert eine Sync-Manager-Konfigurationsseite mit EEPROM-Daten.
       
   666 
       
   667    Der mit \a data referenzierte Speicher muss mindestens EC_SYNC_SIZE Bytes
       
   668    groß sein.
       
   669 */
       
   670 
       
   671 void ec_eeprom_sync_config(const ec_eeprom_sync_t *sync, /**< Sync-Manager */
       
   672                            uint8_t *data /**> Zeiger auf Konfig.-Speicher */
       
   673                            )
       
   674 {
       
   675     EC_WRITE_U16(data,     sync->physical_start_address);
       
   676     EC_WRITE_U16(data + 2, sync->length);
       
   677     EC_WRITE_U8 (data + 4, sync->control_register);
       
   678     EC_WRITE_U8 (data + 5, 0x00); // status byte (read only)
       
   679     EC_WRITE_U16(data + 6, sync->enable ? 0x0001 : 0x0000); // enable
       
   680 }
       
   681 
       
   682 /*****************************************************************************/
       
   683 
       
   684 /**
   665    Initialisiert eine FMMU-Konfigurationsseite.
   685    Initialisiert eine FMMU-Konfigurationsseite.
   666 
   686 
   667    Der mit \a data referenzierte Speicher muss mindestens EC_FMMU_SIZE Bytes
   687    Der mit \a data referenzierte Speicher muss mindestens EC_FMMU_SIZE Bytes
   668    groß sein.
   688    groß sein.
   669 */
   689 */
   776     const ec_slave_type_t *type;
   796     const ec_slave_type_t *type;
   777     const ec_fmmu_t *fmmu;
   797     const ec_fmmu_t *fmmu;
   778     uint8_t data[256];
   798     uint8_t data[256];
   779     uint32_t domain_offset;
   799     uint32_t domain_offset;
   780     ec_domain_t *domain;
   800     ec_domain_t *domain;
       
   801     ec_eeprom_sync_t *eeprom_sync;
   781 
   802 
   782     // Domains erstellen
   803     // Domains erstellen
   783     domain_offset = 0;
   804     domain_offset = 0;
   784     list_for_each_entry(domain, &master->domains, list) {
   805     list_for_each_entry(domain, &master->domains, list) {
   785         if (ec_domain_alloc(domain, domain_offset)) {
   806         if (ec_domain_alloc(domain, domain_offset)) {
   797         // Change state to INIT
   818         // Change state to INIT
   798         if (unlikely(ec_slave_state_change(slave, EC_SLAVE_STATE_INIT)))
   819         if (unlikely(ec_slave_state_change(slave, EC_SLAVE_STATE_INIT)))
   799             return -1;
   820             return -1;
   800 
   821 
   801         // Check if slave was registered...
   822         // Check if slave was registered...
   802         if (!slave->type) {
       
   803             EC_WARN("Slave %i has unknown type!\n", i);
       
   804             continue;
       
   805         }
       
   806 
       
   807         type = slave->type;
   823         type = slave->type;
       
   824         if (!type) EC_WARN("Slave %i has unknown type!\n", i);
   808 
   825 
   809         // Check and reset CRC fault counters
   826         // Check and reset CRC fault counters
   810         ec_slave_check_crc(slave);
   827         ec_slave_check_crc(slave);
   811 
   828 
   812         // Resetting FMMUs
   829         // Resetting FMMUs
   832                 return -1;
   849                 return -1;
   833             }
   850             }
   834         }
   851         }
   835 
   852 
   836         // Set Sync Managers
   853         // Set Sync Managers
   837         for (j = 0; type->sync_managers[j] && j < EC_MAX_SYNC; j++)
   854         if (type) {
   838         {
   855             for (j = 0; type->sync_managers[j] && j < EC_MAX_SYNC; j++)
   839             sync = type->sync_managers[j];
   856             {
   840 
   857                 sync = type->sync_managers[j];
   841             ec_sync_config(sync, data);
   858                 ec_sync_config(sync, data);
   842             ec_command_init_npwr(&command, slave->station_address,
   859                 ec_command_init_npwr(&command, slave->station_address,
   843                                  0x0800 + j * EC_SYNC_SIZE, EC_SYNC_SIZE,
   860                                      0x0800 + j * EC_SYNC_SIZE, EC_SYNC_SIZE,
   844                                  data);
   861                                      data);
   845             if (unlikely(ec_master_simple_io(master, &command))) {
   862                 if (unlikely(ec_master_simple_io(master, &command))) {
   846                 EC_ERR("Setting sync manager %i failed on slave %i!\n",
   863                     EC_ERR("Setting sync manager %i failed on slave %i!\n",
   847                        j, slave->ring_position);
   864                            j, slave->ring_position);
   848                 return -1;
   865                     return -1;
       
   866                 }
       
   867             }
       
   868         }
       
   869         else if (slave->sii_mailbox_protocols) { // Unknown slave, has mailbox
       
   870             list_for_each_entry(eeprom_sync, &slave->eeprom_syncs, list) {
       
   871                 ec_eeprom_sync_config(eeprom_sync, data);
       
   872                 ec_command_init_npwr(&command, slave->station_address,
       
   873                                      0x800 + eeprom_sync->index * EC_SYNC_SIZE,
       
   874                                      EC_SYNC_SIZE, data);
       
   875                 if (unlikely(ec_master_simple_io(master, &command))) {
       
   876                     EC_ERR("Setting sync manager %i failed on slave %i!\n",
       
   877                            eeprom_sync->index, slave->ring_position);
       
   878                     return -1;
       
   879                 }
   849             }
   880             }
   850         }
   881         }
   851 
   882 
   852         // Change state to PREOP
   883         // Change state to PREOP
   853         if (unlikely(ec_slave_state_change(slave, EC_SLAVE_STATE_PREOP)))
   884         if (unlikely(ec_slave_state_change(slave, EC_SLAVE_STATE_PREOP)))
   854             return -1;
   885             return -1;
       
   886 
       
   887         // Stop activation here for slaves without type
       
   888         if (!type) continue;
   855 
   889 
   856         // Slaves that are not registered are only brought into PREOP
   890         // Slaves that are not registered are only brought into PREOP
   857         // state -> nice blinking and mailbox comm. possible
   891         // state -> nice blinking and mailbox comm. possible
   858         if (!slave->registered && !slave->type->bus_coupler) {
   892         if (!slave->registered && !slave->type->bus_coupler) {
   859             EC_WARN("Slave %i was not registered!\n", slave->ring_position);
   893             EC_WARN("Slave %i was not registered!\n", slave->ring_position);
  1167                                   )
  1201                                   )
  1168 {
  1202 {
  1169     ec_slave_t *slave;
  1203     ec_slave_t *slave;
  1170     if (!(slave = ec_master_slave_address(master, slave_address)))
  1204     if (!(slave = ec_master_slave_address(master, slave_address)))
  1171         return -1;
  1205         return -1;
  1172     return ec_slave_sii_write(slave, 0x0004, alias);
  1206     return ec_slave_sii_write16(slave, 0x0004, alias);
  1173 }
  1207 }
  1174 
  1208 
  1175 /*****************************************************************************/
  1209 /*****************************************************************************/
  1176 
  1210 
  1177 EXPORT_SYMBOL(ecrt_master_create_domain);
  1211 EXPORT_SYMBOL(ecrt_master_create_domain);