master/slave_config.c
changeset 1082 ff06c58e269c
parent 1075 94c6e36e0f8d
child 1092 69393cf60399
equal deleted inserted replaced
1081:66c60b99c2e8 1082:ff06c58e269c
    68     sc->position = position;
    68     sc->position = position;
    69     sc->vendor_id = vendor_id;
    69     sc->vendor_id = vendor_id;
    70     sc->product_code = product_code;
    70     sc->product_code = product_code;
    71     sc->slave = NULL;
    71     sc->slave = NULL;
    72 
    72 
    73     for (i = 0; i < EC_MAX_SYNCS; i++)
    73     for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++)
    74         ec_sync_config_init(&sc->sync_configs[i]);
    74         ec_sync_config_init(&sc->sync_configs[i]);
    75 
    75 
    76     INIT_LIST_HEAD(&sc->sdo_configs);
    76     INIT_LIST_HEAD(&sc->sdo_configs);
    77     INIT_LIST_HEAD(&sc->sdo_requests);
    77     INIT_LIST_HEAD(&sc->sdo_requests);
    78 
    78 
    93     ec_sdo_request_t *req, *next_req;
    93     ec_sdo_request_t *req, *next_req;
    94 
    94 
    95     ec_slave_config_detach(sc);
    95     ec_slave_config_detach(sc);
    96 
    96 
    97     // Free sync managers
    97     // Free sync managers
    98     for (i = 0; i < EC_MAX_SYNCS; i++)
    98     for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++)
    99         ec_sync_config_clear(&sc->sync_configs[i]);
    99         ec_sync_config_clear(&sc->sync_configs[i]);
   100 
   100 
   101     // free all Sdo configurations
   101     // free all Sdo configurations
   102     list_for_each_entry_safe(req, next_req, &sc->sdo_configs, list) {
   102     list_for_each_entry_safe(req, next_req, &sc->sdo_configs, list) {
   103         list_del(&req->list);
   103         list_del(&req->list);
   240     const ec_sync_t *sync;
   240     const ec_sync_t *sync;
   241 
   241 
   242     if (!sc->slave)
   242     if (!sc->slave)
   243         return;
   243         return;
   244     
   244     
   245     for (sync_index = 0; sync_index < EC_MAX_SYNCS; sync_index++) {
   245     for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++) {
   246         sync_config = &sc->sync_configs[sync_index];
   246         sync_config = &sc->sync_configs[sync_index];
   247         if ((sync = ec_slave_get_sync(sc->slave, sync_index))) {
   247         if ((sync = ec_slave_get_sync(sc->slave, sync_index))) {
   248             sync_config->dir = ec_sync_default_direction(sync);
   248             sync_config->dir = ec_sync_default_direction(sync);
   249             if (sync_config->dir == EC_DIR_INVALID)
   249             if (sync_config->dir == EC_DIR_INVALID)
   250                 EC_WARN("SM%u of slave %u has an invalid direction field!\n",
   250                 EC_WARN("SM%u of slave %u has an invalid direction field!\n",
   359     
   359     
   360     if (sc->master->debug_level)
   360     if (sc->master->debug_level)
   361         EC_DBG("ecrt_slave_config_sync_manager(sc = 0x%x, sync_index = %u, "
   361         EC_DBG("ecrt_slave_config_sync_manager(sc = 0x%x, sync_index = %u, "
   362                 "dir = %u)\n", (u32) sc, sync_index, dir);
   362                 "dir = %u)\n", (u32) sc, sync_index, dir);
   363 
   363 
   364     if (sync_index >= EC_MAX_SYNCS) {
   364     if (sync_index >= EC_MAX_SYNC_MANAGERS) {
   365         EC_ERR("Invalid sync manager index %u!\n", sync_index);
   365         EC_ERR("Invalid sync manager index %u!\n", sync_index);
   366         return -1;
   366         return -1;
   367     }
   367     }
   368 
   368 
   369     if (dir != EC_DIR_OUTPUT && dir != EC_DIR_INPUT) {
   369     if (dir != EC_DIR_OUTPUT && dir != EC_DIR_INPUT) {
   385 
   385 
   386     if (sc->master->debug_level)
   386     if (sc->master->debug_level)
   387         EC_DBG("ecrt_slave_config_pdo_assign_add(sc = 0x%x, sync_index = %u, "
   387         EC_DBG("ecrt_slave_config_pdo_assign_add(sc = 0x%x, sync_index = %u, "
   388                 "pdo_index = 0x%04X)\n", (u32) sc, sync_index, pdo_index);
   388                 "pdo_index = 0x%04X)\n", (u32) sc, sync_index, pdo_index);
   389 
   389 
   390     if (sync_index >= EC_MAX_SYNCS) {
   390     if (sync_index >= EC_MAX_SYNC_MANAGERS) {
   391         EC_ERR("Invalid sync manager index %u!\n", sync_index);
   391         EC_ERR("Invalid sync manager index %u!\n", sync_index);
   392         return -1;
   392         return -1;
   393     }
   393     }
   394 
   394 
   395     down(&sc->master->master_sem);
   395     down(&sc->master->master_sem);
   414 {
   414 {
   415     if (sc->master->debug_level)
   415     if (sc->master->debug_level)
   416         EC_DBG("ecrt_slave_config_pdo_assign_clear(sc = 0x%x, "
   416         EC_DBG("ecrt_slave_config_pdo_assign_clear(sc = 0x%x, "
   417                 "sync_index = %u)\n", (u32) sc, sync_index);
   417                 "sync_index = %u)\n", (u32) sc, sync_index);
   418 
   418 
   419     if (sync_index >= EC_MAX_SYNCS) {
   419     if (sync_index >= EC_MAX_SYNC_MANAGERS) {
   420         EC_ERR("Invalid sync manager index %u!\n", sync_index);
   420         EC_ERR("Invalid sync manager index %u!\n", sync_index);
   421         return;
   421         return;
   422     }
   422     }
   423 
   423 
   424     down(&sc->master->master_sem);
   424     down(&sc->master->master_sem);
   441                 "pdo_index = 0x%04X, entry_index = 0x%04X, "
   441                 "pdo_index = 0x%04X, entry_index = 0x%04X, "
   442                 "entry_subindex = 0x%02X, entry_bit_length = %u)\n",
   442                 "entry_subindex = 0x%02X, entry_bit_length = %u)\n",
   443                 (u32) sc, pdo_index, entry_index, entry_subindex,
   443                 (u32) sc, pdo_index, entry_index, entry_subindex,
   444                 entry_bit_length);
   444                 entry_bit_length);
   445 
   445 
   446     for (sync_index = 0; sync_index < EC_MAX_SYNCS; sync_index++)
   446     for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++)
   447         if ((pdo = ec_pdo_list_find_pdo(
   447         if ((pdo = ec_pdo_list_find_pdo(
   448                         &sc->sync_configs[sync_index].pdos, pdo_index)))
   448                         &sc->sync_configs[sync_index].pdos, pdo_index)))
   449             break;
   449             break;
   450 
   450 
   451     if (pdo) {
   451     if (pdo) {
   471     
   471     
   472     if (sc->master->debug_level)
   472     if (sc->master->debug_level)
   473         EC_DBG("ecrt_slave_config_pdo_mapping_clear(sc = 0x%x, "
   473         EC_DBG("ecrt_slave_config_pdo_mapping_clear(sc = 0x%x, "
   474                 "pdo_index = 0x%04X)\n", (u32) sc, pdo_index);
   474                 "pdo_index = 0x%04X)\n", (u32) sc, pdo_index);
   475 
   475 
   476     for (sync_index = 0; sync_index < EC_MAX_SYNCS; sync_index++)
   476     for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++)
   477         if ((pdo = ec_pdo_list_find_pdo(
   477         if ((pdo = ec_pdo_list_find_pdo(
   478                         &sc->sync_configs[sync_index].pdos, pdo_index)))
   478                         &sc->sync_configs[sync_index].pdos, pdo_index)))
   479             break;
   479             break;
   480 
   480 
   481     if (pdo) {
   481     if (pdo) {
   488     }
   488     }
   489 }
   489 }
   490 
   490 
   491 /*****************************************************************************/
   491 /*****************************************************************************/
   492 
   492 
   493 int ecrt_slave_config_sync_managers(ec_slave_config_t *sc,
   493 int ecrt_slave_config_pdos(ec_slave_config_t *sc,
   494         unsigned int n_syncs, const ec_sync_info_t syncs[])
   494         unsigned int n_syncs, const ec_sync_info_t syncs[])
   495 {
   495 {
   496     unsigned int i, j, k;
   496     unsigned int i, j, k;
   497     const ec_sync_info_t *sync_info;
   497     const ec_sync_info_t *sync_info;
   498     const ec_pdo_info_t *pdo_info;
   498     const ec_pdo_info_t *pdo_info;
   499     const ec_pdo_entry_info_t *entry_info;
   499     const ec_pdo_entry_info_t *entry_info;
   500 
   500 
   501     if (sc->master->debug_level)
   501     if (sc->master->debug_level)
   502         EC_DBG("ecrt_slave_config_sync_managers(sc = 0x%x, n_syncs = %u, "
   502         EC_DBG("ecrt_slave_config_pdos(sc = 0x%x, n_syncs = %u, "
   503                 "syncs = 0x%x)\n", (u32) sc, n_syncs, (u32) syncs);
   503                 "syncs = 0x%x)\n", (u32) sc, n_syncs, (u32) syncs);
   504 
   504 
   505     if (!syncs)
   505     if (!syncs)
   506         return 0;
   506         return 0;
   507 
   507 
   509         sync_info = &syncs[i];
   509         sync_info = &syncs[i];
   510 
   510 
   511         if (sync_info->index == 0xff)
   511         if (sync_info->index == 0xff)
   512             break;
   512             break;
   513 
   513 
   514         if (sync_info->index >= EC_MAX_SYNCS) {
   514         if (sync_info->index >= EC_MAX_SYNC_MANAGERS) {
   515             EC_ERR("Invalid sync manager index %u!\n", sync_info->index);
   515             EC_ERR("Invalid sync manager index %u!\n", sync_info->index);
   516             return -1;
   516             return -1;
   517         }
   517         }
   518 
   518 
   519         if (ecrt_slave_config_sync_manager(
   519         if (ecrt_slave_config_sync_manager(
   570     if (sc->master->debug_level)
   570     if (sc->master->debug_level)
   571         EC_DBG("ecrt_slave_config_reg_pdo_entry(sc = 0x%x, index = 0x%04X, "
   571         EC_DBG("ecrt_slave_config_reg_pdo_entry(sc = 0x%x, index = 0x%04X, "
   572                 "subindex = 0x%02X, domain = 0x%x, bit_position = 0x%x)\n",
   572                 "subindex = 0x%02X, domain = 0x%x, bit_position = 0x%x)\n",
   573                 (u32) sc, index, subindex, (u32) domain, (u32) bit_position);
   573                 (u32) sc, index, subindex, (u32) domain, (u32) bit_position);
   574 
   574 
   575     for (sync_index = 0; sync_index < EC_MAX_SYNCS; sync_index++) {
   575     for (sync_index = 0; sync_index < EC_MAX_SYNC_MANAGERS; sync_index++) {
   576         sync_config = &sc->sync_configs[sync_index];
   576         sync_config = &sc->sync_configs[sync_index];
   577         bit_offset = 0;
   577         bit_offset = 0;
   578 
   578 
   579         list_for_each_entry(pdo, &sync_config->pdos.list, list) {
   579         list_for_each_entry(pdo, &sync_config->pdos.list, list) {
   580             list_for_each_entry(entry, &pdo->entries, list) {
   580             list_for_each_entry(entry, &pdo->entries, list) {
   729 EXPORT_SYMBOL(ecrt_slave_config_sync_manager);
   729 EXPORT_SYMBOL(ecrt_slave_config_sync_manager);
   730 EXPORT_SYMBOL(ecrt_slave_config_pdo_assign_add);
   730 EXPORT_SYMBOL(ecrt_slave_config_pdo_assign_add);
   731 EXPORT_SYMBOL(ecrt_slave_config_pdo_assign_clear);
   731 EXPORT_SYMBOL(ecrt_slave_config_pdo_assign_clear);
   732 EXPORT_SYMBOL(ecrt_slave_config_pdo_mapping_add);
   732 EXPORT_SYMBOL(ecrt_slave_config_pdo_mapping_add);
   733 EXPORT_SYMBOL(ecrt_slave_config_pdo_mapping_clear);
   733 EXPORT_SYMBOL(ecrt_slave_config_pdo_mapping_clear);
   734 EXPORT_SYMBOL(ecrt_slave_config_sync_managers);
   734 EXPORT_SYMBOL(ecrt_slave_config_pdos);
   735 EXPORT_SYMBOL(ecrt_slave_config_reg_pdo_entry);
   735 EXPORT_SYMBOL(ecrt_slave_config_reg_pdo_entry);
   736 EXPORT_SYMBOL(ecrt_slave_config_sdo);
   736 EXPORT_SYMBOL(ecrt_slave_config_sdo);
   737 EXPORT_SYMBOL(ecrt_slave_config_sdo8);
   737 EXPORT_SYMBOL(ecrt_slave_config_sdo8);
   738 EXPORT_SYMBOL(ecrt_slave_config_sdo16);
   738 EXPORT_SYMBOL(ecrt_slave_config_sdo16);
   739 EXPORT_SYMBOL(ecrt_slave_config_sdo32);
   739 EXPORT_SYMBOL(ecrt_slave_config_sdo32);