master/slave_config.c
changeset 1327 4d179b06dd3c
parent 1326 ef907b0b5125
child 1332 d62633fea8ed
equal deleted inserted replaced
1326:ef907b0b5125 1327:4d179b06dd3c
    92 
    92 
    93     // Free sync managers
    93     // Free sync managers
    94     for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++)
    94     for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++)
    95         ec_sync_config_clear(&sc->sync_configs[i]);
    95         ec_sync_config_clear(&sc->sync_configs[i]);
    96 
    96 
    97     // free all Sdo configurations
    97     // free all SDO configurations
    98     list_for_each_entry_safe(req, next_req, &sc->sdo_configs, list) {
    98     list_for_each_entry_safe(req, next_req, &sc->sdo_configs, list) {
    99         list_del(&req->list);
    99         list_del(&req->list);
   100         ec_sdo_request_clear(req);
   100         ec_sdo_request_clear(req);
   101         kfree(req);
   101         kfree(req);
   102     }
   102     }
   103 
   103 
   104     // free all Sdo requests
   104     // free all SDO requests
   105     list_for_each_entry_safe(req, next_req, &sc->sdo_requests, list) {
   105     list_for_each_entry_safe(req, next_req, &sc->sdo_requests, list) {
   106         list_del(&req->list);
   106         list_del(&req->list);
   107         ec_sdo_request_clear(req);
   107         ec_sdo_request_clear(req);
   108         kfree(req);
   108         kfree(req);
   109     }
   109     }
   132  */
   132  */
   133 int ec_slave_config_prepare_fmmu(
   133 int ec_slave_config_prepare_fmmu(
   134         ec_slave_config_t *sc, /**< Slave configuration. */
   134         ec_slave_config_t *sc, /**< Slave configuration. */
   135         ec_domain_t *domain, /**< Domain. */
   135         ec_domain_t *domain, /**< Domain. */
   136         uint8_t sync_index, /**< Sync manager index. */
   136         uint8_t sync_index, /**< Sync manager index. */
   137         ec_direction_t dir /**< Pdo direction. */
   137         ec_direction_t dir /**< PDO direction. */
   138         )
   138         )
   139 {
   139 {
   140     unsigned int i;
   140     unsigned int i;
   141     ec_fmmu_config_t *fmmu;
   141     ec_fmmu_config_t *fmmu;
   142 
   142 
   232     }
   232     }
   233 }
   233 }
   234 
   234 
   235 /*****************************************************************************/
   235 /*****************************************************************************/
   236 
   236 
   237 /** Loads the default Pdo assignment from the slave object.
   237 /** Loads the default PDO assignment from the slave object.
   238  */
   238  */
   239 void ec_slave_config_load_default_sync_config(ec_slave_config_t *sc)
   239 void ec_slave_config_load_default_sync_config(ec_slave_config_t *sc)
   240 {
   240 {
   241     uint8_t sync_index;
   241     uint8_t sync_index;
   242     ec_sync_config_t *sync_config;
   242     ec_sync_config_t *sync_config;
   257     }
   257     }
   258 }
   258 }
   259 
   259 
   260 /*****************************************************************************/
   260 /*****************************************************************************/
   261 
   261 
   262 /** Loads the default mapping for a Pdo from the slave object.
   262 /** Loads the default mapping for a PDO from the slave object.
   263  */
   263  */
   264 void ec_slave_config_load_default_mapping(
   264 void ec_slave_config_load_default_mapping(
   265         const ec_slave_config_t *sc,
   265         const ec_slave_config_t *sc,
   266         ec_pdo_t *pdo
   266         ec_pdo_t *pdo
   267         )
   267         )
   272 
   272 
   273     if (!sc->slave)
   273     if (!sc->slave)
   274         return;
   274         return;
   275 
   275 
   276     if (sc->master->debug_level)
   276     if (sc->master->debug_level)
   277         EC_DBG("Loading default mapping for Pdo 0x%04X in config %u:%u.\n",
   277         EC_DBG("Loading default mapping for PDO 0x%04X in config %u:%u.\n",
   278                 pdo->index, sc->alias, sc->position);
   278                 pdo->index, sc->alias, sc->position);
   279 
   279 
   280     // find Pdo in any sync manager (it could be reassigned later)
   280     // find PDO in any sync manager (it could be reassigned later)
   281     for (i = 0; i < sc->slave->sii.sync_count; i++) {
   281     for (i = 0; i < sc->slave->sii.sync_count; i++) {
   282         sync = &sc->slave->sii.syncs[i];
   282         sync = &sc->slave->sii.syncs[i];
   283 
   283 
   284         list_for_each_entry(default_pdo, &sync->pdos.list, list) {
   284         list_for_each_entry(default_pdo, &sync->pdos.list, list) {
   285             if (default_pdo->index != pdo->index)
   285             if (default_pdo->index != pdo->index)
   286                 continue;
   286                 continue;
   287 
   287 
   288             if (default_pdo->name) {
   288             if (default_pdo->name) {
   289                 if (sc->master->debug_level)
   289                 if (sc->master->debug_level)
   290                     EC_DBG("Found Pdo name \"%s\".\n", default_pdo->name);
   290                     EC_DBG("Found PDO name \"%s\".\n", default_pdo->name);
   291 
   291 
   292                 // take Pdo name from assigned one
   292                 // take PDO name from assigned one
   293                 ec_pdo_set_name(pdo, default_pdo->name);
   293                 ec_pdo_set_name(pdo, default_pdo->name);
   294             }
   294             }
   295 
   295 
   296             // copy entries (= default Pdo mapping)
   296             // copy entries (= default PDO mapping)
   297             if (ec_pdo_copy_entries(pdo, default_pdo))
   297             if (ec_pdo_copy_entries(pdo, default_pdo))
   298                 return;
   298                 return;
   299 
   299 
   300             if (sc->master->debug_level) {
   300             if (sc->master->debug_level) {
   301                 const ec_pdo_entry_t *entry;
   301                 const ec_pdo_entry_t *entry;
   313         EC_DBG("No default mapping found.\n");
   313         EC_DBG("No default mapping found.\n");
   314 }
   314 }
   315 
   315 
   316 /*****************************************************************************/
   316 /*****************************************************************************/
   317 
   317 
   318 /** Get the number of Sdo configurations.
   318 /** Get the number of SDO configurations.
   319  *
   319  *
   320  * \return Number of Sdo configurations.
   320  * \return Number of SDO configurations.
   321  */
   321  */
   322 unsigned int ec_slave_config_sdo_count(
   322 unsigned int ec_slave_config_sdo_count(
   323         const ec_slave_config_t *sc /**< Slave configuration. */
   323         const ec_slave_config_t *sc /**< Slave configuration. */
   324         )
   324         )
   325 {
   325 {
   333 	return count;
   333 	return count;
   334 }
   334 }
   335 
   335 
   336 /*****************************************************************************/
   336 /*****************************************************************************/
   337 
   337 
   338 /** Finds an Sdo configuration via its position in the list.
   338 /** Finds an SDO configuration via its position in the list.
   339  *
   339  *
   340  * Const version.
   340  * Const version.
   341  */
   341  */
   342 const ec_sdo_request_t *ec_slave_config_get_sdo_by_pos_const(
   342 const ec_sdo_request_t *ec_slave_config_get_sdo_by_pos_const(
   343         const ec_slave_config_t *sc, /**< Slave configuration. */
   343         const ec_slave_config_t *sc, /**< Slave configuration. */
   482                 entry_bit_length);
   482                 entry_bit_length);
   483         up(&sc->master->master_sem);
   483         up(&sc->master->master_sem);
   484         if (IS_ERR(entry))
   484         if (IS_ERR(entry))
   485             retval = PTR_ERR(entry);
   485             retval = PTR_ERR(entry);
   486     } else {
   486     } else {
   487         EC_ERR("Pdo 0x%04X is not assigned in config %u:%u.\n",
   487         EC_ERR("PDO 0x%04X is not assigned in config %u:%u.\n",
   488                 pdo_index, sc->alias, sc->position);
   488                 pdo_index, sc->alias, sc->position);
   489         retval = -ENOENT; 
   489         retval = -ENOENT; 
   490     }
   490     }
   491 
   491 
   492     return retval;
   492     return retval;
   512     if (pdo) {
   512     if (pdo) {
   513         down(&sc->master->master_sem);
   513         down(&sc->master->master_sem);
   514         ec_pdo_clear_entries(pdo);
   514         ec_pdo_clear_entries(pdo);
   515         up(&sc->master->master_sem);
   515         up(&sc->master->master_sem);
   516     } else {
   516     } else {
   517         EC_WARN("Pdo 0x%04X is not assigned in config %u:%u.\n",
   517         EC_WARN("PDO 0x%04X is not assigned in config %u:%u.\n",
   518                 pdo_index, sc->alias, sc->position);
   518                 pdo_index, sc->alias, sc->position);
   519     }
   519     }
   520 }
   520 }
   521 
   521 
   522 /*****************************************************************************/
   522 /*****************************************************************************/
   618                 } else {
   618                 } else {
   619                     bit_pos = bit_offset % 8;
   619                     bit_pos = bit_offset % 8;
   620                     if (bit_position) {
   620                     if (bit_position) {
   621                         *bit_position = bit_pos;
   621                         *bit_position = bit_pos;
   622                     } else if (bit_pos) {
   622                     } else if (bit_pos) {
   623                         EC_ERR("Pdo entry 0x%04X:%02X does not byte-align "
   623                         EC_ERR("PDO entry 0x%04X:%02X does not byte-align "
   624                                 "in config %u:%u.\n", index, subindex,
   624                                 "in config %u:%u.\n", index, subindex,
   625                                 sc->alias, sc->position);
   625                                 sc->alias, sc->position);
   626                         return -EFAULT;
   626                         return -EFAULT;
   627                     }
   627                     }
   628 
   628 
   635                 }
   635                 }
   636             }
   636             }
   637         }
   637         }
   638     }
   638     }
   639 
   639 
   640     EC_ERR("Pdo entry 0x%04X:%02X is not mapped in slave config %u:%u.\n",
   640     EC_ERR("PDO entry 0x%04X:%02X is not mapped in slave config %u:%u.\n",
   641            index, subindex, sc->alias, sc->position);
   641            index, subindex, sc->alias, sc->position);
   642     return -ENOENT;
   642     return -ENOENT;
   643 }
   643 }
   644 
   644 
   645 
   645 
   662         return -EPROTONOSUPPORT; // protocol not supported
   662         return -EPROTONOSUPPORT; // protocol not supported
   663     }
   663     }
   664 
   664 
   665     if (!(req = (ec_sdo_request_t *)
   665     if (!(req = (ec_sdo_request_t *)
   666           kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
   666           kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
   667         EC_ERR("Failed to allocate memory for Sdo configuration!\n");
   667         EC_ERR("Failed to allocate memory for SDO configuration!\n");
   668         return -ENOMEM;
   668         return -ENOMEM;
   669     }
   669     }
   670 
   670 
   671     ec_sdo_request_init(req);
   671     ec_sdo_request_init(req);
   672     ec_sdo_request_address(req, index, subindex);
   672     ec_sdo_request_address(req, index, subindex);
   745                 "index = 0x%04X, subindex = 0x%02X, size = %u)\n", (u32) sc,
   745                 "index = 0x%04X, subindex = 0x%02X, size = %u)\n", (u32) sc,
   746                 index, subindex, size);
   746                 index, subindex, size);
   747 
   747 
   748     if (!(req = (ec_sdo_request_t *)
   748     if (!(req = (ec_sdo_request_t *)
   749                 kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
   749                 kmalloc(sizeof(ec_sdo_request_t), GFP_KERNEL))) {
   750         EC_ERR("Failed to allocate Sdo request memory!\n");
   750         EC_ERR("Failed to allocate SDO request memory!\n");
   751         return ERR_PTR(-ENOMEM);
   751         return ERR_PTR(-ENOMEM);
   752     }
   752     }
   753 
   753 
   754     ec_sdo_request_init(req);
   754     ec_sdo_request_init(req);
   755     ec_sdo_request_address(req, index, subindex);
   755     ec_sdo_request_address(req, index, subindex);
   794         EC_DBG("ecrt_slave_config_create_voe_handler(sc = 0x%x, size = %u)\n",
   794         EC_DBG("ecrt_slave_config_create_voe_handler(sc = 0x%x, size = %u)\n",
   795                 (u32) sc, size);
   795                 (u32) sc, size);
   796 
   796 
   797     if (!(voe = (ec_voe_handler_t *)
   797     if (!(voe = (ec_voe_handler_t *)
   798                 kmalloc(sizeof(ec_voe_handler_t), GFP_KERNEL))) {
   798                 kmalloc(sizeof(ec_voe_handler_t), GFP_KERNEL))) {
   799         EC_ERR("Failed to allocate Sdo request memory!\n");
   799         EC_ERR("Failed to allocate VoE request memory!\n");
   800         return ERR_PTR(-ENOMEM);
   800         return ERR_PTR(-ENOMEM);
   801     }
   801     }
   802 
   802 
   803     ret = ec_voe_handler_init(voe, sc, size);
   803     ret = ec_voe_handler_init(voe, sc, size);
   804     if (ret < 0) {
   804     if (ret < 0) {