33 #include <linux/module.h> 34 #include <linux/slab.h> 35 #include <linux/mman.h> 37 #include <rtdm/rtdm_driver.h> 58 int ec_rtdm_open(
struct rtdm_dev_context *, rtdm_user_info_t *,
int);
59 int ec_rtdm_close(
struct rtdm_dev_context *, rtdm_user_info_t *);
60 int ec_rtdm_ioctl(
struct rtdm_dev_context *, rtdm_user_info_t *,
61 unsigned int,
void __user *);
78 rtdm_dev->
dev = kzalloc(
sizeof(
struct rtdm_device), GFP_KERNEL);
80 EC_MASTER_ERR(master,
"Failed to reserve memory for RTDM device.\n");
84 rtdm_dev->
dev->struct_version = RTDM_DEVICE_STRUCT_VER;
85 rtdm_dev->
dev->device_flags = RTDM_NAMED_DEVICE;
87 snprintf(rtdm_dev->
dev->device_name, RTDM_MAX_DEVNAME_LEN,
88 "EtherCAT%u", master->
index);
93 rtdm_dev->
dev->device_class = RTDM_CLASS_EXPERIMENTAL;
94 rtdm_dev->
dev->device_sub_class = 222;
95 rtdm_dev->
dev->driver_name =
"EtherCAT";
96 rtdm_dev->
dev->driver_version = RTDM_DRIVER_VER(1, 0, 2);
97 rtdm_dev->
dev->peripheral_name = rtdm_dev->
dev->device_name;
98 rtdm_dev->
dev->provider_name =
"EtherLab Community";
99 rtdm_dev->
dev->proc_name = rtdm_dev->
dev->device_name;
100 rtdm_dev->
dev->device_data = rtdm_dev;
103 rtdm_dev->
dev->driver_name);
104 ret = rtdm_dev_register(rtdm_dev->
dev);
106 EC_MASTER_ERR(master,
"Initialization of RTDM interface failed" 107 " (return value %i).\n", ret);
108 kfree(rtdm_dev->
dev);
125 rtdm_dev->
dev->driver_name);
126 ret = rtdm_dev_unregister(rtdm_dev->
dev, 1000 );
129 "Failed to unregister RTDM device (code %i).\n", ret);
132 kfree(rtdm_dev->
dev);
142 struct rtdm_dev_context *context,
143 rtdm_user_info_t *user_info,
153 ctx->
ioctl_ctx.writable = oflags & O_WRONLY || oflags & O_RDWR;
160 context->device->device_name);
172 struct rtdm_dev_context *context,
173 rtdm_user_info_t *user_info
185 context->device->device_name);
197 struct rtdm_dev_context *context,
198 rtdm_user_info_t *user_info,
199 unsigned int request,
207 EC_MASTER_INFO(rtdm_dev->master,
"ioctl(request = %u, ctl = %02x)" 208 " on RTDM device %s.\n", request, _IOC_NR(request),
209 context->device->device_name);
211 return ec_ioctl_rtdm(rtdm_dev->master, &ctx->
ioctl_ctx, request, arg);
221 ec_ioctl_context_t *ioctl_ctx,
230 ioctl_ctx->process_data, ioctl_ctx->process_data_size,
231 PROT_READ | PROT_WRITE,
int ec_rtdm_dev_init(ec_rtdm_dev_t *rtdm_dev, ec_master_t *master)
Initialize an RTDM device.
void ecrt_release_master(ec_master_t *master)
Releases a requested EtherCAT master.
struct rtdm_device * dev
RTDM device.
ec_master_t * master
Master pointer.
int ec_rtdm_close(struct rtdm_dev_context *, rtdm_user_info_t *)
Driver close.
#define DEBUG
Set to 1 to enable device operations debugging.
EtherCAT master structure.
rtdm_user_info_t * user_info
RTDM user data.
ec_ioctl_context_t ioctl_ctx
Context structure.
int ec_rtdm_ioctl(struct rtdm_dev_context *, rtdm_user_info_t *, unsigned int, void __user *)
Driver ioctl.
#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.
Context structure for an open RTDM file handle.
EtherCAT master character device IOCTL commands.
int ec_rtdm_open(struct rtdm_dev_context *, rtdm_user_info_t *, int)
Driver open.
#define EC_MASTER_INFO(master, fmt, args...)
Convenience macro for printing master-specific information to syslog.