Changeset ecbad17 in mainline for uspace/lib/usbhost/src/bandwidth.c


Ignore:
Timestamp:
2018-01-07T17:13:57Z (7 years ago)
Author:
Ondřej Hlavatý <aearsis@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
eb928c4
Parents:
3dc3f99
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-07 17:12:35)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-07 17:13:57)
Message:

usbhost: Implemented bandwidth accounting for USB 2.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/bandwidth.c

    r3dc3f99 recbad17  
    9696
    9797/** Calculate bandwidth that needs to be reserved for communication with EP.
    98  * Calculation follows USB 2.0 specification.
     98 * Calculation follows USB 2.0 specification, chapter 5.11.3.
     99 *
    99100 * @param speed Device's speed.
    100101 * @param type Type of the transfer.
    101102 * @param size Number of byte to transfer.
    102103 * @param max_packet_size Maximum bytes in one packet.
     104 * @return Number of nanoseconds transaction with @c size bytes payload will
     105 *         take.
    103106 */
    104107ssize_t bandwidth_count_usb20(endpoint_t *ep, size_t size)
     
    113116                return 0;
    114117        }
    115         //TODO Implement
    116         return 0;
     118
     119        // FIXME: Come up with some upper bound for these (in ns).
     120        const size_t host_delay = 0;
     121        const size_t hub_ls_setup = 0;
     122
     123        // Approx. Floor(3.167 + BitStuffTime(Data_bc))
     124        const size_t base_time = (size * 8 + 19) / 6;
     125
     126        switch (ep->device->speed) {
     127        case USB_SPEED_LOW:
     128                if (ep->direction == USB_DIRECTION_IN)
     129                        return 64060 + (2 * hub_ls_setup) + (677 * base_time) + host_delay;
     130                else
     131                        return 64107 + (2 * hub_ls_setup) + (667 * base_time) + host_delay;
     132
     133        case USB_SPEED_FULL:
     134                if (ep->transfer_type == USB_TRANSFER_INTERRUPT)
     135                        return 9107 + 84 * base_time + host_delay;
     136
     137                if (ep->direction == USB_DIRECTION_IN)
     138                        return 7268 + 84 * base_time + host_delay;
     139                else
     140                        return 6265 + 84 * base_time + host_delay;
     141
     142        case USB_SPEED_HIGH:
     143                if (ep->transfer_type == USB_TRANSFER_INTERRUPT)
     144                        return (3648 + 25 * base_time + 11) / 12 + host_delay;
     145                else
     146                        return (5280 + 25 * base_time + 11) / 12 + host_delay;
     147
     148        default:
     149                return 0;
     150        }
    117151}
Note: See TracChangeset for help on using the changeset viewer.