Data Transfer Functions

group group_usb_dev_functions_data_transfer

Functions

cy_en_usb_dev_status_t Cy_USB_Dev_StartReadEp(uint32_t endpoint, cy_stc_usb_dev_context_t *context)

Start a reading on a certain endpoint.

note

The read is not allowed for OUT endpoints after SET_CONFIGURATION or SET_INTERFACE request therefore this function must be called before reading data from OUT endpoints.

Return

Status code of the function execution cy_en_usb_dev_status_t.

Parameters
  • endpoint: The OUT data endpoint number.

  • context: The pointer to the context structure cy_stc_usb_dev_context_t allocated by the user. The structure is used during the USB Device operation for internal configuration and data retention. The user must not modify anything in this structure.

cy_en_usb_dev_status_t Cy_USB_Dev_ReadEpBlocking(uint32_t endpoint, uint8_t *buffer, uint32_t size, uint32_t *actSize, int32_t timeout, cy_stc_usb_dev_context_t *context)

Read data received from USB Host from a certain endpoint.

Before calling this function, Cy_USB_Dev_StartReadEp must be called. This function is blocking and returns after successful USB Host transfer, or an error or timeout occurred.

Return

Status code of the function execution cy_en_usb_dev_status_t.

Parameters
  • endpoint: The OUT data endpoint number.

  • buffer: The pointer to buffer that stores data that was read.

    Allocate buffer using

    CY_USB_DEV_ALLOC_ENDPOINT_BUFFER macro to make it USBFS driver configuration independent (See Allocate Data Endpoint Buffer for more information).

  • size: The number of bytes to read. This value must be less or equal to endpoint maximum packet size.

  • actSize: The number of bytes that were actually read.

  • timeout: Defines in milliseconds the time for which this function can block. If that time expires the function returns. To wait forever pass CY_USB_DEV_WAIT_FOREVER.

  • context: The pointer to the context structure cy_stc_usb_dev_context_t allocated by the user. The structure is used during the USB Device operation for internal configuration and data retention. The user must not modify anything in this structure.

cy_en_usb_dev_status_t Cy_USB_Dev_ReadEpNonBlocking(uint32_t endpoint, uint8_t *buffer, uint32_t size, uint32_t *actSize, cy_stc_usb_dev_context_t *context)

Read data received from USB Host from a certain endpoint.

Before calling this function, Cy_USB_Dev_StartReadEp must be called.

Return

Status code of the function execution cy_en_usb_dev_status_t.

Parameters
  • endpoint: The OUT data endpoint number.

  • buffer: The pointer to buffer that stores data that was read.

    Allocate buffer using

    CY_USB_DEV_ALLOC_ENDPOINT_BUFFER macro to make it USBFS driver configuration independent (See Allocate Data Endpoint Buffer for more information).

  • size: The number of bytes to read. This value must be less than or equal to endpoint maximum packet size.

  • actSize: The number of bytes that were actually read.

  • context: The pointer to the context structure cy_stc_usb_dev_context_t allocated by the user. The structure is used during the USB Device operation for internal configuration and data retention. The user must not modify anything in this structure.

cy_en_usb_dev_status_t Cy_USB_Dev_AbortEpTransfer(uint32_t endpoint, cy_stc_usb_dev_context_t *context)

Aborts pending read or write endpoint operation.

If there is any bus activity after abort operation requested the function waits for its completion or timeout. The timeout is time to transfer bulk or interrupt packet of maximum playload size. If this bus activity is a transfer to the aborting endpoint the received data is lost and endpoint transfer completion callbacks is not invoked. After function returns new read or write endpoint operation can be submitted.

note

The abort operation is not supported for ISOC endpoints because these endpoints do not have handshake and are always accessible by the USB Host. Therefore, abort can cause unexpected behavior.

Return

Status code of the function execution cy_en_usb_dev_status_t.

Parameters
  • endpoint: The data endpoint number.

  • context: The pointer to the context structure cy_stc_usb_dev_context_t allocated by the user. The structure is used during the USB Device operation for internal configuration and data retention. The user must not modify anything in this structure.

__STATIC_INLINE uint32_t Cy_USB_Dev_GetEpNumToRead (uint32_t endpoint, cy_stc_usb_dev_context_t const *context)

Returns the number of bytes that available to be read from a certain endpoint buffer.

Before calling this function ensure that the Host wrote data into the endpoint. The returned value is updated after the Host access to the endpoint but remains unchanged after data has been read from the endpoint buffer.

Return

Number of bytes in OUT endpoint buffer.

Parameters
  • endpoint: The OUT data endpoint number.

  • context: The pointer to the context structure cy_stc_usb_dev_context_t allocated by the user. The structure is used during the USB Device operation for internal configuration and data retention. The user must not modify anything in this structure.

cy_en_usb_dev_status_t Cy_USB_Dev_WriteEpBlocking(uint32_t endpoint, uint8_t const *buffer, uint32_t size, int32_t timeout, cy_stc_usb_dev_context_t *context)

Write data to be transferred to USB Host from a certain endpoint.

This function is blocking and returns after successful USB Host transfer, or an error or timeout occurred.

Return

Status code of the function execution cy_en_usb_dev_status_t.

Parameters
  • endpoint: The IN data endpoint number.

  • buffer: The pointer to the buffer containing data bytes to write.

    Allocate buffer using

    CY_USB_DEV_ALLOC_ENDPOINT_BUFFER macro to make it USBFS driver configuration independent (See Allocate Data Endpoint Buffer for more information).

  • size: The number of bytes to write. This value must be less than or equal to endpoint maximum packet size.

  • timeout: Defines in milliseconds the time for which this function can block. If that time expires, the function returns. To wait forever, pass CY_USB_DEV_WAIT_FOREVER.

  • context: The pointer to the context structure cy_stc_usb_dev_context_t allocated by the user. The structure is used during the USB Device operation for internal configuration and data retention. The user must not modify anything in this structure.

cy_en_usb_dev_status_t Cy_USB_Dev_WriteEpNonBlocking(uint32_t endpoint, uint8_t const *buffer, uint32_t size, cy_stc_usb_dev_context_t *context)

Write data to be transferred to USB Host from a certain endpoint.

Return

Status code of the function execution cy_en_usb_dev_status_t.

Parameters
  • endpoint: The IN data endpoint number.

  • buffer: The pointer to the buffer containing data bytes to write.

    Allocate buffer using

    CY_USB_DEV_ALLOC_ENDPOINT_BUFFER macro to make it USBFS driver configuration independent (See Allocate Data Endpoint Buffer for more information).

  • size: The number of bytes to write. This value must be less than or equal to endpoint maximum packet size.

  • context: The pointer to the context structure cy_stc_usb_dev_context_t allocated by the user. The structure is used during the USB Device operation for internal configuration and data retention. The user must not modify anything in this structure.

__STATIC_INLINE void Cy_USB_Dev_OverwriteHandleTimeout (cy_fn_usb_dev_handle_timeout_ptr_t handleTimeout, cy_stc_usb_dev_context_t *context)

Overwrite the handle timeout function that is implemented internally.

The internal implementation converts one timeout unit to milliseconds.

Parameters
  • handleTimeout: The pointer to function to be executed to handle timeout for blocking operations.

  • context: The pointer to the context structure cy_stc_usb_dev_context_t allocated by the user. The structure is used during the USB Device operation for internal configuration and data retention. The user must not modify anything in this structure.