master/ioctl.c
branchstable-1.5
changeset 2522 ec403cf308eb
parent 2505 5ef3197e5e1f
child 2529 c7e1f2616a9d
equal deleted inserted replaced
2521:3d68bb0047a1 2522:ec403cf308eb
    47  *
    47  *
    48  * Requires CPU timestamp counter!
    48  * Requires CPU timestamp counter!
    49  */
    49  */
    50 #define DEBUG_LATENCY 0
    50 #define DEBUG_LATENCY 0
    51 
    51 
       
    52 /** Optional compiler attributes fo ioctl() functions.
       
    53  */
    52 #if 0
    54 #if 0
    53 #define ATTRIBUTES __attribute__ ((__noinline__))
    55 #define ATTRIBUTES __attribute__ ((__noinline__))
    54 #else
    56 #else
    55 #define ATTRIBUTES
    57 #define ATTRIBUTES
    56 #endif
    58 #endif
    73 }
    75 }
    74 
    76 
    75 /*****************************************************************************/
    77 /*****************************************************************************/
    76 
    78 
    77 /** Get module information.
    79 /** Get module information.
       
    80  *
       
    81  * \return Zero on success, otherwise a negative error code.
    78  */
    82  */
    79 static ATTRIBUTES int ec_ioctl_module(
    83 static ATTRIBUTES int ec_ioctl_module(
    80         void *arg /**< Userspace address to store the results. */
    84         void *arg /**< Userspace address to store the results. */
    81         )
    85         )
    82 {
    86 {
    92 }
    96 }
    93 
    97 
    94 /*****************************************************************************/
    98 /*****************************************************************************/
    95 
    99 
    96 /** Get master information.
   100 /** Get master information.
       
   101  *
       
   102  * \return Zero on success, otherwise a negative error code.
    97  */
   103  */
    98 static ATTRIBUTES int ec_ioctl_master(
   104 static ATTRIBUTES int ec_ioctl_master(
    99         ec_master_t *master, /**< EtherCAT master. */
   105         ec_master_t *master, /**< EtherCAT master. */
   100         void *arg /**< Userspace address to store the results. */
   106         void *arg /**< Userspace address to store the results. */
   101         )
   107         )
   185 }
   191 }
   186 
   192 
   187 /*****************************************************************************/
   193 /*****************************************************************************/
   188 
   194 
   189 /** Get slave information.
   195 /** Get slave information.
       
   196  *
       
   197  * \return Zero on success, otherwise a negative error code.
   190  */
   198  */
   191 static ATTRIBUTES int ec_ioctl_slave(
   199 static ATTRIBUTES int ec_ioctl_slave(
   192         ec_master_t *master, /**< EtherCAT master. */
   200         ec_master_t *master, /**< EtherCAT master. */
   193         void *arg /**< Userspace address to store the results. */
   201         void *arg /**< Userspace address to store the results. */
   194         )
   202         )
   270 }
   278 }
   271 
   279 
   272 /*****************************************************************************/
   280 /*****************************************************************************/
   273 
   281 
   274 /** Get slave sync manager information.
   282 /** Get slave sync manager information.
       
   283  *
       
   284  * \return Zero on success, otherwise a negative error code.
   275  */
   285  */
   276 static ATTRIBUTES int ec_ioctl_slave_sync(
   286 static ATTRIBUTES int ec_ioctl_slave_sync(
   277         ec_master_t *master, /**< EtherCAT master. */
   287         ec_master_t *master, /**< EtherCAT master. */
   278         void *arg /**< Userspace address to store the results. */
   288         void *arg /**< Userspace address to store the results. */
   279         )
   289         )
   321 }
   331 }
   322 
   332 
   323 /*****************************************************************************/
   333 /*****************************************************************************/
   324 
   334 
   325 /** Get slave sync manager PDO information.
   335 /** Get slave sync manager PDO information.
       
   336  *
       
   337  * \return Zero on success, otherwise a negative error code.
   326  */
   338  */
   327 static ATTRIBUTES int ec_ioctl_slave_sync_pdo(
   339 static ATTRIBUTES int ec_ioctl_slave_sync_pdo(
   328         ec_master_t *master, /**< EtherCAT master. */
   340         ec_master_t *master, /**< EtherCAT master. */
   329         void *arg /**< Userspace address to store the results. */
   341         void *arg /**< Userspace address to store the results. */
   330         )
   342         )
   378 }
   390 }
   379 
   391 
   380 /*****************************************************************************/
   392 /*****************************************************************************/
   381 
   393 
   382 /** Get slave sync manager PDO entry information.
   394 /** Get slave sync manager PDO entry information.
       
   395  *
       
   396  * \return Zero on success, otherwise a negative error code.
   383  */
   397  */
   384 static ATTRIBUTES int ec_ioctl_slave_sync_pdo_entry(
   398 static ATTRIBUTES int ec_ioctl_slave_sync_pdo_entry(
   385         ec_master_t *master, /**< EtherCAT master. */
   399         ec_master_t *master, /**< EtherCAT master. */
   386         void *arg /**< Userspace address to store the results. */
   400         void *arg /**< Userspace address to store the results. */
   387         )
   401         )
   445 }
   459 }
   446 
   460 
   447 /*****************************************************************************/
   461 /*****************************************************************************/
   448 
   462 
   449 /** Get domain information.
   463 /** Get domain information.
       
   464  *
       
   465  * \return Zero on success, otherwise a negative error code.
   450  */
   466  */
   451 static ATTRIBUTES int ec_ioctl_domain(
   467 static ATTRIBUTES int ec_ioctl_domain(
   452         ec_master_t *master, /**< EtherCAT master. */
   468         ec_master_t *master, /**< EtherCAT master. */
   453         void *arg /**< Userspace address to store the results. */
   469         void *arg /**< Userspace address to store the results. */
   454         )
   470         )
   488 }
   504 }
   489 
   505 
   490 /*****************************************************************************/
   506 /*****************************************************************************/
   491 
   507 
   492 /** Get domain FMMU information.
   508 /** Get domain FMMU information.
       
   509  *
       
   510  * \return Zero on success, otherwise a negative error code.
   493  */
   511  */
   494 static ATTRIBUTES int ec_ioctl_domain_fmmu(
   512 static ATTRIBUTES int ec_ioctl_domain_fmmu(
   495         ec_master_t *master, /**< EtherCAT master. */
   513         ec_master_t *master, /**< EtherCAT master. */
   496         void *arg /**< Userspace address to store the results. */
   514         void *arg /**< Userspace address to store the results. */
   497         )
   515         )
   538 }
   556 }
   539 
   557 
   540 /*****************************************************************************/
   558 /*****************************************************************************/
   541 
   559 
   542 /** Get domain data.
   560 /** Get domain data.
       
   561  *
       
   562  * \return Zero on success, otherwise a negative error code.
   543  */
   563  */
   544 static ATTRIBUTES int ec_ioctl_domain_data(
   564 static ATTRIBUTES int ec_ioctl_domain_data(
   545         ec_master_t *master, /**< EtherCAT master. */
   565         ec_master_t *master, /**< EtherCAT master. */
   546         void *arg /**< Userspace address to store the results. */
   566         void *arg /**< Userspace address to store the results. */
   547         )
   567         )
   581 }
   601 }
   582 
   602 
   583 /*****************************************************************************/
   603 /*****************************************************************************/
   584 
   604 
   585 /** Set master debug level.
   605 /** Set master debug level.
       
   606  *
       
   607  * \return Zero on success, otherwise a negative error code.
   586  */
   608  */
   587 static ATTRIBUTES int ec_ioctl_master_debug(
   609 static ATTRIBUTES int ec_ioctl_master_debug(
   588         ec_master_t *master, /**< EtherCAT master. */
   610         ec_master_t *master, /**< EtherCAT master. */
   589         void *arg /**< ioctl() argument. */
   611         void *arg /**< ioctl() argument. */
   590         )
   612         )
   593 }
   615 }
   594 
   616 
   595 /*****************************************************************************/
   617 /*****************************************************************************/
   596 
   618 
   597 /** Issue a bus scan.
   619 /** Issue a bus scan.
       
   620  *
       
   621  * \return Always zero (success).
   598  */
   622  */
   599 static ATTRIBUTES int ec_ioctl_master_rescan(
   623 static ATTRIBUTES int ec_ioctl_master_rescan(
   600         ec_master_t *master, /**< EtherCAT master. */
   624         ec_master_t *master, /**< EtherCAT master. */
   601         void *arg /**< ioctl() argument. */
   625         void *arg /**< ioctl() argument. */
   602         )
   626         )
   606 }
   630 }
   607 
   631 
   608 /*****************************************************************************/
   632 /*****************************************************************************/
   609 
   633 
   610 /** Set slave state.
   634 /** Set slave state.
       
   635  *
       
   636  * \return Zero on success, otherwise a negative error code.
   611  */
   637  */
   612 static ATTRIBUTES int ec_ioctl_slave_state(
   638 static ATTRIBUTES int ec_ioctl_slave_state(
   613         ec_master_t *master, /**< EtherCAT master. */
   639         ec_master_t *master, /**< EtherCAT master. */
   614         void *arg /**< ioctl() argument. */
   640         void *arg /**< ioctl() argument. */
   615         )
   641         )
   639 }
   665 }
   640 
   666 
   641 /*****************************************************************************/
   667 /*****************************************************************************/
   642 
   668 
   643 /** Get slave SDO information.
   669 /** Get slave SDO information.
       
   670  *
       
   671  * \return Zero on success, otherwise a negative error code.
   644  */
   672  */
   645 static ATTRIBUTES int ec_ioctl_slave_sdo(
   673 static ATTRIBUTES int ec_ioctl_slave_sdo(
   646         ec_master_t *master, /**< EtherCAT master. */
   674         ec_master_t *master, /**< EtherCAT master. */
   647         void *arg /**< ioctl() argument. */
   675         void *arg /**< ioctl() argument. */
   648         )
   676         )
   686 }
   714 }
   687 
   715 
   688 /*****************************************************************************/
   716 /*****************************************************************************/
   689 
   717 
   690 /** Get slave SDO entry information.
   718 /** Get slave SDO entry information.
       
   719  *
       
   720  * \return Zero on success, otherwise a negative error code.
   691  */
   721  */
   692 static ATTRIBUTES int ec_ioctl_slave_sdo_entry(
   722 static ATTRIBUTES int ec_ioctl_slave_sdo_entry(
   693         ec_master_t *master, /**< EtherCAT master. */
   723         ec_master_t *master, /**< EtherCAT master. */
   694         void *arg /**< ioctl() argument. */
   724         void *arg /**< ioctl() argument. */
   695         )
   725         )
   764 }
   794 }
   765 
   795 
   766 /*****************************************************************************/
   796 /*****************************************************************************/
   767 
   797 
   768 /** Upload SDO.
   798 /** Upload SDO.
       
   799  *
       
   800  * \return Zero on success, otherwise a negative error code.
   769  */
   801  */
   770 static ATTRIBUTES int ec_ioctl_slave_sdo_upload(
   802 static ATTRIBUTES int ec_ioctl_slave_sdo_upload(
   771         ec_master_t *master, /**< EtherCAT master. */
   803         ec_master_t *master, /**< EtherCAT master. */
   772         void *arg /**< ioctl() argument. */
   804         void *arg /**< ioctl() argument. */
   773         )
   805         )
   808 }
   840 }
   809 
   841 
   810 /*****************************************************************************/
   842 /*****************************************************************************/
   811 
   843 
   812 /** Download SDO.
   844 /** Download SDO.
       
   845  *
       
   846  * \return Zero on success, otherwise a negative error code.
   813  */
   847  */
   814 static ATTRIBUTES int ec_ioctl_slave_sdo_download(
   848 static ATTRIBUTES int ec_ioctl_slave_sdo_download(
   815         ec_master_t *master, /**< EtherCAT master. */
   849         ec_master_t *master, /**< EtherCAT master. */
   816         void *arg /**< ioctl() argument. */
   850         void *arg /**< ioctl() argument. */
   817         )
   851         )
   854 }
   888 }
   855 
   889 
   856 /*****************************************************************************/
   890 /*****************************************************************************/
   857 
   891 
   858 /** Read a slave's SII.
   892 /** Read a slave's SII.
       
   893  *
       
   894  * \return Zero on success, otherwise a negative error code.
   859  */
   895  */
   860 static ATTRIBUTES int ec_ioctl_slave_sii_read(
   896 static ATTRIBUTES int ec_ioctl_slave_sii_read(
   861         ec_master_t *master, /**< EtherCAT master. */
   897         ec_master_t *master, /**< EtherCAT master. */
   862         void *arg /**< ioctl() argument. */
   898         void *arg /**< ioctl() argument. */
   863         )
   899         )
   900 }
   936 }
   901 
   937 
   902 /*****************************************************************************/
   938 /*****************************************************************************/
   903 
   939 
   904 /** Write a slave's SII.
   940 /** Write a slave's SII.
       
   941  *
       
   942  * \return Zero on success, otherwise a negative error code.
   905  */
   943  */
   906 static ATTRIBUTES int ec_ioctl_slave_sii_write(
   944 static ATTRIBUTES int ec_ioctl_slave_sii_write(
   907         ec_master_t *master, /**< EtherCAT master. */
   945         ec_master_t *master, /**< EtherCAT master. */
   908         void *arg /**< ioctl() argument. */
   946         void *arg /**< ioctl() argument. */
   909         )
   947         )
   986 }
  1024 }
   987 
  1025 
   988 /*****************************************************************************/
  1026 /*****************************************************************************/
   989 
  1027 
   990 /** Read a slave's registers.
  1028 /** Read a slave's registers.
       
  1029  *
       
  1030  * \return Zero on success, otherwise a negative error code.
   991  */
  1031  */
   992 static ATTRIBUTES int ec_ioctl_slave_reg_read(
  1032 static ATTRIBUTES int ec_ioctl_slave_reg_read(
   993         ec_master_t *master, /**< EtherCAT master. */
  1033         ec_master_t *master, /**< EtherCAT master. */
   994         void *arg /**< ioctl() argument. */
  1034         void *arg /**< ioctl() argument. */
   995         )
  1035         )
  1063 }
  1103 }
  1064 
  1104 
  1065 /*****************************************************************************/
  1105 /*****************************************************************************/
  1066 
  1106 
  1067 /** Write a slave's registers.
  1107 /** Write a slave's registers.
       
  1108  *
       
  1109  * \return Zero on success, otherwise a negative error code.
  1068  */
  1110  */
  1069 static ATTRIBUTES int ec_ioctl_slave_reg_write(
  1111 static ATTRIBUTES int ec_ioctl_slave_reg_write(
  1070         ec_master_t *master, /**< EtherCAT master. */
  1112         ec_master_t *master, /**< EtherCAT master. */
  1071         void *arg /**< ioctl() argument. */
  1113         void *arg /**< ioctl() argument. */
  1072         )
  1114         )
  1139 }
  1181 }
  1140 
  1182 
  1141 /*****************************************************************************/
  1183 /*****************************************************************************/
  1142 
  1184 
  1143 /** Get slave configuration information.
  1185 /** Get slave configuration information.
       
  1186  *
       
  1187  * \return Zero on success, otherwise a negative error code.
  1144  */
  1188  */
  1145 static ATTRIBUTES int ec_ioctl_config(
  1189 static ATTRIBUTES int ec_ioctl_config(
  1146         ec_master_t *master, /**< EtherCAT master. */
  1190         ec_master_t *master, /**< EtherCAT master. */
  1147         void *arg /**< ioctl() argument. */
  1191         void *arg /**< ioctl() argument. */
  1148         )
  1192         )
  1195 }
  1239 }
  1196 
  1240 
  1197 /*****************************************************************************/
  1241 /*****************************************************************************/
  1198 
  1242 
  1199 /** Get slave configuration PDO information.
  1243 /** Get slave configuration PDO information.
       
  1244  *
       
  1245  * \return Zero on success, otherwise a negative error code.
  1200  */
  1246  */
  1201 static ATTRIBUTES int ec_ioctl_config_pdo(
  1247 static ATTRIBUTES int ec_ioctl_config_pdo(
  1202         ec_master_t *master, /**< EtherCAT master. */
  1248         ec_master_t *master, /**< EtherCAT master. */
  1203         void *arg /**< ioctl() argument. */
  1249         void *arg /**< ioctl() argument. */
  1204         )
  1250         )
  1249 }
  1295 }
  1250 
  1296 
  1251 /*****************************************************************************/
  1297 /*****************************************************************************/
  1252 
  1298 
  1253 /** Get slave configuration PDO entry information.
  1299 /** Get slave configuration PDO entry information.
       
  1300  *
       
  1301  * \return Zero on success, otherwise a negative error code.
  1254  */
  1302  */
  1255 static ATTRIBUTES int ec_ioctl_config_pdo_entry(
  1303 static ATTRIBUTES int ec_ioctl_config_pdo_entry(
  1256         ec_master_t *master, /**< EtherCAT master. */
  1304         ec_master_t *master, /**< EtherCAT master. */
  1257         void *arg /**< ioctl() argument. */
  1305         void *arg /**< ioctl() argument. */
  1258         )
  1306         )
  1312 }
  1360 }
  1313 
  1361 
  1314 /*****************************************************************************/
  1362 /*****************************************************************************/
  1315 
  1363 
  1316 /** Get slave configuration SDO information.
  1364 /** Get slave configuration SDO information.
       
  1365  *
       
  1366  * \return Zero on success, otherwise a negative error code.
  1317  */
  1367  */
  1318 static ATTRIBUTES int ec_ioctl_config_sdo(
  1368 static ATTRIBUTES int ec_ioctl_config_sdo(
  1319         ec_master_t *master, /**< EtherCAT master. */
  1369         ec_master_t *master, /**< EtherCAT master. */
  1320         void *arg /**< ioctl() argument. */
  1370         void *arg /**< ioctl() argument. */
  1321         )
  1371         )
  1374 }
  1424 }
  1375 
  1425 
  1376 /*****************************************************************************/
  1426 /*****************************************************************************/
  1377 
  1427 
  1378 /** Get slave configuration IDN information.
  1428 /** Get slave configuration IDN information.
       
  1429  *
       
  1430  * \return Zero on success, otherwise a negative error code.
  1379  */
  1431  */
  1380 static ATTRIBUTES int ec_ioctl_config_idn(
  1432 static ATTRIBUTES int ec_ioctl_config_idn(
  1381         ec_master_t *master, /**< EtherCAT master. */
  1433         ec_master_t *master, /**< EtherCAT master. */
  1382         void *arg /**< ioctl() argument. */
  1434         void *arg /**< ioctl() argument. */
  1383         )
  1435         )
  1438 /*****************************************************************************/
  1490 /*****************************************************************************/
  1439 
  1491 
  1440 #ifdef EC_EOE
  1492 #ifdef EC_EOE
  1441 
  1493 
  1442 /** Get EoE handler information.
  1494 /** Get EoE handler information.
       
  1495  *
       
  1496  * \return Zero on success, otherwise a negative error code.
  1443  */
  1497  */
  1444 static ATTRIBUTES int ec_ioctl_eoe_handler(
  1498 static ATTRIBUTES int ec_ioctl_eoe_handler(
  1445         ec_master_t *master, /**< EtherCAT master. */
  1499         ec_master_t *master, /**< EtherCAT master. */
  1446         void *arg /**< ioctl() argument. */
  1500         void *arg /**< ioctl() argument. */
  1447         )
  1501         )
  1488 #endif
  1542 #endif
  1489 
  1543 
  1490 /*****************************************************************************/
  1544 /*****************************************************************************/
  1491 
  1545 
  1492 /** Request the master from userspace.
  1546 /** Request the master from userspace.
       
  1547  *
       
  1548  * \return Zero on success, otherwise a negative error code.
  1493  */
  1549  */
  1494 static ATTRIBUTES int ec_ioctl_request(
  1550 static ATTRIBUTES int ec_ioctl_request(
  1495         ec_master_t *master, /**< EtherCAT master. */
  1551         ec_master_t *master, /**< EtherCAT master. */
  1496         void *arg, /**< ioctl() argument. */
  1552         void *arg, /**< ioctl() argument. */
  1497         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1553         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1511 }
  1567 }
  1512 
  1568 
  1513 /*****************************************************************************/
  1569 /*****************************************************************************/
  1514 
  1570 
  1515 /** Create a domain.
  1571 /** Create a domain.
       
  1572  *
       
  1573  * \return Domain index on success, otherwise a negative error code.
  1516  */
  1574  */
  1517 static ATTRIBUTES int ec_ioctl_create_domain(
  1575 static ATTRIBUTES int ec_ioctl_create_domain(
  1518         ec_master_t *master, /**< EtherCAT master. */
  1576         ec_master_t *master, /**< EtherCAT master. */
  1519         void *arg, /**< ioctl() argument. */
  1577         void *arg, /**< ioctl() argument. */
  1520         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1578         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1533 }
  1591 }
  1534 
  1592 
  1535 /*****************************************************************************/
  1593 /*****************************************************************************/
  1536 
  1594 
  1537 /** Create a slave configuration.
  1595 /** Create a slave configuration.
       
  1596  *
       
  1597  * \return Zero on success, otherwise a negative error code.
  1538  */
  1598  */
  1539 static ATTRIBUTES int ec_ioctl_create_slave_config(
  1599 static ATTRIBUTES int ec_ioctl_create_slave_config(
  1540         ec_master_t *master, /**< EtherCAT master. */
  1600         ec_master_t *master, /**< EtherCAT master. */
  1541         void *arg, /**< ioctl() argument. */
  1601         void *arg, /**< ioctl() argument. */
  1542         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1602         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1577 }
  1637 }
  1578 
  1638 
  1579 /*****************************************************************************/
  1639 /*****************************************************************************/
  1580 
  1640 
  1581 /** Select the DC reference clock.
  1641 /** Select the DC reference clock.
       
  1642  *
       
  1643  * \return Zero on success, otherwise a negative error code.
  1582  */
  1644  */
  1583 static ATTRIBUTES int ec_ioctl_select_ref_clock(
  1645 static ATTRIBUTES int ec_ioctl_select_ref_clock(
  1584         ec_master_t *master, /**< EtherCAT master. */
  1646         ec_master_t *master, /**< EtherCAT master. */
  1585         void *arg, /**< ioctl() argument. */
  1647         void *arg, /**< ioctl() argument. */
  1586         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1648         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1616 }
  1678 }
  1617 
  1679 
  1618 /*****************************************************************************/
  1680 /*****************************************************************************/
  1619 
  1681 
  1620 /** Activates the master.
  1682 /** Activates the master.
       
  1683  *
       
  1684  * \return Zero on success, otherwise a negative error code.
  1621  */
  1685  */
  1622 static ATTRIBUTES int ec_ioctl_activate(
  1686 static ATTRIBUTES int ec_ioctl_activate(
  1623         ec_master_t *master, /**< EtherCAT master. */
  1687         ec_master_t *master, /**< EtherCAT master. */
  1624         void *arg, /**< ioctl() argument. */
  1688         void *arg, /**< ioctl() argument. */
  1625         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1689         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1697 }
  1761 }
  1698 
  1762 
  1699 /*****************************************************************************/
  1763 /*****************************************************************************/
  1700 
  1764 
  1701 /** Deactivates the master.
  1765 /** Deactivates the master.
       
  1766  *
       
  1767  * \return Zero on success, otherwise a negative error code.
  1702  */
  1768  */
  1703 static ATTRIBUTES int ec_ioctl_deactivate(
  1769 static ATTRIBUTES int ec_ioctl_deactivate(
  1704         ec_master_t *master, /**< EtherCAT master. */
  1770         ec_master_t *master, /**< EtherCAT master. */
  1705         void *arg, /**< ioctl() argument. */
  1771         void *arg, /**< ioctl() argument. */
  1706         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1772         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1714 }
  1780 }
  1715 
  1781 
  1716 /*****************************************************************************/
  1782 /*****************************************************************************/
  1717 
  1783 
  1718 /** Set max. number of databytes in a cycle
  1784 /** Set max. number of databytes in a cycle
       
  1785  *
       
  1786  * \return Zero on success, otherwise a negative error code.
  1719  */
  1787  */
  1720 static ATTRIBUTES int ec_ioctl_set_send_interval(
  1788 static ATTRIBUTES int ec_ioctl_set_send_interval(
  1721         ec_master_t *master, /**< EtherCAT master. */
  1789         ec_master_t *master, /**< EtherCAT master. */
  1722         void *arg, /**< ioctl() argument. */
  1790         void *arg, /**< ioctl() argument. */
  1723         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1791         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1744 }
  1812 }
  1745 
  1813 
  1746 /*****************************************************************************/
  1814 /*****************************************************************************/
  1747 
  1815 
  1748 /** Send frames.
  1816 /** Send frames.
       
  1817  *
       
  1818  * \return Zero on success, otherwise a negative error code.
  1749  */
  1819  */
  1750 static ATTRIBUTES int ec_ioctl_send(
  1820 static ATTRIBUTES int ec_ioctl_send(
  1751         ec_master_t *master, /**< EtherCAT master. */
  1821         ec_master_t *master, /**< EtherCAT master. */
  1752         void *arg, /**< ioctl() argument. */
  1822         void *arg, /**< ioctl() argument. */
  1753         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1823         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1762 }
  1832 }
  1763 
  1833 
  1764 /*****************************************************************************/
  1834 /*****************************************************************************/
  1765 
  1835 
  1766 /** Receive frames.
  1836 /** Receive frames.
       
  1837  *
       
  1838  * \return Zero on success, otherwise a negative error code.
  1767  */
  1839  */
  1768 static ATTRIBUTES int ec_ioctl_receive(
  1840 static ATTRIBUTES int ec_ioctl_receive(
  1769         ec_master_t *master, /**< EtherCAT master. */
  1841         ec_master_t *master, /**< EtherCAT master. */
  1770         void *arg, /**< ioctl() argument. */
  1842         void *arg, /**< ioctl() argument. */
  1771         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1843         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1780 }
  1852 }
  1781 
  1853 
  1782 /*****************************************************************************/
  1854 /*****************************************************************************/
  1783 
  1855 
  1784 /** Get the master state.
  1856 /** Get the master state.
       
  1857  *
       
  1858  * \return Zero on success, otherwise a negative error code.
  1785  */
  1859  */
  1786 static ATTRIBUTES int ec_ioctl_master_state(
  1860 static ATTRIBUTES int ec_ioctl_master_state(
  1787         ec_master_t *master, /**< EtherCAT master. */
  1861         ec_master_t *master, /**< EtherCAT master. */
  1788         void *arg, /**< ioctl() argument. */
  1862         void *arg, /**< ioctl() argument. */
  1789         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1863         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1799     return 0;
  1873     return 0;
  1800 }
  1874 }
  1801 
  1875 
  1802 /*****************************************************************************/
  1876 /*****************************************************************************/
  1803 
  1877 
  1804 /** Get the master state.
  1878 /** Get the link state.
       
  1879  *
       
  1880  * \return Zero on success, otherwise a negative error code.
  1805  */
  1881  */
  1806 static ATTRIBUTES int ec_ioctl_master_link_state(
  1882 static ATTRIBUTES int ec_ioctl_master_link_state(
  1807         ec_master_t *master, /**< EtherCAT master. */
  1883         ec_master_t *master, /**< EtherCAT master. */
  1808         void *arg, /**< ioctl() argument. */
  1884         void *arg, /**< ioctl() argument. */
  1809         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1885         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1829     return 0;
  1905     return 0;
  1830 }
  1906 }
  1831 
  1907 
  1832 /*****************************************************************************/
  1908 /*****************************************************************************/
  1833 
  1909 
  1834 /** Set the master dc app time.
  1910 /** Set the master DC application time.
       
  1911  *
       
  1912  * \return Zero on success, otherwise a negative error code.
  1835  */
  1913  */
  1836 static ATTRIBUTES int ec_ioctl_app_time(
  1914 static ATTRIBUTES int ec_ioctl_app_time(
  1837         ec_master_t *master, /**< EtherCAT master. */
  1915         ec_master_t *master, /**< EtherCAT master. */
  1838         void *arg, /**< ioctl() argument. */
  1916         void *arg, /**< ioctl() argument. */
  1839         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1917         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1853 }
  1931 }
  1854 
  1932 
  1855 /*****************************************************************************/
  1933 /*****************************************************************************/
  1856 
  1934 
  1857 /** Sync the reference clock.
  1935 /** Sync the reference clock.
       
  1936  *
       
  1937  * \return Zero on success, otherwise a negative error code.
  1858  */
  1938  */
  1859 static ATTRIBUTES int ec_ioctl_sync_ref(
  1939 static ATTRIBUTES int ec_ioctl_sync_ref(
  1860         ec_master_t *master, /**< EtherCAT master. */
  1940         ec_master_t *master, /**< EtherCAT master. */
  1861         void *arg, /**< ioctl() argument. */
  1941         void *arg, /**< ioctl() argument. */
  1862         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1942         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1871 }
  1951 }
  1872 
  1952 
  1873 /*****************************************************************************/
  1953 /*****************************************************************************/
  1874 
  1954 
  1875 /** Sync the slave clocks.
  1955 /** Sync the slave clocks.
       
  1956  *
       
  1957  * \return Zero on success, otherwise a negative error code.
  1876  */
  1958  */
  1877 static ATTRIBUTES int ec_ioctl_sync_slaves(
  1959 static ATTRIBUTES int ec_ioctl_sync_slaves(
  1878         ec_master_t *master, /**< EtherCAT master. */
  1960         ec_master_t *master, /**< EtherCAT master. */
  1879         void *arg, /**< ioctl() argument. */
  1961         void *arg, /**< ioctl() argument. */
  1880         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1962         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1889 }
  1971 }
  1890 
  1972 
  1891 /*****************************************************************************/
  1973 /*****************************************************************************/
  1892 
  1974 
  1893 /** Get the system time of the reference clock.
  1975 /** Get the system time of the reference clock.
       
  1976  *
       
  1977  * \return Zero on success, otherwise a negative error code.
  1894  */
  1978  */
  1895 static ATTRIBUTES int ec_ioctl_ref_clock_time(
  1979 static ATTRIBUTES int ec_ioctl_ref_clock_time(
  1896         ec_master_t *master, /**< EtherCAT master. */
  1980         ec_master_t *master, /**< EtherCAT master. */
  1897         void *arg, /**< ioctl() argument. */
  1981         void *arg, /**< ioctl() argument. */
  1898         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1982         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1918 }
  2002 }
  1919 
  2003 
  1920 /*****************************************************************************/
  2004 /*****************************************************************************/
  1921 
  2005 
  1922 /** Queue the sync monitoring datagram.
  2006 /** Queue the sync monitoring datagram.
       
  2007  *
       
  2008  * \return Zero on success, otherwise a negative error code.
  1923  */
  2009  */
  1924 static ATTRIBUTES int ec_ioctl_sync_mon_queue(
  2010 static ATTRIBUTES int ec_ioctl_sync_mon_queue(
  1925         ec_master_t *master, /**< EtherCAT master. */
  2011         ec_master_t *master, /**< EtherCAT master. */
  1926         void *arg, /**< ioctl() argument. */
  2012         void *arg, /**< ioctl() argument. */
  1927         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2013         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1936 }
  2022 }
  1937 
  2023 
  1938 /*****************************************************************************/
  2024 /*****************************************************************************/
  1939 
  2025 
  1940 /** Processes the sync monitoring datagram.
  2026 /** Processes the sync monitoring datagram.
       
  2027  *
       
  2028  * \return Zero on success, otherwise a negative error code.
  1941  */
  2029  */
  1942 static ATTRIBUTES int ec_ioctl_sync_mon_process(
  2030 static ATTRIBUTES int ec_ioctl_sync_mon_process(
  1943         ec_master_t *master, /**< EtherCAT master. */
  2031         ec_master_t *master, /**< EtherCAT master. */
  1944         void *arg, /**< ioctl() argument. */
  2032         void *arg, /**< ioctl() argument. */
  1945         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2033         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1959 }
  2047 }
  1960 
  2048 
  1961 /*****************************************************************************/
  2049 /*****************************************************************************/
  1962 
  2050 
  1963 /** Reset configuration.
  2051 /** Reset configuration.
       
  2052  *
       
  2053  * \return Always zero (success).
  1964  */
  2054  */
  1965 static ATTRIBUTES int ec_ioctl_reset(
  2055 static ATTRIBUTES int ec_ioctl_reset(
  1966         ec_master_t *master, /**< EtherCAT master. */
  2056         ec_master_t *master, /**< EtherCAT master. */
  1967         void *arg, /**< ioctl() argument. */
  2057         void *arg, /**< ioctl() argument. */
  1968         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2058         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  1975 }
  2065 }
  1976 
  2066 
  1977 /*****************************************************************************/
  2067 /*****************************************************************************/
  1978 
  2068 
  1979 /** Configure a sync manager.
  2069 /** Configure a sync manager.
       
  2070  *
       
  2071  * \return Zero on success, otherwise a negative error code.
  1980  */
  2072  */
  1981 static ATTRIBUTES int ec_ioctl_sc_sync(
  2073 static ATTRIBUTES int ec_ioctl_sc_sync(
  1982         ec_master_t *master, /**< EtherCAT master. */
  2074         ec_master_t *master, /**< EtherCAT master. */
  1983         void *arg, /**< ioctl() argument. */
  2075         void *arg, /**< ioctl() argument. */
  1984         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2076         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2026 }
  2118 }
  2027 
  2119 
  2028 /*****************************************************************************/
  2120 /*****************************************************************************/
  2029 
  2121 
  2030 /** Configure a slave's watchdogs.
  2122 /** Configure a slave's watchdogs.
       
  2123  *
       
  2124  * \return Zero on success, otherwise a negative error code.
  2031  */
  2125  */
  2032 static ATTRIBUTES int ec_ioctl_sc_watchdog(
  2126 static ATTRIBUTES int ec_ioctl_sc_watchdog(
  2033         ec_master_t *master, /**< EtherCAT master. */
  2127         ec_master_t *master, /**< EtherCAT master. */
  2034         void *arg, /**< ioctl() argument. */
  2128         void *arg, /**< ioctl() argument. */
  2035         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2129         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2069 }
  2163 }
  2070 
  2164 
  2071 /*****************************************************************************/
  2165 /*****************************************************************************/
  2072 
  2166 
  2073 /** Add a PDO to the assignment.
  2167 /** Add a PDO to the assignment.
       
  2168  *
       
  2169  * \return Zero on success, otherwise a negative error code.
  2074  */
  2170  */
  2075 static ATTRIBUTES int ec_ioctl_sc_add_pdo(
  2171 static ATTRIBUTES int ec_ioctl_sc_add_pdo(
  2076         ec_master_t *master, /**< EtherCAT master. */
  2172         ec_master_t *master, /**< EtherCAT master. */
  2077         void *arg, /**< ioctl() argument. */
  2173         void *arg, /**< ioctl() argument. */
  2078         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2174         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2093     if (!(sc = ec_master_get_config(master, data.config_index))) {
  2189     if (!(sc = ec_master_get_config(master, data.config_index))) {
  2094         up(&master->master_sem);
  2190         up(&master->master_sem);
  2095         return -ENOENT;
  2191         return -ENOENT;
  2096     }
  2192     }
  2097 
  2193 
  2098     up(&master->master_sem); /** \fixme sc could be invalidated */
  2194     up(&master->master_sem); /** \todo sc could be invalidated */
  2099 
  2195 
  2100     return ecrt_slave_config_pdo_assign_add(sc, data.sync_index, data.index);
  2196     return ecrt_slave_config_pdo_assign_add(sc, data.sync_index, data.index);
  2101 }
  2197 }
  2102 
  2198 
  2103 /*****************************************************************************/
  2199 /*****************************************************************************/
  2104 
  2200 
  2105 /** Clears the PDO assignment.
  2201 /** Clears the PDO assignment.
       
  2202  *
       
  2203  * \return Zero on success, otherwise a negative error code.
  2106  */
  2204  */
  2107 static ATTRIBUTES int ec_ioctl_sc_clear_pdos(
  2205 static ATTRIBUTES int ec_ioctl_sc_clear_pdos(
  2108         ec_master_t *master, /**< EtherCAT master. */
  2206         ec_master_t *master, /**< EtherCAT master. */
  2109         void *arg, /**< ioctl() argument. */
  2207         void *arg, /**< ioctl() argument. */
  2110         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2208         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2125     if (!(sc = ec_master_get_config(master, data.config_index))) {
  2223     if (!(sc = ec_master_get_config(master, data.config_index))) {
  2126         up(&master->master_sem);
  2224         up(&master->master_sem);
  2127         return -ENOENT;
  2225         return -ENOENT;
  2128     }
  2226     }
  2129 
  2227 
  2130     up(&master->master_sem); /** \fixme sc could be invalidated */
  2228     up(&master->master_sem); /** \todo sc could be invalidated */
  2131 
  2229 
  2132     ecrt_slave_config_pdo_assign_clear(sc, data.sync_index);
  2230     ecrt_slave_config_pdo_assign_clear(sc, data.sync_index);
  2133     return 0;
  2231     return 0;
  2134 }
  2232 }
  2135 
  2233 
  2136 /*****************************************************************************/
  2234 /*****************************************************************************/
  2137 
  2235 
  2138 /** Add an entry to a PDO's mapping.
  2236 /** Add an entry to a PDO's mapping.
       
  2237  *
       
  2238  * \return Zero on success, otherwise a negative error code.
  2139  */
  2239  */
  2140 static ATTRIBUTES int ec_ioctl_sc_add_entry(
  2240 static ATTRIBUTES int ec_ioctl_sc_add_entry(
  2141         ec_master_t *master, /**< EtherCAT master. */
  2241         ec_master_t *master, /**< EtherCAT master. */
  2142         void *arg, /**< ioctl() argument. */
  2242         void *arg, /**< ioctl() argument. */
  2143         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2243         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2158     if (!(sc = ec_master_get_config(master, data.config_index))) {
  2258     if (!(sc = ec_master_get_config(master, data.config_index))) {
  2159         up(&master->master_sem);
  2259         up(&master->master_sem);
  2160         return -ENOENT;
  2260         return -ENOENT;
  2161     }
  2261     }
  2162 
  2262 
  2163     up(&master->master_sem); /** \fixme sc could be invalidated */
  2263     up(&master->master_sem); /** \todo sc could be invalidated */
  2164 
  2264 
  2165     return ecrt_slave_config_pdo_mapping_add(sc, data.pdo_index,
  2265     return ecrt_slave_config_pdo_mapping_add(sc, data.pdo_index,
  2166             data.entry_index, data.entry_subindex, data.entry_bit_length);
  2266             data.entry_index, data.entry_subindex, data.entry_bit_length);
  2167 }
  2267 }
  2168 
  2268 
  2169 /*****************************************************************************/
  2269 /*****************************************************************************/
  2170 
  2270 
  2171 /** Clears the mapping of a PDO.
  2271 /** Clears the mapping of a PDO.
       
  2272  *
       
  2273  * \return Zero on success, otherwise a negative error code.
  2172  */
  2274  */
  2173 static ATTRIBUTES int ec_ioctl_sc_clear_entries(
  2275 static ATTRIBUTES int ec_ioctl_sc_clear_entries(
  2174         ec_master_t *master, /**< EtherCAT master. */
  2276         ec_master_t *master, /**< EtherCAT master. */
  2175         void *arg, /**< ioctl() argument. */
  2277         void *arg, /**< ioctl() argument. */
  2176         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2278         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2191     if (!(sc = ec_master_get_config(master, data.config_index))) {
  2293     if (!(sc = ec_master_get_config(master, data.config_index))) {
  2192         up(&master->master_sem);
  2294         up(&master->master_sem);
  2193         return -ENOENT;
  2295         return -ENOENT;
  2194     }
  2296     }
  2195 
  2297 
  2196     up(&master->master_sem); /** \fixme sc could be invalidated */
  2298     up(&master->master_sem); /** \todo sc could be invalidated */
  2197 
  2299 
  2198     ecrt_slave_config_pdo_mapping_clear(sc, data.index);
  2300     ecrt_slave_config_pdo_mapping_clear(sc, data.index);
  2199     return 0;
  2301     return 0;
  2200 }
  2302 }
  2201 
  2303 
  2202 /*****************************************************************************/
  2304 /*****************************************************************************/
  2203 
  2305 
  2204 /** Registers a PDO entry.
  2306 /** Registers a PDO entry.
       
  2307  *
       
  2308  * \return Process data offset on success, otherwise a negative error code.
  2205  */
  2309  */
  2206 static ATTRIBUTES int ec_ioctl_sc_reg_pdo_entry(
  2310 static ATTRIBUTES int ec_ioctl_sc_reg_pdo_entry(
  2207         ec_master_t *master, /**< EtherCAT master. */
  2311         ec_master_t *master, /**< EtherCAT master. */
  2208         void *arg, /**< ioctl() argument. */
  2312         void *arg, /**< ioctl() argument. */
  2209         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2313         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2231     if (!(domain = ec_master_find_domain(master, data.domain_index))) {
  2335     if (!(domain = ec_master_find_domain(master, data.domain_index))) {
  2232         up(&master->master_sem);
  2336         up(&master->master_sem);
  2233         return -ENOENT;
  2337         return -ENOENT;
  2234     }
  2338     }
  2235 
  2339 
  2236     up(&master->master_sem); /** \fixme sc or domain could be invalidated */
  2340     up(&master->master_sem); /** \todo sc or domain could be invalidated */
  2237 
  2341 
  2238     ret = ecrt_slave_config_reg_pdo_entry(sc, data.entry_index,
  2342     ret = ecrt_slave_config_reg_pdo_entry(sc, data.entry_index,
  2239             data.entry_subindex, domain, &data.bit_position);
  2343             data.entry_subindex, domain, &data.bit_position);
  2240 
  2344 
  2241     if (copy_to_user((void __user *) arg, &data, sizeof(data)))
  2345     if (copy_to_user((void __user *) arg, &data, sizeof(data)))
  2245 }
  2349 }
  2246 
  2350 
  2247 /*****************************************************************************/
  2351 /*****************************************************************************/
  2248 
  2352 
  2249 /** Registers a PDO entry by its position.
  2353 /** Registers a PDO entry by its position.
       
  2354  *
       
  2355  * \return Process data offset on success, otherwise a negative error code.
  2250  */
  2356  */
  2251 static ATTRIBUTES int ec_ioctl_sc_reg_pdo_pos(
  2357 static ATTRIBUTES int ec_ioctl_sc_reg_pdo_pos(
  2252         ec_master_t *master, /**< EtherCAT master. */
  2358         ec_master_t *master, /**< EtherCAT master. */
  2253         void *arg, /**< ioctl() argument. */
  2359         void *arg, /**< ioctl() argument. */
  2254         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2360         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2279     if (!(domain = ec_master_find_domain(master, io.domain_index))) {
  2385     if (!(domain = ec_master_find_domain(master, io.domain_index))) {
  2280         up(&master->master_sem);
  2386         up(&master->master_sem);
  2281         return -ENOENT;
  2387         return -ENOENT;
  2282     }
  2388     }
  2283 
  2389 
  2284     up(&master->master_sem); /** \fixme sc or domain could be invalidated */
  2390     up(&master->master_sem); /** \todo sc or domain could be invalidated */
  2285 
  2391 
  2286     ret = ecrt_slave_config_reg_pdo_entry_pos(sc, io.sync_index,
  2392     ret = ecrt_slave_config_reg_pdo_entry_pos(sc, io.sync_index,
  2287             io.pdo_pos, io.entry_pos, domain, &io.bit_position);
  2393             io.pdo_pos, io.entry_pos, domain, &io.bit_position);
  2288 
  2394 
  2289     if (copy_to_user((void __user *) arg, &io, sizeof(io)))
  2395     if (copy_to_user((void __user *) arg, &io, sizeof(io)))
  2293 }
  2399 }
  2294 
  2400 
  2295 /*****************************************************************************/
  2401 /*****************************************************************************/
  2296 
  2402 
  2297 /** Sets the DC AssignActivate word and the sync signal times.
  2403 /** Sets the DC AssignActivate word and the sync signal times.
       
  2404  *
       
  2405  * \return Zero on success, otherwise a negative error code.
  2298  */
  2406  */
  2299 static ATTRIBUTES int ec_ioctl_sc_dc(
  2407 static ATTRIBUTES int ec_ioctl_sc_dc(
  2300         ec_master_t *master, /**< EtherCAT master. */
  2408         ec_master_t *master, /**< EtherCAT master. */
  2301         void *arg, /**< ioctl() argument. */
  2409         void *arg, /**< ioctl() argument. */
  2302         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2410         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2331 }
  2439 }
  2332 
  2440 
  2333 /*****************************************************************************/
  2441 /*****************************************************************************/
  2334 
  2442 
  2335 /** Configures an SDO.
  2443 /** Configures an SDO.
       
  2444  *
       
  2445  * \return Zero on success, otherwise a negative error code.
  2336  */
  2446  */
  2337 static ATTRIBUTES int ec_ioctl_sc_sdo(
  2447 static ATTRIBUTES int ec_ioctl_sc_sdo(
  2338         ec_master_t *master, /**< EtherCAT master. */
  2448         ec_master_t *master, /**< EtherCAT master. */
  2339         void *arg, /**< ioctl() argument. */
  2449         void *arg, /**< ioctl() argument. */
  2340         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2450         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2372         up(&master->master_sem);
  2482         up(&master->master_sem);
  2373         kfree(sdo_data);
  2483         kfree(sdo_data);
  2374         return -ENOENT;
  2484         return -ENOENT;
  2375     }
  2485     }
  2376 
  2486 
  2377     up(&master->master_sem); /** \fixme sc could be invalidated */
  2487     up(&master->master_sem); /** \todo sc could be invalidated */
  2378 
  2488 
  2379     if (data.complete_access) {
  2489     if (data.complete_access) {
  2380         ret = ecrt_slave_config_complete_sdo(sc,
  2490         ret = ecrt_slave_config_complete_sdo(sc,
  2381                 data.index, sdo_data, data.size);
  2491                 data.index, sdo_data, data.size);
  2382     } else {
  2492     } else {
  2388 }
  2498 }
  2389 
  2499 
  2390 /*****************************************************************************/
  2500 /*****************************************************************************/
  2391 
  2501 
  2392 /** Set the emergency ring buffer size.
  2502 /** Set the emergency ring buffer size.
       
  2503  *
       
  2504  * \return Zero on success, otherwise a negative error code.
  2393  */
  2505  */
  2394 static ATTRIBUTES int ec_ioctl_sc_emerg_size(
  2506 static ATTRIBUTES int ec_ioctl_sc_emerg_size(
  2395         ec_master_t *master, /**< EtherCAT master. */
  2507         ec_master_t *master, /**< EtherCAT master. */
  2396         void *arg, /**< ioctl() argument. */
  2508         void *arg, /**< ioctl() argument. */
  2397         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2509         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2424 }
  2536 }
  2425 
  2537 
  2426 /*****************************************************************************/
  2538 /*****************************************************************************/
  2427 
  2539 
  2428 /** Get an emergency message from the ring.
  2540 /** Get an emergency message from the ring.
       
  2541  *
       
  2542  * \return Zero on success, otherwise a negative error code.
  2429  */
  2543  */
  2430 static ATTRIBUTES int ec_ioctl_sc_emerg_pop(
  2544 static ATTRIBUTES int ec_ioctl_sc_emerg_pop(
  2431         ec_master_t *master, /**< EtherCAT master. */
  2545         ec_master_t *master, /**< EtherCAT master. */
  2432         void *arg, /**< ioctl() argument. */
  2546         void *arg, /**< ioctl() argument. */
  2433         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2547         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2466 }
  2580 }
  2467 
  2581 
  2468 /*****************************************************************************/
  2582 /*****************************************************************************/
  2469 
  2583 
  2470 /** Clear the emergency ring.
  2584 /** Clear the emergency ring.
       
  2585  *
       
  2586  * \return Zero on success, otherwise a negative error code.
  2471  */
  2587  */
  2472 static ATTRIBUTES int ec_ioctl_sc_emerg_clear(
  2588 static ATTRIBUTES int ec_ioctl_sc_emerg_clear(
  2473         ec_master_t *master, /**< EtherCAT master. */
  2589         ec_master_t *master, /**< EtherCAT master. */
  2474         void *arg, /**< ioctl() argument. */
  2590         void *arg, /**< ioctl() argument. */
  2475         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2591         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2497 }
  2613 }
  2498 
  2614 
  2499 /*****************************************************************************/
  2615 /*****************************************************************************/
  2500 
  2616 
  2501 /** Get the number of emergency overruns.
  2617 /** Get the number of emergency overruns.
       
  2618  *
       
  2619  * \return Zero on success, otherwise a negative error code.
  2502  */
  2620  */
  2503 static ATTRIBUTES int ec_ioctl_sc_emerg_overruns(
  2621 static ATTRIBUTES int ec_ioctl_sc_emerg_overruns(
  2504         ec_master_t *master, /**< EtherCAT master. */
  2622         ec_master_t *master, /**< EtherCAT master. */
  2505         void *arg, /**< ioctl() argument. */
  2623         void *arg, /**< ioctl() argument. */
  2506         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2624         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2540 }
  2658 }
  2541 
  2659 
  2542 /*****************************************************************************/
  2660 /*****************************************************************************/
  2543 
  2661 
  2544 /** Create an SDO request.
  2662 /** Create an SDO request.
       
  2663  *
       
  2664  * \return Zero on success, otherwise a negative error code.
  2545  */
  2665  */
  2546 static ATTRIBUTES int ec_ioctl_sc_create_sdo_request(
  2666 static ATTRIBUTES int ec_ioctl_sc_create_sdo_request(
  2547         ec_master_t *master, /**< EtherCAT master. */
  2667         ec_master_t *master, /**< EtherCAT master. */
  2548         void *arg, /**< ioctl() argument. */
  2668         void *arg, /**< ioctl() argument. */
  2549         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2669         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2573 
  2693 
  2574     list_for_each_entry(req, &sc->sdo_requests, list) {
  2694     list_for_each_entry(req, &sc->sdo_requests, list) {
  2575         data.request_index++;
  2695         data.request_index++;
  2576     }
  2696     }
  2577 
  2697 
  2578     up(&master->master_sem); /** \fixme sc could be invalidated */
  2698     up(&master->master_sem); /** \todo sc could be invalidated */
  2579 
  2699 
  2580     req = ecrt_slave_config_create_sdo_request_err(sc, data.sdo_index,
  2700     req = ecrt_slave_config_create_sdo_request_err(sc, data.sdo_index,
  2581             data.sdo_subindex, data.size);
  2701             data.sdo_subindex, data.size);
  2582     if (IS_ERR(req))
  2702     if (IS_ERR(req))
  2583         return PTR_ERR(req);
  2703         return PTR_ERR(req);
  2589 }
  2709 }
  2590 
  2710 
  2591 /*****************************************************************************/
  2711 /*****************************************************************************/
  2592 
  2712 
  2593 /** Create a register request.
  2713 /** Create a register request.
       
  2714  *
       
  2715  * \return Zero on success, otherwise a negative error code.
  2594  */
  2716  */
  2595 static ATTRIBUTES int ec_ioctl_sc_create_reg_request(
  2717 static ATTRIBUTES int ec_ioctl_sc_create_reg_request(
  2596         ec_master_t *master, /**< EtherCAT master. */
  2718         ec_master_t *master, /**< EtherCAT master. */
  2597         void *arg, /**< ioctl() argument. */
  2719         void *arg, /**< ioctl() argument. */
  2598         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2720         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2624 
  2746 
  2625     list_for_each_entry(reg, &sc->reg_requests, list) {
  2747     list_for_each_entry(reg, &sc->reg_requests, list) {
  2626         io.request_index++;
  2748         io.request_index++;
  2627     }
  2749     }
  2628 
  2750 
  2629     up(&master->master_sem); /** \fixme sc could be invalidated */
  2751     up(&master->master_sem); /** \todo sc could be invalidated */
  2630 
  2752 
  2631     reg = ecrt_slave_config_create_reg_request_err(sc, io.mem_size);
  2753     reg = ecrt_slave_config_create_reg_request_err(sc, io.mem_size);
  2632     if (IS_ERR(reg)) {
  2754     if (IS_ERR(reg)) {
  2633         return PTR_ERR(reg);
  2755         return PTR_ERR(reg);
  2634     }
  2756     }
  2641 }
  2763 }
  2642 
  2764 
  2643 /*****************************************************************************/
  2765 /*****************************************************************************/
  2644 
  2766 
  2645 /** Create a VoE handler.
  2767 /** Create a VoE handler.
       
  2768  *
       
  2769  * \return Zero on success, otherwise a negative error code.
  2646  */
  2770  */
  2647 static ATTRIBUTES int ec_ioctl_sc_create_voe_handler(
  2771 static ATTRIBUTES int ec_ioctl_sc_create_voe_handler(
  2648         ec_master_t *master, /**< EtherCAT master. */
  2772         ec_master_t *master, /**< EtherCAT master. */
  2649         void *arg, /**< ioctl() argument. */
  2773         void *arg, /**< ioctl() argument. */
  2650         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2774         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2674 
  2798 
  2675     list_for_each_entry(voe, &sc->voe_handlers, list) {
  2799     list_for_each_entry(voe, &sc->voe_handlers, list) {
  2676         data.voe_index++;
  2800         data.voe_index++;
  2677     }
  2801     }
  2678 
  2802 
  2679     up(&master->master_sem); /** \fixme sc could be invalidated */
  2803     up(&master->master_sem); /** \todo sc could be invalidated */
  2680 
  2804 
  2681     voe = ecrt_slave_config_create_voe_handler_err(sc, data.size);
  2805     voe = ecrt_slave_config_create_voe_handler_err(sc, data.size);
  2682     if (IS_ERR(voe))
  2806     if (IS_ERR(voe))
  2683         return PTR_ERR(voe);
  2807         return PTR_ERR(voe);
  2684 
  2808 
  2689 }
  2813 }
  2690 
  2814 
  2691 /*****************************************************************************/
  2815 /*****************************************************************************/
  2692 
  2816 
  2693 /** Get the slave configuration's state.
  2817 /** Get the slave configuration's state.
       
  2818  *
       
  2819  * \return Zero on success, otherwise a negative error code.
  2694  */
  2820  */
  2695 static ATTRIBUTES int ec_ioctl_sc_state(
  2821 static ATTRIBUTES int ec_ioctl_sc_state(
  2696         ec_master_t *master, /**< EtherCAT master. */
  2822         ec_master_t *master, /**< EtherCAT master. */
  2697         void *arg, /**< ioctl() argument. */
  2823         void *arg, /**< ioctl() argument. */
  2698         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2824         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2725 }
  2851 }
  2726 
  2852 
  2727 /*****************************************************************************/
  2853 /*****************************************************************************/
  2728 
  2854 
  2729 /** Configures an IDN.
  2855 /** Configures an IDN.
       
  2856  *
       
  2857  * \return Zero on success, otherwise a negative error code.
  2730  */
  2858  */
  2731 static ATTRIBUTES int ec_ioctl_sc_idn(
  2859 static ATTRIBUTES int ec_ioctl_sc_idn(
  2732         ec_master_t *master, /**< EtherCAT master. */
  2860         ec_master_t *master, /**< EtherCAT master. */
  2733         void *arg, /**< ioctl() argument. */
  2861         void *arg, /**< ioctl() argument. */
  2734         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2862         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2766         up(&master->master_sem);
  2894         up(&master->master_sem);
  2767         kfree(data);
  2895         kfree(data);
  2768         return -ENOENT;
  2896         return -ENOENT;
  2769     }
  2897     }
  2770 
  2898 
  2771     up(&master->master_sem); /** \fixme sc could be invalidated */
  2899     up(&master->master_sem); /** \todo sc could be invalidated */
  2772 
  2900 
  2773     ret = ecrt_slave_config_idn(
  2901     ret = ecrt_slave_config_idn(
  2774             sc, ioctl.drive_no, ioctl.idn, ioctl.al_state, data, ioctl.size);
  2902             sc, ioctl.drive_no, ioctl.idn, ioctl.al_state, data, ioctl.size);
  2775     kfree(data);
  2903     kfree(data);
  2776     return ret;
  2904     return ret;
  2777 }
  2905 }
  2778 
  2906 
  2779 /*****************************************************************************/
  2907 /*****************************************************************************/
  2780 
  2908 
  2781 /** Gets the domain's data size.
  2909 /** Gets the domain's data size.
       
  2910  *
       
  2911  * \return Domain size, or a negative error code.
  2782  */
  2912  */
  2783 static ATTRIBUTES int ec_ioctl_domain_size(
  2913 static ATTRIBUTES int ec_ioctl_domain_size(
  2784         ec_master_t *master, /**< EtherCAT master. */
  2914         ec_master_t *master, /**< EtherCAT master. */
  2785         void *arg, /**< ioctl() argument. */
  2915         void *arg, /**< ioctl() argument. */
  2786         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2916         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2809 }
  2939 }
  2810 
  2940 
  2811 /*****************************************************************************/
  2941 /*****************************************************************************/
  2812 
  2942 
  2813 /** Gets the domain's offset in the total process data.
  2943 /** Gets the domain's offset in the total process data.
       
  2944  *
       
  2945  * \return Domain offset, or a negative error code.
  2814  */
  2946  */
  2815 static ATTRIBUTES int ec_ioctl_domain_offset(
  2947 static ATTRIBUTES int ec_ioctl_domain_offset(
  2816         ec_master_t *master, /**< EtherCAT master. */
  2948         ec_master_t *master, /**< EtherCAT master. */
  2817         void *arg, /**< ioctl() argument. */
  2949         void *arg, /**< ioctl() argument. */
  2818         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2950         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2841 }
  2973 }
  2842 
  2974 
  2843 /*****************************************************************************/
  2975 /*****************************************************************************/
  2844 
  2976 
  2845 /** Process the domain.
  2977 /** Process the domain.
       
  2978  *
       
  2979  * \return Zero on success, otherwise a negative error code.
  2846  */
  2980  */
  2847 static ATTRIBUTES int ec_ioctl_domain_process(
  2981 static ATTRIBUTES int ec_ioctl_domain_process(
  2848         ec_master_t *master, /**< EtherCAT master. */
  2982         ec_master_t *master, /**< EtherCAT master. */
  2849         void *arg, /**< ioctl() argument. */
  2983         void *arg, /**< ioctl() argument. */
  2850         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2984         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2867 }
  3001 }
  2868 
  3002 
  2869 /*****************************************************************************/
  3003 /*****************************************************************************/
  2870 
  3004 
  2871 /** Queue the domain.
  3005 /** Queue the domain.
       
  3006  *
       
  3007  * \return Zero on success, otherwise a negative error code.
  2872  */
  3008  */
  2873 static ATTRIBUTES int ec_ioctl_domain_queue(
  3009 static ATTRIBUTES int ec_ioctl_domain_queue(
  2874         ec_master_t *master, /**< EtherCAT master. */
  3010         ec_master_t *master, /**< EtherCAT master. */
  2875         void *arg, /**< ioctl() argument. */
  3011         void *arg, /**< ioctl() argument. */
  2876         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3012         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2893 }
  3029 }
  2894 
  3030 
  2895 /*****************************************************************************/
  3031 /*****************************************************************************/
  2896 
  3032 
  2897 /** Get the domain state.
  3033 /** Get the domain state.
       
  3034  *
       
  3035  * \return Zero on success, otherwise a negative error code.
  2898  */
  3036  */
  2899 static ATTRIBUTES int ec_ioctl_domain_state(
  3037 static ATTRIBUTES int ec_ioctl_domain_state(
  2900         ec_master_t *master, /**< EtherCAT master. */
  3038         ec_master_t *master, /**< EtherCAT master. */
  2901         void *arg, /**< ioctl() argument. */
  3039         void *arg, /**< ioctl() argument. */
  2902         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3040         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2929 }
  3067 }
  2930 
  3068 
  2931 /*****************************************************************************/
  3069 /*****************************************************************************/
  2932 
  3070 
  2933 /** Sets an SDO request's SDO index and subindex.
  3071 /** Sets an SDO request's SDO index and subindex.
       
  3072  *
       
  3073  * \return Zero on success, otherwise a negative error code.
  2934  */
  3074  */
  2935 static ATTRIBUTES int ec_ioctl_sdo_request_index(
  3075 static ATTRIBUTES int ec_ioctl_sdo_request_index(
  2936         ec_master_t *master, /**< EtherCAT master. */
  3076         ec_master_t *master, /**< EtherCAT master. */
  2937         void *arg, /**< ioctl() argument. */
  3077         void *arg, /**< ioctl() argument. */
  2938         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3078         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2964 }
  3104 }
  2965 
  3105 
  2966 /*****************************************************************************/
  3106 /*****************************************************************************/
  2967 
  3107 
  2968 /** Sets an SDO request's timeout.
  3108 /** Sets an SDO request's timeout.
       
  3109  *
       
  3110  * \return Zero on success, otherwise a negative error code.
  2969  */
  3111  */
  2970 static ATTRIBUTES int ec_ioctl_sdo_request_timeout(
  3112 static ATTRIBUTES int ec_ioctl_sdo_request_timeout(
  2971         ec_master_t *master, /**< EtherCAT master. */
  3113         ec_master_t *master, /**< EtherCAT master. */
  2972         void *arg, /**< ioctl() argument. */
  3114         void *arg, /**< ioctl() argument. */
  2973         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3115         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  2999 }
  3141 }
  3000 
  3142 
  3001 /*****************************************************************************/
  3143 /*****************************************************************************/
  3002 
  3144 
  3003 /** Gets an SDO request's state.
  3145 /** Gets an SDO request's state.
       
  3146  *
       
  3147  * \return Zero on success, otherwise a negative error code.
  3004  */
  3148  */
  3005 static ATTRIBUTES int ec_ioctl_sdo_request_state(
  3149 static ATTRIBUTES int ec_ioctl_sdo_request_state(
  3006         ec_master_t *master, /**< EtherCAT master. */
  3150         ec_master_t *master, /**< EtherCAT master. */
  3007         void *arg, /**< ioctl() argument. */
  3151         void *arg, /**< ioctl() argument. */
  3008         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3152         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3042 }
  3186 }
  3043 
  3187 
  3044 /*****************************************************************************/
  3188 /*****************************************************************************/
  3045 
  3189 
  3046 /** Starts an SDO read operation.
  3190 /** Starts an SDO read operation.
       
  3191  *
       
  3192  * \return Zero on success, otherwise a negative error code.
  3047  */
  3193  */
  3048 static ATTRIBUTES int ec_ioctl_sdo_request_read(
  3194 static ATTRIBUTES int ec_ioctl_sdo_request_read(
  3049         ec_master_t *master, /**< EtherCAT master. */
  3195         ec_master_t *master, /**< EtherCAT master. */
  3050         void *arg, /**< ioctl() argument. */
  3196         void *arg, /**< ioctl() argument. */
  3051         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3197         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3077 }
  3223 }
  3078 
  3224 
  3079 /*****************************************************************************/
  3225 /*****************************************************************************/
  3080 
  3226 
  3081 /** Starts an SDO write operation.
  3227 /** Starts an SDO write operation.
       
  3228  *
       
  3229  * \return Zero on success, otherwise a negative error code.
  3082  */
  3230  */
  3083 static ATTRIBUTES int ec_ioctl_sdo_request_write(
  3231 static ATTRIBUTES int ec_ioctl_sdo_request_write(
  3084         ec_master_t *master, /**< EtherCAT master. */
  3232         ec_master_t *master, /**< EtherCAT master. */
  3085         void *arg, /**< ioctl() argument. */
  3233         void *arg, /**< ioctl() argument. */
  3086         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3234         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3126 }
  3274 }
  3127 
  3275 
  3128 /*****************************************************************************/
  3276 /*****************************************************************************/
  3129 
  3277 
  3130 /** Read SDO data.
  3278 /** Read SDO data.
       
  3279  *
       
  3280  * \return Zero on success, otherwise a negative error code.
  3131  */
  3281  */
  3132 static ATTRIBUTES int ec_ioctl_sdo_request_data(
  3282 static ATTRIBUTES int ec_ioctl_sdo_request_data(
  3133         ec_master_t *master, /**< EtherCAT master. */
  3283         ec_master_t *master, /**< EtherCAT master. */
  3134         void *arg, /**< ioctl() argument. */
  3284         void *arg, /**< ioctl() argument. */
  3135         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3285         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3164 }
  3314 }
  3165 
  3315 
  3166 /*****************************************************************************/
  3316 /*****************************************************************************/
  3167 
  3317 
  3168 /** Read register data.
  3318 /** Read register data.
       
  3319  *
       
  3320  * \return Zero on success, otherwise a negative error code.
  3169  */
  3321  */
  3170 static ATTRIBUTES int ec_ioctl_reg_request_data(
  3322 static ATTRIBUTES int ec_ioctl_reg_request_data(
  3171         ec_master_t *master, /**< EtherCAT master. */
  3323         ec_master_t *master, /**< EtherCAT master. */
  3172         void *arg, /**< ioctl() argument. */
  3324         void *arg, /**< ioctl() argument. */
  3173         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3325         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3209 }
  3361 }
  3210 
  3362 
  3211 /*****************************************************************************/
  3363 /*****************************************************************************/
  3212 
  3364 
  3213 /** Gets an register request's state.
  3365 /** Gets an register request's state.
       
  3366  *
       
  3367  * \return Zero on success, otherwise a negative error code.
  3214  */
  3368  */
  3215 static ATTRIBUTES int ec_ioctl_reg_request_state(
  3369 static ATTRIBUTES int ec_ioctl_reg_request_state(
  3216         ec_master_t *master, /**< EtherCAT master. */
  3370         ec_master_t *master, /**< EtherCAT master. */
  3217         void *arg, /**< ioctl() argument. */
  3371         void *arg, /**< ioctl() argument. */
  3218         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3372         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3252 }
  3406 }
  3253 
  3407 
  3254 /*****************************************************************************/
  3408 /*****************************************************************************/
  3255 
  3409 
  3256 /** Starts an register write operation.
  3410 /** Starts an register write operation.
       
  3411  *
       
  3412  * \return Zero on success, otherwise a negative error code.
  3257  */
  3413  */
  3258 static ATTRIBUTES int ec_ioctl_reg_request_write(
  3414 static ATTRIBUTES int ec_ioctl_reg_request_write(
  3259         ec_master_t *master, /**< EtherCAT master. */
  3415         ec_master_t *master, /**< EtherCAT master. */
  3260         void *arg, /**< ioctl() argument. */
  3416         void *arg, /**< ioctl() argument. */
  3261         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3417         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3298 }
  3454 }
  3299 
  3455 
  3300 /*****************************************************************************/
  3456 /*****************************************************************************/
  3301 
  3457 
  3302 /** Starts an register read operation.
  3458 /** Starts an register read operation.
       
  3459  *
       
  3460  * \return Zero on success, otherwise a negative error code.
  3303  */
  3461  */
  3304 static ATTRIBUTES int ec_ioctl_reg_request_read(
  3462 static ATTRIBUTES int ec_ioctl_reg_request_read(
  3305         ec_master_t *master, /**< EtherCAT master. */
  3463         ec_master_t *master, /**< EtherCAT master. */
  3306         void *arg, /**< ioctl() argument. */
  3464         void *arg, /**< ioctl() argument. */
  3307         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3465         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3339 }
  3497 }
  3340 
  3498 
  3341 /*****************************************************************************/
  3499 /*****************************************************************************/
  3342 
  3500 
  3343 /** Sets the VoE send header.
  3501 /** Sets the VoE send header.
       
  3502  *
       
  3503  * \return Zero on success, otherwise a negative error code.
  3344  */
  3504  */
  3345 static ATTRIBUTES int ec_ioctl_voe_send_header(
  3505 static ATTRIBUTES int ec_ioctl_voe_send_header(
  3346         ec_master_t *master, /**< EtherCAT master. */
  3506         ec_master_t *master, /**< EtherCAT master. */
  3347         void *arg, /**< ioctl() argument. */
  3507         void *arg, /**< ioctl() argument. */
  3348         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3508         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3382 }
  3542 }
  3383 
  3543 
  3384 /*****************************************************************************/
  3544 /*****************************************************************************/
  3385 
  3545 
  3386 /** Gets the received VoE header.
  3546 /** Gets the received VoE header.
       
  3547  *
       
  3548  * \return Zero on success, otherwise a negative error code.
  3387  */
  3549  */
  3388 static ATTRIBUTES int ec_ioctl_voe_rec_header(
  3550 static ATTRIBUTES int ec_ioctl_voe_rec_header(
  3389         ec_master_t *master, /**< EtherCAT master. */
  3551         ec_master_t *master, /**< EtherCAT master. */
  3390         void *arg, /**< ioctl() argument. */
  3552         void *arg, /**< ioctl() argument. */
  3391         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3553         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3428 }
  3590 }
  3429 
  3591 
  3430 /*****************************************************************************/
  3592 /*****************************************************************************/
  3431 
  3593 
  3432 /** Starts a VoE read operation.
  3594 /** Starts a VoE read operation.
       
  3595  *
       
  3596  * \return Zero on success, otherwise a negative error code.
  3433  */
  3597  */
  3434 static ATTRIBUTES int ec_ioctl_voe_read(
  3598 static ATTRIBUTES int ec_ioctl_voe_read(
  3435         ec_master_t *master, /**< EtherCAT master. */
  3599         ec_master_t *master, /**< EtherCAT master. */
  3436         void *arg, /**< ioctl() argument. */
  3600         void *arg, /**< ioctl() argument. */
  3437         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3601         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3463 }
  3627 }
  3464 
  3628 
  3465 /*****************************************************************************/
  3629 /*****************************************************************************/
  3466 
  3630 
  3467 /** Starts a VoE read operation without sending a sync message first.
  3631 /** Starts a VoE read operation without sending a sync message first.
       
  3632  *
       
  3633  * \return Zero on success, otherwise a negative error code.
  3468  */
  3634  */
  3469 static ATTRIBUTES int ec_ioctl_voe_read_nosync(
  3635 static ATTRIBUTES int ec_ioctl_voe_read_nosync(
  3470         ec_master_t *master, /**< EtherCAT master. */
  3636         ec_master_t *master, /**< EtherCAT master. */
  3471         void *arg, /**< ioctl() argument. */
  3637         void *arg, /**< ioctl() argument. */
  3472         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3638         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3498 }
  3664 }
  3499 
  3665 
  3500 /*****************************************************************************/
  3666 /*****************************************************************************/
  3501 
  3667 
  3502 /** Starts a VoE write operation.
  3668 /** Starts a VoE write operation.
       
  3669  *
       
  3670  * \return Zero on success, otherwise a negative error code.
  3503  */
  3671  */
  3504 static ATTRIBUTES int ec_ioctl_voe_write(
  3672 static ATTRIBUTES int ec_ioctl_voe_write(
  3505         ec_master_t *master, /**< EtherCAT master. */
  3673         ec_master_t *master, /**< EtherCAT master. */
  3506         void *arg, /**< ioctl() argument. */
  3674         void *arg, /**< ioctl() argument. */
  3507         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3675         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3542 }
  3710 }
  3543 
  3711 
  3544 /*****************************************************************************/
  3712 /*****************************************************************************/
  3545 
  3713 
  3546 /** Executes the VoE state machine.
  3714 /** Executes the VoE state machine.
       
  3715  *
       
  3716  * \return Zero on success, otherwise a negative error code.
  3547  */
  3717  */
  3548 static ATTRIBUTES int ec_ioctl_voe_exec(
  3718 static ATTRIBUTES int ec_ioctl_voe_exec(
  3549         ec_master_t *master, /**< EtherCAT master. */
  3719         ec_master_t *master, /**< EtherCAT master. */
  3550         void *arg, /**< ioctl() argument. */
  3720         void *arg, /**< ioctl() argument. */
  3551         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3721         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3585 }
  3755 }
  3586 
  3756 
  3587 /*****************************************************************************/
  3757 /*****************************************************************************/
  3588 
  3758 
  3589 /** Reads the received VoE data.
  3759 /** Reads the received VoE data.
       
  3760  *
       
  3761  * \return Zero on success, otherwise a negative error code.
  3590  */
  3762  */
  3591 static ATTRIBUTES int ec_ioctl_voe_data(
  3763 static ATTRIBUTES int ec_ioctl_voe_data(
  3592         ec_master_t *master, /**< EtherCAT master. */
  3764         ec_master_t *master, /**< EtherCAT master. */
  3593         void *arg, /**< ioctl() argument. */
  3765         void *arg, /**< ioctl() argument. */
  3594         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3766         ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
  3623 }
  3795 }
  3624 
  3796 
  3625 /*****************************************************************************/
  3797 /*****************************************************************************/
  3626 
  3798 
  3627 /** Read a file from a slave via FoE.
  3799 /** Read a file from a slave via FoE.
       
  3800  *
       
  3801  * \return Zero on success, otherwise a negative error code.
  3628  */
  3802  */
  3629 static ATTRIBUTES int ec_ioctl_slave_foe_read(
  3803 static ATTRIBUTES int ec_ioctl_slave_foe_read(
  3630         ec_master_t *master, /**< EtherCAT master. */
  3804         ec_master_t *master, /**< EtherCAT master. */
  3631         void *arg /**< ioctl() argument. */
  3805         void *arg /**< ioctl() argument. */
  3632         )
  3806         )
  3717 }
  3891 }
  3718 
  3892 
  3719 /*****************************************************************************/
  3893 /*****************************************************************************/
  3720 
  3894 
  3721 /** Write a file to a slave via FoE
  3895 /** Write a file to a slave via FoE
       
  3896  *
       
  3897  * \return Zero on success, otherwise a negative error code.
  3722  */
  3898  */
  3723 static ATTRIBUTES int ec_ioctl_slave_foe_write(
  3899 static ATTRIBUTES int ec_ioctl_slave_foe_write(
  3724         ec_master_t *master, /**< EtherCAT master. */
  3900         ec_master_t *master, /**< EtherCAT master. */
  3725         void *arg /**< ioctl() argument. */
  3901         void *arg /**< ioctl() argument. */
  3726         )
  3902         )
  3803 }
  3979 }
  3804 
  3980 
  3805 /*****************************************************************************/
  3981 /*****************************************************************************/
  3806 
  3982 
  3807 /** Read an SoE IDN.
  3983 /** Read an SoE IDN.
       
  3984  *
       
  3985  * \return Zero on success, otherwise a negative error code.
  3808  */
  3986  */
  3809 static ATTRIBUTES int ec_ioctl_slave_soe_read(
  3987 static ATTRIBUTES int ec_ioctl_slave_soe_read(
  3810         ec_master_t *master, /**< EtherCAT master. */
  3988         ec_master_t *master, /**< EtherCAT master. */
  3811         void *arg /**< ioctl() argument. */
  3989         void *arg /**< ioctl() argument. */
  3812         )
  3990         )
  3850 }
  4028 }
  3851 
  4029 
  3852 /*****************************************************************************/
  4030 /*****************************************************************************/
  3853 
  4031 
  3854 /** Write an IDN to a slave via SoE.
  4032 /** Write an IDN to a slave via SoE.
       
  4033  *
       
  4034  * \return Zero on success, otherwise a negative error code.
  3855  */
  4035  */
  3856 static ATTRIBUTES int ec_ioctl_slave_soe_write(
  4036 static ATTRIBUTES int ec_ioctl_slave_soe_write(
  3857         ec_master_t *master, /**< EtherCAT master. */
  4037         ec_master_t *master, /**< EtherCAT master. */
  3858         void *arg /**< ioctl() argument. */
  4038         void *arg /**< ioctl() argument. */
  3859         )
  4039         )
  3893     return retval;
  4073     return retval;
  3894 }
  4074 }
  3895 
  4075 
  3896 /*****************************************************************************/
  4076 /*****************************************************************************/
  3897 
  4077 
       
  4078 /** ioctl() function to use.
       
  4079  */
  3898 #ifdef EC_IOCTL_RTDM
  4080 #ifdef EC_IOCTL_RTDM
  3899 #define EC_IOCTL ec_ioctl_rtdm
  4081 #define EC_IOCTL ec_ioctl_rtdm
  3900 #else
  4082 #else
  3901 #define EC_IOCTL ec_ioctl
  4083 #define EC_IOCTL ec_ioctl
  3902 #endif
  4084 #endif
  3903 
  4085 
  3904 /** Called when an ioctl() command is issued.
  4086 /** Called when an ioctl() command is issued.
  3905  */
  4087  *
  3906 long EC_IOCTL(ec_master_t *master, ec_ioctl_context_t *ctx,
  4088  * \return ioctl() return code.
  3907         unsigned int cmd, void *arg)
  4089  */
       
  4090 long EC_IOCTL(
       
  4091         ec_master_t *master, /**< EtherCAT master. */
       
  4092         ec_ioctl_context_t *ctx, /**< Device context. */
       
  4093         unsigned int cmd, /**< ioctl() command identifier. */
       
  4094         void *arg /**< ioctl() argument. */
       
  4095         )
  3908 {
  4096 {
  3909 #if DEBUG_LATENCY
  4097 #if DEBUG_LATENCY
  3910     cycles_t a = get_cycles(), b;
  4098     cycles_t a = get_cycles(), b;
  3911     unsigned int t;
  4099     unsigned int t;
  3912 #endif
  4100 #endif