author | Florian Pose <fp@igh-essen.com> |
Fri, 01 Feb 2008 20:26:13 +0000 | |
changeset 778 | 7fc85507f49a |
parent 762 | 15214036c72a |
child 792 | 3778920f61e4 |
permissions | -rw-r--r-- |
628
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/****************************************************************************** |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
5 |
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
6 |
* |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
8 |
* |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
10 |
* and/or modify it under the terms of the GNU General Public License |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
11 |
* as published by the Free Software Foundation; either version 2 of the |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
12 |
* License, or (at your option) any later version. |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
13 |
* |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
14 |
* The IgH EtherCAT Master is distributed in the hope that it will be |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
15 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
17 |
* GNU General Public License for more details. |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
18 |
* |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
19 |
* You should have received a copy of the GNU General Public License |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
20 |
* along with the IgH EtherCAT Master; if not, write to the Free Software |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
22 |
* |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
23 |
* The right to use EtherCAT Technology is granted and comes free of |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
24 |
* charge under condition of compatibility of product made by |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
25 |
* Licensee. People intending to distribute/sell products based on the |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
26 |
* code, have to sign an agreement to guarantee that products using |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
27 |
* software based on IgH EtherCAT master stay compatible with the actual |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
* EtherCAT specification (which are released themselves as an open |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
* standard) as the (only) precondition to have the right to use EtherCAT |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
* Technology, IP and trade marks. |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
31 |
* |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
*****************************************************************************/ |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
/** |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
\file |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
EtherCAT sync manager methods. |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
*/ |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
/*****************************************************************************/ |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
40 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
#include "globals.h" |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
#include "slave.h" |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
#include "master.h" |
635
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
44 |
#include "pdo.h" |
628
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
45 |
#include "sync.h" |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
/*****************************************************************************/ |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
48 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
49 |
/** |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
50 |
* Constructor. |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
51 |
*/ |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
52 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
53 |
void ec_sync_init( |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
54 |
ec_sync_t *sync, /**< EtherCAT sync manager */ |
635
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
55 |
ec_slave_t *slave, /**< EtherCAT slave */ |
628
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
56 |
unsigned int index /**< sync manager index */ |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
57 |
) |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
58 |
{ |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
59 |
sync->slave = slave; |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
sync->index = index; |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
61 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
62 |
sync->est_length = 0; |
635
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
63 |
INIT_LIST_HEAD(&sync->pdos); |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
64 |
sync->alt_mapping = 0; |
762
15214036c72a
Store PDO mapping source in sync manager.
Florian Pose <fp@igh-essen.com>
parents:
758
diff
changeset
|
65 |
sync->mapping_source = EC_SYNC_MAPPING_NONE; |
628
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
} |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
67 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
68 |
/*****************************************************************************/ |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
70 |
/** |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
71 |
* Destructor. |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
72 |
*/ |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
73 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
void ec_sync_clear( |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
75 |
ec_sync_t *sync /**< EtherCAT sync manager */ |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
76 |
) |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
77 |
{ |
635
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
78 |
ec_sync_clear_pdos(sync); |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
79 |
} |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
80 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
81 |
/*****************************************************************************/ |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
82 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
83 |
/** |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
84 |
* Calculates the size of a sync manager by evaluating PDO sizes. |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
85 |
* \return sync manager size |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
86 |
*/ |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
87 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
88 |
uint16_t ec_sync_size( |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
89 |
const ec_sync_t *sync /**< sync manager */ |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
90 |
) |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
91 |
{ |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
92 |
const ec_pdo_t *pdo; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
93 |
const ec_pdo_entry_t *pdo_entry; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
94 |
unsigned int bit_size, byte_size; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
95 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
96 |
if (sync->length) return sync->length; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
97 |
if (sync->est_length) return sync->est_length; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
98 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
99 |
bit_size = 0; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
100 |
list_for_each_entry(pdo, &sync->pdos, list) { |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
101 |
list_for_each_entry(pdo_entry, &pdo->entries, list) { |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
102 |
bit_size += pdo_entry->bit_length; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
103 |
} |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
104 |
} |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
105 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
106 |
if (bit_size % 8) // round up to full bytes |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
107 |
byte_size = bit_size / 8 + 1; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
108 |
else |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
109 |
byte_size = bit_size / 8; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
110 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
111 |
return byte_size; |
628
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
112 |
} |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
113 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
114 |
/*****************************************************************************/ |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
115 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
116 |
/** |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
117 |
Initializes a sync manager configuration page with EEPROM data. |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
118 |
The referenced memory (\a data) must be at least EC_SYNC_SIZE bytes. |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
*/ |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
121 |
void ec_sync_config( |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
122 |
const ec_sync_t *sync, /**< sync manager */ |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
123 |
uint8_t *data /**> configuration memory */ |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
124 |
) |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
125 |
{ |
635
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
126 |
size_t sync_size = ec_sync_size(sync); |
628
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
127 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
128 |
if (sync->slave->master->debug_level) { |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
129 |
EC_DBG("SM%i: Addr 0x%04X, Size %3i, Ctrl 0x%02X, En %i\n", |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
130 |
sync->index, sync->physical_start_address, |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
131 |
sync_size, sync->control_register, sync->enable); |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
132 |
} |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
133 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
134 |
EC_WRITE_U16(data, sync->physical_start_address); |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
135 |
EC_WRITE_U16(data + 2, sync_size); |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
136 |
EC_WRITE_U8 (data + 4, sync->control_register); |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
137 |
EC_WRITE_U8 (data + 5, 0x00); // status byte (read only) |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
138 |
EC_WRITE_U16(data + 6, sync->enable ? 0x0001 : 0x0000); // enable |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
139 |
} |
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
140 |
|
e94a16bc52ce
Layed out sync manager structures and methods into own files.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
141 |
/*****************************************************************************/ |
635
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
142 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
143 |
/** |
758
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
748
diff
changeset
|
144 |
* Adds a PDO to the list of known mapped PDOs. |
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
748
diff
changeset
|
145 |
* \return 0 on success, else < 0 |
635
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
146 |
*/ |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
147 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
148 |
int ec_sync_add_pdo( |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
149 |
ec_sync_t *sync, /**< EtherCAT sync manager */ |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
150 |
const ec_pdo_t *pdo /**< PDO to map */ |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
151 |
) |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
152 |
{ |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
153 |
ec_pdo_t *mapped_pdo; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
154 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
155 |
// PDO already mapped? |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
156 |
list_for_each_entry(mapped_pdo, &sync->pdos, list) { |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
157 |
if (mapped_pdo->index != pdo->index) continue; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
158 |
EC_ERR("PDO 0x%04X is already mapped!\n", pdo->index); |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
159 |
return -1; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
160 |
} |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
161 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
162 |
if (!(mapped_pdo = kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) { |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
163 |
EC_ERR("Failed to allocate memory for PDO mapping.\n"); |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
164 |
return -1; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
165 |
} |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
166 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
167 |
ec_pdo_init(mapped_pdo); |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
168 |
if (ec_pdo_copy(mapped_pdo, pdo)) { |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
169 |
ec_pdo_clear(mapped_pdo); |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
170 |
kfree(mapped_pdo); |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
171 |
return -1; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
172 |
} |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
173 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
174 |
// set appropriate sync manager index |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
175 |
mapped_pdo->sync_index = sync->index; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
176 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
177 |
list_add_tail(&mapped_pdo->list, &sync->pdos); |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
178 |
return 0; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
179 |
} |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
180 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
181 |
/*****************************************************************************/ |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
182 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
183 |
/** |
758
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
748
diff
changeset
|
184 |
* Clears the list of known mapped PDOs. |
635
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
185 |
*/ |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
186 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
187 |
void ec_sync_clear_pdos( |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
188 |
ec_sync_t *sync /**< EtherCAT sync manager */ |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
189 |
) |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
190 |
{ |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
191 |
ec_pdo_t *pdo, *next; |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
192 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
193 |
// free all mapped PDOs |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
194 |
list_for_each_entry_safe(pdo, next, &sync->pdos, list) { |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
195 |
list_del(&pdo->list); |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
196 |
ec_pdo_clear(pdo); |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
197 |
kfree(pdo); |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
198 |
} |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
199 |
} |
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
200 |
|
d304ef4af542
Implemented alternative PDO mapping configuration interface.
Florian Pose <fp@igh-essen.com>
parents:
628
diff
changeset
|
201 |
/*****************************************************************************/ |
748
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
202 |
|
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
203 |
/** |
758
8fa6f825eb7d
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
748
diff
changeset
|
204 |
* \return Type of PDOs covered by the given sync manager. |
748
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
205 |
*/ |
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
206 |
|
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
207 |
ec_pdo_type_t ec_sync_get_pdo_type( |
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
208 |
const ec_sync_t *sync /**< EtherCAT sync manager */ |
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
209 |
) |
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
210 |
{ |
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
211 |
int index = sync->index; |
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
212 |
|
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
213 |
if (sync->slave && sync->slave->sii_mailbox_protocols) { |
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
214 |
index -= 2; |
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
215 |
} |
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
216 |
|
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
217 |
if (index < 0 || index > 1) { |
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
218 |
EC_WARN("ec_sync_get_pdo_type(): invalid sync manager index.\n"); |
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
219 |
return EC_RX_PDO; |
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
220 |
} |
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
221 |
|
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
222 |
return (ec_pdo_type_t) index; |
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
223 |
} |
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
224 |
|
6c8801bd547f
Added ec_sync_get_pdo_type().
Florian Pose <fp@igh-essen.com>
parents:
746
diff
changeset
|
225 |
/*****************************************************************************/ |