Loading...
Searching...
No Matches
isrpipe.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Kaspar Schleiser <kaspar@schleiser.de>
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
20
21#include <stdint.h>
22
23#include "mutex.h"
24#include "tsrb.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
33typedef struct {
36} isrpipe_t;
37
45#define ISRPIPE_INIT(buf) { .mutex = MUTEX_INIT_LOCKED, \
46 .tsrb = TSRB_INIT(buf) }
47
57void isrpipe_init(isrpipe_t *isrpipe, uint8_t *buf, size_t bufsize);
58
68int isrpipe_write_one(isrpipe_t *isrpipe, uint8_t c);
69
80int isrpipe_write(isrpipe_t *isrpipe, const uint8_t *buf, size_t n);
81
91int isrpipe_read(isrpipe_t *isrpipe, uint8_t *buf, size_t count);
92
100uint8_t isrpipe_read_one(isrpipe_t *isrpipe);
101
111static inline void isrpipe_clear(isrpipe_t *isrpipe)
112{
113 tsrb_clear(&isrpipe->tsrb);
114}
115
123static inline unsigned int isrpipe_available(isrpipe_t *isrpipe)
124{
125 return tsrb_avail(&isrpipe->tsrb);
126}
127
135static inline unsigned int isrpipe_get_free(isrpipe_t *isrpipe)
136{
137 return tsrb_free(&isrpipe->tsrb);
138}
139
140#ifdef __cplusplus
141}
142#endif
int isrpipe_write_one(isrpipe_t *isrpipe, uint8_t c)
Put one byte into the isrpipe's buffer.
static unsigned int isrpipe_get_free(isrpipe_t *isrpipe)
Get the number of bytes that can still be written to the isrpipe.
Definition isrpipe.h:135
static void isrpipe_clear(isrpipe_t *isrpipe)
Clear the isrpipe's buffer.
Definition isrpipe.h:111
void isrpipe_init(isrpipe_t *isrpipe, uint8_t *buf, size_t bufsize)
Initialisation function for isrpipe.
uint8_t isrpipe_read_one(isrpipe_t *isrpipe)
Read a single byte from isrpipe (blocking)
static unsigned int isrpipe_available(isrpipe_t *isrpipe)
Get the number of bytes available for reading from the isrpipe.
Definition isrpipe.h:123
int isrpipe_read(isrpipe_t *isrpipe, uint8_t *buf, size_t count)
Read data from isrpipe (blocking)
int isrpipe_write(isrpipe_t *isrpipe, const uint8_t *buf, size_t n)
Put number of bytes into the isrpipe's buffer.
static unsigned int tsrb_free(const tsrb_t *rb)
Get free space in ringbuffer.
Definition tsrb.h:130
static unsigned int tsrb_avail(const tsrb_t *rb)
Get number of bytes available for reading.
Definition tsrb.h:103
struct tsrb tsrb_t
thread-safe ringbuffer struct
static void tsrb_clear(tsrb_t *rb)
Clear a tsrb.
Definition tsrb.h:77
Mutex for thread synchronization.
Context structure for isrpipe.
Definition isrpipe.h:33
tsrb_t tsrb
isrpipe thread safe ringbuffer
Definition isrpipe.h:34
mutex_t mutex
isrpipe mutex
Definition isrpipe.h:35
Mutex structure.
Definition mutex.h:36
Thread-safe ringbuffer interface definition.