master/fsm_pdo_mapping.c
changeset 821 c6536d28db56
parent 814 a51f857b1b2d
child 824 e2501463f7d1
equal deleted inserted replaced
820:f8e6f5966cce 821:c6536d28db56
    51 void ec_fsm_pdo_mapping_state_add_pdo(ec_fsm_pdo_mapping_t *);
    51 void ec_fsm_pdo_mapping_state_add_pdo(ec_fsm_pdo_mapping_t *);
    52 void ec_fsm_pdo_mapping_state_pdo_count(ec_fsm_pdo_mapping_t *);
    52 void ec_fsm_pdo_mapping_state_pdo_count(ec_fsm_pdo_mapping_t *);
    53 void ec_fsm_pdo_mapping_state_end(ec_fsm_pdo_mapping_t *);
    53 void ec_fsm_pdo_mapping_state_end(ec_fsm_pdo_mapping_t *);
    54 void ec_fsm_pdo_mapping_state_error(ec_fsm_pdo_mapping_t *);
    54 void ec_fsm_pdo_mapping_state_error(ec_fsm_pdo_mapping_t *);
    55 
    55 
    56 void ec_fsm_pdo_mapping_next_sync(ec_fsm_pdo_mapping_t *);
    56 void ec_fsm_pdo_mapping_next_dir(ec_fsm_pdo_mapping_t *);
    57 
    57 
    58 /*****************************************************************************/
    58 /*****************************************************************************/
    59 
    59 
    60 /** Constructor.
    60 /** Constructor.
    61  */
    61  */
   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.
   270     // find first Pdo
   261     // find first Pdo
   271     if (!(fsm->pdo = ec_fsm_pdo_mapping_next_pdo(fsm, &fsm->mapping->pdos))) {
   262     if (!(fsm->pdo = ec_fsm_pdo_mapping_next_pdo(fsm, &fsm->mapping->pdos))) {
   272         if (fsm->slave->master->debug_level)
   263         if (fsm->slave->master->debug_level)
   273             EC_DBG("No Pdos to map for SM%u of slave %u.\n",
   264             EC_DBG("No Pdos to map for SM%u of slave %u.\n",
   274                     fsm->sync->index, fsm->slave->ring_position);
   265                     fsm->sync->index, fsm->slave->ring_position);
   275         ec_fsm_pdo_mapping_next_sync(fsm);
   266         ec_fsm_pdo_mapping_next_dir(fsm);
   276         return;
   267         return;
   277     }
   268     }
   278 
   269 
   279     // add first Pdo to mapping
   270     // add first Pdo to mapping
   280     fsm->pdo_count = 1;
   271     fsm->pdo_count = 1;
   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  *****************************************************************************/