Example #1
0
static inline int usbd_cdc_Start_Rx(void *pdev)
{

  /* USB_Rx_Buffer_length is used here to keep track of
   * available _contiguous_ buffer space in USB_Rx_Buffer.
   */
  uint32_t USB_Rx_length;
  if (USB_Rx_Buffer_head >= USB_Rx_Buffer_tail)
    USB_Rx_Buffer_length = USB_RX_BUFFER_SIZE;

  USB_Rx_length = ring_space_contig(USB_Rx_Buffer_length, USB_Rx_Buffer_head, USB_Rx_Buffer_tail);

  if (USB_Rx_length < CDC_DATA_OUT_PACKET_SIZE) {
    USB_Rx_length = ring_space_wrapped(USB_Rx_Buffer_length, USB_Rx_Buffer_head, USB_Rx_Buffer_tail);
    if (USB_Rx_length < CDC_DATA_OUT_PACKET_SIZE) {
      if (USB_Rx_State) {
        USB_Rx_State = 0;
        DCD_SetEPStatus(pdev, CDC_OUT_EP, USB_OTG_EP_TX_NAK);
      }
      return 0;
    }
    USB_Rx_Buffer_length = USB_Rx_Buffer_head;
    USB_Rx_Buffer_head = 0;
    if (USB_Rx_Buffer_tail == USB_Rx_Buffer_length)
      USB_Rx_Buffer_tail = 0;
  }
  if (!USB_Rx_State) {
    USB_Rx_State = 1;
    DCD_SetEPStatus(pdev, CDC_OUT_EP, USB_OTG_EP_TX_VALID);
  }
  DCD_EP_PrepareRx(pdev,
                   CDC_OUT_EP,
                   USB_Rx_Buffer + USB_Rx_Buffer_head,
                   CDC_DATA_OUT_PACKET_SIZE);
  return 1;
}
Example #2
0
    while (serial.available() > 0) {
        (void)serial.read();
    }
}

test(0_USBSERIAL_RingBufferHelperIsSane) {
    uint32_t size = 129;
    uint32_t head = 0;
    uint32_t tail = 0;

    head = 0;
    tail = 0;
    assertEqual(0, ring_data_avail(size, head, tail));
    assertEqual(128, ring_space_avail(size, head, tail));
    assertEqual(0, ring_data_contig(size, head, tail));
    assertEqual(128, ring_space_contig(size, head, tail));
    assertEqual(0, ring_space_wrapped(size, head, tail));

    head = 63;
    tail = 0;
    assertEqual(63, ring_data_avail(size, head, tail));
    assertEqual(65, ring_space_avail(size, head, tail));
    assertEqual(63, ring_data_contig(size, head, tail));
    assertEqual(65, ring_space_contig(size, head, tail));
    assertEqual(0, ring_space_wrapped(size, head, tail));

    head = 63;
    tail = 32;
    assertEqual(31, ring_data_avail(size, head, tail));
    assertEqual(97, ring_space_avail(size, head, tail));
    assertEqual(31, ring_data_contig(size, head, tail));