148 if (!fsm->slave->config) { |
148 if (!fsm->slave->config) { |
149 fsm->state = ec_fsm_pdo_mapping_state_end; |
149 fsm->state = ec_fsm_pdo_mapping_state_end; |
150 return; |
150 return; |
151 } |
151 } |
152 |
152 |
153 fsm->sync = NULL; |
153 fsm->dir = (ec_direction_t) -1; // next is EC_DIR_OUTPUT |
154 ec_fsm_pdo_mapping_next_sync(fsm); |
154 ec_fsm_pdo_mapping_next_dir(fsm); |
155 } |
155 } |
156 |
156 |
157 /*****************************************************************************/ |
157 /*****************************************************************************/ |
158 |
158 |
159 /** Process mapping of next sync manager. |
159 /** Process mapping of next direction. |
160 */ |
160 */ |
161 void ec_fsm_pdo_mapping_next_sync( |
161 void ec_fsm_pdo_mapping_next_dir( |
162 ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */ |
162 ec_fsm_pdo_mapping_t *fsm /**< mapping state machine */ |
163 ) |
163 ) |
164 { |
164 { |
165 ec_direction_t dir; |
165 for (; fsm->dir <= EC_DIR_INPUT; fsm->dir++) { |
166 const ec_sync_t *sync; |
166 fsm->mapping = &fsm->slave->config->mapping[fsm->dir]; |
167 const ec_pdo_mapping_t *map; |
167 |
168 |
168 if (!(fsm->sync = ec_slave_get_pdo_sync(fsm->slave, fsm->dir))) { |
169 for (dir = EC_DIR_OUTPUT; dir <= EC_DIR_INPUT; dir++) { |
169 if (!list_empty(&fsm->mapping->pdos)) { |
170 if (!(sync = ec_slave_get_pdo_sync(fsm->slave, dir))) { |
170 EC_ERR("No sync manager for direction %u!\n", fsm->dir); |
171 EC_WARN("No sync manager for direction %u!\n", dir); |
171 fsm->state = ec_fsm_pdo_mapping_state_end; |
|
172 return; |
|
173 } |
172 continue; |
174 continue; |
173 } |
175 } |
174 |
176 |
175 if (fsm->sync) { // there is a last SM |
177 // check if mapping has to be altered |
176 if (sync == fsm->sync) // this is the last SM |
178 if (ec_pdo_mapping_equal(&fsm->sync->mapping, fsm->mapping)) |
177 fsm->sync = NULL; // take the next one |
179 continue; |
178 } else { |
180 |
179 map = &fsm->slave->config->mapping[dir]; |
181 if (fsm->slave->master->debug_level) { |
180 if (ec_pdo_mapping_equal(&sync->mapping, map)) |
182 EC_DBG("Configuring Pdo mapping for SM%u of slave %u.\n", |
181 continue; |
183 fsm->sync->index, fsm->slave->ring_position); |
182 |
|
183 fsm->sync = sync; |
|
184 fsm->mapping = map; |
|
185 break; |
|
186 } |
184 } |
187 } |
185 |
188 |
186 // set mapped Pdo count to zero |
189 if (!fsm->sync) { |
187 fsm->sdodata.index = 0x1C10 + fsm->sync->index; |
|
188 fsm->sdodata.subindex = 0; // mapped Pdo count |
|
189 EC_WRITE_U8(&fsm->sdo_value, 0); // zero Pdos mapped |
|
190 fsm->sdodata.size = 1; |
190 if (fsm->slave->master->debug_level) |
191 if (fsm->slave->master->debug_level) |
191 EC_DBG("Pdo mapping finished for slave %u.\n", |
192 EC_DBG("Setting Pdo count to zero for SM%u.\n", fsm->sync->index); |
192 fsm->slave->ring_position); |
193 |
193 fsm->state = ec_fsm_pdo_mapping_state_end; |
194 fsm->state = ec_fsm_pdo_mapping_state_zero_count; |
194 return; |
195 ec_fsm_coe_download(fsm->fsm_coe, fsm->slave, &fsm->sdodata); |
195 } |
196 ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately |
196 |
197 return; |
197 if (fsm->slave->master->debug_level) { |
198 } |
198 EC_DBG("Configuring Pdo mapping for SM%u of slave %u.\n", |
199 |
199 fsm->sync->index, fsm->slave->ring_position); |
|
200 } |
|
201 |
|
202 // set mapped Pdo count to zero |
|
203 fsm->sdodata.index = 0x1C10 + fsm->sync->index; |
|
204 fsm->sdodata.subindex = 0; // mapped Pdo count |
|
205 EC_WRITE_U8(&fsm->sdo_value, 0); // zero Pdos mapped |
|
206 fsm->sdodata.size = 1; |
|
207 if (fsm->slave->master->debug_level) |
200 if (fsm->slave->master->debug_level) |
208 EC_DBG("Setting Pdo count to zero for SM%u.\n", fsm->sync->index); |
201 EC_DBG("Pdo mapping finished for slave %u.\n", |
209 |
202 fsm->slave->ring_position); |
210 fsm->state = ec_fsm_pdo_mapping_state_zero_count; |
203 fsm->state = ec_fsm_pdo_mapping_state_end; |
211 ec_fsm_coe_download(fsm->fsm_coe, fsm->slave, &fsm->sdodata); |
|
212 ec_fsm_coe_exec(fsm->fsm_coe); // execute immediately |
|
213 } |
204 } |
214 |
205 |
215 /*****************************************************************************/ |
206 /*****************************************************************************/ |
216 |
207 |
217 /** Process mapping of next Pdo. |
208 /** Process mapping of next Pdo. |
339 |
330 |
340 if (fsm->slave->master->debug_level) |
331 if (fsm->slave->master->debug_level) |
341 EC_DBG("Successfully set Pdo mapping for SM%u of slave %u.\n", |
332 EC_DBG("Successfully set Pdo mapping for SM%u of slave %u.\n", |
342 fsm->sync->index, fsm->slave->ring_position); |
333 fsm->sync->index, fsm->slave->ring_position); |
343 |
334 |
344 // mapping configuration for this sync manager complete. |
335 // mapping configuration for this direction finished |
345 ec_fsm_pdo_mapping_next_sync(fsm); |
336 ec_fsm_pdo_mapping_next_dir(fsm); |
346 } |
337 } |
347 |
338 |
348 /****************************************************************************** |
339 /****************************************************************************** |
349 * Common state functions |
340 * Common state functions |
350 *****************************************************************************/ |
341 *****************************************************************************/ |