Exemple #1
0
static void TestCase_StaticMemory(void)
{
    FIFO_t MyFifo;
    int ret = 0;
    T MyT_A, MyT_B, MyT_C;
    T MyT;

    MyT.sex  = 0;
    MyT.addr = 0;
    MyT.tel  = 0;

    MyT_A.sex  = 1;
    MyT_A.addr = 1;
    MyT_A.tel  = 1;

    MyT_B.sex  = 2;
    MyT_B.addr = 2;
    MyT_B.tel  = 2;

    MyT_C.sex  = 3;
    MyT_C.addr = 3;
    MyT_C.tel  = 3;

    FIFO_Init(&MyFifo, FIFO_Pool, sizeof(T), ELE_CNT);

    ret = FIFO_IsEmpty(&MyFifo);
    ret = FIFO_IsFull(&MyFifo);
    ret = FIFO_CountFree(&MyFifo);
    ret = FIFO_CountUsed(&MyFifo);

    FIFO_Put(&MyFifo, &MyT_A);
    FIFO_Put(&MyFifo, &MyT_B);
    FIFO_Put(&MyFifo, &MyT_C);

    ret = FIFO_IsEmpty(&MyFifo);
    ret = FIFO_IsFull(&MyFifo);
    ret = FIFO_CountFree(&MyFifo);
    ret = FIFO_CountUsed(&MyFifo);

    FIFO_Get(&MyFifo, &MyT);
    FIFO_Get(&MyFifo, &MyT);
    FIFO_Get(&MyFifo, &MyT);

    ret = FIFO_IsEmpty(&MyFifo);
    ret = FIFO_IsFull(&MyFifo);
    ret = FIFO_CountFree(&MyFifo);
    ret = FIFO_CountUsed(&MyFifo);

    FIFO_Put(&MyFifo, &MyT_A);
    FIFO_Put(&MyFifo, &MyT_B);
    FIFO_Put(&MyFifo, &MyT_C);

    ret = FIFO_Flush(&MyFifo);

    ret = FIFO_IsEmpty(&MyFifo);
    ret = FIFO_IsFull(&MyFifo);
    ret = FIFO_CountFree(&MyFifo);
    ret = FIFO_CountUsed(&MyFifo);
}
Exemple #2
0
/** Add one or more elements to the FIFO.

    This function allows one to add one or more elements, as specified by Count,
    to the FIFO.  Each element is of the size specified when the FIFO object
    was instantiated (FIFO.ElementSize).

    pElement points to the first byte of the first element to be added.
    If multiple elements are to be added, the elements are expected to be
    organized as a packed array.

    @param[in]    Self        Pointer to the FIFO instance.
    @param[in]    pElement    Pointer to the element(s) to enqueue (add).
    @param[in]    Count       Number of elements to add.

    @retval   0       The FIFO is full.
    @retval   >=0     The number of elements added to the FIFO.
**/
static
size_t
EFIAPI
FIFO_Enqueue (
  cFIFO        *Self,
  const void   *pElement,
  size_t        Count
  )
{
  uintptr_t     ElemPtr;
  uintptr_t     QPtr;
  size_t        i;
  UINT32        SizeOfElement;
  UINT32        Windex;

  assert(Self != NULL);
  assert(pElement != NULL);
  assert(Count >= 0);

  if(FIFO_IsFull(Self)) {
    Count = 0;
  }
  else {
    Count = MIN(Count, Self->FreeSpace(Self, AsElements));
    SizeOfElement = Self->ElementSize;
    Windex = Self->WriteIndex;

    ElemPtr = (uintptr_t)pElement;

    QPtr   = (uintptr_t)Self->Queue + (SizeOfElement * Windex);
    for(i = 0; i < Count; ++i) {
      (void)CopyMem((void *)QPtr, (const void *)ElemPtr, SizeOfElement);
      Windex = (UINT32)ModuloIncrement(Windex, Self->NumElements);
      if(Windex == 0) {   // If the index wrapped
        QPtr = (uintptr_t)Self->Queue;
      }
      else {
        QPtr += SizeOfElement;
      }
      ElemPtr += SizeOfElement;
    }
    (void)ZeroMem((void*)QPtr, SizeOfElement);
    Self->WriteIndex = Windex;
  }
  return Count;
}
Exemple #3
0
bool SOCKETFIFO_IsFull (void) {
    return FIFO_IsFull (socketfifo);
}