forked from haraldwolff/avr-fw-modules
25 lines
401 B
C
Executable File
25 lines
401 B
C
Executable File
#include <hwo/fifo.h>
|
|
#include <sys/atomic.h>
|
|
#include <hwo/threads.h>
|
|
|
|
uint16_t fifo_read(FIFO* fifo)
|
|
{
|
|
wait_async_set(&fifo->wtimeout,fifo->timeout);
|
|
do
|
|
{
|
|
{
|
|
ATOMIC
|
|
uint16_t ch = fifo_poll(fifo);
|
|
if (ch != -1)
|
|
return ch;
|
|
|
|
if (fifo->irq_rd)
|
|
return -1;
|
|
}
|
|
yield();
|
|
} while (fifo->blocking || (fifo->timeout == -1) || (!wait_async_test(&fifo->wtimeout)));
|
|
|
|
return -1;
|
|
};
|
|
|