equal
deleted
inserted
replaced
42 |
42 |
43 #include "pdo.h" |
43 #include "pdo.h" |
44 |
44 |
45 /*****************************************************************************/ |
45 /*****************************************************************************/ |
46 |
46 |
47 void ec_pdo_clear_entries(ec_pdo_t *); |
|
48 |
|
49 /*****************************************************************************/ |
|
50 |
|
51 /** Pdo constructor. |
47 /** Pdo constructor. |
52 */ |
48 */ |
53 void ec_pdo_init( |
49 void ec_pdo_init( |
54 ec_pdo_t *pdo /**< EtherCAT Pdo */ |
50 ec_pdo_t *pdo /**< EtherCAT Pdo */ |
55 ) |
51 ) |
56 { |
52 { |
57 pdo->sync_index = -1; // not assigned |
53 pdo->sync_index = -1; // not assigned |
58 pdo->name = NULL; |
54 pdo->name = NULL; |
59 INIT_LIST_HEAD(&pdo->entries); |
55 INIT_LIST_HEAD(&pdo->entries); |
|
56 pdo->default_config = 0; |
60 } |
57 } |
61 |
58 |
62 /*****************************************************************************/ |
59 /*****************************************************************************/ |
63 |
60 |
64 /** Pdo copy constructor. |
61 /** Pdo copy constructor. |
68 pdo->dir = other_pdo->dir; |
65 pdo->dir = other_pdo->dir; |
69 pdo->index = other_pdo->index; |
66 pdo->index = other_pdo->index; |
70 pdo->sync_index = other_pdo->sync_index; |
67 pdo->sync_index = other_pdo->sync_index; |
71 pdo->name = NULL; |
68 pdo->name = NULL; |
72 INIT_LIST_HEAD(&pdo->entries); |
69 INIT_LIST_HEAD(&pdo->entries); |
|
70 pdo->default_config = other_pdo->default_config; |
73 |
71 |
74 if (ec_pdo_set_name(pdo, other_pdo->name)) |
72 if (ec_pdo_set_name(pdo, other_pdo->name)) |
75 goto out_return; |
73 goto out_return; |
76 |
74 |
77 if (ec_pdo_copy_entries(pdo, other_pdo)) |
75 if (ec_pdo_copy_entries(pdo, other_pdo)) |
87 |
85 |
88 /*****************************************************************************/ |
86 /*****************************************************************************/ |
89 |
87 |
90 /** Pdo destructor. |
88 /** Pdo destructor. |
91 */ |
89 */ |
92 void ec_pdo_clear(ec_pdo_t *pdo /**< EtherCAT Pdo */) |
90 void ec_pdo_clear(ec_pdo_t *pdo /**< EtherCAT Pdo. */) |
93 { |
91 { |
94 if (pdo->name) |
92 if (pdo->name) |
95 kfree(pdo->name); |
93 kfree(pdo->name); |
96 |
94 |
97 ec_pdo_clear_entries(pdo); |
95 ec_pdo_clear_entries(pdo); |
99 |
97 |
100 /*****************************************************************************/ |
98 /*****************************************************************************/ |
101 |
99 |
102 /** Clear Pdo entry list. |
100 /** Clear Pdo entry list. |
103 */ |
101 */ |
104 void ec_pdo_clear_entries(ec_pdo_t *pdo /**< EtherCAT Pdo */) |
102 void ec_pdo_clear_entries(ec_pdo_t *pdo /**< EtherCAT Pdo. */) |
105 { |
103 { |
106 ec_pdo_entry_t *entry, *next; |
104 ec_pdo_entry_t *entry, *next; |
107 |
105 |
108 // free all Pdo entries |
106 // free all Pdo entries |
109 list_for_each_entry_safe(entry, next, &pdo->entries, list) { |
107 list_for_each_entry_safe(entry, next, &pdo->entries, list) { |
140 return 0; |
138 return 0; |
141 } |
139 } |
142 |
140 |
143 /*****************************************************************************/ |
141 /*****************************************************************************/ |
144 |
142 |
|
143 /** Add a new Pdo entry to the configuration. |
|
144 */ |
|
145 ec_pdo_entry_t *ec_pdo_add_entry( |
|
146 ec_pdo_t *pdo, |
|
147 uint16_t index, |
|
148 uint8_t subindex, |
|
149 uint8_t bit_length |
|
150 ) |
|
151 { |
|
152 ec_pdo_entry_t *entry; |
|
153 |
|
154 if (!(entry = kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) { |
|
155 EC_ERR("Failed to allocate memory for Pdo entry.\n"); |
|
156 return NULL; |
|
157 } |
|
158 |
|
159 ec_pdo_entry_init(entry); |
|
160 entry->index = index; |
|
161 entry->subindex = subindex; |
|
162 entry->bit_length = bit_length; |
|
163 list_add_tail(&entry->list, &pdo->entries); |
|
164 return entry; |
|
165 } |
|
166 |
|
167 /*****************************************************************************/ |
|
168 |
145 /** Copy Pdo entries from another Pdo. |
169 /** Copy Pdo entries from another Pdo. |
146 */ |
170 */ |
147 int ec_pdo_copy_entries(ec_pdo_t *pdo, const ec_pdo_t *other) |
171 int ec_pdo_copy_entries(ec_pdo_t *pdo, const ec_pdo_t *other) |
148 { |
172 { |
149 ec_pdo_entry_t *entry, *other_entry; |
173 ec_pdo_entry_t *entry, *other_entry; |