예제 #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);
}
예제 #2
0
/**
 * @brief Get a complete frame from USART2 (nonblocking)
 * @param buf Buffer for data (data will be null terminated for easier string manipulation)
 * @param len Length not including terminator character
 * @retval 0 Received frame
 * @retval 1 No frame in buffer
 * @retval 2 Frame error
 * TODO Add maximum length checking so as not to overflow
 */
int COMM_GetFrame(uint8_t* buf, uint8_t* len) {

  uint8_t c;
  *len = 0; // zero out length variable

  if (gotFrame) {
    while (1) {

      // no more data and terminator wasn't reached => error
      if (FIFO_IsEmpty(&rxFifo)) {
        *len = 0;
        println("Invalid frame");
        return 2;
      }
      FIFO_Pop(&rxFifo, &c);
      buf[(*len)++] = c;

      // if end of frame
      if (c == COMM_TERMINATOR) {
        (*len)--; // length without terminator character
        buf[*len] = 0; // USART terminator character converted to NULL terminator
        break;
      }

    }
    gotFrame--;
    return 0;

  } else {

    return 1;
  }

}
예제 #3
0
/**
 * @brief Get a char from USART2
 * @return Received char.
 * @warning Blocking function! Waits until char is received.
 */
char COMM_Getc(void) {

  uint8_t c;

  while (FIFO_IsEmpty(&rxFifo) == 1); // wait until buffer is not empty
  // buffer not empty => char was received

  FIFO_Pop(&rxFifo,&c); // Get data from RX buffer

  return c;
}
예제 #4
0
/**
 * @brief Callback for transmitting data to lower layer
 * @param c Transmitted data
 * @retval 0 There is no more data in buffer (stop transmitting)
 * @retval 1 Valid data in c
 */
int COMM_TxCallback(char* buf) {

  if (FIFO_IsEmpty(&txFifo)) {
    return 0;
  }

  // get all the data at one go
  int i = 0;
  while (!FIFO_Pop(&txFifo, buf+i)) {
    i++;
  }

  return i;
}
예제 #5
0
파일: uart2.c 프로젝트: kvp7206/STM32F4_SD
/**
 * @brief Get a char from USART2
 * @return Received char.
 * @warning Blocking function!
 */
uint8_t USART2_Getc(void) {

  uint8_t c;

  while (FIFO_IsEmpty(&rxFifo) == 1); // wait until buffer is not empty
  // buffer not empty => char was received

  USART_ITConfig(USART2, USART_IT_RXNE, DISABLE); // disable RX interrupt

  FIFO_Pop(&rxFifo,&c); // Get data from RX buffer

  USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); // enable RX interrupt

  return c;
}
예제 #6
0
파일: Fifo.c 프로젝트: B-Rich/edk2
/** Read or copy elements from the FIFO.

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

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

    @param[in]    Self        Pointer to the FIFO instance.
    @param[out]   pElement    Pointer to where to store the element(s) read from the FIFO.
    @param[in]    Count       Number of elements to dequeue.
    @param[in]    Consume     If TRUE, consume read elements.  Otherwise, preserve.

    @retval   0       The FIFO is empty.
    @retval   >=0     The number of elements read from the FIFO.
**/
static
size_t
EFIAPI
FIFO_Dequeue (
  cFIFO    *Self,
  void     *pElement,
  size_t    Count,
  BOOLEAN   Consume
  )
{
  UINTN         ElemPtr;
  UINTN         QPtr;
  UINT32        RDex;
  UINT32        SizeOfElement;
  UINT32        i;

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

  if(FIFO_IsEmpty(Self)) {
    Count = 0;
  }
  else {
    RDex          = Self->ReadIndex;
    SizeOfElement = Self->ElementSize;
    ElemPtr       = (UINTN)pElement;
    Count         = MIN(Count, Self->Count(Self, AsElements));

    QPtr = (UINTN)Self->Queue + (RDex * Self->ElementSize);
    for(i = 0; i < Count; ++i) {
      (void)CopyMem((void *)ElemPtr, (const void *)QPtr, Self->ElementSize);
      RDex = (UINT32)ModuloIncrement(RDex, Self->NumElements);
      if(RDex == 0) {   // If the index wrapped
        QPtr = (UINTN)Self->Queue;
      }
      else {
        QPtr += Self->ElementSize;
      }
      ElemPtr += Self->ElementSize;
    }
    if(Consume) {
      Self->ReadIndex = RDex;
    }
  }
  return Count;
}
예제 #7
0
void USART3_IRQHandler(void)
{  
    if(USART_GetITStatus(USART3, USART_IT_TXE) != RESET)
    {   
		while(!FIFO_IsEmpty(usart3_tx_fifo))
		{
			uint8_t tx_data;
			FIFO_Pop(usart3_tx_fifo, &tx_data);
			while (USART_GetFlagStatus(USART3,USART_FLAG_TC) == RESET);
			USART_SendData(USART3, tx_data);
		}
		USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
    }
	else if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
    {
        uint8_t rx_data = USART_ReceiveData(USART3);
       
    }       
}
예제 #8
0
bool SOCKETFIFO_IsEmpty (void) {
    return FIFO_IsEmpty (socketfifo);
}