/**************************************************************************//**
\brief Receive byte from usb FIFO.

\param[out]
  p - pointer to byte memory;

\return
    true - there is received byte; \n
    false - there is not received byte;
******************************************************************************/
bool getByteUsbFifo(uint8_t *p)
{
  if (!GPIO_RXF_read())
  {
    GPIO_RD_clr();
    NOP;
    *p = USB_DATA_PIN;
    GPIO_RD_set();
    return true;
  }

  return false;
}
/**************************************************************************//**
\brief Puts the byte received to the cyclic buffer.
******************************************************************************/
static void usbfifoRxBufferFiller(void)
{
  uint16_t           old;
  uint16_t           poW;
  uint16_t           poR;
  uint8_t           *buffer;
  HalUsartService_t *control;

  if (!usbfifoPointDescrip)
  { // unregistered intrrupt is occurred
    HAL_DisableIrq(IRQ_7);
    return;
  }

  control = &usbfifoPointDescrip->service;
  poW = control->rxPointOfWrite;
  poR = control->rxPointOfRead;
  buffer = usbfifoPointDescrip->rxBuffer;

  if (!buffer)
  {
    HAL_DisableIrq(IRQ_7);
    return;
  }

  old = poW;

  if (++poW == usbfifoPointDescrip->rxBufferLength)
    poW = 0;

  if (poW == poR)
  { // Buffer full.
    HAL_DisableIrq(IRQ_7);
    return;
  } // Buffer full.

  control->rxPointOfWrite = poW;
  GPIO_RD_clr();
  NOP;
  buffer[old] = USB_DATA_PIN;
  GPIO_RD_set();
  control->rxBytesInBuffer++;
  usbfifoPostTask(USB_FIFO_TASK_RX);
}