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


Ignore:
Timestamp:
2018-01-25T02:05: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:
d369b3b
Parents:
5f0b366
git-author:
Ondřej Hlavatý <aearsis@…> (2018-01-25 01:23:20)
git-committer:
Ondřej Hlavatý <aearsis@…> (2018-01-25 02:05:57)
Message:

usbhost: make bandwidth accounting a usb2_bus-thing

File:
1 edited

Legend:

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

    r5f0b366 rb357377  
    4242#include "bandwidth.h"
    4343
     44/** Bytes per second in FULL SPEED */
     45#define BANDWIDTH_TOTAL_USB11 (12000000 / 8)
     46/** 90% of total bandwidth is available for periodic transfers */
     47#define BANDWIDTH_AVAILABLE_USB11 ((BANDWIDTH_TOTAL_USB11 * 9) / 10)
     48
    4449/**
    4550 * Calculate bandwidth that needs to be reserved for communication with EP.
    4651 * Calculation follows USB 1.1 specification.
    47  * @param ep Registered endpoint
    48  * @param size Number of bytes to transfer.
    49  * @param max_packet_size Maximum bytes in one packet.
     52 *
     53 * @param ep An endpoint for which the bandwidth is to be counted
    5054 */
    51 ssize_t bandwidth_count_usb11(endpoint_t *ep, size_t size)
     55static size_t bandwidth_count_usb11(endpoint_t *ep)
    5256{
    5357        assert(ep);
     
    6367
    6468        const size_t max_packet_size = ep->max_packet_size;
     69        const size_t packet_count = ep->packets_per_uframe;
    6570
    66         const unsigned packet_count =
    67             (size + max_packet_size - 1) / max_packet_size;
    6871        /* TODO: It may be that ISO and INT transfers use only one packet per
    6972         * transaction, but I did not find text in USB spec to confirm this */
     
    9699}
    97100
    98 /**
     101const bandwidth_accounting_t bandwidth_accounting_usb11 = {
     102        .available_bandwidth = BANDWIDTH_AVAILABLE_USB11,
     103        .count_bw = &bandwidth_count_usb11,
     104};
     105
     106/** Number of nanoseconds in one microframe */
     107#define BANDWIDTH_TOTAL_USB2 (125000)
     108/** 90% of total bandwidth is available for periodic transfers */
     109#define BANDWIDTH_AVAILABLE_USB2  ((BANDWIDTH_TOTAL_USB2 * 9) / 10)
     110
     111/**
    99112 * Calculate bandwidth that needs to be reserved for communication with EP.
    100113 * Calculation follows USB 2.0 specification, chapter 5.11.3.
    101114 *
    102  * @param speed Device's speed.
    103  * @param type Type of the transfer.
    104  * @param size Number of byte to transfer.
    105  * @param max_packet_size Maximum bytes in one packet.
     115 * FIXME: Interrupt transfers shall be probably divided by their polling interval.
     116 *
     117 * @param ep An endpoint for which the bandwidth is to be counted
    106118 * @return Number of nanoseconds transaction with @c size bytes payload will
    107119 *         take.
    108120 */
    109 ssize_t bandwidth_count_usb20(endpoint_t *ep, size_t size)
     121static size_t bandwidth_count_usb2(endpoint_t *ep)
    110122{
    111123        assert(ep);
     124        assert(ep->device);
    112125
    113126        const usb_transfer_type_t type = ep->transfer_type;
     
    124137
    125138        // Approx. Floor(3.167 + BitStuffTime(Data_bc))
    126         const size_t base_time = (size * 8 + 19) / 6;
     139        const size_t base_time = (ep->max_transfer_size * 8 + 19) / 6;
    127140
    128141        switch (ep->device->speed) {
     
    152165        }
    153166}
     167
     168const bandwidth_accounting_t bandwidth_accounting_usb2 = {
     169        .available_bandwidth = BANDWIDTH_AVAILABLE_USB2,
     170        .count_bw = &bandwidth_count_usb2,
     171};
Note: See TracChangeset for help on using the changeset viewer.