IgH EtherCAT Master  1.5.3
reg_request.c
Go to the documentation of this file.
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 
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 
49  ec_reg_request_t *reg,
50  size_t size
51  )
52 {
53  if (!(reg->data = (uint8_t *) kmalloc(size, GFP_KERNEL))) {
54  EC_ERR("Failed to allocate %zu bytes of register memory.\n", size);
55  return -ENOMEM;
56  }
57 
58  INIT_LIST_HEAD(&reg->list);
59  reg->mem_size = size;
60  memset(reg->data, 0x00, size);
61  reg->dir = EC_DIR_INVALID;
62  reg->address = 0;
63  reg->transfer_size = 0;
64  reg->state = EC_INT_REQUEST_INIT;
65  reg->ring_position = 0;
66  return 0;
67 }
68 
69 /*****************************************************************************/
70 
74  ec_reg_request_t *reg
75  )
76 {
77  if (reg->data) {
78  kfree(reg->data);
79  }
80 }
81 
82 /*****************************************************************************
83  * Application interface.
84  ****************************************************************************/
85 
87 {
88  return reg->data;
89 }
90 
91 /*****************************************************************************/
92 
94 {
96 }
97 
98 /*****************************************************************************/
99 
100 void ecrt_reg_request_write(ec_reg_request_t *reg, uint16_t address,
101  size_t size)
102 {
103  reg->dir = EC_DIR_OUTPUT;
104  reg->address = address;
105  reg->transfer_size = min(size, reg->mem_size);
106  reg->state = EC_INT_REQUEST_QUEUED;
107 }
108 
109 /*****************************************************************************/
110 
111 void ecrt_reg_request_read(ec_reg_request_t *reg, uint16_t address,
112  size_t size)
113 {
114  reg->dir = EC_DIR_INPUT;
115  reg->address = address;
116  reg->transfer_size = min(size, reg->mem_size);
117  reg->state = EC_INT_REQUEST_QUEUED;
118 }
119 
120 /*****************************************************************************/
121 
124 EXPORT_SYMBOL(ecrt_reg_request_data);
125 EXPORT_SYMBOL(ecrt_reg_request_state);
126 EXPORT_SYMBOL(ecrt_reg_request_write);
127 EXPORT_SYMBOL(ecrt_reg_request_read);
128 
131 /*****************************************************************************/
void ecrt_reg_request_write(ec_reg_request_t *reg, uint16_t address, size_t size)
Schedule an register write operation.
Definition: reg_request.c:100
uint16_t ring_position
Ring position for emergency requests.
Definition: reg_request.h:57
ec_internal_request_state_t state
Request state.
Definition: reg_request.h:56
void ecrt_reg_request_read(ec_reg_request_t *reg, uint16_t address, size_t size)
Schedule a register read operation.
Definition: reg_request.c:111
size_t transfer_size
Size of the data to transfer.
Definition: reg_request.h:55
uint16_t address
Register address.
Definition: reg_request.h:54
Register request.
Definition: reg_request.h:48
size_t mem_size
Size of data memory.
Definition: reg_request.h:50
int ec_reg_request_init(ec_reg_request_t *reg, size_t size)
Register request constructor.
Definition: reg_request.c:48
Values read by the master.
Definition: ecrt.h:449
EtherCAT register request structure.
Invalid direction.
Definition: ecrt.h:447
uint8_t * data
Pointer to data memory.
Definition: reg_request.h:51
#define EC_ERR(fmt, args...)
Convenience macro for printing EtherCAT-specific errors to syslog.
Definition: globals.h:215
ec_direction_t dir
Direction.
Definition: reg_request.h:52
void ec_reg_request_clear(ec_reg_request_t *reg)
Register request destructor.
Definition: reg_request.c:73
ec_request_state_t
Request state.
Definition: ecrt.h:546
uint8_t * ecrt_reg_request_data(ec_reg_request_t *reg)
Access to the register request&#39;s data.
Definition: reg_request.c:86
Values written by the master.
Definition: ecrt.h:448
const ec_request_state_t ec_request_state_translation_table[]
Global request state type translation table.
Definition: module.c:662
struct list_head list
List item.
Definition: reg_request.h:49
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:93