fp@2443: /****************************************************************************** fp@2443: * fp@2443: * $Id$ fp@2443: * fp@2443: * Copyright (C) 2012 Florian Pose, Ingenieurgemeinschaft IgH fp@2443: * fp@2443: * This file is part of the IgH EtherCAT Master. fp@2443: * fp@2443: * The IgH EtherCAT Master is free software; you can redistribute it and/or fp@2443: * modify it under the terms of the GNU General Public License version 2, as fp@2443: * published by the Free Software Foundation. fp@2443: * fp@2443: * The IgH EtherCAT Master is distributed in the hope that it will be useful, fp@2443: * but WITHOUT ANY WARRANTY; without even the implied warranty of fp@2443: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General fp@2443: * Public License for more details. fp@2443: * fp@2443: * You should have received a copy of the GNU General Public License along fp@2443: * with the IgH EtherCAT Master; if not, write to the Free Software fp@2443: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA fp@2443: * fp@2443: * --- fp@2443: * fp@2443: * The license mentioned above concerns the source code only. Using the fp@2443: * EtherCAT technology and brand is only permitted in compliance with the fp@2443: * industrial property and similar rights of Beckhoff Automation GmbH. fp@2443: * fp@2443: *****************************************************************************/ fp@2443: fp@2443: /** \file fp@2443: * Register request functions. fp@2443: */ fp@2443: fp@2443: /*****************************************************************************/ fp@2443: fp@2443: #include fp@2443: #include fp@2443: #include fp@2443: fp@2443: #include "reg_request.h" fp@2443: fp@2443: /*****************************************************************************/ fp@2443: fp@2443: /** Register request constructor. fp@2522: * fp@2522: * \return Zero on success, otherwise a negative error code. fp@2443: */ fp@2443: int ec_reg_request_init( fp@2443: ec_reg_request_t *reg, /**< Register request. */ fp@2443: size_t size /**< Memory size. */ fp@2443: ) fp@2443: { fp@2443: if (!(reg->data = (uint8_t *) kmalloc(size, GFP_KERNEL))) { fp@2443: EC_ERR("Failed to allocate %zu bytes of register memory.\n", size); fp@2443: return -ENOMEM; fp@2443: } fp@2443: fp@2443: INIT_LIST_HEAD(®->list); fp@2443: reg->mem_size = size; fp@2443: memset(reg->data, 0x00, size); fp@2443: reg->dir = EC_DIR_INVALID; fp@2443: reg->address = 0; fp@2443: reg->transfer_size = 0; fp@2443: reg->state = EC_INT_REQUEST_INIT; fp@2529: reg->ring_position = 0; fp@2443: return 0; fp@2443: } fp@2443: fp@2443: /*****************************************************************************/ fp@2443: fp@2443: /** Register request destructor. fp@2443: */ fp@2443: void ec_reg_request_clear( fp@2443: ec_reg_request_t *reg /**< Register request. */ fp@2443: ) fp@2443: { fp@2443: if (reg->data) { fp@2443: kfree(reg->data); fp@2443: } fp@2443: } fp@2443: fp@2443: /***************************************************************************** fp@2443: * Application interface. fp@2443: ****************************************************************************/ fp@2443: fp@2443: uint8_t *ecrt_reg_request_data(ec_reg_request_t *reg) fp@2443: { fp@2443: return reg->data; fp@2443: } fp@2443: fp@2443: /*****************************************************************************/ fp@2443: fp@2443: ec_request_state_t ecrt_reg_request_state(const ec_reg_request_t *reg) fp@2443: { fp@2443: return ec_request_state_translation_table[reg->state]; fp@2443: } fp@2443: fp@2443: /*****************************************************************************/ fp@2443: fp@2443: void ecrt_reg_request_write(ec_reg_request_t *reg, uint16_t address, fp@2443: size_t size) fp@2443: { fp@2443: reg->dir = EC_DIR_OUTPUT; fp@2443: reg->address = address; fp@2443: reg->transfer_size = min(size, reg->mem_size); fp@2443: reg->state = EC_INT_REQUEST_QUEUED; fp@2443: } fp@2443: fp@2443: /*****************************************************************************/ fp@2443: fp@2443: void ecrt_reg_request_read(ec_reg_request_t *reg, uint16_t address, fp@2443: size_t size) fp@2443: { fp@2443: reg->dir = EC_DIR_INPUT; fp@2443: reg->address = address; fp@2443: reg->transfer_size = min(size, reg->mem_size); fp@2443: reg->state = EC_INT_REQUEST_QUEUED; fp@2443: } fp@2443: fp@2443: /*****************************************************************************/ fp@2443: fp@2443: /** \cond */ fp@2443: fp@2443: EXPORT_SYMBOL(ecrt_reg_request_data); fp@2443: EXPORT_SYMBOL(ecrt_reg_request_state); fp@2443: EXPORT_SYMBOL(ecrt_reg_request_write); fp@2443: EXPORT_SYMBOL(ecrt_reg_request_read); fp@2443: fp@2443: /** \endcond */ fp@2443: fp@2443: /*****************************************************************************/