From 774e765d59b8532cbc0e146f861ebdbd95953303 Mon Sep 17 00:00:00 2001 From: Hendrik van Essen Date: Mon, 29 Nov 2021 17:18:50 +0100 Subject: [PATCH] sys/isrpipe: add isrpipe_write --- sys/include/isrpipe.h | 20 ++++++++++++++++---- sys/isrpipe/isrpipe.c | 9 +++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/sys/include/isrpipe.h b/sys/include/isrpipe.h index df2fde7439..b1a18434f8 100644 --- a/sys/include/isrpipe.h +++ b/sys/include/isrpipe.h @@ -55,16 +55,28 @@ typedef struct { void isrpipe_init(isrpipe_t *isrpipe, uint8_t *buf, size_t bufsize); /** - * @brief Put one character into the isrpipe's buffer + * @brief Put one byte into the isrpipe's buffer * - * @param[in] isrpipe isrpipe object to initialize - * @param[in] c character to add to isrpipe buffer + * @param[in] isrpipe isrpipe object to operate on + * @param[in] c byte to add to isrpipe buffer * - * @returns 0 if character could be added + * @returns 0 if byte could be added * @returns -1 if buffer was full */ int isrpipe_write_one(isrpipe_t *isrpipe, uint8_t c); +/** + * @brief Put number of bytes into the isrpipe's buffer + * + * @param[in] isrpipe isrpipe object to operate on + * @param[in] buf bytes to add to isrpipe buffer + * @param[in] n number of bytes to add from buf to isrpipe's buffer + * + * @returns number of bytes that could be added + * @returns -1 if buffer was full + */ +int isrpipe_write(isrpipe_t *isrpipe, const uint8_t *buf, size_t n); + /** * @brief Read data from isrpipe (blocking) * diff --git a/sys/isrpipe/isrpipe.c b/sys/isrpipe/isrpipe.c index cb01b5b807..6534a6ae45 100644 --- a/sys/isrpipe/isrpipe.c +++ b/sys/isrpipe/isrpipe.c @@ -37,6 +37,15 @@ int isrpipe_write_one(isrpipe_t *isrpipe, uint8_t c) return res; } +int isrpipe_write(isrpipe_t *isrpipe, const uint8_t *buf, size_t n) +{ + int res = tsrb_add(&isrpipe->tsrb, buf, n); + + mutex_unlock(&isrpipe->mutex); + + return res; +} + int isrpipe_read(isrpipe_t *isrpipe, uint8_t *buffer, size_t count) { int res;