master/rtdm.c
branchstable-1.5
changeset 2524 6d9865c37b6f
parent 2522 ec403cf308eb
child 2700 93ef210e9b56
equal deleted inserted replaced
2523:c5c81a52fc30 2524:6d9865c37b6f
    24  *  EtherCAT technology and brand is only permitted in compliance with the
    24  *  EtherCAT technology and brand is only permitted in compliance with the
    25  *  industrial property and similar rights of Beckhoff Automation GmbH.
    25  *  industrial property and similar rights of Beckhoff Automation GmbH.
    26  *
    26  *
    27  ****************************************************************************/
    27  ****************************************************************************/
    28 
    28 
       
    29 /** \file
       
    30  * RTDM interface.
       
    31  */
       
    32 
    29 #include <linux/module.h>
    33 #include <linux/module.h>
    30 #include <linux/slab.h>
    34 #include <linux/slab.h>
    31 #include <linux/mman.h>
    35 #include <linux/mman.h>
    32 
    36 
    33 #include <rtdm/rtdm_driver.h>
    37 #include <rtdm/rtdm_driver.h>
    43 /****************************************************************************/
    47 /****************************************************************************/
    44 
    48 
    45 /** Context structure for an open RTDM file handle.
    49 /** Context structure for an open RTDM file handle.
    46  */
    50  */
    47 typedef struct {
    51 typedef struct {
    48     rtdm_user_info_t *user_info; /**< RTDM user info. */
    52     rtdm_user_info_t *user_info; /**< RTDM user data. */
    49     ec_ioctl_context_t ioctl_ctx; /**< Context structure. */
    53     ec_ioctl_context_t ioctl_ctx; /**< Context structure. */
    50 } ec_rtdm_context_t;
    54 } ec_rtdm_context_t;
    51 
    55 
    52 /****************************************************************************/
    56 /****************************************************************************/
    53 
    57 
    56 int ec_rtdm_ioctl(struct rtdm_dev_context *, rtdm_user_info_t *,
    60 int ec_rtdm_ioctl(struct rtdm_dev_context *, rtdm_user_info_t *,
    57         unsigned int, void __user *);
    61         unsigned int, void __user *);
    58 
    62 
    59 /****************************************************************************/
    63 /****************************************************************************/
    60 
    64 
       
    65 /** Initialize an RTDM device.
       
    66  *
       
    67  * \return Zero on success, otherwise a negative error code.
       
    68  */
    61 int ec_rtdm_dev_init(
    69 int ec_rtdm_dev_init(
    62         ec_rtdm_dev_t *rtdm_dev,
    70         ec_rtdm_dev_t *rtdm_dev, /**< EtherCAT RTDM device. */
    63         ec_master_t *master
    71         ec_master_t *master /**< EtherCAT master. */
    64         )
    72         )
    65 {
    73 {
    66     int ret;
    74     int ret;
    67 
    75 
    68     rtdm_dev->master = master;
    76     rtdm_dev->master = master;
   103     return ret;
   111     return ret;
   104 }
   112 }
   105 
   113 
   106 /****************************************************************************/
   114 /****************************************************************************/
   107 
   115 
       
   116 /** Clear an RTDM device.
       
   117  */
   108 void ec_rtdm_dev_clear(
   118 void ec_rtdm_dev_clear(
   109         ec_rtdm_dev_t *rtdm_dev
   119         ec_rtdm_dev_t *rtdm_dev /**< EtherCAT RTDM device. */
   110         )
   120         )
   111 {
   121 {
   112     int ret;
   122     int ret;
   113 
   123 
   114     EC_MASTER_INFO(rtdm_dev->master, "Unregistering RTDM device %s.\n",
   124     EC_MASTER_INFO(rtdm_dev->master, "Unregistering RTDM device %s.\n",
   123 }
   133 }
   124 
   134 
   125 /****************************************************************************/
   135 /****************************************************************************/
   126 
   136 
   127 /** Driver open.
   137 /** Driver open.
       
   138  *
       
   139  * \return Always zero (success).
   128  */
   140  */
   129 int ec_rtdm_open(
   141 int ec_rtdm_open(
   130         struct rtdm_dev_context *context,
   142         struct rtdm_dev_context *context, /**< Context. */
   131         rtdm_user_info_t *user_info,
   143         rtdm_user_info_t *user_info, /**< User data. */
   132         int oflags
   144         int oflags /**< Open flags. */
   133         )
   145         )
   134 {
   146 {
   135     ec_rtdm_context_t *ctx = (ec_rtdm_context_t *) context->dev_private;
   147     ec_rtdm_context_t *ctx = (ec_rtdm_context_t *) context->dev_private;
   136 #if DEBUG
   148 #if DEBUG
   137     ec_rtdm_dev_t *rtdm_dev = (ec_rtdm_dev_t *) context->device->device_data;
   149     ec_rtdm_dev_t *rtdm_dev = (ec_rtdm_dev_t *) context->device->device_data;
   151 }
   163 }
   152 
   164 
   153 /****************************************************************************/
   165 /****************************************************************************/
   154 
   166 
   155 /** Driver close.
   167 /** Driver close.
   156  */
   168  *
   157 int ec_rtdm_close(struct rtdm_dev_context *context,
   169  * \return Always zero (success).
   158         rtdm_user_info_t *user_info)
   170  */
       
   171 int ec_rtdm_close(
       
   172         struct rtdm_dev_context *context, /**< Context. */
       
   173         rtdm_user_info_t *user_info /**< User data. */
       
   174         )
   159 {
   175 {
   160     ec_rtdm_context_t *ctx = (ec_rtdm_context_t *) context->dev_private;
   176     ec_rtdm_context_t *ctx = (ec_rtdm_context_t *) context->dev_private;
   161     ec_rtdm_dev_t *rtdm_dev = (ec_rtdm_dev_t *) context->device->device_data;
   177     ec_rtdm_dev_t *rtdm_dev = (ec_rtdm_dev_t *) context->device->device_data;
   162 
   178 
   163     if (ctx->ioctl_ctx.requested) {
   179     if (ctx->ioctl_ctx.requested) {
   172 }
   188 }
   173 
   189 
   174 /****************************************************************************/
   190 /****************************************************************************/
   175 
   191 
   176 /** Driver ioctl.
   192 /** Driver ioctl.
       
   193  *
       
   194  * \return ioctl() return code.
   177  */
   195  */
   178 int ec_rtdm_ioctl(
   196 int ec_rtdm_ioctl(
   179         struct rtdm_dev_context *context, /**< Context. */
   197         struct rtdm_dev_context *context, /**< Context. */
   180         rtdm_user_info_t *user_info, /**< User data. */
   198         rtdm_user_info_t *user_info, /**< User data. */
   181         unsigned int request, /**< Request. */
   199         unsigned int request, /**< Request. */
   194 }
   212 }
   195 
   213 
   196 /****************************************************************************/
   214 /****************************************************************************/
   197 
   215 
   198 /** Memory-map process data to user space.
   216 /** Memory-map process data to user space.
   199  */
   217  *
   200 int ec_rtdm_mmap(ec_ioctl_context_t *ioctl_ctx, void **user_address)
   218  * \return Zero on success, otherwise a negative error code.
       
   219  */
       
   220 int ec_rtdm_mmap(
       
   221         ec_ioctl_context_t *ioctl_ctx, /**< Context. */
       
   222         void **user_address /**< Userspace address. */
       
   223         )
   201 {
   224 {
   202     ec_rtdm_context_t *ctx =
   225     ec_rtdm_context_t *ctx =
   203         container_of(ioctl_ctx, ec_rtdm_context_t, ioctl_ctx);
   226         container_of(ioctl_ctx, ec_rtdm_context_t, ioctl_ctx);
   204     int ret;
   227     int ret;
   205 
   228