little fix in USB ringbuffer for STM32F103

This commit is contained in:
2022-08-31 14:48:21 +03:00
parent a56bc1bf14
commit fcf5e03338
4 changed files with 19 additions and 17 deletions

View File

@@ -63,7 +63,7 @@ int RB_read(char s[BLOCKSIZE]){
return _1st;
}
static int addportion(const char *str, int l){
int RB_write(const char *str, int l){
int r = restlen();
if(l > r) l = r;
if(!l) return 0;
@@ -77,13 +77,3 @@ static int addportion(const char *str, int l){
return l;
}
void RB_write(const char *str, int l){
if(!str || !*str) return;
if(!usbON) return;
while(l){
if(tx_succesfull) send_next();
int a = addportion(str, l);
l -= a;
str += a;
}
}

View File

@@ -28,6 +28,6 @@
#define BLOCKSIZE (USB_TXBUFSZ)
int RB_read(char s[BLOCKSIZE]);
void RB_write(const char *str, int l);
int RB_write(const char *str, int l);
#endif // RINGBUFFER_H__

View File

@@ -40,12 +40,18 @@ void send_next(){
// put `buf` into queue to send
void USB_send(const char *buf){
if(!buf) return;
if(!buf || !usbON) return;
int len = 0;
const char *b = buf;
while(*b++) ++len;
if(!usbON || !len) return;
RB_write(buf, len); // this is a blocking procedure if there's too little free memory in buffer
int l = len;
while(l){
if(tx_succesfull) send_next();
int a = RB_write(buf, l);
l -= a;
buf += a;
}
}
// interrupt IN handler (never used?)