forked from grblHAL/Plugin_networking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sfifo.h
47 lines (37 loc) · 1 KB
/
sfifo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
/*
------------------------------------------------------------
SFIFO 1.3
------------------------------------------------------------
* Simple portable lock-free FIFO
* (c) 2000-2002, David Olofson
*
*/
#if defined(ARDUINO)
#include "../driver.h"
#else
#include "driver.h"
#endif
#if FTP_ENABLE
#include "lwip/errno.h"
#ifndef EINVAL
#define EINVAL 1
#define ENOMEM 2
#define ENODEV 3
#endif
#define SFIFO_MAX_BUFFER_SIZE 0x7fffffff
#define SFIFO_SIZEMASK(x) ((x)->size - 1)
#define sfifo_used(x) (((x)->writepos - (x)->readpos) & SFIFO_SIZEMASK(x))
#define sfifo_space(x) ((x)->size - 1 - sfifo_used(x))
typedef int sfifo_atomic_t;
typedef struct
{
char *buffer;
int size; /* Number of bytes */
volatile sfifo_atomic_t readpos; /* Read position */
volatile sfifo_atomic_t writepos; /* Write position */
} sfifo_t;
int sfifo_init(sfifo_t *f, int size);
int sfifo_write(sfifo_t *f, const void *_buf, int len);
void sfifo_close(sfifo_t *f);
#endif