isrpipe: change API to be in line with tsrb
The API of `tsrb` was changed because of confusing type situations. This API change takes this API change of changing `char` to `uint8_t` up a level. Since `isrpipe` most often is used together with `periph_uart` this change even is beneficial, as `periph_uart` also uses `uint8_t` instead of `char`.
This commit is contained in:
parent
9b47dcb542
commit
d9049dad87
@ -52,7 +52,7 @@ typedef struct {
|
|||||||
* @param[in] buf buffer to use as ringbuffer (must be power of two sized!)
|
* @param[in] buf buffer to use as ringbuffer (must be power of two sized!)
|
||||||
* @param[in] bufsize size of @p buf
|
* @param[in] bufsize size of @p buf
|
||||||
*/
|
*/
|
||||||
void isrpipe_init(isrpipe_t *isrpipe, char *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 character into the isrpipe's buffer
|
||||||
@ -63,7 +63,7 @@ void isrpipe_init(isrpipe_t *isrpipe, char *buf, size_t bufsize);
|
|||||||
* @returns 0 if character could be added
|
* @returns 0 if character could be added
|
||||||
* @returns -1 if buffer was full
|
* @returns -1 if buffer was full
|
||||||
*/
|
*/
|
||||||
int isrpipe_write_one(isrpipe_t *isrpipe, char c);
|
int isrpipe_write_one(isrpipe_t *isrpipe, uint8_t c);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Read data from isrpipe (blocking)
|
* @brief Read data from isrpipe (blocking)
|
||||||
@ -74,7 +74,7 @@ int isrpipe_write_one(isrpipe_t *isrpipe, char c);
|
|||||||
*
|
*
|
||||||
* @returns number of bytes read
|
* @returns number of bytes read
|
||||||
*/
|
*/
|
||||||
int isrpipe_read(isrpipe_t *isrpipe, char *buf, size_t count);
|
int isrpipe_read(isrpipe_t *isrpipe, uint8_t *buf, size_t count);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,7 +44,7 @@ extern "C" {
|
|||||||
* @returns number of bytes read
|
* @returns number of bytes read
|
||||||
* @returns -ETIMEDOUT on timeout
|
* @returns -ETIMEDOUT on timeout
|
||||||
*/
|
*/
|
||||||
int isrpipe_read_timeout(isrpipe_t *isrpipe, char *buf, size_t count, uint32_t timeout);
|
int isrpipe_read_timeout(isrpipe_t *isrpipe, uint8_t *buf, size_t count, uint32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Read data from isrpipe (with timeout, blocking, wait until all read)
|
* @brief Read data from isrpipe (with timeout, blocking, wait until all read)
|
||||||
@ -60,7 +60,7 @@ int isrpipe_read_timeout(isrpipe_t *isrpipe, char *buf, size_t count, uint32_t t
|
|||||||
* @returns number of bytes read
|
* @returns number of bytes read
|
||||||
* @returns -ETIMEDOUT on timeout
|
* @returns -ETIMEDOUT on timeout
|
||||||
*/
|
*/
|
||||||
int isrpipe_read_all_timeout(isrpipe_t *isrpipe, char *buf, size_t count, uint32_t timeout);
|
int isrpipe_read_all_timeout(isrpipe_t *isrpipe, uint8_t *buf, size_t count, uint32_t timeout);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,13 +19,13 @@
|
|||||||
|
|
||||||
#include "isrpipe.h"
|
#include "isrpipe.h"
|
||||||
|
|
||||||
void isrpipe_init(isrpipe_t *isrpipe, char *buf, size_t bufsize)
|
void isrpipe_init(isrpipe_t *isrpipe, uint8_t *buf, size_t bufsize)
|
||||||
{
|
{
|
||||||
mutex_init(&isrpipe->mutex);
|
mutex_init(&isrpipe->mutex);
|
||||||
tsrb_init(&isrpipe->tsrb, (uint8_t *)buf, bufsize);
|
tsrb_init(&isrpipe->tsrb, buf, bufsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
int isrpipe_write_one(isrpipe_t *isrpipe, char c)
|
int isrpipe_write_one(isrpipe_t *isrpipe, uint8_t c)
|
||||||
{
|
{
|
||||||
int res = tsrb_add_one(&isrpipe->tsrb, c);
|
int res = tsrb_add_one(&isrpipe->tsrb, c);
|
||||||
|
|
||||||
@ -37,11 +37,11 @@ int isrpipe_write_one(isrpipe_t *isrpipe, char c)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int isrpipe_read(isrpipe_t *isrpipe, char *buffer, size_t count)
|
int isrpipe_read(isrpipe_t *isrpipe, uint8_t *buffer, size_t count)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
while (!(res = tsrb_get(&isrpipe->tsrb, (uint8_t *)buffer, count))) {
|
while (!(res = tsrb_get(&isrpipe->tsrb, buffer, count))) {
|
||||||
mutex_lock(&isrpipe->mutex);
|
mutex_lock(&isrpipe->mutex);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@ -35,7 +35,7 @@ static void _cb(void *arg)
|
|||||||
mutex_unlock(_timeout->mutex);
|
mutex_unlock(_timeout->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
int isrpipe_read_timeout(isrpipe_t *isrpipe, char *buffer, size_t count, uint32_t timeout)
|
int isrpipe_read_timeout(isrpipe_t *isrpipe, uint8_t *buffer, size_t count, uint32_t timeout)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ int isrpipe_read_timeout(isrpipe_t *isrpipe, char *buffer, size_t count, uint32_
|
|||||||
xtimer_t timer = { .callback = _cb, .arg = &_timeout };
|
xtimer_t timer = { .callback = _cb, .arg = &_timeout };
|
||||||
|
|
||||||
xtimer_set(&timer, timeout);
|
xtimer_set(&timer, timeout);
|
||||||
while (!(res = tsrb_get(&isrpipe->tsrb, (uint8_t *)buffer, count))) {
|
while (!(res = tsrb_get(&isrpipe->tsrb, buffer, count))) {
|
||||||
mutex_lock(&isrpipe->mutex);
|
mutex_lock(&isrpipe->mutex);
|
||||||
if (_timeout.flag) {
|
if (_timeout.flag) {
|
||||||
res = -ETIMEDOUT;
|
res = -ETIMEDOUT;
|
||||||
@ -57,9 +57,9 @@ int isrpipe_read_timeout(isrpipe_t *isrpipe, char *buffer, size_t count, uint32_
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int isrpipe_read_all_timeout(isrpipe_t *isrpipe, char *buffer, size_t count, uint32_t timeout)
|
int isrpipe_read_all_timeout(isrpipe_t *isrpipe, uint8_t *buffer, size_t count, uint32_t timeout)
|
||||||
{
|
{
|
||||||
char *pos = buffer;
|
uint8_t *pos = buffer;
|
||||||
|
|
||||||
while (count) {
|
while (count) {
|
||||||
int res = isrpipe_read_timeout(isrpipe, pos, count, timeout);
|
int res = isrpipe_read_timeout(isrpipe, pos, count, timeout);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user