83 } |
83 } |
84 } |
84 } |
85 |
85 |
86 /*****************************************************************************/ |
86 /*****************************************************************************/ |
87 |
87 |
88 /** Calculates the total size of the mapped PDO entries. |
88 /** Calculates the total size of the mapped Pdo entries. |
89 * |
89 * |
90 * \retval Data size in byte. |
90 * \retval Data size in byte. |
91 */ |
91 */ |
92 uint16_t ec_pdo_mapping_total_size( |
92 uint16_t ec_pdo_mapping_total_size( |
93 const ec_pdo_mapping_t *pm /**< Pdo mapping. */ |
93 const ec_pdo_mapping_t *pm /**< Pdo mapping. */ |
119 * |
119 * |
120 * \return 0 on success, else < 0 |
120 * \return 0 on success, else < 0 |
121 */ |
121 */ |
122 int ec_pdo_mapping_add_pdo( |
122 int ec_pdo_mapping_add_pdo( |
123 ec_pdo_mapping_t *pm, /**< Pdo mapping. */ |
123 ec_pdo_mapping_t *pm, /**< Pdo mapping. */ |
124 const ec_pdo_t *pdo /**< PDO to add. */ |
124 const ec_pdo_t *pdo /**< Pdo to add. */ |
125 ) |
125 ) |
126 { |
126 { |
127 ec_pdo_t *mapped_pdo; |
127 ec_pdo_t *mapped_pdo; |
128 |
128 |
129 // PDO already mapped? |
129 // Pdo already mapped? |
130 list_for_each_entry(mapped_pdo, &pm->pdos, list) { |
130 list_for_each_entry(mapped_pdo, &pm->pdos, list) { |
131 if (mapped_pdo->index != pdo->index) continue; |
131 if (mapped_pdo->index != pdo->index) continue; |
132 EC_ERR("PDO 0x%04X is already mapped!\n", pdo->index); |
132 EC_ERR("Pdo 0x%04X is already mapped!\n", pdo->index); |
133 return -1; |
133 return -1; |
134 } |
134 } |
135 |
135 |
136 if (!(mapped_pdo = kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) { |
136 if (!(mapped_pdo = kmalloc(sizeof(ec_pdo_t), GFP_KERNEL))) { |
137 EC_ERR("Failed to allocate memory for PDO mapping.\n"); |
137 EC_ERR("Failed to allocate memory for Pdo mapping.\n"); |
138 return -1; |
138 return -1; |
139 } |
139 } |
140 |
140 |
141 if (ec_pdo_init_copy(mapped_pdo, pdo)) { |
141 if (ec_pdo_init_copy(mapped_pdo, pdo)) { |
142 kfree(mapped_pdo); |
142 kfree(mapped_pdo); |
191 |
191 |
192 for (i = 0; i < pdo_info->n_entries; i++) { |
192 for (i = 0; i < pdo_info->n_entries; i++) { |
193 entry_info = &pdo_info->entries[i]; |
193 entry_info = &pdo_info->entries[i]; |
194 |
194 |
195 if (!(entry = kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) { |
195 if (!(entry = kmalloc(sizeof(ec_pdo_entry_t), GFP_KERNEL))) { |
196 EC_ERR("Failed to allocate memory for PDO entry.\n"); |
196 EC_ERR("Failed to allocate memory for Pdo entry.\n"); |
197 goto out_free; |
197 goto out_free; |
198 } |
198 } |
199 |
199 |
200 ec_pdo_entry_init(entry); |
200 ec_pdo_entry_init(entry); |
201 entry->index = entry_info->index; |
201 entry->index = entry_info->index; |
258 * |
258 * |
259 * \return 0 on success, else < 0 |
259 * \return 0 on success, else < 0 |
260 */ |
260 */ |
261 int ec_pdo_mapping_copy( |
261 int ec_pdo_mapping_copy( |
262 ec_pdo_mapping_t *pm, /**< Pdo mapping. */ |
262 ec_pdo_mapping_t *pm, /**< Pdo mapping. */ |
263 const ec_pdo_mapping_t *other /**< PDO mapping to copy from. */ |
263 const ec_pdo_mapping_t *other /**< Pdo mapping to copy from. */ |
264 ) |
264 ) |
265 { |
265 { |
266 ec_pdo_t *other_pdo; |
266 ec_pdo_t *other_pdo; |
267 |
267 |
268 ec_pdo_mapping_clear_pdos(pm); |
268 ec_pdo_mapping_clear_pdos(pm); |
269 |
269 |
270 // PDO already mapped? |
270 // Pdo already mapped? |
271 list_for_each_entry(other_pdo, &other->pdos, list) { |
271 list_for_each_entry(other_pdo, &other->pdos, list) { |
272 if (ec_pdo_mapping_add_pdo(pm, other_pdo)) |
272 if (ec_pdo_mapping_add_pdo(pm, other_pdo)) |
273 return -1; |
273 return -1; |
274 } |
274 } |
275 |
275 |