forked from haraldwolff/avr-fw-modules
47 lines
833 B
C
47 lines
833 B
C
|
#pragma once
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <sys/threads.h>
|
||
|
|
||
|
struct __pipe
|
||
|
{
|
||
|
volatile uint8_t *buffer;
|
||
|
volatile int size;
|
||
|
volatile int
|
||
|
read,
|
||
|
write;
|
||
|
|
||
|
uint8_t options;
|
||
|
|
||
|
THREAD *wait_get,
|
||
|
*wait_put;
|
||
|
};
|
||
|
typedef struct __pipe PIPE;
|
||
|
#define PIPE(ptr) ((PIPE*)ptr)
|
||
|
|
||
|
typedef struct {
|
||
|
FILE file;
|
||
|
PIPE pipe;
|
||
|
} fdPIPE;
|
||
|
#define fdPIPE(ptr) ((fdPIPE*)(ptr))
|
||
|
|
||
|
int pipe_clear(FILE* pipe);
|
||
|
int pipe_options(FILE* pipe,uint8_t options);
|
||
|
|
||
|
int pipe_get(FILE* stream);
|
||
|
int pipe_put(char c,FILE* stream);
|
||
|
|
||
|
static inline int pipe_full(FILE* pipe)
|
||
|
{
|
||
|
return (
|
||
|
((fdPIPE(pipe)->pipe.read == 0) && (fdPIPE(pipe)->pipe.write == fdPIPE(pipe)->pipe.size - 1)) ||
|
||
|
(fdPIPE(pipe)->pipe.write + 1 == fdPIPE(pipe)->pipe.read)
|
||
|
);
|
||
|
};
|
||
|
|
||
|
static inline int pipe_empty(FILE* pipe)
|
||
|
{
|
||
|
return (fdPIPE(pipe)->pipe.read == fdPIPE(pipe)->pipe.write);
|
||
|
};
|
||
|
|