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