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 
21 #include <stdint.h>
22 
23 #include "mutex.h"
24 #include "tsrb.h"
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
33 typedef struct {
36 } isrpipe_t;
37 
45 #define ISRPIPE_INIT(buf) { .mutex = MUTEX_INIT_LOCKED, \
46  .tsrb = TSRB_INIT(buf) }
47 
57 void isrpipe_init(isrpipe_t *isrpipe, uint8_t *buf, size_t bufsize);
58 
68 int isrpipe_write_one(isrpipe_t *isrpipe, uint8_t c);
69 
80 int isrpipe_write(isrpipe_t *isrpipe, const uint8_t *buf, size_t n);
81 
91 int isrpipe_read(isrpipe_t *isrpipe, uint8_t *buf, size_t count);
92 
93 #ifdef __cplusplus
94 }
95 #endif
int isrpipe_write_one(isrpipe_t *isrpipe, uint8_t c)
Put one byte into the isrpipe's buffer.
void isrpipe_init(isrpipe_t *isrpipe, uint8_t *buf, size_t bufsize)
Initialisation function for isrpipe.
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.
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 struct
Definition: tsrb.h:35
Thread-safe ringbuffer interface definition.