remove free-interrupt context for endpoint allocator
This commit is contained in:
parent
4a90b9a6c8
commit
f7c4b48b85
97
src/lib.rs
97
src/lib.rs
|
@ -24,60 +24,57 @@ impl<const L: usize> UsbBus for UsbDevice<L> {
|
||||||
_interval: u8,
|
_interval: u8,
|
||||||
) -> UsbResult<EndpointAddress> {
|
) -> UsbResult<EndpointAddress> {
|
||||||
// Handle first endpoint. //
|
// Handle first endpoint. //
|
||||||
free(|_cs| {
|
if ep_addr == Some(EndpointAddress::from_parts(0, UsbDirection::In)) {
|
||||||
if ep_addr == Some(EndpointAddress::from_parts(0, UsbDirection::In)) {
|
Ok(ep_addr.unwrap())
|
||||||
Ok(ep_addr.unwrap())
|
} else {
|
||||||
} else {
|
let address = match ep_addr {
|
||||||
let address = match ep_addr {
|
// If current endpoint doesn't allocated, assign ep_addr to variable. //
|
||||||
// If current endpoint doesn't allocated, assign ep_addr to variable. //
|
Some(addr) if !self.ep_table[addr.index()].is_allocated => addr,
|
||||||
Some(addr) if !self.ep_table[addr.index()].is_allocated => addr,
|
|
||||||
|
|
||||||
// If ep_aadr not provided, or current endpoint is allocated, try to find next free endpoint, otherwise return UsbError. //
|
// If ep_aadr not provided, or current endpoint is allocated, try to find next free endpoint, otherwise return UsbError. //
|
||||||
_ => {
|
_ => {
|
||||||
let index = self
|
let index = self
|
||||||
.ep_table
|
.ep_table
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.skip(1)
|
.skip(1)
|
||||||
.find(|(index, ep)| {
|
.find(|(index, ep)| {
|
||||||
!ep.is_allocated
|
!ep.is_allocated && max_packet_size <= ENDPOINTS_ALLOC_LAYOUT[*index]
|
||||||
&& max_packet_size <= ENDPOINTS_ALLOC_LAYOUT[*index]
|
})
|
||||||
})
|
.ok_or(UsbError::EndpointOverflow)?
|
||||||
.ok_or(UsbError::EndpointOverflow)?
|
.0;
|
||||||
.0;
|
|
||||||
|
|
||||||
EndpointAddress::from_parts(index, ep_dir)
|
EndpointAddress::from_parts(index, ep_dir)
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Select endpoint info by address index. //
|
|
||||||
|
|
||||||
let target_endpoint = &mut self.ep_table[address.index()];
|
|
||||||
|
|
||||||
// Get power of two number of endpoint size. //
|
|
||||||
|
|
||||||
let ep_size = max(8, max_packet_size.next_power_of_two());
|
|
||||||
|
|
||||||
// Endpoint allocation marker. //
|
|
||||||
|
|
||||||
if DPRAM_SIZE - self.dpram_already_used < ep_size {
|
|
||||||
Err(UsbError::EndpointMemoryOverflow)
|
|
||||||
} else {
|
|
||||||
// Set endpoint parameters. //
|
|
||||||
|
|
||||||
target_endpoint.set_dir(ep_dir);
|
|
||||||
target_endpoint.set_type(ep_type);
|
|
||||||
target_endpoint.set_size(ep_size)?;
|
|
||||||
|
|
||||||
// Add used dpram memory. //
|
|
||||||
|
|
||||||
target_endpoint.is_allocated = true;
|
|
||||||
self.dpram_already_used += ep_size;
|
|
||||||
|
|
||||||
Ok(address)
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Select endpoint info by address index. //
|
||||||
|
|
||||||
|
let target_endpoint = &mut self.ep_table[address.index()];
|
||||||
|
|
||||||
|
// Get power of two number of endpoint size. //
|
||||||
|
|
||||||
|
let ep_size = max(8, max_packet_size.next_power_of_two());
|
||||||
|
|
||||||
|
// Endpoint allocation marker. //
|
||||||
|
|
||||||
|
if DPRAM_SIZE - self.dpram_already_used < ep_size {
|
||||||
|
Err(UsbError::EndpointMemoryOverflow)
|
||||||
|
} else {
|
||||||
|
// Set endpoint parameters. //
|
||||||
|
|
||||||
|
target_endpoint.set_dir(ep_dir);
|
||||||
|
target_endpoint.set_type(ep_type);
|
||||||
|
target_endpoint.set_size(ep_size)?;
|
||||||
|
|
||||||
|
// Add used dpram memory. //
|
||||||
|
|
||||||
|
target_endpoint.is_allocated = true;
|
||||||
|
self.dpram_already_used += ep_size;
|
||||||
|
|
||||||
|
Ok(address)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enable(&mut self) {
|
fn enable(&mut self) {
|
||||||
|
|
Loading…
Reference in New Issue