コード例 #1
0
ファイル: host_main.c プロジェクト: jewlenchow/MQX_3.8.1
/*FUNCTION*-------------------------------------------------------------
*
*  Function Name  : _usb_host_init_call_interface
*  Returned Value : USB_OK or error
*  Comments       :
*  _usb_host_init_call_interface routine is used to initialize device
*  drivers when the USB host stack is initialized.  Device drivers may
*  perform device register, interrupt, and internal data structure
*  initialization.
*
*END*-----------------------------------------------------------------*/
USB_STATUS _usb_host_init_call_interface
(
   /* [IN] the USB Host state structure */
   _usb_host_handle              handle
)
{
   USB_STATUS error = USB_OK;
   USB_HOST_CALLBACK_FUNCTIONS_STRUCT_PTR temp_ptr;
   USB_HOST_STATE_STRUCT_PTR usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)handle;
   
#ifdef USB_HOST_INCLUDE_TASK_SUPPORT
   error = _usb_rtos_host_init ();
   
   if (error != USB_OK)
   {
      return USB_log_error(__FILE__,__LINE__,error);
   }
#endif
   
   temp_ptr = (USB_HOST_CALLBACK_FUNCTIONS_STRUCT_PTR)usb_host_ptr->CALLBACK_STRUCT_PTR;

   if (temp_ptr->HOST_INIT != NULL)
   {
      error = temp_ptr->HOST_INIT (handle);
   }

#ifdef USB_HOST_INCLUDE_TASK_SUPPORT
   if (error != USB_OK)
   {
      error = _usb_rtos_host_shutdown();
   }
#endif

   return USB_log_error(__FILE__,__LINE__,error);
}
コード例 #2
0
ファイル: host_ch9.c プロジェクト: gxliu/MQX_3.8.0
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_ch9_clear_feature
* Returned Value : USB_OK, or error status
* Comments       :
*     Function to process standard device request in Chapter 9.
*     See Table 9-3 p. 250 of USB 2.0 specification.
* 
*END*--------------------------------------------------------------------*/
USB_STATUS  _usb_host_ch9_clear_feature
   (
      /* usb device */
      _usb_device_instance_handle   dev_handle,

      /* request type device/interface/endpoint */
      uint_8                        req_type,

      /* device = 0, or interface/endpoint */
      uint_8                        intf_endpt,

      /* feature selection */
      uint_16                       feature
   )
{ /* Body */

   USB_SETUP  request = req_prototype;
   USB_STATUS error = USB_OK;

   #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_ch9_clear_feature");
   #endif

   USB_lock();
   
   switch (req_type) {
      case REQ_TYPE_DEVICE:
         break;
      case REQ_TYPE_INTERFACE:
      case REQ_TYPE_ENDPOINT:
         *(uint_16*)request.WINDEX = HOST_TO_LE_SHORT(intf_endpt);
         break;
      default:
         USB_unlock();
         #ifdef _HOST_DEBUG_
               DEBUG_LOG_TRACE("_usb_host_ch9_clear_feature, invalid request");
         #endif
         return USB_log_error(__FILE__,__LINE__,USBERR_INVALID_BMREQ_TYPE);
   } /* EndSwitch */

   request.BMREQUESTTYPE = (uchar)(req_type | REQ_TYPE_OUT);
   request.BREQUEST = REQ_CLEAR_FEATURE;
   *(uint_16*)request.WVALUE = HOST_TO_LE_SHORT(feature);

   error = usb_host_ch9_dev_req(dev_handle, &request, NULL);

   USB_unlock();

   #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_ch9_clear_feature, SUCCESSFUL");
   #endif
   return USB_log_error(__FILE__,__LINE__,error);

} /* EndBody */
コード例 #3
0
ファイル: host_ch9.c プロジェクト: gxliu/MQX_3.8.0
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_ch9_get_status
* Returned Value : USB_OK, or error status
* Comments       :
*     Function to process standard device request in Chapter 9.
*     See Table 9-3 p. 250 of USB 2.0 specification.
* 
*END*--------------------------------------------------------------------*/
USB_STATUS  _usb_host_ch9_get_status
   (
      /* usb device */
      _usb_device_instance_handle   dev_handle,

      /* request type device/interface/endpoint */
      uint_8            req_type,

      /* device = 0, or interface/endpoint */
      uint_8            intf_endpt,

      /* returned status */
      uchar_ptr         buffer
   )
{ /* Body */

   USB_SETUP  request = req_prototype;
   USB_STATUS error = USB_OK;

   #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_ch9_get_status");
   #endif

   USB_lock();

   switch (req_type) {
      case REQ_TYPE_DEVICE:
      case REQ_TYPE_INTERFACE:
      case REQ_TYPE_ENDPOINT:
         break;
      default:
         USB_unlock();
         #ifdef _HOST_DEBUG_
               DEBUG_LOG_TRACE("_usb_host_ch9_get_status, invalid parameter");
         #endif
         return USB_log_error(__FILE__,__LINE__,USBERR_INVALID_BMREQ_TYPE);
   } /* EndSwitch */

   request.BMREQUESTTYPE = (uchar)(req_type | REQ_TYPE_IN);
   request.BREQUEST = REQ_GET_STATUS;
   *(uint_16*)request.WINDEX = HOST_TO_LE_SHORT(intf_endpt);
   *(uint_16*)request.WLENGTH = HOST_TO_LE_SHORT_CONST(2);

   error = usb_host_ch9_dev_req(dev_handle, &request, buffer);
   USB_unlock();

   #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_ch9_get_status, SUCCESSFUL");
   #endif
   return USB_log_error(__FILE__,__LINE__,error);

} /* EndBody */
コード例 #4
0
ファイル: usb_host_msd_bo.c プロジェクト: gxliu/MQX_3.8.0
USB_STATUS usb_class_mass_getmaxlun_bulkonly
   (
      CLASS_CALL_STRUCT_PTR      ccs_ptr,
      uint_8_ptr                 pLUN,
      tr_callback                callback
   )
{ /* Body */
   USB_STATUS                       status = USBERR_NO_INTERFACE;
   USB_SETUP                        request;
   USB_MASS_CLASS_INTF_STRUCT_PTR   intf_ptr;

   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_class_mass_getmaxlun_bulkonly");
   #endif
   
   /* Pointer validity-checking, clear memory, init header */
   USB_lock();
   if (usb_host_class_intf_validate(ccs_ptr)) {
      intf_ptr = (USB_MASS_CLASS_INTF_STRUCT_PTR) ccs_ptr->class_intf_handle;
      status = usb_hostdev_validate(intf_ptr->G.dev_handle);
   } /* Endif */

   if (status) {
      USB_unlock();

      #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("usb_class_mass_getmaxlun_bulkonly, error status");
      #endif
   return USB_log_error(__FILE__,__LINE__,status);
   } /* Endif */

   /* Get the number of logical units on the device */
   request.BMREQUESTTYPE = REQ_TYPE_CLASS | REQ_TYPE_INTERFACE | REQ_TYPE_IN;
   request.BREQUEST = GET_MAX_LUN;
   *(uint_16*)request.WVALUE = HOST_TO_LE_SHORT_CONST(0);
   *(uint_16*)request.WINDEX = HOST_TO_LE_SHORT(((INTERFACE_DESCRIPTOR_PTR)intf_ptr->G.intf_handle)->bInterfaceNumber);
   *(uint_16*)request.WLENGTH = HOST_TO_LE_SHORT_CONST(1);

   /* Send request */
   status = _usb_hostdev_cntrl_request (intf_ptr->G.dev_handle,
      &request, (uchar_ptr)pLUN, callback, NULL);
   USB_unlock();

   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_class_mass_getmaxlun_bulkonly, SUCCESSFUL");
   #endif
   
   return USB_log_error(__FILE__,__LINE__,status);


} /* Endbody */
コード例 #5
0
ファイル: usb_host_msd_bo.c プロジェクト: gxliu/MQX_3.8.0
/*FUNCTION*----------------------------------------------------------------
*
* Function Name  : usb_class_mass_get_app
* Returned Value : CLASS_CALL_STRUCT_PTR if class found
* Comments       :
*     This function returns stored application handle as it was passed as
*     a param in select_interface.
*
*END*--------------------------------------------------------------------*/
USB_STATUS usb_class_mass_get_app
   (
      /* [IN] handle of device */
      _usb_device_instance_handle dev_ptr,

      /* [IN] pointer to interface descriptor */
      _usb_interface_descriptor_handle intf_ptr,

      /* [OUT] pointer to CLASS_CALL_STRUCT to be filled in */
      CLASS_CALL_STRUCT_PTR   _PTR_ ccs_ptr
   )
{
    USB_STATUS                    error;
    GENERAL_CLASS_PTR             parser;

    USB_lock();
 
    error = usb_hostdev_validate (dev_ptr);
    if (error != USB_OK) {
        USB_unlock();
        #ifdef _HOST_DEBUG_
            DEBUG_LOG_TRACE("usb_class_hub_get_app, FAILED");
        #endif
        return USB_log_error(__FILE__,__LINE__,error);
    } /* EndIf */
    
    for (parser = (GENERAL_CLASS_PTR) mass_anchor; parser != NULL; parser = parser->next) {
        if (parser->dev_handle == dev_ptr && parser->intf_handle == intf_ptr)
            break;
    }
    
    if (parser != NULL) {
        USB_MASS_CLASS_INTF_STRUCT_PTR msd = (USB_MASS_CLASS_INTF_STRUCT_PTR) parser;
        *ccs_ptr = msd->APP;
    }
    else {
        USB_unlock();
        #ifdef _HOST_DEBUG_
            DEBUG_LOG_TRACE("usb_class_mass_get_app, not found");
        #endif
        return USB_log_error(__FILE__,__LINE__,USBERR_NOT_FOUND);
    }
    
    USB_unlock();
    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("usb_class_mass_get_app, SUCCESSFUL");
    #endif
    return USB_OK;
    
}
コード例 #6
0
ファイル: usb_host_msd_bo.c プロジェクト: gxliu/MQX_3.8.0
USB_STATUS usb_class_mass_clear_bulk_pipe_on_usb
   (
      USB_MASS_CLASS_INTF_STRUCT_PTR   intf_ptr
   )
{ /* Body */
   USB_STATUS                    status = USB_OK;
   PIPE_INIT_PARAM_STRUCT_PTR    pBulk_pipe = NULL;
   COMMAND_OBJECT_PTR            cmd_ptr = NULL;
   uint_8                        direction;

   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_class_mass_clear_bulk_pipe_on_usb");
   #endif
   
   /* Nothing can be done if there is nothing pending */
   usb_class_mass_get_pending_request(intf_ptr, &cmd_ptr);
   if (cmd_ptr == NULL) 
   {
      #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("usb_class_mass_clear_bulk_pipe_on_usb, no matching request");
      #endif
      return USB_log_error(__FILE__,__LINE__,(USB_STATUS)USB_MASS_NO_MATCHING_REQUEST);
   } /* Endif */

   /* Determine pipe (Bulk IN or Bulk OUT) to clear */
   if ((cmd_ptr->CBW_PTR->BMCBWFLAGS & MASK_NON_DIRECTION_BITS) == DIRECTION_IN) {
      pBulk_pipe = (PIPE_INIT_PARAM_STRUCT_PTR)intf_ptr->BULK_IN_PIPE;
      direction = REQ_TYPE_IN;
   } else {
      pBulk_pipe = (PIPE_INIT_PARAM_STRUCT_PTR)intf_ptr->BULK_OUT_PIPE;
      direction = REQ_TYPE_OUT;
   } /* Endif */

   status = _usb_host_register_ch9_callback(intf_ptr->G.dev_handle,
      usb_class_mass_reset_callback, (pointer)intf_ptr);

   if (status == USB_OK || status == USB_STATUS_TRANSFER_QUEUED) {
      /* Send a CLEAR PIPE command */
      cmd_ptr->STATUS = STATUS_CLEAR_BULK_PIPE;
      status = _usb_host_ch9_clear_feature(intf_ptr->G.dev_handle,
         REQ_TYPE_ENDPOINT, (uint_8)(pBulk_pipe->ENDPOINT_NUMBER | direction), ENDPOINT_HALT);
   } /* Endif */

   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_class_mass_clear_bulk_pipe_on_usb, SUCCESSFUL");
   #endif
   
   return USB_log_error(__FILE__,__LINE__,status);
} /* Endbody */
コード例 #7
0
ファイル: host_main.c プロジェクト: jewlenchow/MQX_3.8.1
/*FUNCTION*-------------------------------------------------------------
*
*  Function Name  : _usb_host_cancel_call_interface
*  Returned Value : USB_OK or error
*  Comments       :
*  _usb_host_cancel_call_interface routine is used to cancel pending
*  transactions.  Device drivers may update/free internal data structures
* and/or modify registers to cancel the transaction.
*
*END*-----------------------------------------------------------------*/
USB_STATUS _usb_host_cancel_call_interface
(
   /* [IN] the USB Host state structure */
   _usb_host_handle     handle,
   
   /* [IN] Pipe descriptor */
   struct pipe_struct   _PTR_ pipe_ptr,
   
   /* [IN] Pipe transfer descriptor */
   struct tr_struct     _PTR_ tr_ptr
)
{
   USB_STATUS error = USB_OK;
   USB_HOST_CALLBACK_FUNCTIONS_STRUCT_PTR temp_ptr;
   USB_HOST_STATE_STRUCT_PTR usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)handle;
   
   temp_ptr = (USB_HOST_CALLBACK_FUNCTIONS_STRUCT_PTR)usb_host_ptr->CALLBACK_STRUCT_PTR;

   if (temp_ptr->HOST_CANCEL != NULL)
   {
      error = temp_ptr->HOST_CANCEL (handle, pipe_ptr, tr_ptr);
   }

   return USB_log_error(__FILE__,__LINE__,error);
}
コード例 #8
0
ファイル: usb_host_msd_bo.c プロジェクト: gxliu/MQX_3.8.0
boolean usb_class_mass_storage_device_command_cancel
   (
      /* Handle to class struct with the key */
      CLASS_CALL_STRUCT_PTR      ccs_ptr,

      /*Command */
      COMMAND_OBJECT_PTR         cmd_ptr
   )
{ /* Body */
   USB_MASS_CLASS_INTF_STRUCT_PTR   intf_ptr;
   USB_STATUS                       error = USBERR_NO_INTERFACE;
   boolean                          result = FALSE;
   
   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_class_mass_storage_device_command_cancel");
   #endif
   
   /* Pointer validity-checking, clear memory, init header */
   USB_lock();
   if (usb_host_class_intf_validate(ccs_ptr)) {
      intf_ptr = (USB_MASS_CLASS_INTF_STRUCT_PTR) ccs_ptr->class_intf_handle;
      error = usb_hostdev_validate (intf_ptr->G.dev_handle);
   } /* Endif */

   if ((error == USB_OK) || (error == USB_STATUS_TRANSFER_QUEUED)) {
      result = usb_class_mass_cancelq(intf_ptr, cmd_ptr);
   }
   USB_unlock();

   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_class_mass_storage_device_command_cancel, SUCCESSFUL");
   #endif
   
   return USB_log_error(__FILE__,__LINE__,result);
} /* Endbody */
コード例 #9
0
ファイル: host_ch9.c プロジェクト: gxliu/MQX_3.8.0
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_ch9_set_configuration
* Returned Value : USB_OK, or error status
* Comments       :
*     Function to process standard device request in Chapter 9.
*     See Table 9-3 p. 250 of USB 2.0 specification.
* 
*END*--------------------------------------------------------------------*/
USB_STATUS  _usb_host_ch9_set_configuration
   (
      /* usb device */
      _usb_device_instance_handle   dev_handle,

      /* configuration value */
      uint_16                       config
   )
{ /* Body */

   USB_SETUP  request = req_prototype;
   USB_STATUS error = USB_OK;

   #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_ch9_set_configuration");
   #endif

   USB_lock();

   request.BMREQUESTTYPE = REQ_TYPE_DEVICE | REQ_TYPE_OUT;
   request.BREQUEST = REQ_SET_CONFIGURATION;
   *(uint_16*)request.WVALUE = HOST_TO_LE_SHORT(config);

   error = usb_host_ch9_dev_req(dev_handle, &request, NULL);

   USB_unlock();
   
   #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_ch9_set_configuration SUCCESSFUL");
   #endif
   return USB_log_error(__FILE__,__LINE__,error);

} /* EndBody */
コード例 #10
0
ファイル: host_ch9.c プロジェクト: gxliu/MQX_3.8.0
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_ch9_set_address
* Returned Value : USB_OK, or error status
* Comments       :
*     Function to process standard device request in Chapter 9.
*     See Table 9-3 p. 250 of USB 2.0 specification.
* 
*END*--------------------------------------------------------------------*/
USB_STATUS  _usb_host_ch9_set_address
   (
      /* usb device */
      _usb_device_instance_handle   dev_handle
   )
{ /* Body */

   DEV_INSTANCE_PTR  dev_ptr = (DEV_INSTANCE_PTR)dev_handle;
   USB_SETUP  request = req_prototype;
   USB_STATUS error = USB_OK;

   #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_ch9_set_address");
   #endif

   USB_lock();

   request.BMREQUESTTYPE = REQ_TYPE_DEVICE | REQ_TYPE_OUT;
   request.BREQUEST = REQ_SET_ADDRESS;
   *(uint_16*)request.WVALUE = HOST_TO_LE_SHORT(dev_ptr->address);

   error = usb_host_ch9_dev_req(dev_handle, &request, NULL);

   USB_unlock();

   #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_ch9_set_address,SUCCESSFUL");
   #endif
   return USB_log_error(__FILE__,__LINE__,error);

} /* EndBody */
コード例 #11
0
ファイル: host_ch9.c プロジェクト: gxliu/MQX_3.8.0
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_ch9_get_configuration
* Returned Value : USB_OK, or error status
* Comments       :
*     Function to process standard device request in Chapter 9.
*     See Table 9-3 p. 250 of USB 2.0 specification.
* 
*END*--------------------------------------------------------------------*/
USB_STATUS  _usb_host_ch9_get_configuration
   (
      /* [IN] usb device */
      _usb_device_instance_handle   dev_handle,

      /* [OUT] configuration value */
      uchar_ptr                     buffer
   )
{ /* Body */

   USB_SETUP  request = req_prototype;
   USB_STATUS error = USB_OK;

   #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_ch9_get_configuration");
   #endif
   
   USB_lock();

   request.BMREQUESTTYPE = REQ_TYPE_DEVICE | REQ_TYPE_IN;
   request.BREQUEST = REQ_GET_CONFIGURATION;
   *(uint_16*)request.WLENGTH = HOST_TO_LE_SHORT_CONST(1);

   error = usb_host_ch9_dev_req(dev_handle, &request, buffer);

   USB_unlock();

   #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_ch9_get_configuration, SUCCESSFUL");
   #endif
   return USB_log_error(__FILE__,__LINE__,error);

} /* EndBody */
コード例 #12
0
ファイル: host_main.c プロジェクト: jewlenchow/MQX_3.8.1
/*FUNCTION*-------------------------------------------------------------
*
*  Function Name  : _usb_host_iso_packet_desc_list_alloc
*  Returned Value : USB_OK or error
*  Comments       :
*  _usb_host_iso_packet_desc_list_alloc is used by Host Controller Drivers (HCDs)
*  to allocate Isochronous Packet Descriptors.  HCDs allocate Isochronous Packet
*  Descriptors in response to HCD Requests from the USB Host Stack to initiate
*  isochronous transfers over the USB bus.  Note that the USB Host Stack passes
*  a PIPE_TR_STRUCT along with each data transfer request made to the HCD (see
*  definition of USB_CALLBACK_FUNCTIONS_STRUCT for a list of all HCD Requests).
*  
*  As isochronous packets are completed by physical host controllers, HCDs
*  store status, transfer size, and memory offsets of data for each completed
*  isochronous packet in Isochronous Packet Descriptors for later consumption
*  by USB Clients (e.g. class drivers, applications, etc.).  Note that a single
*  PIPE_TR_STRUCT representing an isochronous transfer may transfer multiple
*  isochronous packets across the USB bus.
*  
*  As an implementation note, each PIPE_TR_STRUCT structure provides ISO_PACKET_DESC_LIST
*  and ISO_PACKET_DESC_CURRENT_PTR members.  These members are owned by the HCD until
*  the HCD invokes the ISO_TR_CALLBACK function pointer in the PIPE_TR_STRUCT.  After
*  ISO_TR_CALLBACK is invoked the HCD reliquishes control of the PIPE_TR_STRUCT to
*  the USB Client which registered the callback (see usb_hostdev_iso_tr_init).  While
*  the HCD has ownership of the PIPE_TR_STRUCT, the ISO_PACKET_DESC_LIST member is used
*  to store the HCD-allocated descriptors while the ISO_PACKET_DESC_CURRENT_PTR member
*  is used by the HCD to keep track of the next unused descriptor on the list.
*  
*  Note: Isochronous Packet Descriptors are allocated from the Isochronous Packet
*  Descriptor Pool created during USB Host Stack initialization.  The number of descriptors
*  in the Isochronous Packet Descriptor Pool is user-configurable and can be changed by
*  adjusting the value of the USBCFG_HOST_NUM_ISO_PACKET_DESCRIPTORS macro in user_config.h.
*
*  Note: This function is not thread-safe
*
*END*-----------------------------------------------------------------*/
USB_STATUS _usb_host_iso_packet_desc_list_alloc
(
   uint_32 num_descs,   /* must not be zero */
   USB_ISO_PACKET_DESC_LIST_STRUCT_PTR desc_list_ptr  /* output */
)
{
   MQX_DLL_NODE_PTR sublist_head_ptr;
   MQX_DLL_NODE_PTR sublist_tail_ptr;
   uint_32 i;

   /* always allocate descriptors from the head of the free list */
   _mqx_dll_get_head_node (&usb_host_iso_packet_desc_pool.free_list, &sublist_head_ptr);
   
   /* check for allocation errors */
   sublist_tail_ptr = sublist_head_ptr;

   for (i = 0; i < num_descs - 1; i++)
   {
      _mqx_dll_get_next_node (sublist_tail_ptr, &sublist_tail_ptr);

      if (sublist_tail_ptr == NULL)
      {
         return USB_log_error(__FILE__,__LINE__,USBERR_ALLOC);
      }
   }

   /* allocate a block of descriptors */
   _mqx_dll_create_sublist ((MQX_DLL_LIST_PTR)&usb_host_iso_packet_desc_pool.free_list, sublist_head_ptr, sublist_tail_ptr, &desc_list_ptr->desc_list);
   
   return USB_OK;
}
コード例 #13
0
ファイル: host_main.c プロジェクト: jewlenchow/MQX_3.8.1
USB_STATUS _usb_host_iso_packet_desc_pool_create
(
   uint_32 num_descs
)
{
   uchar_ptr   mem_ptr;
   uint_32     pool_num_bytes;
   uint_32     i;
   
   pool_num_bytes = sizeof (USB_ISO_PACKET_DESC_STRUCT) * num_descs;

   mem_ptr = (uchar_ptr)USB_mem_alloc_zero(pool_num_bytes);
   
   if (mem_ptr == NULL)
   {
      return USB_log_error(__FILE__,__LINE__,USBERR_ALLOC);
   }

   _mem_set_type(mem_ptr, MEM_TYPE_USB_ISO_PACKET_DESC_STRUCT);

   usb_host_iso_packet_desc_pool.mem_ptr = mem_ptr;   
   _mqx_dll_list_init ((MQX_DLL_LIST_PTR)&usb_host_iso_packet_desc_pool.free_list);
   
   for (i = 0; i < num_descs; i++)
   {
      _mqx_dll_node_init (&((USB_ISO_PACKET_DESC_STRUCT_PTR)mem_ptr)[i].node);
      _mqx_dll_insert_at_tail ((MQX_DLL_LIST_PTR)&usb_host_iso_packet_desc_pool.free_list, &((USB_ISO_PACKET_DESC_STRUCT_PTR)mem_ptr)[i].node);
      ((USB_ISO_PACKET_DESC_STRUCT_PTR)mem_ptr)[i].buf_offset = 0;
      ((USB_ISO_PACKET_DESC_STRUCT_PTR)mem_ptr)[i].buf_length = 0;
      ((USB_ISO_PACKET_DESC_STRUCT_PTR)mem_ptr)[i].packet_status = USB_OK;
   }
   
   return USB_OK;
}
コード例 #14
0
ファイル: usb_host_ch9.c プロジェクト: BillyZhangZ/wifi
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_ch9_get_configuration
* Returned Value : USB_OK, or error status
* Comments       :
*     Function to process standard device request in Chapter 9.
*     See Table 9-3 p. 250 of USB 2.0 specification.
* 
*END*--------------------------------------------------------------------*/
usb_status  _usb_host_ch9_get_configuration
(
    /* [IN] usb device */
    usb_device_instance_handle   dev_handle,
    /* [OUT] configuration value */
    uint8_t *                     buffer
)
{ /* Body */
    usb_setup_t  request = req_prototype;
    usb_status error = USB_OK;

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_get_configuration");
    #endif

    request.bmrequesttype = REQ_TYPE_DEVICE | REQ_TYPE_IN;
    request.brequest = REQ_GET_CONFIGURATION;
    *(uint16_t*)request.wlength = USB_HOST_TO_LE_SHORT_CONST(1);

    error = usb_host_ch9_dev_req(dev_handle, &request, buffer);

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_get_configuration, SUCCESSFUL");
    #endif
    return USB_log_error(__FILE__,__LINE__,error);

} /* EndBody */
コード例 #15
0
ファイル: usb_host_ch9.c プロジェクト: BillyZhangZ/wifi
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_ch9_set_configuration
* Returned Value : USB_OK, or error status
* Comments       :
*     Function to process standard device request in Chapter 9.
*     See Table 9-3 p. 250 of USB 2.0 specification.
* 
*END*--------------------------------------------------------------------*/
usb_status  _usb_host_ch9_set_configuration
(
    /* usb device */
    usb_device_instance_handle     dev_handle,
    /* configuration value */
    uint16_t                       config
)
{ /* Body */
    usb_setup_t  request = req_prototype;
    usb_status   error = USB_OK;

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_set_configuration");
    #endif

    request.bmrequesttype = REQ_TYPE_DEVICE | REQ_TYPE_OUT;
    request.brequest = REQ_SET_CONFIGURATION;
    *(uint16_t*)request.wvalue = USB_HOST_TO_LE_SHORT(config);

    error = usb_host_ch9_dev_req(dev_handle, &request, NULL);

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_set_configuration SUCCESSFUL");
    #endif
    return USB_log_error(__FILE__,__LINE__,error);
} /* EndBody */
コード例 #16
0
ファイル: usb_host_ch9.c プロジェクト: BillyZhangZ/wifi
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_ch9_set_interface
* Returned Value : USB_OK, or error status
* Comments       :
*     Function to process standard device request in Chapter 9.
*     See Table 9-3 p. 250 of USB 2.0 specification.
* 
*END*--------------------------------------------------------------------*/
usb_status  _usb_host_ch9_set_interface
(
    /* usb device */
    usb_device_instance_handle   dev_handle,
    /* alternate setting */
    uint8_t            alternate,
    /* interface */
    uint8_t            intf
)
{ /* Body */
    usb_setup_t  request = req_prototype;
    usb_status error = USB_OK;

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_set_interface");
    #endif

    request.bmrequesttype = REQ_TYPE_INTERFACE | REQ_TYPE_OUT;
    request.brequest = REQ_SET_INTERFACE;
    *(uint16_t*)request.wvalue = USB_HOST_TO_LE_SHORT(alternate);
    *(uint16_t*)request.windex = USB_HOST_TO_LE_SHORT(intf);

    error = usb_host_ch9_dev_req(dev_handle, &request, NULL);

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_set_interface, SUCCESSFUL");
    #endif

    return USB_log_error(__FILE__,__LINE__,error);
} /* EndBody */
コード例 #17
0
ファイル: usb_host_ch9.c プロジェクト: BillyZhangZ/wifi
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_ch9_set_descriptor
* Returned Value : USB_OK, or error status
* Comments       :
*     Function to process standard device request in Chapter 9.
*     See Table 9-3 p. 250 of USB 2.0 specification.
* 
*END*--------------------------------------------------------------------*/
usb_status  _usb_host_ch9_set_descriptor
(
    /* usb device */
    usb_device_instance_handle   dev_handle,
    /* descriptor type & index */
    uint16_t           type_index,
    /* Language ID or 0 */
    uint16_t           lang_id,
    /* buffer length */
    uint16_t           buflen,
    /* descriptor buffer */
    uint8_t *         buffer
)
{ /* Body */
    usb_setup_t  request;
    usb_status error = USB_OK;
    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_set_descriptor");
    #endif

    request.bmrequesttype = REQ_TYPE_DEVICE | REQ_TYPE_OUT;
    request.brequest = REQ_SET_DESCRIPTOR;
    *(uint16_t*)request.wvalue = USB_HOST_TO_LE_SHORT(type_index);
    *(uint16_t*)request.windex = USB_HOST_TO_LE_SHORT(lang_id);
    *(uint16_t*)request.wlength = USB_HOST_TO_LE_SHORT(buflen);

    error = usb_host_ch9_dev_req(dev_handle, &request, buffer);

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_set_descriptor SUCCESSFUL");
    #endif

    return USB_log_error(__FILE__,__LINE__,error);
} /* EndBody */
コード例 #18
0
ファイル: usb_host_ch9.c プロジェクト: BillyZhangZ/wifi
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_ch9_set_address
* Returned Value : USB_OK, or error status
* Comments       :
*     Function to process standard device request in Chapter 9.
*     See Table 9-3 p. 250 of USB 2.0 specification.
* 
*END*--------------------------------------------------------------------*/
usb_status  _usb_host_ch9_set_address
(
    /* usb device */
    usb_device_instance_handle   dev_handle
)
{ /* Body */
    dev_instance_t*  dev_ptr = (dev_instance_t*)dev_handle;
    usb_setup_t  request = req_prototype;
    usb_status error = USB_OK;

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_set_address");
    #endif

    request.bmrequesttype = REQ_TYPE_DEVICE | REQ_TYPE_OUT;
    request.brequest = REQ_SET_ADDRESS;
    *(uint16_t*)request.wvalue = USB_HOST_TO_LE_SHORT(dev_ptr->target_address);

    error = usb_host_ch9_dev_req(dev_handle, &request, NULL);

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_set_address,SUCCESSFUL");
    #endif
    return USB_log_error(__FILE__,__LINE__,error);
} /* EndBody */
コード例 #19
0
ファイル: usb_host_ch9.c プロジェクト: BillyZhangZ/wifi
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_ch9_synch_frame
* Returned Value : USB_OK, or error status
* Comments       :
*     Function to process standard device request in Chapter 9.
*     See Table 9-3 p. 250 of USB 2.0 specification.
* 
*END*--------------------------------------------------------------------*/
usb_status  _usb_host_ch9_synch_frame
(
    /* usb device */
    usb_device_instance_handle   dev_handle,
    /* interface index */
    uint8_t                      interface,
    /* configuration buffer */
    uint8_t *                    buffer
)
{ /* Body */
    usb_setup_t  request = req_prototype;
    usb_status error = USB_OK;

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_synch_frame");
    #endif

    request.bmrequesttype = REQ_TYPE_ENDPOINT | REQ_TYPE_IN;
    request.brequest = REQ_SYNCH_FRAME;
    *(uint16_t*)request.windex = USB_HOST_TO_LE_SHORT(interface);
    *(uint16_t*)request.wlength = USB_HOST_TO_LE_SHORT_CONST(2);

    error = usb_host_ch9_dev_req(dev_handle, &request, buffer);

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_synch_frame, SUCCESSFUL");
    #endif

    return USB_log_error(__FILE__,__LINE__,error);
} /* EndBody */
コード例 #20
0
ファイル: usb_host_common.c プロジェクト: BillyZhangZ/wifi
/*FUNCTION*----------------------------------------------------------------
*
* Function Name  : usb_hostdev_validate
* Returned Value : USB_OK or USBERR_DEVICE_NOT_FOUND
* Comments       :
*     Function to verify pointer is address of an instance on device list.
*  It is presumed that this function is called with USB interrupts disabled
*
*END*--------------------------------------------------------------------*/
usb_status  usb_hostdev_validate
(
    usb_device_instance_handle  device_handle
)
{ /* Body */
    dev_instance_t*           dev_ptr = (dev_instance_t*)device_handle;
    usb_host_state_struct_t*  usb_host_ptr;
    dev_instance_t*           test_ptr;
    usb_status                error;
    //uint32_t                    i;

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("usb_hostdev_validate");
    #endif

    if (device_handle == NULL)
    {
        #ifdef _HOST_DEBUG_
            DEBUG_LOG_TRACE("usb_hostdev_validate FAILED, invalid device number");
        #endif
        return USB_log_error(__FILE__,__LINE__,USBERR_INVALID_DEVICE_NUM);
    }
    usb_host_ptr = (usb_host_state_struct_t*)dev_ptr->host;

    USB_Host_lock();
    /* usb_host_ptr is valid host state structure, check for list of attached device instances */
    test_ptr = (dev_instance_t*)usb_host_ptr->device_list_ptr;
    while ((test_ptr != dev_ptr) && (test_ptr != NULL))
    {
        test_ptr = test_ptr->next;
    }
    USB_Host_unlock();

    #ifdef _HOST_DEBUG_
    if (test_ptr == NULL) 
    {
        DEBUG_LOG_TRACE("usb_hostdev_validate null device handle");
    }
    else
    {
        DEBUG_LOG_TRACE("usb_hostdev_validate SUCCESSFUL");
    }
    #endif

    error = (test_ptr == NULL) ? USBERR_DEVICE_NOT_FOUND : USB_OK;
    return USB_log_error(__FILE__,__LINE__,error);
} /* EndBody */
コード例 #21
0
ファイル: usb_host_msd_bo.c プロジェクト: gxliu/MQX_3.8.0
USB_STATUS usb_class_mass_storage_device_command
   (
      /* Handle to class struct with the key */
      CLASS_CALL_STRUCT_PTR      ccs_ptr,

      /*Command */
      COMMAND_OBJECT_PTR         cmd_ptr
   )
{ /* Body */
   USB_MASS_CLASS_INTF_STRUCT_PTR   intf_ptr;
   int                              temp;
   USB_STATUS                       error = USBERR_NO_INTERFACE;
   CBW_STRUCT_PTR                   pCbw = (CBW_STRUCT_PTR) cmd_ptr->CBW_PTR;
   boolean                          empty;

   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_class_mass_storage_device_command");
   #endif
   
   /* Pointer validity-checking, clear memory, init header */
   USB_lock();
   if (usb_host_class_intf_validate(ccs_ptr)) {
      intf_ptr = (USB_MASS_CLASS_INTF_STRUCT_PTR) ccs_ptr->class_intf_handle;
      error = usb_hostdev_validate (intf_ptr->G.dev_handle);
   } /* Endif */

   if ((error == USB_OK) || (error == USB_STATUS_TRANSFER_QUEUED)) {
      /* Fill in the remaining CBW fields as per the USB Mass Storage specs */
      *(uint_32_ptr)pCbw->DCBWSIGNATURE = HOST_TO_LE_LONG_CONST(CBW_SIGNATURE);

      /* CBW is ready so queue it and update status */
      empty = USB_CLASS_MASS_IS_Q_EMPTY(intf_ptr);
      temp = usb_class_mass_q_insert(intf_ptr, cmd_ptr);
      if (temp >= 0) {
         cmd_ptr->STATUS = STATUS_QUEUED_IN_DRIVER;
         
         /* The tag for the command packet is its queue number. */
         *(uint_32_ptr)pCbw->DCBWTAG = HOST_TO_LE_LONG(temp);

         /*
         ** If queue was empty send CBW to USB immediately, otherwise it will be
         ** taken from queue later by a callback function
         */
         if (empty) {
            error = usb_class_mass_pass_on_usb(intf_ptr);
         } /* Endif */
      } else {
         error = (USB_STATUS)USB_MASS_QUEUE_FULL;
      } /* Endif */
   } /* Endif */
   USB_unlock();

   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_class_mass_storage_device_command, SUCCESSFUL");
   #endif
   
   return USB_log_error(__FILE__,__LINE__,error);
} /* Endbody */
コード例 #22
0
ファイル: usb_host_ch9.c プロジェクト: BillyZhangZ/wifi
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_ch9_set_feature
* Returned Value : USB_OK, or error status
* Comments       :
*     Function to process standard device request in Chapter 9.
*     See Table 9-3 p. 250 of USB 2.0 specification.
* 
*END*--------------------------------------------------------------------*/
usb_status  _usb_host_ch9_set_feature
(
    /* usb device */
    usb_device_instance_handle   dev_handle,
    /* request type device/interface/endpoint */
    uint8_t            req_type,
    /* device = 0, or interface/endpoint */
    uint8_t            intf_endpt,
    /* feature selection */
    uint16_t           feature
)
{ /* Body */
    usb_setup_t  request = req_prototype;
    usb_status error = USB_OK;

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_set_feature");
    #endif

    switch (req_type) {
        case REQ_TYPE_DEVICE:
            break;
        case REQ_TYPE_INTERFACE:
        case REQ_TYPE_ENDPOINT:
            *(uint16_t*)request.windex = USB_HOST_TO_LE_SHORT(intf_endpt);
            break;
        default:
            OS_Unlock();
            #ifdef _HOST_DEBUG_
                DEBUG_LOG_TRACE("_usb_host_ch9_set_feature, invalid param");
            #endif
            return USB_log_error(__FILE__,__LINE__,USBERR_INVALID_BMREQ_TYPE);
    } /* EndSwitch */

    request.bmrequesttype = (uint8_t)(req_type | REQ_TYPE_OUT);
    request.brequest = REQ_SET_FEATURE;
    *(uint16_t*)request.wvalue = USB_HOST_TO_LE_SHORT(feature);

    error = usb_host_ch9_dev_req(dev_handle, &request, NULL);

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_set_feature, SUCCESSFUL");
    #endif
    return USB_log_error(__FILE__,__LINE__,error);
} /* EndBody */
コード例 #23
0
ファイル: usb_host_ch9.c プロジェクト: BillyZhangZ/wifi
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_ch9_get_status
* Returned Value : USB_OK, or error status
* Comments       :
*     Function to process standard device request in Chapter 9.
*     See Table 9-3 p. 250 of USB 2.0 specification.
* 
*END*--------------------------------------------------------------------*/
usb_status  _usb_host_ch9_get_status
(
/* usb device */
    usb_device_instance_handle  dev_handle,
    /* request type device/interface/endpoint */
    uint8_t                     req_type,
    /* device = 0, or interface/endpoint */
    uint16_t                     intf_endpt,
    /* returned status */
    uint8_t *                   buffer
)
{ /* Body */
    usb_setup_t  request = req_prototype;
    usb_status error = USB_OK;

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_get_status");
    #endif

    switch (req_type) 
    {
        case REQ_TYPE_DEVICE:
        case REQ_TYPE_INTERFACE:
        case REQ_TYPE_ENDPOINT:
            break;
        default:
            #ifdef _HOST_DEBUG_
            DEBUG_LOG_TRACE("_usb_host_ch9_get_status, invalid parameter");
            #endif
            return USB_log_error(__FILE__,__LINE__,USBERR_INVALID_BMREQ_TYPE);
    } /* EndSwitch */

    request.bmrequesttype = (uint8_t)(req_type | REQ_TYPE_IN);
    request.brequest = REQ_GET_STATUS;
    *(uint16_t*)request.windex = USB_HOST_TO_LE_SHORT(intf_endpt);
    *(uint16_t*)request.wlength = USB_HOST_TO_LE_SHORT_CONST(2);

    error = usb_host_ch9_dev_req(dev_handle, &request, buffer);

    #ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("_usb_host_ch9_get_status, SUCCESSFUL");
    #endif
    return USB_log_error(__FILE__,__LINE__,error);
} /* EndBody */
コード例 #24
0
ファイル: host_main.c プロジェクト: jewlenchow/MQX_3.8.1
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_unregister_service
* Returned Value : USB_OK or error code
* Comments       :
*     Unregisters a callback routine for a specified event or endpoint.
* 
*END*--------------------------------------------------------------------*/
USB_STATUS _usb_host_unregister_service
   (
      /* [IN] Handle to the USB device */
      _usb_host_handle           handle,

      /* [IN] type of event or endpoint number to service */
      uint_8                     type
   )
{ /* Body */
   USB_HOST_STATE_STRUCT_PTR           usb_host_ptr;
   USB_SERVICE_STRUCT_PTR              service_ptr;
   USB_SERVICE_STRUCT_PTR _PTR_        search_ptr;
   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("_usb_host_unregister_service");
   #endif

   usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)handle;
   /* Needs mutual exclusion */
   USB_lock();
   
   /* Search for an existing entry for type */
   for (search_ptr = &usb_host_ptr->SERVICE_HEAD_PTR;
      *search_ptr;
      search_ptr = &(*search_ptr)->NEXT) 
   {
      if ((*search_ptr)->TYPE == type) {
         /* Found an existing entry - delete it */
         break;
      } /* Endif */
   } /* Endfor */
   
   /* No existing entry found */
   if (!*search_ptr) {
      USB_unlock();
      #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_unregister_service no service found");
      #endif
      return USB_log_error(__FILE__,__LINE__,USBERR_CLOSED_SERVICE);
   } /* Endif */
   
   service_ptr = *search_ptr;
   *search_ptr = service_ptr->NEXT;

   USB_unlock();
   
   USB_mem_free((pointer)service_ptr);
   
   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("_usb_host_unregister_service SUCCESSFUL");
   #endif
   return USB_OK;

} /* EndBody */
コード例 #25
0
ファイル: host_main.c プロジェクト: jewlenchow/MQX_3.8.1
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_call_service
* Returned Value : USB_OK or error code
* Comments       :
*     Calls the appropriate service for the specified type, if one is
*     registered.
* 
*END*--------------------------------------------------------------------*/
USB_STATUS _usb_host_call_service
   (
      /* [IN] Handle to the USB device */
      _usb_host_handle handle,

      /* [IN] Type of service or endpoint */
      uint_8           type,
      
      /* [IN] Number of bytes in transmission */
      uint_32          length
   )
{ /* Body */
   USB_HOST_STATE_STRUCT_PTR           usb_host_ptr;
   USB_SERVICE_STRUCT_PTR              service_ptr;
   
   usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)handle;
   
   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("_usb_host_call_service");
   #endif

   /* Needs mutual exclusion */
   USB_lock();
   
   /* Search for an existing entry for type */
   for (service_ptr = usb_host_ptr->SERVICE_HEAD_PTR;
      service_ptr;
      service_ptr = service_ptr->NEXT) 
   {
      if (service_ptr->TYPE == type) {
         if (service_ptr->SERVICE) {
            service_ptr->SERVICE(handle, length);
         }
         USB_unlock();
         #ifdef _HOST_DEBUG_
            DEBUG_LOG_TRACE("_usb_host_call_service, service exists");
         #endif
         return USB_OK;
      } /* Endif */
      
   } /* Endfor */

   USB_unlock();
   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("_usb_host_call_service, service closed");
   #endif
   return USB_log_error(__FILE__,__LINE__,USBERR_CLOSED_SERVICE);
} /* EndBody */
コード例 #26
0
ファイル: host_dev_list.c プロジェクト: BillyZhangZ/wifi
/*FUNCTION*----------------------------------------------------------------
*
* Function Name  : usb_dev_list_free_memlist
* Returned Value : USB_OK if valid device, else error code
* Comments       :
*     Close pipes & free memory on device's linked list, whose
*        anchor is dev_handle-->memlist
*
*END*--------------------------------------------------------------------*/
USB_STATUS usb_dev_list_free_memlist
(
    /* [IN] Handle for the USB device */
    _usb_device_instance_handle   dev_handle
)
{   /* Body */
    DEV_INSTANCE_PTR  dev;
    DEV_MEMORY_PTR    mem_ptr, list_ptr;
    USB_STATUS        error;
    uint_8            intf_no;

#ifdef _HOST_DEBUG_
    DEBUG_LOG_TRACE("usb_dev_list_free_memlist");
#endif

    error = usb_hostdev_validate(dev_handle);
    // EAI - missing {} so failed if debug on
    if (error != USB_OK) {
#ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("usb_dev_list_free_memlist invalid device handle");
#endif
        return USB_log_error(__FILE__,__LINE__,error);
    }
    dev = (DEV_INSTANCE_PTR)dev_handle;

    /* Deleting interfaces closes their pipes */
    for (intf_no = 0; intf_no < dev->num_of_interfaces; intf_no++)
        usb_hostdev_delete_interface(dev, dev->intf_descriptor[intf_no]);

    /* Free memory blocks on this device's list */
    USB_lock();
    mem_ptr = dev->memlist;

    while (mem_ptr != NULL) {
        list_ptr = mem_ptr->next;
        USB_mem_free(mem_ptr);
        mem_ptr = list_ptr;
    }

    dev->memlist = NULL;
    USB_unlock();

#ifdef _HOST_DEBUG_
    DEBUG_LOG_TRACE("usb_dev_list_free_memlist SUCCESSFUL");
#endif
    return USB_OK;

} /* Endbody */
コード例 #27
0
ファイル: host_ch9.c プロジェクト: gxliu/MQX_3.8.0
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_register_ch9_callback
* Returned Value : USB_OK, or error status
* Comments       :
*     This function registers a callback function that will be called 
*  to notify the user of a ch9 command completion. This should be used 
*  only after enumeration is completed
* 
*END*--------------------------------------------------------------------*/
USB_STATUS  _usb_host_register_ch9_callback
   (
      /* usb device */
      _usb_device_instance_handle   dev_handle,

      /* Callback upon completion */
      tr_callback                   callback,

      /* User provided callback param */
      pointer                       callback_param
   )
{ /* Body */
   DEV_INSTANCE_PTR           dev_inst_ptr;
   USB_STATUS                 error;

   #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_register_ch9_callback");
   #endif
   /* Verify that device handle is valid */
   USB_lock();   
   error = usb_hostdev_validate(dev_handle);

   if (error != USB_OK) {
      USB_unlock();
      #ifdef _HOST_DEBUG_
            DEBUG_LOG_TRACE("_usb_host_register_ch9_callback, device not found");
      #endif
      return USB_log_error(__FILE__,__LINE__,USBERR_DEVICE_NOT_FOUND);
   } /* Endif */
     
   dev_inst_ptr = (DEV_INSTANCE_PTR)dev_handle;

   /* This will be called if the device is already enumerated */
   dev_inst_ptr->control_callback = callback;
   dev_inst_ptr->control_callback_param = callback_param;

   USB_unlock();

   #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_register_ch9_callback, SUCCESSFUL");
   #endif
   return USB_OK;

} /* EndBody */
コード例 #28
0
ファイル: host_ch9.c プロジェクト: gxliu/MQX_3.8.0
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : _usb_host_ch9_set_descriptor
* Returned Value : USB_OK, or error status
* Comments       :
*     Function to process standard device request in Chapter 9.
*     See Table 9-3 p. 250 of USB 2.0 specification.
* 
*END*--------------------------------------------------------------------*/
USB_STATUS  _usb_host_ch9_set_descriptor
   (
      /* usb device */
      _usb_device_instance_handle   dev_handle,

      /* descriptor type & index */
      uint_16           type_index,

      /* Language ID or 0 */
      uint_16           lang_id,

      /* buffer length */
      uint_16           buflen,         

      /* descriptor buffer */
      uchar_ptr         buffer
   )
{ /* Body */

   USB_SETUP  request;
   USB_STATUS error = USB_OK;
   #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_ch9_set_descriptor");
   #endif

   USB_lock();

   request.BMREQUESTTYPE = REQ_TYPE_DEVICE | REQ_TYPE_OUT;
   request.BREQUEST = REQ_SET_DESCRIPTOR;
   *(uint_16*)request.WVALUE = HOST_TO_LE_SHORT(type_index);
   *(uint_16*)request.WINDEX = HOST_TO_LE_SHORT(lang_id);
   *(uint_16*)request.WLENGTH = HOST_TO_LE_SHORT(buflen);

   error = usb_host_ch9_dev_req(dev_handle, &request, buffer);

   USB_unlock();

   #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_ch9_set_descriptor SUCCESSFUL");
   #endif

   return USB_log_error(__FILE__,__LINE__,error);

} /* EndBody */
コード例 #29
0
ファイル: host_main.c プロジェクト: jewlenchow/MQX_3.8.1
/*FUNCTION*-------------------------------------------------------------
*
*  Function Name  : _usb_host_get_transfer_status
*  Returned Value : Status
*  Comments       :
* _usb_host_get_transfer_status is a routine that returns status of a transfer. 
*
*END*-----------------------------------------------------------------*/
uint_32 _usb_host_get_transfer_status
   (
      /* [IN] the pipe handle */
      _usb_pipe_handle     pipe_handle,

      /* [IN] the transfer number */
      uint_32              tr_number
   )
{ /* Body */
   PIPE_STRUCT_PTR            pipe_ptr;
   TR_STRUCT_PTR              tr_list_ptr;
   uint_32                    status = USB_log_error(__FILE__,__LINE__,USBERR_INVALID_PIPE_HANDLE);

   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("_usb_host_get_transfer_status");
   #endif
      
   USB_lock();

   pipe_ptr = (PIPE_STRUCT_PTR)pipe_handle;
   if (pipe_ptr!= NULL) {
      tr_list_ptr = pipe_ptr->tr_list_ptr;
      if (tr_list_ptr != NULL) {
         do {
            if (tr_list_ptr->TR_INDEX == tr_number) {
               status = tr_list_ptr->STATUS;
               break;
            } /* Endif */
            tr_list_ptr = tr_list_ptr->NEXT;   
         } while (tr_list_ptr != pipe_ptr->tr_list_ptr);
      } /* Endif */
      if (tr_list_ptr->TR_INDEX != tr_number) {
         /* Transaction done */
         status = USB_STATUS_IDLE;
      } /* Endif */
   } /* Endif */
   
   USB_unlock();
   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("_usb_host_get_transfer_status SUCCESSFUL");
   #endif

   return status;
} /* Endbody */
コード例 #30
0
ファイル: usb_host_msd_bo.c プロジェクト: gxliu/MQX_3.8.0
USB_STATUS usb_class_mass_reset_recovery_on_usb
   (
      USB_MASS_CLASS_INTF_STRUCT_PTR   intf_ptr
   )
{ /* Body */
   COMMAND_OBJECT_PTR         cmd_ptr = NULL;
   USB_STATUS                 status = USB_OK;
   USB_SETUP                  request;

   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_class_mass_reset_recovery_on_usb");
   #endif
   
   /* Nothing can be done if there is nothing pending*/
   usb_class_mass_get_pending_request(intf_ptr,&cmd_ptr);
   if(cmd_ptr == NULL) 
   {
      #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("usb_class_mass_reset_recovery_on_usb,no matching request");
      #endif
      return (USB_STATUS) USB_MASS_NO_MATCHING_REQUEST;
   } /* Endif */

   /* BULK device mass storage reset */
   request.BMREQUESTTYPE   = REQ_TYPE_CLASS | REQ_TYPE_INTERFACE | REQ_TYPE_OUT;
   request.BREQUEST        = MASS_STORAGE_RESET;
   *(uint_16*)request.WVALUE = HOST_TO_LE_SHORT_CONST(0);
   *(uint_16*)request.WINDEX = HOST_TO_LE_SHORT(((INTERFACE_DESCRIPTOR_PTR)intf_ptr->G.intf_handle)->bInterfaceNumber);
   *(uint_16*)request.WLENGTH = HOST_TO_LE_SHORT_CONST(0);

   cmd_ptr->STATUS = STATUS_RESET_DEVICE;
   status = _usb_hostdev_cntrl_request (intf_ptr->G.dev_handle, &request, NULL,
      usb_class_mass_reset_callback, (pointer)intf_ptr);

   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_class_mass_reset_recovery_on_usb,SUCCESSFUL");
   #endif
      
   return USB_log_error(__FILE__,__LINE__,status);
} /* Endbody */