27 #include <linux/module.h> 28 #include <linux/slab.h> 29 #include <linux/mman.h> 35 #include "rtdm_details.h" 38 #include <rtdm/rtdm_driver.h> 46 static int ec_rtdm_open(
struct rtdm_dev_context *, rtdm_user_info_t *,
int);
47 static int ec_rtdm_close(
struct rtdm_dev_context *, rtdm_user_info_t *);
49 rtdm_user_info_t *,
unsigned int,
void __user *);
51 rtdm_user_info_t *,
unsigned int,
void __user *);
68 rtdm_dev->
dev = kzalloc(
sizeof(
struct rtdm_device), GFP_KERNEL);
70 EC_MASTER_ERR(master,
"Failed to reserve memory for RTDM device.\n");
74 rtdm_dev->
dev->struct_version = RTDM_DEVICE_STRUCT_VER;
75 rtdm_dev->
dev->device_flags = RTDM_NAMED_DEVICE;
77 snprintf(rtdm_dev->
dev->device_name, RTDM_MAX_DEVNAME_LEN,
78 "EtherCAT%u", master->
index);
83 rtdm_dev->
dev->device_class = RTDM_CLASS_EXPERIMENTAL;
84 rtdm_dev->
dev->device_sub_class = 222;
85 rtdm_dev->
dev->driver_name =
"EtherCAT";
86 rtdm_dev->
dev->driver_version = RTDM_DRIVER_VER(1, 0, 2);
87 rtdm_dev->
dev->peripheral_name = rtdm_dev->
dev->device_name;
88 rtdm_dev->
dev->provider_name =
"EtherLab Community";
89 rtdm_dev->
dev->proc_name = rtdm_dev->
dev->device_name;
90 rtdm_dev->
dev->device_data = rtdm_dev;
93 rtdm_dev->
dev->driver_name);
94 ret = rtdm_dev_register(rtdm_dev->
dev);
96 EC_MASTER_ERR(master,
"Initialization of RTDM interface failed" 97 " (return value %i).\n", ret);
115 rtdm_dev->
dev->driver_name);
116 ret = rtdm_dev_unregister(rtdm_dev->
dev, 1000 );
119 "Failed to unregister RTDM device (code %i).\n", ret);
122 kfree(rtdm_dev->
dev);
132 struct rtdm_dev_context *context,
133 rtdm_user_info_t *user_info,
143 ctx->
ioctl_ctx.writable = oflags & O_WRONLY || oflags & O_RDWR;
150 context->device->device_name);
162 struct rtdm_dev_context *context,
163 rtdm_user_info_t *user_info
175 context->device->device_name);
187 struct rtdm_dev_context *context,
188 rtdm_user_info_t *user_info,
189 unsigned int request,
197 EC_MASTER_INFO(rtdm_dev->master,
"ioctl(request = %u, ctl = %02x)" 198 " on RTDM device %s.\n", request, _IOC_NR(request),
199 context->device->device_name);
201 return ec_ioctl_rtdm_nrt(rtdm_dev->master, &ctx->
ioctl_ctx, request, arg);
207 struct rtdm_dev_context *context,
208 rtdm_user_info_t *user_info,
209 unsigned int request,
218 EC_MASTER_INFO(rtdm_dev->master,
"ioctl(request = %u, ctl = %02x)" 219 " on RTDM device %s.\n", request, _IOC_NR(request),
220 context->device->device_name);
223 ec_ioctl_rtdm_rt(rtdm_dev->master, &ctx->
ioctl_ctx, request, arg);
225 if (result == -ENOTTY) {
239 ec_ioctl_context_t *ioctl_ctx,
247 ret = rtdm_mmap_to_user(ctx->
user_fd,
248 ioctl_ctx->process_data, ioctl_ctx->process_data_size,
249 PROT_READ | PROT_WRITE,
static int ec_rtdm_ioctl_nrt_handler(struct rtdm_dev_context *, rtdm_user_info_t *, unsigned int, void __user *)
Driver ioctl.
int ec_rtdm_dev_init(ec_rtdm_dev_t *rtdm_dev, ec_master_t *master)
Initialize an RTDM device.
ec_ioctl_context_t ioctl_ctx
Context structure.
static int ec_rtdm_close(struct rtdm_dev_context *, rtdm_user_info_t *)
Driver close.
struct rtdm_device * dev
RTDM device.
static int ec_rtdm_open(struct rtdm_dev_context *, rtdm_user_info_t *, int)
Driver open.
ec_master_t * master
Master pointer.
Context structure for an open RTDM file handle.
#define DEBUG
Set to 1 to enable device operations debugging.
EtherCAT master structure.
EC_RTDM_USERFD_T * user_fd
RTDM user data.
#define EC_MASTER_WARN(master, fmt, args...)
Convenience macro for printing master-specific warnings to syslog.
#define EC_MASTER_ERR(master, fmt, args...)
Convenience macro for printing master-specific errors to syslog.
int ec_rtdm_mmap(ec_ioctl_context_t *ioctl_ctx, void **user_address)
Memory-map process data to user space.
void ec_rtdm_dev_clear(ec_rtdm_dev_t *rtdm_dev)
Clear an RTDM device.
static int ec_rtdm_ioctl_rt_handler(struct rtdm_dev_context *, rtdm_user_info_t *, unsigned int, void __user *)
EtherCAT master character device IOCTL commands.
#define EC_MASTER_INFO(master, fmt, args...)
Convenience macro for printing master-specific information to syslog.
void ecrt_release_master(ec_master_t *master)
Releases a requested EtherCAT master.