add timeouts

This commit is contained in:
Edward Emelianov
2026-02-09 21:04:47 +03:00
parent 87683a12e6
commit 3a903d7d8c
7 changed files with 31 additions and 17 deletions

View File

@@ -15,6 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h> // memcpy
#include "ringbuffer.h"
static int datalen(ringbuffer *b){
@@ -57,11 +58,11 @@ int RB_hasbyte(ringbuffer *b, uint8_t byte){
b->busy = 0;
return ret;
}
/*
// poor memcpy
static void mcpy(uint8_t *targ, const uint8_t *src, int l){
while(l--) *targ++ = *src++;
}
}*/
// increment head or tail
TRUE_INLINE void incr(ringbuffer *b, volatile int *what, int n){
@@ -76,9 +77,11 @@ static int read(ringbuffer *b, uint8_t *s, int len){
int _1st = b->length - b->head;
if(_1st > l) _1st = l;
if(_1st > len) _1st = len;
mcpy(s, b->data + b->head, _1st);
//mcpy(s, b->data + b->head, _1st);
memcpy(s, b->data + b->head, _1st);
if(_1st < len && l > _1st){
mcpy(s+_1st, b->data, l - _1st);
//mcpy(s+_1st, b->data, l - _1st);
memcpy(s+_1st, b->data, l - _1st);
incr(b, &b->head, l);
return l;
}
@@ -132,9 +135,11 @@ static int write(ringbuffer *b, const uint8_t *str, int l){
if(l > r || !l) return 0;
int _1st = b->length - b->tail;
if(_1st > l) _1st = l;
mcpy(b->data + b->tail, str, _1st);
//mcpy(b->data + b->tail, str, _1st);
memcpy(b->data + b->tail, str, _1st);
if(_1st < l){ // add another piece from start
mcpy(b->data, str+_1st, l-_1st);
//mcpy(b->data, str+_1st, l-_1st);
memcpy(b->data, str+_1st, l-_1st);
}
incr(b, &b->tail, l);
return l;