mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
chunk data to the USB subsystem
the chunks match the size of the application buffer, eliminating the possibility of an overrun (of the buffer at least) there is a possibility still i think of overrunning USB itself but i think the CPU can't produce data fast enough to actually do that.
This commit is contained in:
parent
e98ffaadfd
commit
37ff052b34
1 changed files with 4 additions and 14 deletions
|
|
@ -745,20 +745,10 @@ pub(crate) fn main_hw() -> ! {
|
||||||
let buffer = unsafe { Buffer::from_memory_message(mem_msg) };
|
let buffer = unsafe { Buffer::from_memory_message(mem_msg) };
|
||||||
match buffer.to_original::<api::UsbString, _>() {
|
match buffer.to_original::<api::UsbString, _>() {
|
||||||
Ok(usb_send) => {
|
Ok(usb_send) => {
|
||||||
// this is implemented as a "blocking write": the routine will block until the
|
for chunk in
|
||||||
// data has all been written.
|
usb_send.s.as_bytes().chunks(bao1x_hal::usb::driver::CRG_UDC_APP_BUFSIZE)
|
||||||
let send_data = usb_send.s.as_bytes();
|
{
|
||||||
let to_send = usb_send.s.len();
|
cu.serial_port.write(&chunk).ok();
|
||||||
let mut sent = 0;
|
|
||||||
while sent < to_send {
|
|
||||||
match cu.serial_port.write(&send_data[sent..to_send]) {
|
|
||||||
Ok(written) => {
|
|
||||||
sent += written;
|
|
||||||
}
|
|
||||||
Err(_) => {
|
|
||||||
// just drop characters
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cu.serial_port.flush().ok(); // just drop characters on error
|
cu.serial_port.flush().ok(); // just drop characters on error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue