master/cdev.c
changeset 1327 4d179b06dd3c
parent 1326 ef907b0b5125
child 1328 00c0e0ecd2c4
equal deleted inserted replaced
1326:ef907b0b5125 1327:4d179b06dd3c
   304     return 0;
   304     return 0;
   305 }
   305 }
   306 
   306 
   307 /*****************************************************************************/
   307 /*****************************************************************************/
   308 
   308 
   309 /** Get slave sync manager Pdo information.
   309 /** Get slave sync manager PDO information.
   310  */
   310  */
   311 int ec_cdev_ioctl_slave_sync_pdo(
   311 int ec_cdev_ioctl_slave_sync_pdo(
   312         ec_master_t *master, /**< EtherCAT master. */
   312         ec_master_t *master, /**< EtherCAT master. */
   313         unsigned long arg /**< Userspace address to store the results. */
   313         unsigned long arg /**< Userspace address to store the results. */
   314         )
   314         )
   341 
   341 
   342     sync = &slave->sii.syncs[data.sync_index];
   342     sync = &slave->sii.syncs[data.sync_index];
   343     if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
   343     if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
   344                     &sync->pdos, data.pdo_pos))) {
   344                     &sync->pdos, data.pdo_pos))) {
   345         up(&master->master_sem);
   345         up(&master->master_sem);
   346         EC_ERR("Sync manager %u does not contain a Pdo with "
   346         EC_ERR("Sync manager %u does not contain a PDO with "
   347                 "position %u in slave %u!\n", data.sync_index,
   347                 "position %u in slave %u!\n", data.sync_index,
   348                 data.pdo_pos, data.slave_position);
   348                 data.pdo_pos, data.slave_position);
   349         return -EINVAL;
   349         return -EINVAL;
   350     }
   350     }
   351 
   351 
   361     return 0;
   361     return 0;
   362 }
   362 }
   363 
   363 
   364 /*****************************************************************************/
   364 /*****************************************************************************/
   365 
   365 
   366 /** Get slave sync manager Pdo entry information.
   366 /** Get slave sync manager PDO entry information.
   367  */
   367  */
   368 int ec_cdev_ioctl_slave_sync_pdo_entry(
   368 int ec_cdev_ioctl_slave_sync_pdo_entry(
   369         ec_master_t *master, /**< EtherCAT master. */
   369         ec_master_t *master, /**< EtherCAT master. */
   370         unsigned long arg /**< Userspace address to store the results. */
   370         unsigned long arg /**< Userspace address to store the results. */
   371         )
   371         )
   399 
   399 
   400     sync = &slave->sii.syncs[data.sync_index];
   400     sync = &slave->sii.syncs[data.sync_index];
   401     if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
   401     if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
   402                     &sync->pdos, data.pdo_pos))) {
   402                     &sync->pdos, data.pdo_pos))) {
   403         up(&master->master_sem);
   403         up(&master->master_sem);
   404         EC_ERR("Sync manager %u does not contain a Pdo with "
   404         EC_ERR("Sync manager %u does not contain a PDO with "
   405                 "position %u in slave %u!\n", data.sync_index,
   405                 "position %u in slave %u!\n", data.sync_index,
   406                 data.pdo_pos, data.slave_position);
   406                 data.pdo_pos, data.slave_position);
   407         return -EINVAL;
   407         return -EINVAL;
   408     }
   408     }
   409 
   409 
   410     if (!(entry = ec_pdo_find_entry_by_pos_const(
   410     if (!(entry = ec_pdo_find_entry_by_pos_const(
   411                     pdo, data.entry_pos))) {
   411                     pdo, data.entry_pos))) {
   412         up(&master->master_sem);
   412         up(&master->master_sem);
   413         EC_ERR("Pdo 0x%04X does not contain an entry with "
   413         EC_ERR("PDO 0x%04X does not contain an entry with "
   414                 "position %u in slave %u!\n", data.pdo_pos,
   414                 "position %u in slave %u!\n", data.pdo_pos,
   415                 data.entry_pos, data.slave_position);
   415                 data.entry_pos, data.slave_position);
   416         return -EINVAL;
   416         return -EINVAL;
   417     }
   417     }
   418 
   418 
   602     return 0;
   602     return 0;
   603 }
   603 }
   604 
   604 
   605 /*****************************************************************************/
   605 /*****************************************************************************/
   606 
   606 
   607 /** Get slave Sdo information.
   607 /** Get slave SDO information.
   608  */
   608  */
   609 int ec_cdev_ioctl_slave_sdo(
   609 int ec_cdev_ioctl_slave_sdo(
   610         ec_master_t *master, /**< EtherCAT master. */
   610         ec_master_t *master, /**< EtherCAT master. */
   611         unsigned long arg /**< ioctl() argument. */
   611         unsigned long arg /**< ioctl() argument. */
   612         )
   612         )
   630     }
   630     }
   631 
   631 
   632     if (!(sdo = ec_slave_get_sdo_by_pos_const(
   632     if (!(sdo = ec_slave_get_sdo_by_pos_const(
   633                     slave, data.sdo_position))) {
   633                     slave, data.sdo_position))) {
   634         up(&master->master_sem);
   634         up(&master->master_sem);
   635         EC_ERR("Sdo %u does not exist in slave %u!\n",
   635         EC_ERR("SDO %u does not exist in slave %u!\n",
   636                 data.sdo_position, data.slave_position);
   636                 data.sdo_position, data.slave_position);
   637         return -EINVAL;
   637         return -EINVAL;
   638     }
   638     }
   639 
   639 
   640     data.sdo_index = sdo->index;
   640     data.sdo_index = sdo->index;
   649     return 0;
   649     return 0;
   650 }
   650 }
   651 
   651 
   652 /*****************************************************************************/
   652 /*****************************************************************************/
   653 
   653 
   654 /** Get slave Sdo entry information.
   654 /** Get slave SDO entry information.
   655  */
   655  */
   656 int ec_cdev_ioctl_slave_sdo_entry(
   656 int ec_cdev_ioctl_slave_sdo_entry(
   657         ec_master_t *master, /**< EtherCAT master. */
   657         ec_master_t *master, /**< EtherCAT master. */
   658         unsigned long arg /**< ioctl() argument. */
   658         unsigned long arg /**< ioctl() argument. */
   659         )
   659         )
   679 
   679 
   680     if (data.sdo_spec <= 0) {
   680     if (data.sdo_spec <= 0) {
   681         if (!(sdo = ec_slave_get_sdo_by_pos_const(
   681         if (!(sdo = ec_slave_get_sdo_by_pos_const(
   682                         slave, -data.sdo_spec))) {
   682                         slave, -data.sdo_spec))) {
   683             up(&master->master_sem);
   683             up(&master->master_sem);
   684             EC_ERR("Sdo %u does not exist in slave %u!\n",
   684             EC_ERR("SDO %u does not exist in slave %u!\n",
   685                     -data.sdo_spec, data.slave_position);
   685                     -data.sdo_spec, data.slave_position);
   686             return -EINVAL;
   686             return -EINVAL;
   687         }
   687         }
   688     } else {
   688     } else {
   689         if (!(sdo = ec_slave_get_sdo_const(
   689         if (!(sdo = ec_slave_get_sdo_const(
   690                         slave, data.sdo_spec))) {
   690                         slave, data.sdo_spec))) {
   691             up(&master->master_sem);
   691             up(&master->master_sem);
   692             EC_ERR("Sdo 0x%04X does not exist in slave %u!\n",
   692             EC_ERR("SDO 0x%04X does not exist in slave %u!\n",
   693                     data.sdo_spec, data.slave_position);
   693                     data.sdo_spec, data.slave_position);
   694             return -EINVAL;
   694             return -EINVAL;
   695         }
   695         }
   696     }
   696     }
   697 
   697 
   698     if (!(entry = ec_sdo_get_entry_const(
   698     if (!(entry = ec_sdo_get_entry_const(
   699                     sdo, data.sdo_entry_subindex))) {
   699                     sdo, data.sdo_entry_subindex))) {
   700         up(&master->master_sem);
   700         up(&master->master_sem);
   701         EC_ERR("Sdo entry 0x%04X:%02X does not exist "
   701         EC_ERR("SDO entry 0x%04X:%02X does not exist "
   702                 "in slave %u!\n", sdo->index,
   702                 "in slave %u!\n", sdo->index,
   703                 data.sdo_entry_subindex, data.slave_position);
   703                 data.sdo_entry_subindex, data.slave_position);
   704         return -EINVAL;
   704         return -EINVAL;
   705     }
   705     }
   706 
   706 
   716     return 0;
   716     return 0;
   717 }
   717 }
   718 
   718 
   719 /*****************************************************************************/
   719 /*****************************************************************************/
   720 
   720 
   721 /** Upload Sdo.
   721 /** Upload SDO.
   722  */
   722  */
   723 int ec_cdev_ioctl_slave_sdo_upload(
   723 int ec_cdev_ioctl_slave_sdo_upload(
   724         ec_master_t *master, /**< EtherCAT master. */
   724         ec_master_t *master, /**< EtherCAT master. */
   725         unsigned long arg /**< ioctl() argument. */
   725         unsigned long arg /**< ioctl() argument. */
   726         )
   726         )
   801     return retval;
   801     return retval;
   802 }
   802 }
   803 
   803 
   804 /*****************************************************************************/
   804 /*****************************************************************************/
   805 
   805 
   806 /** Download Sdo.
   806 /** Download SDO.
   807  */
   807  */
   808 int ec_cdev_ioctl_slave_sdo_download(
   808 int ec_cdev_ioctl_slave_sdo_download(
   809         ec_master_t *master, /**< EtherCAT master. */
   809         ec_master_t *master, /**< EtherCAT master. */
   810         unsigned long arg /**< ioctl() argument. */
   810         unsigned long arg /**< ioctl() argument. */
   811         )
   811         )
  1217     return 0;
  1217     return 0;
  1218 }
  1218 }
  1219 
  1219 
  1220 /*****************************************************************************/
  1220 /*****************************************************************************/
  1221 
  1221 
  1222 /** Get slave configuration Pdo information.
  1222 /** Get slave configuration PDO information.
  1223  */
  1223  */
  1224 int ec_cdev_ioctl_config_pdo(
  1224 int ec_cdev_ioctl_config_pdo(
  1225         ec_master_t *master, /**< EtherCAT master. */
  1225         ec_master_t *master, /**< EtherCAT master. */
  1226         unsigned long arg /**< ioctl() argument. */
  1226         unsigned long arg /**< ioctl() argument. */
  1227         )
  1227         )
  1253 
  1253 
  1254     if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
  1254     if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
  1255                     &sc->sync_configs[data.sync_index].pdos,
  1255                     &sc->sync_configs[data.sync_index].pdos,
  1256                     data.pdo_pos))) {
  1256                     data.pdo_pos))) {
  1257         up(&master->master_sem);
  1257         up(&master->master_sem);
  1258         EC_ERR("Invalid Pdo position!\n");
  1258         EC_ERR("Invalid PDO position!\n");
  1259         return -EINVAL;
  1259         return -EINVAL;
  1260     }
  1260     }
  1261 
  1261 
  1262     data.index = pdo->index;
  1262     data.index = pdo->index;
  1263     data.entry_count = ec_pdo_entry_count(pdo);
  1263     data.entry_count = ec_pdo_entry_count(pdo);
  1271     return 0;
  1271     return 0;
  1272 }
  1272 }
  1273 
  1273 
  1274 /*****************************************************************************/
  1274 /*****************************************************************************/
  1275 
  1275 
  1276 /** Get slave configuration Pdo entry information.
  1276 /** Get slave configuration PDO entry information.
  1277  */
  1277  */
  1278 int ec_cdev_ioctl_config_pdo_entry(
  1278 int ec_cdev_ioctl_config_pdo_entry(
  1279         ec_master_t *master, /**< EtherCAT master. */
  1279         ec_master_t *master, /**< EtherCAT master. */
  1280         unsigned long arg /**< ioctl() argument. */
  1280         unsigned long arg /**< ioctl() argument. */
  1281         )
  1281         )
  1308 
  1308 
  1309     if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
  1309     if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
  1310                     &sc->sync_configs[data.sync_index].pdos,
  1310                     &sc->sync_configs[data.sync_index].pdos,
  1311                     data.pdo_pos))) {
  1311                     data.pdo_pos))) {
  1312         up(&master->master_sem);
  1312         up(&master->master_sem);
  1313         EC_ERR("Invalid Pdo position!\n");
  1313         EC_ERR("Invalid PDO position!\n");
  1314         return -EINVAL;
  1314         return -EINVAL;
  1315     }
  1315     }
  1316 
  1316 
  1317     if (!(entry = ec_pdo_find_entry_by_pos_const(
  1317     if (!(entry = ec_pdo_find_entry_by_pos_const(
  1318                     pdo, data.entry_pos))) {
  1318                     pdo, data.entry_pos))) {
  1334     return 0;
  1334     return 0;
  1335 }
  1335 }
  1336 
  1336 
  1337 /*****************************************************************************/
  1337 /*****************************************************************************/
  1338 
  1338 
  1339 /** Get slave configuration Sdo information.
  1339 /** Get slave configuration SDO information.
  1340  */
  1340  */
  1341 int ec_cdev_ioctl_config_sdo(
  1341 int ec_cdev_ioctl_config_sdo(
  1342         ec_master_t *master, /**< EtherCAT master. */
  1342         ec_master_t *master, /**< EtherCAT master. */
  1343         unsigned long arg /**< ioctl() argument. */
  1343         unsigned long arg /**< ioctl() argument. */
  1344         )
  1344         )
  1363     }
  1363     }
  1364 
  1364 
  1365     if (!(req = ec_slave_config_get_sdo_by_pos_const(
  1365     if (!(req = ec_slave_config_get_sdo_by_pos_const(
  1366                     sc, data.sdo_pos))) {
  1366                     sc, data.sdo_pos))) {
  1367         up(&master->master_sem);
  1367         up(&master->master_sem);
  1368         EC_ERR("Invalid Sdo position!\n");
  1368         EC_ERR("Invalid SDO position!\n");
  1369         return -EINVAL;
  1369         return -EINVAL;
  1370     }
  1370     }
  1371 
  1371 
  1372     data.index = req->index;
  1372     data.index = req->index;
  1373     data.subindex = req->subindex;
  1373     data.subindex = req->subindex;
  1640     return ret;
  1640     return ret;
  1641 }
  1641 }
  1642 
  1642 
  1643 /*****************************************************************************/
  1643 /*****************************************************************************/
  1644 
  1644 
  1645 /** Add a Pdo to the assignment.
  1645 /** Add a PDO to the assignment.
  1646  */
  1646  */
  1647 int ec_cdev_ioctl_sc_add_pdo(
  1647 int ec_cdev_ioctl_sc_add_pdo(
  1648         ec_master_t *master, /**< EtherCAT master. */
  1648         ec_master_t *master, /**< EtherCAT master. */
  1649         unsigned long arg, /**< ioctl() argument. */
  1649         unsigned long arg, /**< ioctl() argument. */
  1650         ec_cdev_priv_t *priv /**< Private data structure of file handle. */
  1650         ec_cdev_priv_t *priv /**< Private data structure of file handle. */
  1672     return ecrt_slave_config_pdo_assign_add(sc, data.sync_index, data.index);
  1672     return ecrt_slave_config_pdo_assign_add(sc, data.sync_index, data.index);
  1673 }
  1673 }
  1674 
  1674 
  1675 /*****************************************************************************/
  1675 /*****************************************************************************/
  1676 
  1676 
  1677 /** Clears the Pdo assignment.
  1677 /** Clears the PDO assignment.
  1678  */
  1678  */
  1679 int ec_cdev_ioctl_sc_clear_pdos(
  1679 int ec_cdev_ioctl_sc_clear_pdos(
  1680         ec_master_t *master, /**< EtherCAT master. */
  1680         ec_master_t *master, /**< EtherCAT master. */
  1681         unsigned long arg, /**< ioctl() argument. */
  1681         unsigned long arg, /**< ioctl() argument. */
  1682         ec_cdev_priv_t *priv /**< Private data structure of file handle. */
  1682         ec_cdev_priv_t *priv /**< Private data structure of file handle. */
  1705     return 0;
  1705     return 0;
  1706 }
  1706 }
  1707 
  1707 
  1708 /*****************************************************************************/
  1708 /*****************************************************************************/
  1709 
  1709 
  1710 /** Add an entry to a Pdo's mapping.
  1710 /** Add an entry to a PDO's mapping.
  1711  */
  1711  */
  1712 int ec_cdev_ioctl_sc_add_entry(
  1712 int ec_cdev_ioctl_sc_add_entry(
  1713         ec_master_t *master, /**< EtherCAT master. */
  1713         ec_master_t *master, /**< EtherCAT master. */
  1714         unsigned long arg, /**< ioctl() argument. */
  1714         unsigned long arg, /**< ioctl() argument. */
  1715         ec_cdev_priv_t *priv /**< Private data structure of file handle. */
  1715         ec_cdev_priv_t *priv /**< Private data structure of file handle. */
  1738             data.entry_index, data.entry_subindex, data.entry_bit_length);
  1738             data.entry_index, data.entry_subindex, data.entry_bit_length);
  1739 }
  1739 }
  1740 
  1740 
  1741 /*****************************************************************************/
  1741 /*****************************************************************************/
  1742 
  1742 
  1743 /** Clears the mapping of a Pdo.
  1743 /** Clears the mapping of a PDO.
  1744  */
  1744  */
  1745 int ec_cdev_ioctl_sc_clear_entries(
  1745 int ec_cdev_ioctl_sc_clear_entries(
  1746         ec_master_t *master, /**< EtherCAT master. */
  1746         ec_master_t *master, /**< EtherCAT master. */
  1747         unsigned long arg, /**< ioctl() argument. */
  1747         unsigned long arg, /**< ioctl() argument. */
  1748         ec_cdev_priv_t *priv /**< Private data structure of file handle. */
  1748         ec_cdev_priv_t *priv /**< Private data structure of file handle. */
  1771     return 0;
  1771     return 0;
  1772 }
  1772 }
  1773 
  1773 
  1774 /*****************************************************************************/
  1774 /*****************************************************************************/
  1775 
  1775 
  1776 /** Registers a Pdo entry.
  1776 /** Registers a PDO entry.
  1777  */
  1777  */
  1778 int ec_cdev_ioctl_sc_reg_pdo_entry(
  1778 int ec_cdev_ioctl_sc_reg_pdo_entry(
  1779         ec_master_t *master, /**< EtherCAT master. */
  1779         ec_master_t *master, /**< EtherCAT master. */
  1780         unsigned long arg, /**< ioctl() argument. */
  1780         unsigned long arg, /**< ioctl() argument. */
  1781         ec_cdev_priv_t *priv /**< Private data structure of file handle. */
  1781         ec_cdev_priv_t *priv /**< Private data structure of file handle. */
  1816     return ret;
  1816     return ret;
  1817 }
  1817 }
  1818 
  1818 
  1819 /*****************************************************************************/
  1819 /*****************************************************************************/
  1820 
  1820 
  1821 /** Configures an Sdo.
  1821 /** Configures an SDO.
  1822  */
  1822  */
  1823 int ec_cdev_ioctl_sc_sdo(
  1823 int ec_cdev_ioctl_sc_sdo(
  1824         ec_master_t *master, /**< EtherCAT master. */
  1824         ec_master_t *master, /**< EtherCAT master. */
  1825         unsigned long arg, /**< ioctl() argument. */
  1825         unsigned long arg, /**< ioctl() argument. */
  1826         ec_cdev_priv_t *priv /**< Private data structure of file handle. */
  1826         ec_cdev_priv_t *priv /**< Private data structure of file handle. */