mirror of
https://github.com/eddyem/stm32samples.git
synced 2026-02-28 03:44:30 +03:00
little fix in USB ringbuffer for STM32F103
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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__
|
||||
|
||||
@@ -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?)
|
||||
|
||||
Reference in New Issue
Block a user