Changeset 25d224c6 in mainline


Ignore:
Timestamp:
2011-09-16T10:19:08Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
058fd76
Parents:
db2cb04
Message:

uhci: Use new batch_direction.

Get rid of nasty setup data parsing hack to determine direction.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/uhci/uhci_batch.c

    rdb2cb04 r25d224c6  
    4545#define DEFAULT_ERROR_COUNT 3
    4646
    47 static void batch_control(uhci_transfer_batch_t *uhci_batch,
    48     usb_packet_id data_stage, usb_packet_id status_stage);
    49 static void batch_data(uhci_transfer_batch_t *uhci_batch);
    50 /*----------------------------------------------------------------------------*/
    5147static void uhci_transfer_batch_dispose(uhci_transfer_batch_t *uhci_batch)
    5248{
     
    7268}
    7369/*----------------------------------------------------------------------------*/
    74 static void (* const batch_setup[4][3])(uhci_transfer_batch_t*);
     70static void (*const batch_setup[4][3])(uhci_transfer_batch_t*, usb_direction_t);
    7571/*----------------------------------------------------------------------------*/
    7672/** Allocate memory and initialize internal data structure.
     
    143139            USB_TRANSFER_BATCH_ARGS(*usb_batch));
    144140
    145         assert(
    146             batch_setup[usb_batch->ep->transfer_type][usb_batch->ep->direction]);
    147         batch_setup[usb_batch->ep->transfer_type][usb_batch->ep->direction](
    148             uhci_batch);
     141        const usb_direction_t dir = usb_transfer_batch_direction(usb_batch);
     142
     143        assert(batch_setup[usb_batch->ep->transfer_type][dir]);
     144        batch_setup[usb_batch->ep->transfer_type][dir](uhci_batch, dir);
    149145
    150146        return uhci_batch;
     
    204200}
    205201/*----------------------------------------------------------------------------*/
     202static const usb_packet_id direction_pids[] = {
     203        [USB_DIRECTION_IN] = USB_PID_IN,
     204        [USB_DIRECTION_OUT] = USB_PID_OUT,
     205};
     206/*----------------------------------------------------------------------------*/
    206207/** Prepare generic data transfer
    207208 *
    208209 * @param[in] uhci_batch Batch structure to use.
    209  * @param[in] pid Pid to use for data transactions.
     210 * @param[in] dir Communication direction.
    210211 *
    211212 * Transactions with alternating toggle bit and supplied pid value.
    212213 * The last transfer is marked with IOC flag.
    213214 */
    214 static void batch_data(uhci_transfer_batch_t *uhci_batch)
     215static void batch_data(uhci_transfer_batch_t *uhci_batch, usb_direction_t dir)
    215216{
    216217        assert(uhci_batch);
    217218        assert(uhci_batch->usb_batch);
    218219        assert(uhci_batch->usb_batch->ep);
    219         assert(uhci_batch->usb_batch->ep->direction == USB_DIRECTION_OUT ||
    220             uhci_batch->usb_batch->ep->direction == USB_DIRECTION_IN);
    221 
    222         static const usb_packet_id pids[] = {
    223                 [USB_DIRECTION_IN] = USB_PID_IN,
    224                 [USB_DIRECTION_OUT] = USB_PID_OUT,
    225         };
    226 
    227         const usb_packet_id pid = pids[uhci_batch->usb_batch->ep->direction];
     220        assert(dir == USB_DIRECTION_OUT || dir == USB_DIRECTION_IN);
     221
     222
     223        const usb_packet_id pid = direction_pids[dir];
    228224        const bool low_speed =
    229225            uhci_batch->usb_batch->ep->speed == USB_SPEED_LOW;
     
    270266 *
    271267 * @param[in] uhci_batch Batch structure to use.
    272  * @param[in] data_stage Pid to use for data tds.
    273  * @param[in] status_stage Pid to use for data tds.
     268 * @param[in] dir Communication direction.
    274269 *
    275270 * Setup stage with toggle 0 and USB_PID_SETUP.
    276  * Data stage with alternating toggle and pid supplied by parameter.
    277  * Status stage with toggle 1 and pid supplied by parameter.
     271 * Data stage with alternating toggle and pid determined by the communication
     272 * direction.
     273 * Status stage with toggle 1 and pid determined by the communication direction.
    278274 * The last transfer is marked with IOC.
    279275 */
    280 static void batch_control(uhci_transfer_batch_t *uhci_batch,
    281    usb_packet_id data_stage_pid, usb_packet_id status_stage_pid)
     276static void batch_control(uhci_transfer_batch_t *uhci_batch, usb_direction_t dir)
    282277{
    283278        assert(uhci_batch);
    284279        assert(uhci_batch->usb_batch);
    285280        assert(uhci_batch->usb_batch->ep);
     281        assert(dir == USB_DIRECTION_OUT || dir == USB_DIRECTION_IN);
    286282        assert(uhci_batch->td_count >= 2);
    287 
     283        static const usb_packet_id status_stage_pids[] = {
     284                [USB_DIRECTION_IN] = USB_PID_OUT,
     285                [USB_DIRECTION_OUT] = USB_PID_IN,
     286        };
     287
     288        const usb_packet_id data_stage_pid = direction_pids[dir];
     289        const usb_packet_id status_stage_pid = status_stage_pids[dir];
    288290        const bool low_speed =
    289291            uhci_batch->usb_batch->ep->speed == USB_SPEED_LOW;
     
    334336}
    335337/*----------------------------------------------------------------------------*/
    336 static void batch_setup_control(uhci_transfer_batch_t *uhci_batch)
    337 {
    338         assert(uhci_batch);
    339         assert(uhci_batch->usb_batch);
    340         assert(uhci_batch->usb_batch->setup_buffer);
    341         // TODO Find a better way to do this
    342         /* Check first bit of the first setup request byte
    343          * (it signals hc-> dev or dev->hc communication) */
    344         const char *direction = NULL;
    345         if (uhci_batch->usb_batch->setup_buffer[0] & (1 << 7)) {
    346                 batch_control(uhci_batch, USB_PID_IN, USB_PID_OUT);
    347                 direction = "read";
    348         } else {
    349                 batch_control(uhci_batch, USB_PID_OUT, USB_PID_IN);
    350                 direction = "write";
    351         }
    352         usb_log_debug2(
    353             "Batch %p %s %s " USB_TRANSFER_BATCH_FMT " initialized.\n", \
    354             uhci_batch->usb_batch,
    355             usb_str_transfer_type(uhci_batch->usb_batch->ep->transfer_type),
    356             direction, USB_TRANSFER_BATCH_ARGS(*uhci_batch->usb_batch));
    357 }
    358 /*----------------------------------------------------------------------------*/
    359 static void (* const batch_setup[4][3])(uhci_transfer_batch_t*) =
    360 {
    361         { NULL, NULL, batch_setup_control },
     338static void (*const batch_setup[4][3])(uhci_transfer_batch_t*, usb_direction_t) =
     339{
     340        { batch_control, batch_control, NULL },
    362341        { NULL, NULL, NULL },
    363342        { batch_data, batch_data, NULL },
Note: See TracChangeset for help on using the changeset viewer.