Merge pull request #17336 from HendrikVE/pr/isrpipe_write

sys/isrpipe: add isrpipe_write
This commit is contained in:
Francisco 2021-12-07 17:10:44 +01:00 committed by GitHub
commit 07e7a6edce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View File

@ -55,16 +55,28 @@ typedef struct {
void isrpipe_init(isrpipe_t *isrpipe, uint8_t *buf, size_t bufsize); 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] isrpipe isrpipe object to operate on
* @param[in] c character to add to isrpipe buffer * @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 * @returns -1 if buffer was full
*/ */
int isrpipe_write_one(isrpipe_t *isrpipe, uint8_t c); 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) * @brief Read data from isrpipe (blocking)
* *

View File

@ -37,6 +37,15 @@ int isrpipe_write_one(isrpipe_t *isrpipe, uint8_t c)
return res; 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 isrpipe_read(isrpipe_t *isrpipe, uint8_t *buffer, size_t count)
{ {
int res; int res;