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