IgH EtherCAT Master  1.5.2
sdo.c
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * $Id$
4 *
5 * Copyright (C) 2006-2008 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
35/*****************************************************************************/
36
37#include <linux/slab.h>
38
39#include "master.h"
40
41#include "sdo.h"
42
43/*****************************************************************************/
44
48 ec_sdo_t *sdo,
49 ec_slave_t *slave,
50 uint16_t index
51 )
52{
53 sdo->slave = slave;
54 sdo->index = index;
55 sdo->object_code = 0x00;
56 sdo->name = NULL;
57 sdo->max_subindex = 0;
58 INIT_LIST_HEAD(&sdo->entries);
59}
60
61/*****************************************************************************/
62
68 ec_sdo_t *sdo
69 )
70{
71 ec_sdo_entry_t *entry, *next;
72
73 // free all entries
74 list_for_each_entry_safe(entry, next, &sdo->entries, list) {
75 list_del(&entry->list);
76 ec_sdo_entry_clear(entry);
77 kfree(entry);
78 }
79
80 if (sdo->name)
81 kfree(sdo->name);
82}
83
84/*****************************************************************************/
85
92 ec_sdo_t *sdo,
93 uint8_t subindex
94 )
95{
96 ec_sdo_entry_t *entry;
97
98 list_for_each_entry(entry, &sdo->entries, list) {
99 if (entry->subindex != subindex)
100 continue;
101 return entry;
102 }
103
104 return NULL;
105}
106
107/*****************************************************************************/
108
117 const ec_sdo_t *sdo,
118 uint8_t subindex
119 )
120{
121 const ec_sdo_entry_t *entry;
122
123 list_for_each_entry(entry, &sdo->entries, list) {
124 if (entry->subindex != subindex)
125 continue;
126 return entry;
127 }
128
129 return NULL;
130}
131
132/*****************************************************************************/
EtherCAT master structure.
void ec_sdo_init(ec_sdo_t *sdo, ec_slave_t *slave, uint16_t index)
Constructor.
Definition: sdo.c:47
const ec_sdo_entry_t * ec_sdo_get_entry_const(const ec_sdo_t *sdo, uint8_t subindex)
Get an SDO entry from an SDO via its subindex.
Definition: sdo.c:116
void ec_sdo_clear(ec_sdo_t *sdo)
SDO destructor.
Definition: sdo.c:67
ec_sdo_entry_t * ec_sdo_get_entry(ec_sdo_t *sdo, uint8_t subindex)
Get an SDO entry from an SDO via its subindex.
Definition: sdo.c:91
EtherCAT CANopen SDO structure.
void ec_sdo_entry_clear(ec_sdo_entry_t *entry)
Destructor.
Definition: sdo_entry.c:68
CANopen SDO entry.
Definition: sdo_entry.h:54
uint8_t subindex
Subindex.
Definition: sdo_entry.h:57
struct list_head list
List item.
Definition: sdo_entry.h:55
CANopen SDO.
Definition: sdo.h:49
uint16_t index
SDO index.
Definition: sdo.h:52
char * name
SDO name.
Definition: sdo.h:54
struct list_head entries
List of entries.
Definition: sdo.h:56
ec_slave_t * slave
Parent slave.
Definition: sdo.h:51
uint8_t object_code
Object code.
Definition: sdo.h:53
uint8_t max_subindex
Maximum subindex.
Definition: sdo.h:55
EtherCAT slave.
Definition: slave.h:177