master/slave_config.c
branchstable-1.4
changeset 1686 e206f4485f60
parent 1685 399ef727bf62
equal deleted inserted replaced
1685:399ef727bf62 1686:e206f4485f60
    89 
    89 
    90     // Free sync managers
    90     // Free sync managers
    91     for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++)
    91     for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++)
    92         ec_sync_config_clear(&sc->sync_configs[i]);
    92         ec_sync_config_clear(&sc->sync_configs[i]);
    93 
    93 
    94     // free all Sdo configurations
    94     // free all SDO configurations
    95     list_for_each_entry_safe(req, next_req, &sc->sdo_configs, list) {
    95     list_for_each_entry_safe(req, next_req, &sc->sdo_configs, list) {
    96         list_del(&req->list);
    96         list_del(&req->list);
    97         ec_sdo_request_clear(req);
    97         ec_sdo_request_clear(req);
    98         kfree(req);
    98         kfree(req);
    99     }
    99     }
   100 
   100 
   101     // free all Sdo requests
   101     // free all SDO requests
   102     list_for_each_entry_safe(req, next_req, &sc->sdo_requests, list) {
   102     list_for_each_entry_safe(req, next_req, &sc->sdo_requests, list) {
   103         list_del(&req->list);
   103         list_del(&req->list);
   104         ec_sdo_request_clear(req);
   104         ec_sdo_request_clear(req);
   105         kfree(req);
   105         kfree(req);
   106     }
   106     }
   122  */
   122  */
   123 int ec_slave_config_prepare_fmmu(
   123 int ec_slave_config_prepare_fmmu(
   124         ec_slave_config_t *sc, /**< Slave configuration. */
   124         ec_slave_config_t *sc, /**< Slave configuration. */
   125         ec_domain_t *domain, /**< Domain. */
   125         ec_domain_t *domain, /**< Domain. */
   126         uint8_t sync_index, /**< Sync manager index. */
   126         uint8_t sync_index, /**< Sync manager index. */
   127         ec_direction_t dir /**< Pdo direction. */
   127         ec_direction_t dir /**< PDO direction. */
   128         )
   128         )
   129 {
   129 {
   130     unsigned int i;
   130     unsigned int i;
   131     ec_fmmu_config_t *fmmu;
   131     ec_fmmu_config_t *fmmu;
   132 
   132 
   224     }
   224     }
   225 }
   225 }
   226 
   226 
   227 /*****************************************************************************/
   227 /*****************************************************************************/
   228 
   228 
   229 /** Loads the default Pdo assignment from the slave object.
   229 /** Loads the default PDO assignment from the slave object.
   230  */
   230  */
   231 void ec_slave_config_load_default_sync_config(ec_slave_config_t *sc)
   231 void ec_slave_config_load_default_sync_config(ec_slave_config_t *sc)
   232 {
   232 {
   233     uint8_t sync_index;
   233     uint8_t sync_index;
   234     ec_sync_config_t *sync_config;
   234     ec_sync_config_t *sync_config;
   249     }
   249     }
   250 }
   250 }
   251 
   251 
   252 /*****************************************************************************/
   252 /*****************************************************************************/
   253 
   253 
   254 /** Loads the default mapping for a Pdo from the slave object.
   254 /** Loads the default mapping for a PDO from the slave object.
   255  */
   255  */
   256 void ec_slave_config_load_default_mapping(
   256 void ec_slave_config_load_default_mapping(
   257         const ec_slave_config_t *sc,
   257         const ec_slave_config_t *sc,
   258         ec_pdo_t *pdo
   258         ec_pdo_t *pdo
   259         )
   259         )
   264 
   264 
   265     if (!sc->slave)
   265     if (!sc->slave)
   266         return;
   266         return;
   267 
   267 
   268     if (sc->master->debug_level)
   268     if (sc->master->debug_level)
   269         EC_DBG("Loading default mapping for Pdo 0x%04X in config %u:%u.\n",
   269         EC_DBG("Loading default mapping for PDO 0x%04X in config %u:%u.\n",
   270                 pdo->index, sc->alias, sc->position);
   270                 pdo->index, sc->alias, sc->position);
   271 
   271 
   272     // find Pdo in any sync manager (it could be reassigned later)
   272     // find PDO in any sync manager (it could be reassigned later)
   273     for (i = 0; i < sc->slave->sii.sync_count; i++) {
   273     for (i = 0; i < sc->slave->sii.sync_count; i++) {
   274         sync = &sc->slave->sii.syncs[i];
   274         sync = &sc->slave->sii.syncs[i];
   275 
   275 
   276         list_for_each_entry(default_pdo, &sync->pdos.list, list) {
   276         list_for_each_entry(default_pdo, &sync->pdos.list, list) {
   277             if (default_pdo->index != pdo->index)
   277             if (default_pdo->index != pdo->index)
   278                 continue;
   278                 continue;
   279 
   279 
   280             if (default_pdo->name) {
   280             if (default_pdo->name) {
   281                 if (sc->master->debug_level)
   281                 if (sc->master->debug_level)
   282                     EC_DBG("Found Pdo name \"%s\".\n", default_pdo->name);
   282                     EC_DBG("Found PDO name \"%s\".\n", default_pdo->name);
   283 
   283 
   284                 // take Pdo name from assigned one
   284                 // take PDO name from assigned one
   285                 ec_pdo_set_name(pdo, default_pdo->name);
   285                 ec_pdo_set_name(pdo, default_pdo->name);
   286             }
   286             }
   287 
   287 
   288             // copy entries (= default Pdo mapping)
   288             // copy entries (= default PDO mapping)
   289             if (ec_pdo_copy_entries(pdo, default_pdo))
   289             if (ec_pdo_copy_entries(pdo, default_pdo))
   290                 return;
   290                 return;
   291 
   291 
   292             if (sc->master->debug_level) {
   292             if (sc->master->debug_level) {
   293                 const ec_pdo_entry_t *entry;
   293                 const ec_pdo_entry_t *entry;
   305         EC_DBG("No default mapping found.\n");
   305         EC_DBG("No default mapping found.\n");
   306 }
   306 }
   307 
   307 
   308 /*****************************************************************************/
   308 /*****************************************************************************/
   309 
   309 
   310 /** Get the number of Sdo configurations.
   310 /** Get the number of SDO configurations.
   311  *
   311  *
   312  * \return Number of Sdo configurations.
   312  * \return Number of SDO configurations.
   313  */
   313  */
   314 unsigned int ec_slave_config_sdo_count(
   314 unsigned int ec_slave_config_sdo_count(
   315         const ec_slave_config_t *sc /**< Slave configuration. */
   315         const ec_slave_config_t *sc /**< Slave configuration. */
   316         )
   316         )
   317 {
   317 {
   325 	return count;
   325 	return count;
   326 }
   326 }
   327 
   327 
   328 /*****************************************************************************/
   328 /*****************************************************************************/
   329 
   329 
   330 /** Finds an Sdo configuration via its position in the list.
   330 /** Finds an SDO configuration via its position in the list.
   331  *
   331  *
   332  * Const version.
   332  * Const version.
   333  */
   333  */
   334 const ec_sdo_request_t *ec_slave_config_get_sdo_by_pos_const(
   334 const ec_sdo_request_t *ec_slave_config_get_sdo_by_pos_const(
   335         const ec_slave_config_t *sc, /**< Slave configuration. */
   335         const ec_slave_config_t *sc, /**< Slave configuration. */
   451         down(&sc->master->master_sem);
   451         down(&sc->master->master_sem);
   452         retval = ec_pdo_add_entry(pdo, entry_index, entry_subindex,
   452         retval = ec_pdo_add_entry(pdo, entry_index, entry_subindex,
   453                 entry_bit_length) ? 0 : -1;
   453                 entry_bit_length) ? 0 : -1;
   454         up(&sc->master->master_sem);
   454         up(&sc->master->master_sem);
   455     } else {
   455     } else {
   456         EC_ERR("Pdo 0x%04X is not assigned in config %u:%u.\n",
   456         EC_ERR("PDO 0x%04X is not assigned in config %u:%u.\n",
   457                 pdo_index, sc->alias, sc->position);
   457                 pdo_index, sc->alias, sc->position);
   458     }
   458     }
   459 
   459 
   460     return retval;
   460     return retval;
   461 }
   461 }
   480     if (pdo) {
   480     if (pdo) {
   481         down(&sc->master->master_sem);
   481         down(&sc->master->master_sem);
   482         ec_pdo_clear_entries(pdo);
   482         ec_pdo_clear_entries(pdo);
   483         up(&sc->master->master_sem);
   483         up(&sc->master->master_sem);
   484     } else {
   484     } else {
   485         EC_WARN("Pdo 0x%04X is not assigned in config %u:%u.\n",
   485         EC_WARN("PDO 0x%04X is not assigned in config %u:%u.\n",
   486                 pdo_index, sc->alias, sc->position);
   486                 pdo_index, sc->alias, sc->position);
   487     }
   487     }
   488 }
   488 }
   489 
   489 
   490 /*****************************************************************************/
   490 /*****************************************************************************/
   582                 } else {
   582                 } else {
   583                     bit_pos = bit_offset % 8;
   583                     bit_pos = bit_offset % 8;
   584                     if (bit_position) {
   584                     if (bit_position) {
   585                         *bit_position = bit_pos;
   585                         *bit_position = bit_pos;
   586                     } else if (bit_pos) {
   586                     } else if (bit_pos) {
   587                         EC_ERR("Pdo entry 0x%04X:%02X does not byte-align "
   587                         EC_ERR("PDO entry 0x%04X:%02X does not byte-align "
   588                                 "in config %u:%u.\n", index, subindex,
   588                                 "in config %u:%u.\n", index, subindex,
   589                                 sc->alias, sc->position);
   589                                 sc->alias, sc->position);
   590                         return -3;
   590                         return -3;
   591                     }
   591                     }
   592 
   592 
   599                 }
   599                 }
   600             }
   600             }
   601         }
   601         }
   602     }
   602     }
   603 
   603 
   604     EC_ERR("Pdo entry 0x%04X:%02X is not mapped in slave config %u:%u.\n",
   604     EC_ERR("PDO entry 0x%04X:%02X is not mapped in slave config %u:%u.\n",
   605            index, subindex, sc->alias, sc->position);
   605            index, subindex, sc->alias, sc->position);
   606     return -1;
   606     return -1;
   607 }
   607 }
   608 
   608 
   609 
   609 
   625         return -1;
   625         return -1;
   626     }
   626     }
   627 
   627 
   628     if (!(req = (ec_sdo_request_t *)
   628     if (!(req = (ec_sdo_request_t *)
   629           kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
   629           kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
   630         EC_ERR("Failed to allocate memory for Sdo configuration!\n");
   630         EC_ERR("Failed to allocate memory for SDO configuration!\n");
   631         return -1;
   631         return -1;
   632     }
   632     }
   633 
   633 
   634     ec_sdo_request_init(req);
   634     ec_sdo_request_init(req);
   635     ec_sdo_request_address(req, index, subindex);
   635     ec_sdo_request_address(req, index, subindex);
   707                 "index = 0x%04X, subindex = 0x%02X, size = %u)\n", (u32) sc,
   707                 "index = 0x%04X, subindex = 0x%02X, size = %u)\n", (u32) sc,
   708                 index, subindex, size);
   708                 index, subindex, size);
   709 
   709 
   710     if (!(req = (ec_sdo_request_t *)
   710     if (!(req = (ec_sdo_request_t *)
   711                 kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
   711                 kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
   712         EC_ERR("Failed to allocate Sdo request memory!\n");
   712         EC_ERR("Failed to allocate SDO request memory!\n");
   713         return NULL;
   713         return NULL;
   714     }
   714     }
   715 
   715 
   716     ec_sdo_request_init(req);
   716     ec_sdo_request_init(req);
   717     ec_sdo_request_address(req, index, subindex);
   717     ec_sdo_request_address(req, index, subindex);