Changeset 1d1f894 in mainline for uspace/lib/usb/hcd.c


Ignore:
Timestamp:
2010-11-03T15:05:41Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d70a463
Parents:
af894a21
Message:

Old code removal

Completely removed old methods for communicating with HCD (the ones
that used callback phones). Now only methods using the async framework
are available.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/hcd.c

    raf894a21 r1d1f894  
    9090}
    9191
    92 /** Create necessary phones for comunicating with HCD.
     92/** Create necessary phones for communicating with HCD.
    9393 * This function wraps following calls:
    9494 * -# open <code>/dev/usb/<i>hcd_path</i></code> for reading
    9595 * -# access phone of file opened in previous step
    96  * -# create callback through just opened phone
    97  * -# set handler for this callback
    9896 * -# return the (outgoing) phone
    9997 *
    10098 * @warning This function is wrapper for several actions and therefore
    10199 * it is not possible - in case of error - to determine at which point
    102  * error occured.
     100 * error occurred.
    103101 *
    104102 * @param hcd_path HCD identification under devfs
    105103 *     (without <code>/dev/usb/</code>).
    106  * @param callback_connection Handler for callbacks from HCD.
    107  * @return Phone for comunicating with HCD or error code from errno.h.
    108  */
    109 int usb_hcd_create_phones(const char * hcd_path,
    110     async_client_conn_t callback_connection)
     104 * @return Phone for communicating with HCD or error code from errno.h.
     105 */
     106int usb_hcd_connect(const char * hcd_path)
    111107{
    112108        char dev_path[DEVMAP_NAME_MAXLEN + 1];
     
    124120                return hcd_phone;
    125121        }
    126        
    127         ipcarg_t phonehash;
    128         int rc = ipc_connect_to_me(hcd_phone, 0, 0, 0, &phonehash);
    129         if (rc != EOK) {
    130                 return rc;
    131         }
    132         async_new_connection(phonehash, 0, NULL, callback_connection);
    133        
     122
    134123        return hcd_phone;
    135124}
    136 
    137 /** Send data from USB host to a function.
    138  *
    139  * @param hcd_phone Connected phone to HCD.
    140  * @param target USB function address.
    141  * @param transfer_type USB transfer type.
    142  * @param buffer Buffer with data to be sent.
    143  * @param len Buffer @p buffer size.
    144  * @param[out] transaction_handle Handle of created transaction (NULL to ignore).
    145  * @return Error status.
    146  * @retval EOK Everything OK, buffer transfered to HCD and queued there.
    147  * @retval EINVAL Invalid phone.
    148  * @retval EINVAL @p buffer is NULL.
    149  */
    150 int usb_hcd_send_data_to_function(int hcd_phone,
    151     usb_target_t target, usb_transfer_type_t transfer_type,
    152     void * buffer, size_t len,
    153     usb_transaction_handle_t * transaction_handle)
    154 {
    155         if (hcd_phone < 0) {
    156                 return EINVAL;
    157         }
    158         if (buffer == NULL) {
    159                 return EINVAL;
    160         }
    161 
    162         ipc_call_t answer_data;
    163         ipcarg_t answer_rc;
    164         aid_t req;
    165         int rc;
    166        
    167         req = async_send_4(hcd_phone,
    168             IPC_M_USB_HCD_SEND_DATA,
    169             target.address, target.endpoint,
    170             transfer_type, 0,
    171             &answer_data);
    172        
    173         rc = async_data_write_start(hcd_phone, buffer, len);
    174         if (rc != EOK) {
    175                 async_wait_for(req, NULL);
    176                 return rc;
    177         }
    178        
    179         async_wait_for(req, &answer_rc);
    180         rc = (int)answer_rc;
    181         if (rc != EOK) {
    182                 return rc;
    183         }
    184        
    185         if (transaction_handle != NULL) {
    186                 *transaction_handle = IPC_GET_ARG1(answer_data);
    187         }
    188        
    189         return EOK;
    190 }
    191 
    192 
    193 /** Inform HCD about data reception.
    194  * The actual reception is handled in callback.
    195  *
    196  * @param hcd_phone Connected phone to HCD.
    197  * @param target USB function address.
    198  * @param transfer_type USB transfer type.
    199  * @param len Maximum accepted packet size.
    200  * @param[out] transaction_handle Handle of created transaction (NULL to ignore).
    201  * @return Error status.
    202  */
    203 int usb_hcd_prepare_data_reception(int hcd_phone,
    204     usb_target_t target, usb_transfer_type_t transfer_type,
    205     size_t len,
    206     usb_transaction_handle_t * transaction_handle)
    207 {
    208         if (hcd_phone < 0) {
    209                 return EINVAL;
    210         }
    211        
    212         usb_transaction_handle_t handle;
    213        
    214         int rc = ipc_call_sync_5_1(hcd_phone, IPC_M_USB_HCD_RECEIVE_DATA,
    215             target.address, target.endpoint,
    216             transfer_type, len, 0, &handle);
    217        
    218         if (rc != EOK) {
    219                 return rc;
    220         }
    221        
    222         if (transaction_handle != NULL) {
    223                 *transaction_handle = handle;
    224         }
    225        
    226         return EOK;
    227 }
    228 
    229 
    230 static int send_buffer(int phone, ipcarg_t method, usb_target_t target,
    231     void *buffer, size_t size, usb_transaction_handle_t * transaction_handle)
    232 {
    233         if (phone < 0) {
    234                 return EINVAL;
    235         }
    236        
    237         if ((buffer == NULL) && (size > 0)) {
    238                 return EINVAL;
    239         }
    240 
    241         ipc_call_t answer_data;
    242         ipcarg_t answer_rc;
    243         aid_t req;
    244         int rc;
    245        
    246         req = async_send_3(phone,
    247             method,
    248             target.address, target.endpoint,
    249             size,
    250             &answer_data);
    251        
    252         if (size > 0) {
    253                 rc = async_data_write_start(phone, buffer, size);
    254                 if (rc != EOK) {
    255                         async_wait_for(req, NULL);
    256                         return rc;
    257                 }
    258         }
    259        
    260         async_wait_for(req, &answer_rc);
    261         rc = (int)answer_rc;
    262         if (rc != EOK) {
    263                 return rc;
    264         }
    265        
    266         if (transaction_handle != NULL) {
    267                 *transaction_handle = IPC_GET_ARG1(answer_data);
    268         }
    269        
    270         return EOK;
    271 }
    272 
    273 
    274 static int prep_receive_data(int phone, ipcarg_t method, usb_target_t target,
    275     size_t size, usb_transaction_handle_t * transaction_handle)
    276 {
    277         if (phone < 0) {
    278                 return EINVAL;
    279         }
    280        
    281         usb_transaction_handle_t handle;
    282        
    283         int rc = ipc_call_sync_3_1(phone,
    284             method,
    285             target.address, target.endpoint,
    286             size,
    287             &handle);
    288        
    289         if (rc != EOK) {
    290                 return rc;
    291         }
    292        
    293         if (transaction_handle != NULL) {
    294                 *transaction_handle = handle;
    295         }
    296        
    297         return EOK;
    298 }
    299 
    300 
    301 int usb_hcd_transfer_interrupt_out(int hcd_phone, usb_target_t target,
    302     void *buffer, size_t size, usb_transaction_handle_t *handle)
    303 {
    304         return send_buffer(hcd_phone, IPC_M_USB_HCD_INTERRUPT_OUT,
    305             target, buffer, size, handle);
    306 }
    307 
    308 int usb_hcd_transfer_interrupt_in(int hcd_phone, usb_target_t target,
    309     size_t size, usb_transaction_handle_t *handle)
    310 {
    311         return prep_receive_data(hcd_phone, IPC_M_USB_HCD_INTERRUPT_IN,
    312             target, size, handle);
    313 }
    314 
    315 int usb_hcd_transfer_control_write_setup(int hcd_phone, usb_target_t target,
    316     void *buffer, size_t size, usb_transaction_handle_t *handle)
    317 {
    318         return send_buffer(hcd_phone, IPC_M_USB_HCD_CONTROL_WRITE_SETUP,
    319             target, buffer, size, handle);
    320 }
    321 
    322 int usb_hcd_transfer_control_write_data(int hcd_phone, usb_target_t target,
    323     void *buffer, size_t size, usb_transaction_handle_t *handle)
    324 {
    325         return send_buffer(hcd_phone, IPC_M_USB_HCD_CONTROL_WRITE_DATA,
    326             target, buffer, size, handle);
    327        
    328 }
    329 int usb_hcd_transfer_control_write_status(int hcd_phone, usb_target_t target,
    330     usb_transaction_handle_t *handle)
    331 {
    332         return prep_receive_data(hcd_phone, IPC_M_USB_HCD_CONTROL_WRITE_STATUS,
    333             target, 0, handle);
    334 }
    335 
    336 int usb_hcd_transfer_control_read_setup(int hcd_phone, usb_target_t target,
    337     void *buffer, size_t size, usb_transaction_handle_t *handle)
    338 {
    339         return send_buffer(hcd_phone, IPC_M_USB_HCD_CONTROL_READ_SETUP,
    340             target, buffer, size, handle);
    341 }
    342 int usb_hcd_transfer_control_read_data(int hcd_phone, usb_target_t target,
    343     size_t size, usb_transaction_handle_t *handle)
    344 {
    345         return prep_receive_data(hcd_phone, IPC_M_USB_HCD_CONTROL_READ_DATA,
    346            target, size, handle);
    347 }
    348 int usb_hcd_transfer_control_read_status(int hcd_phone, usb_target_t target,
    349     usb_transaction_handle_t *handle)
    350 {
    351         return send_buffer(hcd_phone, IPC_M_USB_HCD_CONTROL_READ_STATUS,
    352             target, NULL, 0, handle);
    353 }
    354 
    355 
    356 
    357 
    358 
    359 /*
    360  * =================
    361  * async versions of the above functions
    362  * =================
    363  */
    364125
    365126/** Send data to HCD.
Note: See TracChangeset for help on using the changeset viewer.