Цитата(Alt.F4 @ Jan 12 2015, 21:37)

Подскажите, пожалуйста, как это можно реализовать?
Спасибо.
Как ни странно - легко и без затей.
Фокус в том, что если поразбираться, то окажется что каждая функция меняет только один указатель/индекс, а второй только читает. Поэтому при "внезапном" изменении значения этого второго индекса ничего страшного не происходит.
Единственное, что требуется - чтобы операции чтения и записи индексов были атомарны, по этой причине на 8-битниках индексы придётся сделать тоже uint8_t, но там и этого будет достаточно.
CODE
typedef struct
{
uint32_t PushIndx;
uint32_t PopIndx;
uint8_t Buffer[UART_FIFO_SIZE];
} UartFifo_t;
inline static bool FifoPush( UartFifo_t* Fifo, uint8_t Data)
{
// calculate next push index
uint32_t IndxTmp = Fifo->PushIndx + 1;
if( IndxTmp == UART_FIFO_SIZE )
IndxTmp = 0;
if (IndxTmp == Fifo->PopIndx) // Check FIFO state
return(false); // The FIFO is full
Fifo->Buffer[Fifo->PushIndx] = Data; // Push the data
Fifo->PushIndx = IndxTmp; // Updating the push's index
return(true);
}
static bool FifoPop( UartFifo_t *Fifo, uint8_t *pData)
{
if (Fifo->PushIndx == Fifo->PopIndx) // Check FIFO state
return(false);// The FIFO is empty
*pData = Fifo->Buffer[Fifo->PopIndx]; // Pop the data
// Calculate the next pop index
uint32_t IndxTmp = Fifo->PopIndx + 1;
if( IndxTmp == UART_FIFO_SIZE )
IndxTmp = 0;
Fifo->PopIndx = IndxTmp; // Updating of the pop's index
return(true);
}
Russia est omnis divisa in partes octo.