host_snd.c 3.66 KB
/*HEADER******************************************************************
**************************************************************************
*** 
*** Copyright (c) 2001-2002 ARC International.
*** All rights reserved                                          
***                                                              
*** This software embodies materials and concepts which are      
*** confidential to ARC International and is made
*** available solely pursuant to the terms of a written license   
*** agreement with ARC International             
***
*** File: hostapi.c
***
*** Comments:      
***   This file contains the USB Host API specific functions.
***                                                               
**************************************************************************
*END*********************************************************************/
#ifdef __USB_OS_MQX__
#include "mqx.h"
#include "bsp.h"
#else
#include "types.h"
#include "vusb11.h"
#include "usb.h"
#include "hostapi.h"
#endif
#include "usbprv.h"
#include "usbhprv.h"

/*FUNCTION*-------------------------------------------------------------
*
*  Function Name  : _usb_host_send_data
*  Returned Value : error or status of the transfer
*  Comments       :
* The Send Data routine is non-blocking routine that causes a block of data 
* to be made available for transmission to the USB host.
*
*END*-----------------------------------------------------------------*/
uint_8 _usb_host_send_data
   (
      /* [IN] the USB Host state structure */
      _usb_host_handle  handle,
      
      /* Index into the Pipe Descriptor Array */
      int_16            pipeid,

      /* Address of the data to send */
      uchar_ptr         buff_ptr,

      /* Number of bytes to Send */
      uint_32           length
   )
{ /* Body */
   PIPE_DESCRIPTOR_STRUCT_PTR pipe_descr_ptr;
   USB_HOST_STATE_STRUCT_PTR usb_host_ptr;
   
   usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)handle;

   /* Check if pipe id is valid */
   if (pipeid < usb_host_ptr->MAX_PIPES) {
      pipe_descr_ptr = &usb_host_ptr->PIPE_DESCRIPTOR_BASE_PTR[pipeid];
   } else {
      return USBERR_INVALID_PIPE_ID;
   } /* Endif */

   USB_lock();

   /* Check if a previously queued transfer is still in progress */
   if (pipe_descr_ptr->STATUS != USB_STATUS_IDLE) {
      USB_unlock();
      return USB_STATUS_TRANSFER_IN_PROGRESS;
   } else {
      USB_unlock();
      /* Initialize the pipe descriptor with the new send request */
      pipe_descr_ptr->SOFAR = 0;
      pipe_descr_ptr->TX1_PTR = buff_ptr;
      if ((pipe_descr_ptr->PIPETYPE == USB_ISOCHRONOUS_PIPE) && 
         (pipe_descr_ptr->TODO1 > pipe_descr_ptr->MAX_PKT_SIZE)) 
      {
         /* For isochronous pipes, we transfer a mzximum of MAX_PKT_SIZE 
         ** packet 
         */
         pipe_descr_ptr->TODO1 = pipe_descr_ptr->MAX_PKT_SIZE;
      } else {
         /* For all others max of 64KB */
         pipe_descr_ptr->TODO1 = length;
      } /* Endif */

      USB_lock();
      
      /* return successful transfer initiation status */
      pipe_descr_ptr->STATUS = USB_STATUS_TRANSFER_QUEUED;

#ifdef __USB_OS_MQX__

      /* Call the low-level send routine */      
      ((USB_CALLBACK_FUNCTIONS_STRUCT_PTR)usb_host_ptr->CALLBACK_STRUCT_PTR)->\
         HOST_SEND(handle, pipe_descr_ptr);
#else
      _usb_hci_vusb11_send_data(handle, pipe_descr_ptr);
#endif

      /* Indicate that a packet is pending */      
      pipe_descr_ptr->PACKETPENDING = TRUE;

      USB_unlock();
   } /* Endif */
   
   return USB_STATUS_TRANSFER_QUEUED;

} /* Endbody */

/* EOF */