diff --git a/F0:F030,F042,F072/PL2303_ringbuffer/PL2303.bin b/F0:F030,F042,F072/PL2303_ringbuffer/PL2303.bin index 2ccd7a8..f2ab216 100755 Binary files a/F0:F030,F042,F072/PL2303_ringbuffer/PL2303.bin and b/F0:F030,F042,F072/PL2303_ringbuffer/PL2303.bin differ diff --git a/F0:F030,F042,F072/PL2303_ringbuffer/proto.c b/F0:F030,F042,F072/PL2303_ringbuffer/proto.c index 2e70caf..62ae31f 100644 --- a/F0:F030,F042,F072/PL2303_ringbuffer/proto.c +++ b/F0:F030,F042,F072/PL2303_ringbuffer/proto.c @@ -23,6 +23,7 @@ extern uint32_t Tms; +// 250 symbols == 1000 bit const char *test = "123456789A123456789B123456789C123456789D123456789E123456789F123456789G123456789H123456789I123456789J123456789K123456789L123456789M123456789N123456789O123456789P123456789Q123456789R123456789S123456789T123456789U123456789V123456789W123456789X123456789Y"; char *omit_spaces(const char *buf){ @@ -198,7 +199,11 @@ const char *parse_cmd(const char *buf){ u3 = Tms; for(int i = 0; i < 1000; ++i) USB_sendstr(test); add2buf("\n\nspd="); - add2buf(u2str(2000000000/(Tms - u3))); add2buf("\n"); // strlen == 2Mbit, speed in bits per second + // strlen == 2Mbit, speed in bits per second + add2buf(u2str(2000000000/(Tms - u3))); + add2buf("\ntransfer time is "); + add2buf(u2str(Tms - u3)); + add2buf("\n"); break; case 'U': add2buf("USB status: "); diff --git a/F0:F030,F042,F072/PL2303_ringbuffer/usb.c b/F0:F030,F042,F072/PL2303_ringbuffer/usb.c index e5ef3a1..bf03dd6 100644 --- a/F0:F030,F042,F072/PL2303_ringbuffer/usb.c +++ b/F0:F030,F042,F072/PL2303_ringbuffer/usb.c @@ -16,7 +16,15 @@ * along with this program. If not, see . */ -// USB read/write for text or binary data through ring-buffers (mean 5187476b/s) +// USB read/write for text or binary data through ring-buffers +/* + * mean speeds (bit/s) @ buffer size (bytes): + 5333333 @ 128 + 5249343 @ 256 + 5181347 @ 512 + 5277044 @ 2048 + 5434782 @ 4096 +*/ #include "ringbuffer.h" #include "usb.h" @@ -28,27 +36,26 @@ static uint8_t obuf[RBOUTSZ], ibuf[RBINSZ]; static ringbuffer out = {.data = obuf, .length = RBOUTSZ, .head = 0, .tail = 0}; static ringbuffer in = {.data = ibuf, .length = RBINSZ, .head = 0, .tail = 0}; // transmission is succesfull -static volatile uint8_t tx_succesfull = 1; +static volatile uint8_t bufisempty = 1; static volatile uint8_t bufovrfl = 0; static void send_next(){ - if(!tx_succesfull) return; + if(bufisempty) return; static int lastdsz = 0; int buflen = RB_read(&out, usbbuff, USB_TXBUFSZ); if(!buflen){ if(lastdsz == 64) EP_Write(3, NULL, 0); // send ZLP after 64 bits packet when nothing more to send lastdsz = 0; + bufisempty = 1; return; } - tx_succesfull = 0; EP_Write(3, usbbuff, buflen); lastdsz = buflen; } // send full content of ring buffer int USB_sendall(){ - while(RB_datalen(&out)){ - send_next(); + while(!bufisempty){ if(!usbON) return 0; } return 1; @@ -58,10 +65,13 @@ int USB_sendall(){ int USB_send(const uint8_t *buf, int len){ if(!buf || !usbON || !len) return 0; while(len){ - if(tx_succesfull) send_next(); int a = RB_write(&out, buf, len); len -= a; buf += a; + if(bufisempty){ + bufisempty = 0; + send_next(); + } } return 1; } @@ -119,10 +129,10 @@ static void EP1_Handler(){ // data IN/OUT handlers static void transmit_Handler(){ // EP3IN - tx_succesfull = 1; uint16_t epstatus = KEEP_DTOG_STAT(USB->EPnR[3]); // clear CTR keep DTOGs & STATs USB->EPnR[3] = (epstatus & ~(USB_EPnR_CTR_TX)); // clear TX ctr + send_next(); } static void receive_Handler(){ // EP2OUT @@ -153,6 +163,5 @@ void USB_proc(){ break; default: // USB_STATE_CONNECTED - send next data portion if(!usbON) return; - if(tx_succesfull) send_next(); } } diff --git a/F0:F030,F042,F072/PL2303_ringbuffer/version.inc b/F0:F030,F042,F072/PL2303_ringbuffer/version.inc index d4f59f2..21af120 100644 --- a/F0:F030,F042,F072/PL2303_ringbuffer/version.inc +++ b/F0:F030,F042,F072/PL2303_ringbuffer/version.inc @@ -1,2 +1,2 @@ -#define BUILD_NUMBER "111" +#define BUILD_NUMBER "120" #define BUILD_DATE "2022-10-27"