master/reg_request.c
branchstable-1.5
changeset 2443 2c3ccdde3919
child 2521 3d68bb0047a1
equal deleted inserted replaced
2442:86ebf18a029f 2443:2c3ccdde3919
       
     1 /******************************************************************************
       
     2  *
       
     3  *  $Id$
       
     4  *
       
     5  *  Copyright (C) 2012  Florian Pose, Ingenieurgemeinschaft IgH
       
     6  *
       
     7  *  This file is part of the IgH EtherCAT Master.
       
     8  *
       
     9  *  The IgH EtherCAT Master is free software; you can redistribute it and/or
       
    10  *  modify it under the terms of the GNU General Public License version 2, as
       
    11  *  published by the Free Software Foundation.
       
    12  *
       
    13  *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
       
    14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
       
    16  *  Public License for more details.
       
    17  *
       
    18  *  You should have received a copy of the GNU General Public License along
       
    19  *  with the IgH EtherCAT Master; if not, write to the Free Software
       
    20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       
    21  *
       
    22  *  ---
       
    23  *
       
    24  *  The license mentioned above concerns the source code only. Using the
       
    25  *  EtherCAT technology and brand is only permitted in compliance with the
       
    26  *  industrial property and similar rights of Beckhoff Automation GmbH.
       
    27  *
       
    28  *****************************************************************************/
       
    29 
       
    30 /** \file
       
    31  * Register request functions.
       
    32  */
       
    33 
       
    34 /*****************************************************************************/
       
    35 
       
    36 #include <linux/module.h>
       
    37 #include <linux/jiffies.h>
       
    38 #include <linux/slab.h>
       
    39 
       
    40 #include "reg_request.h"
       
    41 
       
    42 /*****************************************************************************/
       
    43 
       
    44 void ec_reg_request_clear_data(ec_reg_request_t *);
       
    45 
       
    46 /*****************************************************************************/
       
    47 
       
    48 /** Register request constructor.
       
    49  */
       
    50 int ec_reg_request_init(
       
    51         ec_reg_request_t *reg, /**< Register request. */
       
    52         size_t size /**< Memory size. */
       
    53         )
       
    54 {
       
    55     if (!(reg->data = (uint8_t *) kmalloc(size, GFP_KERNEL))) {
       
    56         EC_ERR("Failed to allocate %zu bytes of register memory.\n", size);
       
    57         return -ENOMEM;
       
    58     }
       
    59 
       
    60     INIT_LIST_HEAD(&reg->list);
       
    61     reg->mem_size = size;
       
    62     memset(reg->data, 0x00, size);
       
    63     reg->dir = EC_DIR_INVALID;
       
    64     reg->address = 0;
       
    65     reg->transfer_size = 0;
       
    66     reg->state = EC_INT_REQUEST_INIT;
       
    67     return 0;
       
    68 }
       
    69 
       
    70 /*****************************************************************************/
       
    71 
       
    72 /** Register request destructor.
       
    73  */
       
    74 void ec_reg_request_clear(
       
    75         ec_reg_request_t *reg /**< Register request. */
       
    76         )
       
    77 {
       
    78     if (reg->data) {
       
    79         kfree(reg->data);
       
    80     }
       
    81 }
       
    82 
       
    83 /*****************************************************************************
       
    84  * Application interface.
       
    85  ****************************************************************************/
       
    86 
       
    87 uint8_t *ecrt_reg_request_data(ec_reg_request_t *reg)
       
    88 {
       
    89     return reg->data;
       
    90 }
       
    91 
       
    92 /*****************************************************************************/
       
    93 
       
    94 ec_request_state_t ecrt_reg_request_state(const ec_reg_request_t *reg)
       
    95 {
       
    96    return ec_request_state_translation_table[reg->state];
       
    97 }
       
    98 
       
    99 /*****************************************************************************/
       
   100 
       
   101 void ecrt_reg_request_write(ec_reg_request_t *reg, uint16_t address,
       
   102         size_t size)
       
   103 {
       
   104     reg->dir = EC_DIR_OUTPUT;
       
   105     reg->address = address;
       
   106     reg->transfer_size = min(size, reg->mem_size);
       
   107     reg->state = EC_INT_REQUEST_QUEUED;
       
   108 }
       
   109 
       
   110 /*****************************************************************************/
       
   111 
       
   112 void ecrt_reg_request_read(ec_reg_request_t *reg, uint16_t address,
       
   113         size_t size)
       
   114 {
       
   115     reg->dir = EC_DIR_INPUT;
       
   116     reg->address = address;
       
   117     reg->transfer_size = min(size, reg->mem_size);
       
   118     reg->state = EC_INT_REQUEST_QUEUED;
       
   119 }
       
   120 
       
   121 /*****************************************************************************/
       
   122 
       
   123 /** \cond */
       
   124 
       
   125 EXPORT_SYMBOL(ecrt_reg_request_data);
       
   126 EXPORT_SYMBOL(ecrt_reg_request_state);
       
   127 EXPORT_SYMBOL(ecrt_reg_request_write);
       
   128 EXPORT_SYMBOL(ecrt_reg_request_read);
       
   129 
       
   130 /** \endcond */
       
   131 
       
   132 /*****************************************************************************/