IgH EtherCAT Master  1.6.9
reg_request.c
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 * Copyright (C) 2012 Florian Pose, Ingenieurgemeinschaft IgH
4 *
5 * This file is part of the IgH EtherCAT Master.
6 *
7 * The IgH EtherCAT Master is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 2, as
9 * published by the Free Software Foundation.
10 *
11 * The IgH EtherCAT Master is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14 * Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with the IgH EtherCAT Master; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 ****************************************************************************/
21
25
26/****************************************************************************/
27
28#include <linux/module.h>
29#include <linux/jiffies.h>
30#include <linux/slab.h>
31
32#include "reg_request.h"
33
34/****************************************************************************/
35
41 ec_reg_request_t *reg,
42 size_t size
43 )
44{
45 if (!(reg->data = (uint8_t *) kmalloc(size, GFP_KERNEL))) {
46 EC_ERR("Failed to allocate %zu bytes of register memory.\n", size);
47 return -ENOMEM;
48 }
49
50 INIT_LIST_HEAD(&reg->list);
51 reg->mem_size = size;
52 memset(reg->data, 0x00, size);
53 reg->dir = EC_DIR_INVALID;
54 reg->address = 0;
55 reg->transfer_size = 0;
56 reg->state = EC_INT_REQUEST_INIT;
57 reg->ring_position = 0;
58 return 0;
59}
60
61/****************************************************************************/
62
67 )
68{
69 if (reg->data) {
70 kfree(reg->data);
71 }
72}
73
74/*****************************************************************************
75 * Application interface.
76 ****************************************************************************/
77
79{
80 return reg->data;
81}
82
83/****************************************************************************/
84
89
90/****************************************************************************/
91
92int ecrt_reg_request_write(ec_reg_request_t *reg, uint16_t address,
93 size_t size)
94{
95 reg->dir = EC_DIR_OUTPUT;
96 reg->address = address;
97 reg->transfer_size = min(size, reg->mem_size);
98 reg->state = EC_INT_REQUEST_QUEUED;
99 return 0;
100}
101
102/****************************************************************************/
103
104int ecrt_reg_request_read(ec_reg_request_t *reg, uint16_t address,
105 size_t size)
106{
107 reg->dir = EC_DIR_INPUT;
108 reg->address = address;
109 reg->transfer_size = min(size, reg->mem_size);
110 reg->state = EC_INT_REQUEST_QUEUED;
111 return 0;
112}
113
114/****************************************************************************/
115
117
118EXPORT_SYMBOL(ecrt_reg_request_data);
119EXPORT_SYMBOL(ecrt_reg_request_state);
120EXPORT_SYMBOL(ecrt_reg_request_write);
121EXPORT_SYMBOL(ecrt_reg_request_read);
122
124
125/****************************************************************************/
const ec_request_state_t ec_request_state_translation_table[]
Global request state type translation table.
Definition module.c:658
#define EC_ERR(fmt, args...)
Convenience macro for printing EtherCAT-specific errors to syslog.
Definition globals.h:224
uint8_t * ecrt_reg_request_data(const ec_reg_request_t *reg)
Access to the register request's data.
Definition reg_request.c:78
int ecrt_reg_request_write(ec_reg_request_t *reg, uint16_t address, size_t size)
Schedule an register write operation.
Definition reg_request.c:92
struct ec_reg_request ec_reg_request_t
Definition ecrt.h:318
ec_request_state_t ecrt_reg_request_state(const ec_reg_request_t *reg)
Get the current state of the register request.
Definition reg_request.c:85
int ecrt_reg_request_read(ec_reg_request_t *reg, uint16_t address, size_t size)
Schedule a register read operation.
ec_request_state_t
Request state.
Definition ecrt.h:604
@ EC_DIR_INVALID
Invalid direction.
Definition ecrt.h:505
@ EC_DIR_INPUT
Values read by the master.
Definition ecrt.h:507
@ EC_DIR_OUTPUT
Values written by the master.
Definition ecrt.h:506
void ec_reg_request_clear(ec_reg_request_t *reg)
Register request destructor.
Definition reg_request.c:65
int ec_reg_request_init(ec_reg_request_t *reg, size_t size)
Register request constructor.
Definition reg_request.c:40
EtherCAT register request structure.
size_t mem_size
Size of data memory.
Definition reg_request.h:42
uint8_t * data
Pointer to data memory.
Definition reg_request.h:43
struct list_head list
List item.
Definition reg_request.h:41
uint16_t address
Register address.
Definition reg_request.h:46
uint16_t ring_position
Ring position for emergency requests.
Definition reg_request.h:49
ec_direction_t dir
Direction.
Definition reg_request.h:44
ec_internal_request_state_t state
Request state.
Definition reg_request.h:48
size_t transfer_size
Size of the data to transfer.
Definition reg_request.h:47