| 1 | #ifndef FIFO_H |
| 2 | #define FIFO_H |
| 3 | |
| 4 | #include "lwip/sys.h" |
| 5 | |
| 6 | /** How many bytes in fifo */ |
| 7 | #define FIFOSIZE 2048 |
| 8 | |
| 9 | /** fifo data structure, this one is passed to all fifo functions */ |
| 10 | typedef struct fifo_t { |
| 11 | u8_t data[FIFOSIZE+10]; /* data segment, +10 is a hack probably not needed.. FIXME! */ |
| 12 | int dataslot; /* index to next char to be read */ |
| 13 | int emptyslot; /* index to next empty slot */ |
| 14 | int len; /* len probably not needed, may be calculated from dataslot and emptyslot in conjunction with FIFOSIZE */ |
| 15 | |
| 16 | sys_sem_t sem; /* semaphore protecting simultaneous data manipulation */ |
| 17 | sys_sem_t getSem; /* sepaphore used to signal new data if getWaiting is set */ |
| 18 | u8_t getWaiting; /* flag used to indicate that fifoget is waiting for data. fifoput is suposed to clear */ |
| 19 | /* this flag prior to signaling the getSem semaphore */ |
| 20 | } fifo_t; |
| 21 | |
| 22 | |
| 23 | /** |
| 24 | * Get a character from fifo |
| 25 | * Blocking call. |
| 26 | * @param pointer to fifo data structure |
| 27 | * @return character read from fifo |
| 28 | */ |
| 29 | u8_t fifoGet(fifo_t * fifo); |
| 30 | |
| 31 | /** |
| 32 | * Get a character from fifo |
| 33 | * Non blocking call. |
| 34 | * @param pointer to fifo data structure |
| 35 | * @return character read from fifo, or < zero if non was available |
| 36 | */ |
| 37 | s16_t fifoGetNonBlock(fifo_t * fifo); |
| 38 | |
| 39 | /** |
| 40 | * fifoput is called by the signalhandler when new data has arrived (or some other event is indicated) |
| 41 | * fifoput reads directly from the serialport and is thus highly dependent on unix arch at this moment |
| 42 | * @param fifo pointer to fifo data structure |
| 43 | * @param fd unix file descriptor |
| 44 | */ |
| 45 | void fifoPut(fifo_t * fifo, int fd); |
| 46 | |
| 47 | /** |
| 48 | * fifoinit initiate fifo |
| 49 | * @param fifo pointer to fifo data structure, allocated by the user |
| 50 | */ |
| 51 | void fifoInit(fifo_t * fifo); |
| 52 | |
| 53 | #endif |
| 54 |