Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ohci/ohci_batch.c

    r549ff23 r11cb0565  
    3434#include <errno.h>
    3535#include <str_error.h>
     36#include <macros.h>
    3637
    3738#include <usb/usb.h>
     
    5354                return;
    5455        if (ohci_batch->tds) {
     56                const ohci_endpoint_t *ohci_ep =
     57                    ohci_endpoint_get(ohci_batch->usb_batch->ep);
     58                assert(ohci_ep);
    5559                for (unsigned i = 0; i < ohci_batch->td_count; ++i) {
    56                         if (i != ohci_batch->leave_td)
     60                        if (ohci_batch->tds[i] != ohci_ep->td)
    5761                                free32(ohci_batch->tds[i]);
    5862                }
     
    6468}
    6569/*----------------------------------------------------------------------------*/
     70/** Finishes usb_transfer_batch and destroys the structure.
     71 *
     72 * @param[in] uhci_batch Instance to finish and destroy.
     73 */
    6674void ohci_transfer_batch_finish_dispose(ohci_transfer_batch_t *ohci_batch)
    6775{
     
    6977        assert(ohci_batch->usb_batch);
    7078        usb_transfer_batch_finish(ohci_batch->usb_batch,
    71             ohci_batch->device_buffer + ohci_batch->usb_batch->setup_size,
    72             ohci_batch->usb_batch->buffer_size);
     79            ohci_batch->device_buffer + ohci_batch->usb_batch->setup_size);
    7380        ohci_transfer_batch_dispose(ohci_batch);
    7481}
    7582/*----------------------------------------------------------------------------*/
     83/** Allocate memory and initialize internal data structure.
     84 *
     85 * @param[in] usb_batch Pointer to generic USB batch structure.
     86 * @return Valid pointer if all structures were successfully created,
     87 * NULL otherwise.
     88 *
     89 * Determines the number of needed transfer descriptors (TDs).
     90 * Prepares a transport buffer (that is accessible by the hardware).
     91 * Initializes parameters needed for the transfer and callback.
     92 */
    7693ohci_transfer_batch_t * ohci_transfer_batch_get(usb_transfer_batch_t *usb_batch)
    7794{
     
    105122        ohci_batch->ed = ohci_endpoint_get(usb_batch->ep)->ed;
    106123        ohci_batch->tds[0] = ohci_endpoint_get(usb_batch->ep)->td;
    107         ohci_batch->leave_td = 0;
    108124
    109125        for (unsigned i = 1; i <= ohci_batch->td_count; ++i) {
     
    152168 * completes with the last TD.
    153169 */
    154 bool ohci_transfer_batch_is_complete(ohci_transfer_batch_t *ohci_batch)
     170bool ohci_transfer_batch_is_complete(const ohci_transfer_batch_t *ohci_batch)
    155171{
    156172        assert(ohci_batch);
     
    174190
    175191        /* Assume we will leave the last(unused) TD behind */
    176         ohci_batch->leave_td = ohci_batch->td_count;
     192        unsigned leave_td = ohci_batch->td_count;
    177193
    178194        /* Check all TDs */
     
    212228                         * It will be the one TD we leave behind.
    213229                         */
    214                         ohci_batch->leave_td = i + 1;
     230                        leave_td = i + 1;
    215231
    216232                        /* Check TD assumption */
    217                         const uint32_t pa = addr_to_phys(
    218                             ohci_batch->tds[ohci_batch->leave_td]);
    219                         assert((ohci_batch->ed->td_head & ED_TDTAIL_PTR_MASK)
     233                        const uint32_t pa =
     234                            addr_to_phys(ohci_batch->tds[leave_td]);
     235                        assert((ohci_batch->ed->td_head & ED_TDHEAD_PTR_MASK)
    220236                            == pa);
    221237
    222238                        ed_set_tail_td(ohci_batch->ed,
    223                             ohci_batch->tds[ohci_batch->leave_td]);
     239                            ohci_batch->tds[leave_td]);
    224240
    225241                        /* Clear possible ED HALT */
     
    234250        ohci_endpoint_t *ohci_ep = ohci_endpoint_get(ohci_batch->usb_batch->ep);
    235251        assert(ohci_ep);
    236         ohci_ep->td = ohci_batch->tds[ohci_batch->leave_td];
     252        ohci_ep->td = ohci_batch->tds[leave_td];
    237253
    238254        /* Make sure that we are leaving the right TD behind */
     
    248264 * @param[in] ohci_batch Batch structure to use
    249265 */
    250 void ohci_transfer_batch_commit(ohci_transfer_batch_t *ohci_batch)
     266void ohci_transfer_batch_commit(const ohci_transfer_batch_t *ohci_batch)
    251267{
    252268        assert(ohci_batch);
     
    295311        while (remain_size > 0) {
    296312                const size_t transfer_size =
    297                     remain_size > OHCI_TD_MAX_TRANSFER ?
    298                     OHCI_TD_MAX_TRANSFER : remain_size;
     313                    min(remain_size, OHCI_TD_MAX_TRANSFER);
    299314                toggle = 1 - toggle;
    300315
     
    378393}
    379394/*----------------------------------------------------------------------------*/
     395/** Transfer setup table. */
    380396static void (*const batch_setup[])(ohci_transfer_batch_t*, usb_direction_t) =
    381397{
Note: See TracChangeset for help on using the changeset viewer.