dev_sts.c 6.06 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             
***
*** $Workfile:devapi.c$
*** $Revision: 1.1 $
*** $Date: 2003/04/08 06:19:42 $
***
*** Comments:      
***   This file contains the USB device API.
***                                                               
**************************************************************************
*END*********************************************************************/

#include "os_bb.h"
#include "osint.h"

/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_device_unstall_endpoint
* Returned Value : USB_OK or error code
* Comments       :
*     Clears an endpoint after a stall
* 
*END*--------------------------------------------------------------------*/
void _usb_device_unstall_endpoint
   (
      /* [IN] Handle to the USB device */
      _usb_device_handle handle,
      
      /* [IN] Endpoint to clear */
      uint_8               endpoint_number,
      
      /* [IN] the direction */
      uint_8               direction
   )
{ /* Body */
   USB_DEV_STATE_STRUCT_PTR usb_dev_ptr;
   
   usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle;
   USB_lock();   

   _usb_dci_vusb11_unstall_endpoint(handle, endpoint_number);
      
   usb_dev_ptr->XDSEND[endpoint_number].STATUS = USB_STATUS_IDLE;
   usb_dev_ptr->XDRECV[endpoint_number].STATUS = USB_STATUS_IDLE;

   USB_unlock();
} /* EndBody */

/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_device_get_status
* Returned Value : USB_OK or error code
* Comments       :
*     Provides API to access the USB internal state.
* 
*END*--------------------------------------------------------------------*/
uint_8 _usb_device_get_status
   (
      /* [IN] Handle to the USB device */
      _usb_device_handle handle,
      
      /* [IN] What to get the status of */
      uint_8 component,
      
      /* [OUT] The requested status */
      uint_16_ptr status
   )
{ /* Body */
   USB_DEV_STATE_STRUCT_PTR usb_dev_ptr;

   usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle;
   USB_lock();
   switch (component) {

      case USB_STATUS_DEVICE_STATE:
         *status = usb_dev_ptr->USB_STATE;
         break;

      case USB_STATUS_DEVICE:
         *status = usb_dev_ptr->USB_DEVICE_STATE;
         break;

      case USB_STATUS_INTERFACE:
         break;
         
      case USB_STATUS_ADDRESS:
         *status = usb_dev_ptr->USB->ADDRESS;
         break;
         
      case USB_STATUS_CURRENT_CONFIG:
         *status = usb_dev_ptr->USB_CURR_CONFIG;
         break;

      case USB_STATUS_SOF_COUNT:
         *status = usb_dev_ptr->USB_SOF_COUNT;
         break;
         
      default:
         if (component & USB_STATUS_ENDPOINT) {
            *status = _usb_dci_vusb11_get_endpoint_status(handle,
               component & USB_STATUS_ENDPOINT_NUMBER_MASK);
         } else {
            USB_unlock();
            return USBERR_BAD_STATUS;
         } /* Endif */
         break;

   } /* Endswitch */
   USB_unlock();
   return USB_OK;   
} /* EndBody */

/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_device_set_status
* Returned Value : USB_OK or error code
* Comments       :
*     Provides API to set internal state
* 
*END*--------------------------------------------------------------------*/
uint_8 _usb_device_set_status
   (
      /* [IN] Handle to the usb device */
      _usb_device_handle handle,
      
      /* [IN] What to set the status of */
      uint_8             component,
      
      /* [IN] What to set the status to */
      uint_16            setting
   )
{ /* Body */
   USB_DEV_STATE_STRUCT_PTR usb_dev_ptr;

   usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle;
   USB_lock();
   switch (component) {

      case USB_STATUS_DEVICE_STATE:
         usb_dev_ptr->USB_STATE = setting;
         break;

      case USB_STATUS_DEVICE:
         usb_dev_ptr->USB_DEVICE_STATE = setting;
         break;

      case USB_STATUS_INTERFACE:
         break;

      case USB_STATUS_ADDRESS:
         usb_dev_ptr->USB->ADDRESS = setting;
         break;

      case USB_STATUS_CURRENT_CONFIG:
         usb_dev_ptr->USB_CURR_CONFIG = setting;
         break;
         
      case USB_STATUS_SOF_COUNT:
         usb_dev_ptr->USB_SOF_COUNT = setting;
         break;
         
      default:
         if (component & USB_STATUS_ENDPOINT) {
            _usb_dci_vusb11_set_endpoint_status(handle,
               component & USB_STATUS_ENDPOINT_NUMBER_MASK,
               setting);
         } else {
            USB_unlock();
            return USBERR_BAD_STATUS;
         } /* Endif */
         break;

   } /* Endswitch */
   USB_unlock();
   return USB_OK;   
} /* EndBody */

/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_device_stall_endpoint
* Returned Value : None
* Comments       :
*     Stalls the specified endpoint
* 
*END*--------------------------------------------------------------------*/
void _usb_device_stall_endpoint
   (
      /* [IN] Handle to the USB device */
      _usb_device_handle   handle,
      
      /* [IN] The endpoint to stall */
      uint_8               endpoint_num,
            
      /* [IN] the direction */
      uint_8               direction
   )
{ /* Body */
   USB_DEV_STATE_STRUCT_PTR usb_dev_ptr;
   
   usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle;

   usb_dev_ptr->XDSEND[endpoint_num].STATUS = USB_STATUS_STALLED;
   usb_dev_ptr->XDRECV[endpoint_num].STATUS = USB_STATUS_STALLED;

   _usb_device_set_status(handle, USB_STATUS_ENDPOINT | endpoint_num, 1);

   return;   
} /* EndBody */