master/master.c
branchstable-1.5
changeset 2124 c4afc5fede19
parent 2115 2ec1239216e5
child 2157 8fa0571f9996
child 2168 670cd8aa273d
equal deleted inserted replaced
2123:4c335a1d4db0 2124:c4afc5fede19
  2444     }
  2444     }
  2445 }
  2445 }
  2446 
  2446 
  2447 /*****************************************************************************/
  2447 /*****************************************************************************/
  2448 
  2448 
       
  2449 int ecrt_master_sdo_download_complete(ec_master_t *master,
       
  2450         uint16_t slave_position, uint16_t index, uint8_t *data,
       
  2451         size_t data_size, uint32_t *abort_code)
       
  2452 {
       
  2453     ec_master_sdo_request_t request;
       
  2454 
       
  2455     EC_MASTER_DBG(master, 1, "%s(master = 0x%p,"
       
  2456             " slave_position = %u, index = 0x%04X,"
       
  2457             " data = 0x%p, data_size = %zu, abort_code = 0x%p)\n",
       
  2458             __func__, master, slave_position, index, data, data_size,
       
  2459             abort_code);
       
  2460 
       
  2461     if (!data_size) {
       
  2462         EC_MASTER_ERR(master, "Zero data size!\n");
       
  2463         return -EINVAL;
       
  2464     }
       
  2465 
       
  2466     ec_sdo_request_init(&request.req);
       
  2467     ec_sdo_request_address(&request.req, index, 0);
       
  2468     if (ec_sdo_request_alloc(&request.req, data_size)) {
       
  2469         ec_sdo_request_clear(&request.req);
       
  2470         return -ENOMEM;
       
  2471     }
       
  2472 
       
  2473     request.req.complete_access = 1;
       
  2474     memcpy(request.req.data, data, data_size);
       
  2475     request.req.data_size = data_size;
       
  2476     ecrt_sdo_request_write(&request.req);
       
  2477 
       
  2478     if (down_interruptible(&master->master_sem))
       
  2479         return -EINTR;
       
  2480 
       
  2481     if (!(request.slave = ec_master_find_slave(master, 0, slave_position))) {
       
  2482         up(&master->master_sem);
       
  2483         EC_MASTER_ERR(master, "Slave %u does not exist!\n", slave_position);
       
  2484         ec_sdo_request_clear(&request.req);
       
  2485         return -EINVAL;
       
  2486     }
       
  2487 
       
  2488     EC_SLAVE_DBG(request.slave, 1, "Schedule SDO download request"
       
  2489             " (complete access).\n");
       
  2490 
       
  2491     // schedule request.
       
  2492     list_add_tail(&request.list, &request.slave->slave_sdo_requests);
       
  2493 
       
  2494     up(&master->master_sem);
       
  2495 
       
  2496     // wait for processing through FSM
       
  2497     if (wait_event_interruptible(request.slave->sdo_queue,
       
  2498                 request.req.state != EC_INT_REQUEST_QUEUED)) {
       
  2499         // interrupted by signal
       
  2500         down(&master->master_sem);
       
  2501         if (request.req.state == EC_INT_REQUEST_QUEUED) {
       
  2502             list_del(&request.list);
       
  2503             up(&master->master_sem);
       
  2504             ec_sdo_request_clear(&request.req);
       
  2505             return -EINTR;
       
  2506         }
       
  2507         // request already processing: interrupt not possible.
       
  2508         up(&master->master_sem);
       
  2509     }
       
  2510 
       
  2511     // wait until master FSM has finished processing
       
  2512     wait_event(request.slave->sdo_queue,
       
  2513             request.req.state != EC_INT_REQUEST_BUSY);
       
  2514 
       
  2515     EC_SLAVE_DBG(request.slave, 1, "Finished SDO download request"
       
  2516             " (complete access).\n");
       
  2517 
       
  2518     *abort_code = request.req.abort_code;
       
  2519 
       
  2520     if (request.req.state == EC_INT_REQUEST_SUCCESS) {
       
  2521         return 0;
       
  2522     } else if (request.req.errno) {
       
  2523         return -request.req.errno;
       
  2524     } else {
       
  2525         return -EIO;
       
  2526     }
       
  2527 }
       
  2528 
       
  2529 /*****************************************************************************/
       
  2530 
  2449 int ecrt_master_sdo_upload(ec_master_t *master, uint16_t slave_position,
  2531 int ecrt_master_sdo_upload(ec_master_t *master, uint16_t slave_position,
  2450         uint16_t index, uint8_t subindex, uint8_t *target,
  2532         uint16_t index, uint8_t subindex, uint8_t *target,
  2451         size_t target_size, size_t *result_size, uint32_t *abort_code)
  2533         size_t target_size, size_t *result_size, uint32_t *abort_code)
  2452 {
  2534 {
  2453     ec_master_sdo_request_t request;
  2535     ec_master_sdo_request_t request;
  2715 EXPORT_SYMBOL(ecrt_master_sync_reference_clock);
  2797 EXPORT_SYMBOL(ecrt_master_sync_reference_clock);
  2716 EXPORT_SYMBOL(ecrt_master_sync_slave_clocks);
  2798 EXPORT_SYMBOL(ecrt_master_sync_slave_clocks);
  2717 EXPORT_SYMBOL(ecrt_master_sync_monitor_queue);
  2799 EXPORT_SYMBOL(ecrt_master_sync_monitor_queue);
  2718 EXPORT_SYMBOL(ecrt_master_sync_monitor_process);
  2800 EXPORT_SYMBOL(ecrt_master_sync_monitor_process);
  2719 EXPORT_SYMBOL(ecrt_master_sdo_download);
  2801 EXPORT_SYMBOL(ecrt_master_sdo_download);
       
  2802 EXPORT_SYMBOL(ecrt_master_sdo_download_complete);
  2720 EXPORT_SYMBOL(ecrt_master_sdo_upload);
  2803 EXPORT_SYMBOL(ecrt_master_sdo_upload);
  2721 EXPORT_SYMBOL(ecrt_master_write_idn);
  2804 EXPORT_SYMBOL(ecrt_master_write_idn);
  2722 EXPORT_SYMBOL(ecrt_master_read_idn);
  2805 EXPORT_SYMBOL(ecrt_master_read_idn);
  2723 EXPORT_SYMBOL(ecrt_master_reset);
  2806 EXPORT_SYMBOL(ecrt_master_reset);
  2724 
  2807