Changeset b357377 in mainline for uspace/lib/usbhost/src/bandwidth.c
- Timestamp:
- 2018-01-25T02:05:57Z (7 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhost/src/bandwidth.c
r5f0b366 rb357377 42 42 #include "bandwidth.h" 43 43 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 44 49 /** 45 50 * Calculate bandwidth that needs to be reserved for communication with EP. 46 51 * 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 50 54 */ 51 s size_t bandwidth_count_usb11(endpoint_t *ep, size_t size)55 static size_t bandwidth_count_usb11(endpoint_t *ep) 52 56 { 53 57 assert(ep); … … 63 67 64 68 const size_t max_packet_size = ep->max_packet_size; 69 const size_t packet_count = ep->packets_per_uframe; 65 70 66 const unsigned packet_count =67 (size + max_packet_size - 1) / max_packet_size;68 71 /* TODO: It may be that ISO and INT transfers use only one packet per 69 72 * transaction, but I did not find text in USB spec to confirm this */ … … 96 99 } 97 100 98 /** 101 const 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 /** 99 112 * Calculate bandwidth that needs to be reserved for communication with EP. 100 113 * Calculation follows USB 2.0 specification, chapter 5.11.3. 101 114 * 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 106 118 * @return Number of nanoseconds transaction with @c size bytes payload will 107 119 * take. 108 120 */ 109 s size_t bandwidth_count_usb20(endpoint_t *ep, size_t size)121 static size_t bandwidth_count_usb2(endpoint_t *ep) 110 122 { 111 123 assert(ep); 124 assert(ep->device); 112 125 113 126 const usb_transfer_type_t type = ep->transfer_type; … … 124 137 125 138 // 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; 127 140 128 141 switch (ep->device->speed) { … … 152 165 } 153 166 } 167 168 const 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.