diff options
author | Marti Bolivar <mbolivar@leaflabs.com> | 2011-02-12 03:09:40 -0500 |
---|---|---|
committer | Marti Bolivar <mbolivar@leaflabs.com> | 2011-02-12 03:09:40 -0500 |
commit | 1fb0e0d727089e23d4b30e1efba5410dc4b4da14 (patch) | |
tree | 0fa1cf4d66be6bccab4ddd563b4070b2559bcc0a /wirish | |
parent | dba5b94ff3d1a5b9929abee53d6777128a5acc48 (diff) | |
parent | 61b310c5124b27226f1a6ade5cd726128fed61aa (diff) | |
download | librambutan-1fb0e0d727089e23d4b30e1efba5410dc4b4da14.tar.gz librambutan-1fb0e0d727089e23d4b30e1efba5410dc4b4da14.zip |
Merge branch 'debug-serialusb'
Conflicts:
libmaple/usb/usb.c
notes/coding_standard.txt
Diffstat (limited to 'wirish')
-rw-r--r-- | wirish/usb_serial.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/wirish/usb_serial.cpp b/wirish/usb_serial.cpp index 5c8a65f..e2cdee3 100644 --- a/wirish/usb_serial.cpp +++ b/wirish/usb_serial.cpp @@ -101,17 +101,27 @@ uint32 USBSerial::available(void) { return usbBytesAvailable(); } +/* blocks forever until len_bytes is received */ uint32 USBSerial::read(void *buf, uint32 len) { if (!buf) { return 0; } - return usbReceiveBytes((uint8*)buf, len); + uint32 bytes_in = 0; + while (len > 0) { + uint32 new_bytes = usbReceiveBytes((uint8*)((uint8*)buf+bytes_in), len); + len -= new_bytes; + bytes_in += new_bytes; + } + + return len; } +/* blocks forever until 1 byte is received */ uint8 USBSerial::read(void) { uint8 ch; - usbReceiveBytes(&ch, 1); + + while (usbReceiveBytes(&ch, 1) == 0); return ch; } |