IPC@CHIP® RTOS-PPC – API Documentation

Header image

Main page


usbHostTransfer.c

This example demonstrates the several applications of the function usbHostTransfer(). Besides this, the function usbHostReserveEp0() can be seen in action.

// -----------------------------------------------------------------------------
// 1st example: Send some data on out endpoint 1
void example1(void)
{
  int result;
  unsigned char *buffer;
  
  
  // Allocate buffer
  buffer = malloc(BUFFER_SIZE);
  if(!buffer)
    ;  // Error handling
  
  // Fill the buffer
  ...
  
  // Send
  result = usbHostTransfer(gAddress, 1, USB_SPEC_PID_OUT, buffer, BUFFER_SIZE);
  if(result != USB_ERROR_NO)
    ;  // Error handling
}



// -----------------------------------------------------------------------------
// 2nd example: Send a standard device request on endpoint 0
void example2(void)
{
  int result;
  UsbSpecDeviceRequest *request;
  
  
  // Reserve endpoint 0
  while((result = usbHostReserveEp0(gDriverId, gAddress)) == USB_ERROR_BUSY)
    RTX_Sleep_Time(1);
  if(result != USB_ERROR_NO)
    ;  // Error handling
    
  // Allocate memory for the request  
  request = malloc(sizeof(UsbSpecDeviceRequest));
  if(!request)
    ;  // Error handling
    
  // Fill the request - class-specific request, data transfer from one of the
  // device's interfaces to the host
  request->requestType = USB_SPEC_DEVICE_REQUEST_TYPE_DEVICE_TO_HOST
                         | USB_SPEC_DEVICE_REQUEST_TYPE_CLASS_SPECIFIC
                         | USB_SPEC_DEVICE_REQUEST_TYPE_RECEIVER_INTERFACE;
  request->...
  
  // Send the request
  result = usbHostTransfer(gAddress, 0, USB_SPEC_PID_SETUP,
                           (unsigned char *)request,
                           sizeof(UsbSpecDeviceRequest));
  if(result != USB_ERROR_NO)
    ;  // Error handling
    
  // The endpoint 0 will be released, when the whole transaction is finished.
}



// -----------------------------------------------------------------------------
// 3rd example: Receive some data on in endpoint 4
void example3(void)
{
  int result;
  unsigned char *buffer;
  
  
  // Allocate buffer
  buffer = malloc(BUFFER_SIZE);
  if(!buffer)
    ;  // Error handling
  
  // Receive
  result = usbHostTransfer(gAddress, 4, USB_SPEC_PID_IN, buffer, BUFFER_SIZE);
  if(result != USB_ERROR_NO)
    ;  // Error handling
}





Top of page | Main page

Copyright © 2017 Beck IPC GmbH
Generated on Thu Jan 26 16:21:35 2017 by Doxygen 1.6.1