예제 #1
0
/**************************************************************************//*!
 *
 * @name  USB_MSC_SCSI_Init
 *
 * @brief The funtion initializes the SCSI parameters and callbacks
 *
 * @param controller_ID:        To identify the controller :       
 * @param class_callback:       event callback
 *
 * @return status
 *         USB_OK           : When Successfull
 *         Others           : Errors
 *
 *****************************************************************************/
uint_8 USB_MSC_SCSI_Init
(
     uint_8  controller_ID,
     USB_CLASS_CALLBACK callback
)
{
    UNUSED(controller_ID)
    /* initialize the Global Variable Structure */
	USB_memzero(&g_msc_scsi, sizeof(MSC_SCSI_GLOBAL_VARIABLE_STRUCT));

    /* save input parameters */
    g_msc_scsi.scsi_callback = callback;

    /* no need to initialize other structure fields as g_resquest_sense has
       been declared as static */
    g_msc_scsi.request_sense.valid_error_code = REQ_SENSE_VALID_ERROR_CODE;
    g_msc_scsi.request_sense.add_sense_len = REQ_SENSE_ADDITIONAL_SENSE_LEN;
    g_msc_scsi.request_sense.sense_key = NO_SENSE;
    g_msc_scsi.request_sense.add_sense_code = NO_SENSE;
    g_msc_scsi.request_sense.add_sense_code_qual = NO_SENSE;    
    
    if(g_msc_scsi.scsi_callback != NULL) 
    {				
		    g_msc_scsi.scsi_callback(controller_ID, USB_MSC_DEVICE_GET_INFO, 
			    &g_msc_scsi.device_info);	
    }
    
    return USB_OK;
}
예제 #2
0
/*FUNCTION*-------------------------------------------------------------
*
*  Function Name  : _usb_device_init
*  Returned Value : USB_OK or error code
*  Comments       :
*        Initializes the USB device specific data structures and calls 
*  the low-level device controller chip initialization routine.
*
*END*-----------------------------------------------------------------*/
uint_8 _usb_device_init
   (
      /* [IN] the USB device controller to initialize */
      uint_8                    devnum,

      /* [OUT] the USB_USB_dev_initialize state structure */
      _usb_device_handle _PTR_  handle,
            
      /* [IN] number of endpoints to initialize */
      uint_8                    endpoints 
   )
{ /* Body */

   USB_DEV_STATE_STRUCT_PTR         usb_dev_ptr;
   XD_STRUCT_PTR                    xd_ptr;
   uint_8                           temp, i, error;
   SCRATCH_STRUCT_PTR               temp_scratch_ptr;
   //uint_32                          total_memory;
   //uint_8_ptr                       stack_mem_ptr;
   
   #ifdef _DEVICE_DEBUG_
      DEBUG_LOG_TRACE("_usb_device_init");
   #endif
   
   #ifndef REDUCED_ERROR_CHECKING                   
      
      if (devnum > MAX_USB_DEVICES) 
      {
         #ifdef _DEVICE_DEBUG_
            DEBUG_LOG_TRACE("_usb_device_init, error invalid device number");
         #endif
         return USBERR_INVALID_DEVICE_NUM;
      } /* Endif */
   #endif
      
   /**************************************************************
   All memory allocations should be consolidated in one.
   **************************************************************/
                                       
         /* Allocate memory for the state structure */
         //usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)
         //   USB_memalloc(sizeof(USB_DEV_STATE_STRUCT));
         usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)
            malloc(sizeof(USB_DEV_STATE_STRUCT));
      
         if (usb_dev_ptr == NULL) 
         {
            #ifdef _DEVICE_DEBUG_
               DEBUG_LOG_TRACE("_usb_device_init, error NULL device handle");
            #endif
            return USBERR_ALLOC_STATE;
         } /* Endif */
   
         /* Zero out the internal USB state structure */
         USB_memzero((char *)usb_dev_ptr,sizeof(USB_DEV_STATE_STRUCT));
  
   /**************************************************************
   **************************************************************/
        
   /* Multiple devices will have different base addresses and 
   ** interrupt vectors (For future)
   */   
   //usb_dev_ptr->DEV_PTR = 0x1cb20100;
   usb_dev_ptr->DEV_PTR = (VUSB20_REG_STRUCT_PTR)otg_base + 0x100;
   usb_dev_ptr->DEV_VEC = otg_irq;
   usb_dev_ptr->USB_STATE = USB_STATE_UNKNOWN;
   
   usb_dev_ptr->MAX_ENDPOINTS = endpoints;

   #ifndef SMALL_CODE_SIZE                   
      temp = (usb_dev_ptr->MAX_ENDPOINTS * 2);
   #endif
                
      /* Allocate MAX_XDS_FOR_TR_CALLS */
      xd_ptr = (XD_STRUCT_PTR)
         malloc(sizeof(XD_STRUCT) * MAX_XDS_FOR_TR_CALLS);
         //USB_memalloc(sizeof(XD_STRUCT) * MAX_XDS_FOR_TR_CALLS);
      if (xd_ptr == NULL) 
      {
         #ifdef _DEVICE_DEBUG_
            DEBUG_LOG_TRACE("_usb_device_init, malloc error");
         #endif
         return USBERR_ALLOC_TR;
      }

      USB_memzero((char *)xd_ptr, sizeof(XD_STRUCT) * MAX_XDS_FOR_TR_CALLS);

      /* Allocate memory for internal scratch structure */   
      usb_dev_ptr->XD_SCRATCH_STRUCT_BASE = (SCRATCH_STRUCT_PTR)
         malloc(sizeof(SCRATCH_STRUCT)*MAX_XDS_FOR_TR_CALLS);
         //USB_memalloc(sizeof(SCRATCH_STRUCT)*MAX_XDS_FOR_TR_CALLS);
   
      if (usb_dev_ptr->XD_SCRATCH_STRUCT_BASE == NULL) 
      {
         #ifdef _DEVICE_DEBUG_
            DEBUG_LOG_TRACE("_usb_device_init, malloc error");
         #endif
         return USBERR_ALLOC;
      } /* Endif */
   
   usb_dev_ptr->XD_BASE = xd_ptr;
   

   temp_scratch_ptr = usb_dev_ptr->XD_SCRATCH_STRUCT_BASE;
   
   #ifndef SMALL_CODE_SIZE
      usb_dev_ptr->XD_HEAD = NULL;
      usb_dev_ptr->XD_TAIL = NULL;
      usb_dev_ptr->XD_ENTRIES = 0;
   #endif
   
   /* Enqueue all the XDs */   
   for (i=0;i<MAX_XDS_FOR_TR_CALLS;i++) {
      xd_ptr->SCRATCH_PTR = temp_scratch_ptr;
      xd_ptr->SCRATCH_PTR->FREE = _usb_device_free_XD;
      xd_ptr->SCRATCH_PTR->PRIVATE = (pointer)usb_dev_ptr;
      _usb_device_free_XD((pointer)xd_ptr);
      xd_ptr++;
      temp_scratch_ptr++;
   } /* Endfor */

      usb_dev_ptr->TEMP_XD_PTR = (XD_STRUCT_PTR)malloc(sizeof(XD_STRUCT));
      USB_memzero((char *)usb_dev_ptr->TEMP_XD_PTR, sizeof(XD_STRUCT));
      
   /* Initialize the USB controller chip */

   error = _usb_dci_vusb20_init(devnum, usb_dev_ptr);

   if (error) 
   {
      #ifdef _DEVICE_DEBUG_
         DEBUG_LOG_TRACE("_usb_device_init, init failed");
      #endif
      return USBERR_INIT_FAILED;
   } /* Endif */
   
   *handle = usb_dev_ptr;
   #ifdef _DEVICE_DEBUG_
      DEBUG_LOG_TRACE("_usb_device_init, SUCCESSFUL");
   #endif
   return USB_OK;
   
} /* EndBody */
예제 #3
0
/*FUNCTION*----------------------------------------------------------------
* 
* Function Name  : usb_dev_list_attach_device
* Returned Value : 
* Comments       :
*     This function will be called when attach interrupt happens, to
*       add onto the device list and do common initialization.     
* 
*END*--------------------------------------------------------------------*/
void usb_dev_list_attach_device
   (
      _usb_host_handle  handle,
      uint_8            speed,
      uint_8            hub_no,
      uint_8            port_no
   )
{ /* Body */
   DEV_INSTANCE_PTR           dev_instance_ptr;
   PIPE_INIT_PARAM_STRUCT     ctrl_pipe_init_params;
   USB_HOST_STATE_STRUCT_PTR  usb_host_ptr;
   DEV_INSTANCE_PTR           device_root = NULL;
   // clean warning uint_32                    state;

   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_dev_list_attach_device attach device");
      DEBUGMSG(USB_DBG_LEVEL, ("usb_dev_list_attach_device attach device\n"));
   #endif
      //DEBUGMSG(1,("d"));
 
	
	//DEBUGMSG(TTC_DBG_LEVEL,("usb_dev_list_attach_device attach device\r\n"));
   
   usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)handle;

   /* Allocate new device instance */
   dev_instance_ptr = (DEV_INSTANCE_PTR)\
       USB_Uncached_memalloc(sizeof(DEV_INSTANCE));

   if (dev_instance_ptr == NULL) {
      #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("usb_dev_list_attach_device failed to malloc device handle");
      #endif
     	//DEBUGMSG(TTC_DBG_LEVEL,("usb_dev_list_attach_device failed to malloc device handle\r\n"));
      return;
   } /* EndIf */

   USB_memzero(dev_instance_ptr, sizeof(DEV_INSTANCE));

   dev_instance_ptr->host = handle;
   dev_instance_ptr->speed = speed;
   dev_instance_ptr->hub_no = hub_no;
   dev_instance_ptr->port_no = port_no;
   dev_instance_ptr->cfg_value = 0; /* We don't know yet what the 
                                    ** device's default configuration is 
                                    */

   USB_lock();
   /* Insert instance in pushdown list of devices */
   dev_instance_ptr->next = usb_host_ptr->DEVICE_LIST_PTR;     /* existing list */
   usb_host_ptr->DEVICE_LIST_PTR = (pointer)dev_instance_ptr;  /* root = new device */
   device_root = dev_instance_ptr;

   /* Find unused address from 1 - 127 for this host */
   device_root->address = 1;
   do {
      dev_instance_ptr = device_root->next; /* 2nd device, if any */
      while (dev_instance_ptr != NULL) {    /* step through list  */
         if (device_root->address == dev_instance_ptr->address) {
            device_root->address++;
            break;
         } /* EndIf */
         dev_instance_ptr = dev_instance_ptr->next;
      } /* EndWhile */
   } while ((dev_instance_ptr != NULL) && (device_root->address <= 127));

   dev_instance_ptr = device_root;   

   /* If all 127 addresses used up, delete instance & bail out */
   if (dev_instance_ptr->address > 127) {
      usb_host_ptr->DEVICE_LIST_PTR = (pointer)\
         dev_instance_ptr->next; /* pop off list */
      USB_unlock();
      USB_memfree((pointer)dev_instance_ptr);
      #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("usb_dev_list_attach_device out of addresses");
      #endif
     	//DEBUGMSG(TTC_DBG_LEVEL,("usb_dev_list_attach_device out of addresses\r\n"));
      return;
   } /* EndIf */
      
   USB_unlock();

   /*-----------------------------------------------------------**
   ** Open control pipe, get first 8 bytes of device descriptor **
   ** The host_ch9 routine internally sets the callback to      **
   **    usb_host_cntrl_transaction_done (in usb_host_ch9.c)    **
   **    where the action resumes on completion of the get.     **
   **-----------------------------------------------------------*/
   
   ctrl_pipe_init_params = pipe_init_params_prototype;
   ctrl_pipe_init_params.DEV_INSTANCE = dev_instance_ptr;
   ctrl_pipe_init_params.PIPETYPE = USB_CONTROL_PIPE;   
   ctrl_pipe_init_params.SPEED = dev_instance_ptr->speed;

#ifdef __USB_OTG__
   _usb_otg_get_status((pointer)usb_otg_state_struct_ptr, 
      USB_OTG_STATE, &state);
   
   if (state < B_IDLE) {
      _usb_otg_set_status((pointer)usb_otg_state_struct_ptr, 
         USB_OTG_A_BUS_REQ, TRUE);
      _usb_otg_set_status((pointer)usb_otg_state_struct_ptr, 
         USB_OTG_B_CONN, TRUE);
   } else {
      _usb_otg_set_status((pointer)usb_otg_state_struct_ptr, 
         USB_OTG_A_CONN, TRUE);
   } /* Endif */
#endif

   if (USB_OK != _usb_host_open_pipe(dev_instance_ptr->host, 
      &ctrl_pipe_init_params, 
      &dev_instance_ptr->control_pipe))
   {
      #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("usb_dev_list_attach_device open pipe failed");
         DEBUGMSG(USB_DBG_LEVEL, ("usb_dev_list_attach_device attach device open pipe failed\n"));
      #endif
      	//DEBUGMSG(TTC_DBG_LEVEL,("usb_dev_list_attach_device open pipe failed\r\n"));
      return;
   } /* Endif */

   /* Set state to enter after transaction completion */
   dev_instance_ptr->state = DEVSTATE_DEVDESC8;

   _usb_host_ch9_get_descriptor((pointer)dev_instance_ptr,
      DESCTYPE_DEVICE<<8, 0, 8, 
      (uchar_ptr)&dev_instance_ptr->dev_descriptor);
   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_dev_list_attach_device SUCCESSFUL");
      DEBUGMSG(USB_DBG_LEVEL, ("usb_dev_list_attach_device SUCCESSFUL\n"));
   #endif
   	//DEBUGMSG(TTC_DBG_LEVEL,("usb_dev_list_attach_device SUCCESSFUL\r\n"));

} /* EndBody */
/*FUNCTION*-------------------------------------------------------------
*
*  Function Name  : _usb_device_init
*  Returned Value : USB_OK or error code
*  Comments       :
*        Initializes the USB device specific data structures and calls 
*  the low-level device controller chip initialization routine.
*
*END*-----------------------------------------------------------------*/
uint_8 _usb_device_init
   (
      /* [IN] the USB device controller to initialize */
      uint_8                    devnum,

      /* [OUT] the USB_USB_dev_initialize state structure */
      _usb_device_handle*       handle
   )
{ /* Body */
   USB_DEV_STATE_STRUCT_PTR         usb_dev_ptr;
   XD_STRUCT_PTR                    xd_ptr;
   uint_8                           i, error;
   SCRATCH_STRUCT_PTR               temp_scratch_ptr;

   /* global_import_funcs must be initailized before */
   if(global_import_funcs == NULL)
       return USBERR_INIT_FAILED;

   if (devnum > MAX_USB_DEVICES) 
   {
        USB_printf("_usb_device_init, error invalid device number");
        return USBERR_INVALID_DEVICE_NUM;
   } /* Endif */
   
   /* Allocate memory for the state structure */
   usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)USB_memalloc(sizeof(USB_DEV_STATE_STRUCT));      
   if (usb_dev_ptr == NULL) 
   {
        USB_printf("_usb_device_init, malloc of %d bytes for USB_DEV_STATE_STRUCT failed\n", 
                    sizeof(USB_DEV_STATE_STRUCT));
        return USBERR_ALLOC_STATE;
   } /* Endif */
   
   /* Zero out the internal USB state structure */
   USB_memzero(usb_dev_ptr, sizeof(USB_DEV_STATE_STRUCT));
    
   usb_dev_ptr->DEV_NUM = devnum;

   /* Multiple devices will have different base addresses and 
   ** interrupt vectors (For future)
   */   
   usb_dev_ptr->USB_STATE = ARC_USB_STATE_UNKNOWN;
   
   /* Allocate MAX_XDS_FOR_TR_CALLS */
   xd_ptr = (XD_STRUCT_PTR)USB_memalloc(sizeof(XD_STRUCT) * MAX_XDS_FOR_TR_CALLS);      
   if (xd_ptr == NULL) 
   {
        _usb_device_cleanup(usb_dev_ptr);
        USB_printf("_usb_device_init, malloc of %d bytes for %d XD_STRUCT failed\n", 
                        sizeof(XD_STRUCT) * MAX_XDS_FOR_TR_CALLS, MAX_XDS_FOR_TR_CALLS);
        return USBERR_ALLOC_TR;
   } /* Endif */
   
   usb_dev_ptr->XD_BASE = xd_ptr;

   _usb_clear_stats(usb_dev_ptr);

   USB_memzero(xd_ptr, sizeof(XD_STRUCT) * MAX_XDS_FOR_TR_CALLS);

   /* Allocate memory for internal scratch structure */   
   usb_dev_ptr->XD_SCRATCH_STRUCT_BASE = (SCRATCH_STRUCT_PTR)
                    USB_memalloc(sizeof(SCRATCH_STRUCT) * MAX_XDS_FOR_TR_CALLS);
   if (usb_dev_ptr->XD_SCRATCH_STRUCT_BASE == NULL) 
   {
        _usb_device_cleanup(usb_dev_ptr);
        USB_printf("_usb_device_init, malloc of %d bytes for %d XD_STRUCT failed\n", 
                        sizeof(SCRATCH_STRUCT) * MAX_XDS_FOR_TR_CALLS, MAX_XDS_FOR_TR_CALLS);
        return USBERR_ALLOC;
   } /* Endif */

   temp_scratch_ptr = usb_dev_ptr->XD_SCRATCH_STRUCT_BASE;
   usb_dev_ptr->XD_HEAD = NULL;
   usb_dev_ptr->XD_TAIL = NULL;
   usb_dev_ptr->XD_ENTRIES = 0;

   /* Enqueue all the XDs */   
   for (i=0;i<MAX_XDS_FOR_TR_CALLS;i++) 
   {
      xd_ptr->SCRATCH_PTR = temp_scratch_ptr;
      xd_ptr->SCRATCH_PTR->FREE = _usb_device_free_XD;
      xd_ptr->SCRATCH_PTR->PRIVATE = (pointer)usb_dev_ptr;
      _usb_device_free_XD((pointer)xd_ptr);
      xd_ptr++;
      temp_scratch_ptr++;
   } /* Endfor */

   usb_dev_ptr->TEMP_XD_PTR = (XD_STRUCT_PTR)USB_memalloc(sizeof(XD_STRUCT));
   if(usb_dev_ptr->TEMP_XD_PTR == NULL)
   {
        USB_printf("_usb_device_init, malloc of %d bytes for TEMP_XD_STRUCT failed\n", 
                        sizeof(XD_STRUCT));
        _usb_device_cleanup(usb_dev_ptr);
        return USBERR_ALLOC;
   }
   USB_memzero(usb_dev_ptr->TEMP_XD_PTR, sizeof(XD_STRUCT));

   /* Allocate 2 bytes for USB_STATUS to be sent over USB, so Cache line aligned */
   usb_dev_ptr->STATUS_UNAIGNED_PTR = (uint_8*)USB_memalloc(sizeof(uint_16) + PSP_CACHE_LINE_SIZE);
   if(usb_dev_ptr->STATUS_UNAIGNED_PTR == NULL)
   {
        USB_printf("_usb_device_init, malloc of %d bytes for USB_STATUS failed\n", 
                        sizeof(uint_16) + PSP_CACHE_LINE_SIZE);
        _usb_device_cleanup(usb_dev_ptr);
        return USBERR_ALLOC;
   }
   USB_memzero(usb_dev_ptr->STATUS_UNAIGNED_PTR, sizeof(uint_16) + PSP_CACHE_LINE_SIZE);
   usb_dev_ptr->STATUS_PTR = (uint_16*)USB_CACHE_ALIGN((uint_32)usb_dev_ptr->STATUS_UNAIGNED_PTR);

   /* Allocate 53 bytes for USB Test packet to be sent over USB, so Cache line aligned */
   usb_dev_ptr->TEST_PKT_UNAIGNED_PTR = (uint_8*)USB_memalloc(USB_TEST_MODE_TEST_PACKET_LENGTH + PSP_CACHE_LINE_SIZE);
   if(usb_dev_ptr->TEST_PKT_UNAIGNED_PTR == NULL)
   {
        USB_printf("_usb_device_init, malloc of %d bytes for USB Test packet failed\n", 
                        USB_TEST_MODE_TEST_PACKET_LENGTH + PSP_CACHE_LINE_SIZE);
        _usb_device_cleanup(usb_dev_ptr);
        return USBERR_ALLOC;
   }
   USB_memzero(usb_dev_ptr->TEST_PKT_UNAIGNED_PTR, USB_TEST_MODE_TEST_PACKET_LENGTH + PSP_CACHE_LINE_SIZE);
   usb_dev_ptr->TEST_PKT_PTR = (uint_8*)USB_CACHE_ALIGN((uint_32)usb_dev_ptr->TEST_PKT_UNAIGNED_PTR);

   /* Initialize the USB controller chip */
   error = _usb_dci_vusb20_init(devnum, usb_dev_ptr);
   if (error) 
   {
        _usb_device_cleanup(usb_dev_ptr);
        USB_printf("_usb_device_init, init failed");
        return USBERR_INIT_FAILED;
   } /* Endif */

   USB_printf("device_init: pDev=0x%x, pXD(%d)=0x%x, pSCRATCH(%d)=0x%x, pTempXD=0x%x\n",
                (unsigned)usb_dev_ptr, MAX_XDS_FOR_TR_CALLS, (unsigned)usb_dev_ptr->XD_BASE,
                MAX_XDS_FOR_TR_CALLS, (unsigned)usb_dev_ptr->XD_SCRATCH_STRUCT_BASE,
                (unsigned)usb_dev_ptr->TEMP_XD_PTR);

   *handle = usb_dev_ptr;
   return USB_OK;   
} /* EndBody */