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