fp@361: /****************************************************************************** fp@361: * fp@361: * $Id$ fp@361: * fp@361: * Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH fp@361: * fp@361: * This file is part of the IgH EtherCAT Master. fp@361: * fp@361: * The IgH EtherCAT Master is free software; you can redistribute it fp@361: * and/or modify it under the terms of the GNU General Public License fp@361: * as published by the Free Software Foundation; either version 2 of the fp@361: * License, or (at your option) any later version. fp@361: * fp@361: * The IgH EtherCAT Master is distributed in the hope that it will be fp@361: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of fp@361: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fp@361: * GNU General Public License for more details. fp@361: * fp@361: * You should have received a copy of the GNU General Public License fp@361: * along with the IgH EtherCAT Master; if not, write to the Free Software fp@361: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@361: * fp@361: * The right to use EtherCAT Technology is granted and comes free of fp@361: * charge under condition of compatibility of product made by fp@361: * Licensee. People intending to distribute/sell products based on the fp@361: * code, have to sign an agreement to guarantee that products using fp@361: * software based on IgH EtherCAT master stay compatible with the actual fp@361: * EtherCAT specification (which are released themselves as an open fp@361: * standard) as the (only) precondition to have the right to use EtherCAT fp@361: * Technology, IP and trade marks. fp@361: * fp@361: *****************************************************************************/ fp@361: fp@361: /** fp@361: \file fp@361: EtherCAT XML device. fp@361: */ fp@361: fp@361: /*****************************************************************************/ fp@361: fp@361: #include fp@361: fp@361: #include "master.h" fp@361: #include "xmldev.h" fp@361: fp@361: /*****************************************************************************/ fp@361: fp@758: /** \cond */ fp@758: fp@361: static char *test_str = "hello world!\n"; fp@361: fp@361: int ecxmldev_open(struct inode *, struct file *); fp@361: int ecxmldev_release(struct inode *, struct file *); fp@361: ssize_t ecxmldev_read(struct file *, char __user *, size_t, loff_t *); fp@361: ssize_t ecxmldev_write(struct file *, const char __user *, size_t, loff_t *); fp@361: fp@361: /*****************************************************************************/ fp@361: fp@489: /** \cond */ fp@489: fp@361: static struct file_operations fops = { fp@361: .owner = THIS_MODULE, fp@361: .open = ecxmldev_open, fp@361: .release = ecxmldev_release, fp@361: .read = ecxmldev_read, fp@361: .write = ecxmldev_write fp@361: }; fp@361: fp@489: /** \endcond */ fp@489: fp@361: /*****************************************************************************/ fp@361: fp@361: /** fp@361: XML device constructor. fp@361: \return 0 in case of success, else < 0 fp@361: */ fp@361: fp@361: int ec_xmldev_init(ec_xmldev_t *xmldev, /**< EtherCAT XML device */ fp@361: ec_master_t *master, /**< EtherCAT master */ fp@361: dev_t dev_num /**< device number */ fp@361: ) fp@361: { fp@362: atomic_set(&xmldev->available, 1); fp@361: cdev_init(&xmldev->cdev, &fops); fp@361: xmldev->cdev.owner = THIS_MODULE; fp@361: if (cdev_add(&xmldev->cdev, fp@361: MKDEV(MAJOR(dev_num), master->index), 1)) { fp@361: EC_ERR("Failed to add character device!\n"); fp@361: return -1; fp@361: } fp@361: return 0; fp@361: } fp@361: fp@361: /*****************************************************************************/ fp@361: fp@361: /** fp@361: XML device destructor. fp@361: */ fp@361: fp@361: void ec_xmldev_clear(ec_xmldev_t *xmldev /**< EtherCAT XML device */) fp@361: { fp@361: cdev_del(&xmldev->cdev); fp@361: } fp@361: fp@361: /*****************************************************************************/ fp@361: fp@362: int ec_xmldev_request(ec_xmldev_t *xmldev, fp@362: uint32_t vendor_id, fp@362: uint32_t product_code fp@362: ) fp@362: { fp@362: return 1; fp@362: } fp@362: fp@362: /****************************************************************************** fp@362: * file_operations fp@362: *****************************************************************************/ fp@362: fp@361: int ecxmldev_open(struct inode *inode, struct file *filp) fp@361: { fp@361: ec_xmldev_t *xmldev; fp@361: fp@361: xmldev = container_of(inode->i_cdev, ec_xmldev_t, cdev); fp@362: fp@362: if (!atomic_dec_and_test(&xmldev->available)) { fp@362: atomic_inc(&xmldev->available); fp@362: return -EBUSY; fp@362: } fp@362: fp@361: filp->private_data = xmldev; fp@361: fp@361: EC_DBG("File opened.\n"); fp@361: fp@361: return 0; fp@361: } fp@361: fp@361: /*****************************************************************************/ fp@361: fp@361: int ecxmldev_release(struct inode *inode, struct file *filp) fp@361: { fp@362: ec_xmldev_t *xmldev = container_of(inode->i_cdev, ec_xmldev_t, cdev); fp@362: atomic_inc(&xmldev->available); fp@361: EC_DBG("File closed.\n"); fp@361: return 0; fp@361: } fp@361: fp@361: /*****************************************************************************/ fp@361: fp@361: ssize_t ecxmldev_read(struct file *filp, char __user *buf, fp@361: size_t count, loff_t *f_pos) fp@361: { fp@361: size_t len = strlen(test_str); fp@361: fp@361: if (*f_pos >= len) return 0; fp@361: if (*f_pos + count > len) count = len - *f_pos; fp@361: fp@361: if (copy_to_user(buf, test_str + *f_pos, count)) return -EFAULT; fp@361: fp@361: *f_pos += count; fp@361: fp@361: return count; fp@361: } fp@361: fp@361: /*****************************************************************************/ fp@361: fp@361: ssize_t ecxmldev_write(struct file *filp, fp@361: const char __user *buf, fp@361: size_t count, fp@361: loff_t *f_pos) fp@361: { fp@361: return -EFAULT; fp@361: } fp@361: fp@758: /** \endcond */ fp@758: fp@361: /*****************************************************************************/