lib/master.c
changeset 1441 27a8d6f97a95
parent 1434 4c6fe0ae37f1
child 1494 6c632c8f45cc
equal deleted inserted replaced
1440:1b32fe09c689 1441:27a8d6f97a95
   220         fprintf(stderr, "Failed to sync slave clocks: %s\n", strerror(errno));
   220         fprintf(stderr, "Failed to sync slave clocks: %s\n", strerror(errno));
   221     }
   221     }
   222 }
   222 }
   223 
   223 
   224 /*****************************************************************************/
   224 /*****************************************************************************/
       
   225 
       
   226 int ecrt_slave_sdo_download(ec_master_t* master, uint16_t slave_position,
       
   227         uint16_t index, uint8_t subindex, uint8_t *data,
       
   228         size_t data_size, uint32_t *abort_code)
       
   229 {
       
   230     ec_ioctl_slave_sdo_download_t download;
       
   231 
       
   232     download.slave_position = slave_position;
       
   233     download.sdo_index = index;
       
   234     download.sdo_entry_subindex = subindex;
       
   235     download.data_size = data_size;
       
   236     download.data = data;
       
   237 
       
   238     if (ioctl(master->fd, EC_IOCTL_SLAVE_SDO_DOWNLOAD, &download) == -1) {
       
   239         if (errno == -EIO) {
       
   240             if (abort_code) {
       
   241                 *abort_code = download.abort_code;
       
   242             }
       
   243         }
       
   244         fprintf(stderr, "Failed to execute SDO download: %s\n",
       
   245             strerror(errno));
       
   246         return -1;
       
   247     }
       
   248 
       
   249     return 0;
       
   250 }
       
   251 
       
   252 /*****************************************************************************/
       
   253 
       
   254 int ecrt_slave_sdo_upload(ec_master_t* master, uint16_t slave_position,
       
   255         uint16_t index, uint8_t subindex, uint8_t *target,
       
   256         size_t target_size, size_t *result_size, uint32_t *abort_code)
       
   257 {
       
   258     ec_ioctl_slave_sdo_upload_t upload;
       
   259 
       
   260     upload.slave_position = slave_position;
       
   261     upload.sdo_index = index;
       
   262     upload.sdo_entry_subindex = subindex;
       
   263     upload.target_size = target_size;
       
   264     upload.target = target;
       
   265 
       
   266     if (ioctl(master->fd, EC_IOCTL_SLAVE_SDO_UPLOAD, &upload) == -1) {
       
   267         if (errno == -EIO) {
       
   268             if (abort_code) {
       
   269                 *abort_code = upload.abort_code;
       
   270             }
       
   271         }
       
   272         fprintf(stderr, "Failed to execute SDO upload: %s\n",
       
   273                 strerror(errno));
       
   274         return -1;
       
   275     }
       
   276 
       
   277     *result_size = upload.data_size;
       
   278     return 0;
       
   279 }
       
   280 
       
   281 /*****************************************************************************/