/*FUNCTION*-------------------------------------------------------------
*
*  Function Name  : _usb_host_close_all_pipes
*  Returned Value : None
*  Comments       :
*  _usb_host_close_all_pipes routine removes the pipe from the open pipe list
*
*END*-----------------------------------------------------------------*/
void  _usb_host_close_all_pipes
   (
      /* [IN] the USB Host state structure */
      _usb_host_handle  handle
   )
{ /* Body */
   USB_HOST_STATE_STRUCT_PTR usb_host_ptr;
   PIPE_STRUCT_PTR pipe_ptr, pipe_bkp_ptr;
   TR_STRUCT_PTR tr_ptr, tr_ptr_next;
   
   usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)handle;

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

   USB_lock();

   for (pipe_ptr = usb_host_ptr->PIPE_DESCRIPTOR_BASE_PTR; pipe_ptr != NULL; pipe_ptr = pipe_ptr->NEXT) {
      if (pipe_ptr->OPEN) {
         /* Call the low-level routine to free the controller specific resources for this pipe */
         _usb_host_close_pipe_call_interface (handle, pipe_ptr);

         /* before cleaning pipe_ptr struct we need to deallocate structures in the circullar list */
         if (pipe_ptr->tr_list_ptr != NULL) {
            tr_ptr = pipe_ptr->tr_list_ptr;
            do {
               tr_ptr_next = tr_ptr->NEXT;
               /* free transaction belonging to this pipe */
               USB_mem_free(tr_ptr);
               tr_ptr = tr_ptr_next;
            } while (tr_ptr != pipe_ptr->tr_list_ptr);  

            //pipe_ptr->tr_list_ptr = NULL; //this will be done later by zeroing pipe_ptr
         }

         /* de-initialise the pipe descriptor, but prevent the chain */
         pipe_bkp_ptr = pipe_ptr->NEXT;

         USB_mem_zero(pipe_ptr, sizeof(PIPE_STRUCT));
         /* restore the chain */
         pipe_ptr->NEXT = pipe_bkp_ptr;
      } /* Endif */
   } /* Endfor */
   
   USB_unlock();
   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("_usb_host_close_all_pipes SUCCESSFUL");
   #endif
   
} /* Endbody */
Exemple #2
0
/*FUNCTION*-------------------------------------------------------------
*
*  Function Name  : _usb_dev_driver_install
*  Returned Value : None
*  Comments       :
*        Installs the device
*END*-----------------------------------------------------------------*/
uint_8 _usb_dev_driver_install
   (
      /* [IN] device number */
      uint_32  device_number,
            
      /* [IN] address if the callback functions structure */
      pointer  callback_struct_ptr
   )
{ /* Body */
   pointer callback_struct_table_ptr;
   
   callback_struct_table_ptr = _mqx_get_io_component_handle(IO_USB_COMPONENT);
   
   if (!callback_struct_table_ptr) 
   {
      callback_struct_table_ptr = 
         USB_mem_alloc_zero((BSP_MAX_USB_DRIVERS * sizeof(USB_DEV_CALLBACK_FUNCTIONS_STRUCT)));
      if (!callback_struct_table_ptr) 
      {
         #if _DEBUG
            printf("memalloc failed in _usb_driver_install\n");
         #endif 
         return USBERR_DRIVER_INSTALL_FAILED;
      } /* Endif */
      
      USB_mem_zero((uint_8_ptr)callback_struct_table_ptr, 
         sizeof(callback_struct_table_ptr));
      
      _mqx_set_io_component_handle(IO_USB_COMPONENT, 
         callback_struct_table_ptr);
   } /* Endif */

   *((USB_DEV_CALLBACK_FUNCTIONS_STRUCT_PTR)\
      (((USB_DEV_CALLBACK_FUNCTIONS_STRUCT_PTR)callback_struct_table_ptr) + 
      device_number)) = 
      *((USB_DEV_CALLBACK_FUNCTIONS_STRUCT_PTR)callback_struct_ptr);

   return USB_OK;

} /* EndBody */
Exemple #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*--------------------------------------------------------------------*/
USB_STATUS usb_dev_list_attach_device
(
    _usb_host_handle  handle,
    uint_8            speed,
    uint_8            hub_no,
    uint_8            port_no
)
{   /* Body */
    USB_STATUS                 status;
    DEV_INSTANCE_PTR           new_instance_ptr, dev_instance_ptr, dev_instance_prev_ptr;
    PIPE_INIT_PARAM_STRUCT     ctrl_pipe_init_params;
    USB_HOST_STATE_STRUCT_PTR  usb_host_ptr;
    DEV_INSTANCE_PTR           device_root = NULL;
#ifdef __USB_OTG__
    uint_32                    state;
#endif

#ifdef _HOST_DEBUG_
    DEBUG_LOG_TRACE("usb_dev_list_attach_device attach device");
#endif
    usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)handle;

    /* Allocate new device instance */
    new_instance_ptr = (DEV_INSTANCE_PTR) USB_mem_alloc_uncached(sizeof(DEV_INSTANCE));

    if (new_instance_ptr == NULL) {
#ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("usb_dev_list_attach_device failed to malloc device handle");
#endif
        return USB_log_error(__FILE__,__LINE__, USBERR_GET_MEMORY_FAILED);
    } /* EndIf */
    _mem_set_type(new_instance_ptr, MEM_TYPE_USB_HOST_STATE_STRUCT);

    USB_mem_zero(new_instance_ptr, sizeof(DEV_INSTANCE));

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

    USB_lock();

    /* Find unused address from 1 - 127 for this host */
    dev_instance_ptr = usb_host_ptr->DEVICE_LIST_PTR;
    if ((dev_instance_ptr == NULL) || (dev_instance_ptr->address != 1)) {
        /* Insert at the beginning of list */
        new_instance_ptr->address = 1;
        new_instance_ptr->next = dev_instance_ptr;
        usb_host_ptr->DEVICE_LIST_PTR = new_instance_ptr;
    }
    else {
        dev_instance_prev_ptr = dev_instance_ptr;
        /* Searching for a 'hole' in devices instance adresses */
        while (dev_instance_ptr->address <= (dev_instance_prev_ptr->address + 1)) {
            new_instance_ptr->address = dev_instance_ptr->address;
            dev_instance_prev_ptr = dev_instance_ptr;
            dev_instance_ptr = dev_instance_ptr->next;
            if (dev_instance_ptr == NULL)
                break;
        } /* EndWhile */
        if (new_instance_ptr->address >= 127) {
            /* If all 127 addresses used up, delete instance & bail out */
            USB_unlock();
            USB_mem_free((pointer)new_instance_ptr);
#ifdef _HOST_DEBUG_
            DEBUG_LOG_TRACE("usb_dev_list_attach_device out of addresses");
#endif
            return USB_log_error(__FILE__,__LINE__, USBERR_ADDRESS_ALLOC_FAILED);
        } /* EndIf */
        new_instance_ptr->address++;
        new_instance_ptr->next = dev_instance_ptr;
        dev_instance_prev_ptr->next = new_instance_ptr;
    };

    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.G.DEV_INSTANCE = new_instance_ptr;
    ctrl_pipe_init_params.G.PIPETYPE = USB_CONTROL_PIPE;
    ctrl_pipe_init_params.G.SPEED = new_instance_ptr->speed;

    ctrl_pipe_init_params.G.HUB_DEVICE_ADDR = hub_no;
    ctrl_pipe_init_params.G.HUB_PORT_NUM = port_no;
#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(new_instance_ptr->host,
                                      &ctrl_pipe_init_params,
                                      &new_instance_ptr->control_pipe))
    {
        USB_mem_free((pointer)new_instance_ptr);
#ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("usb_dev_list_attach_device open pipe failed");
#endif
        return USB_log_error(__FILE__,__LINE__, USBERR_PIPE_OPENED_FAILED);
    } /* Endif */

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

    status = _usb_host_ch9_get_descriptor((_usb_device_instance_handle)new_instance_ptr,
                                          USB_DESC_TYPE_DEV << 8, 0, 8,
                                          (uchar_ptr)&new_instance_ptr->dev_descriptor);

    if (status != USB_STATUS_TRANSFER_QUEUED)
    {
        new_instance_ptr->state = DEVSTATE_INITIAL;
#ifdef _HOST_DEBUG_
        DEBUG_LOG_TRACE("usb_dev_list_attach_device FAILED");
#endif
        return USB_log_error(__FILE__,__LINE__, USBERR_NO_DESCRIPTOR);
    }

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

} /* EndBody */
Exemple #4
0
void usb_printer_init
   (
      /* [IN] device/descriptor/pipe handles */
      PIPE_BUNDLE_STRUCT_PTR  pbs_ptr,
      
      /* [IN] class-interface data pointer + key */
      CLASS_CALL_STRUCT_PTR   prt_call_ptr
   )
{ /* Body */

   PRINTER_INTERFACE_STRUCT_PTR  prt_intf;

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

   /* Pointer validity-checking, clear memory, init header */
   prt_intf = prt_call_ptr->class_intf_handle;
   if (USB_OK != usb_host_class_intf_init (pbs_ptr, (pointer)prt_intf, (pointer)&prt_anchor, NULL))
   {
      #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("usb_printer_init, error class init");
      #endif
      return;
   }

   USB_lock();
   prt_call_ptr->code_key = 0;
   prt_call_ptr->code_key = usb_host_class_intf_validate(prt_call_ptr);

   if (NULL == 
         (prt_intf->control_pipe = usb_hostdev_get_pipe_handle 
         (pbs_ptr, USB_CONTROL_PIPE, 0) ))
      goto Bad_Exit;

   if (NULL == 
         (prt_intf->bulk_out_pipe = usb_hostdev_get_pipe_handle 
         (pbs_ptr, USB_BULK_PIPE, USB_SEND) ))
      goto Bad_Exit;

   /* Uni-directional printers don't have a bulk-in pipe */
   if (((INTERFACE_DESCRIPTOR_PTR)prt_intf->intf_handle)->
         bInterfaceSubClass > USB_PROTOCOL_PRT_UNIDIR)
      {
      if (NULL ==
            (prt_intf->bulk_in_pipe = usb_hostdev_get_pipe_handle 
            (pbs_ptr, USB_BULK_PIPE, USB_RECV) ))
         goto Bad_Exit;
      } /* EndIf */

   USB_unlock ();
   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_printer_init, SUCCESSFUL");
   #endif
   
   return;  /* Good exit, interface struct initialized */

   Bad_Exit:
   USB_mem_zero (prt_intf,sizeof(PRINTER_INTERFACE_STRUCT_PTR));
   prt_call_ptr->class_intf_handle = NULL;
   prt_call_ptr->code_key = 0;
   USB_unlock ();
   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_printer_init, bad exit");
   #endif
   
} /* Endbody */
Exemple #5
0
/*FUNCTION*----------------------------------------------------------------
*
* Function Name  : Main_Task
* Returned Value : None
* Comments       :
*     First function called.  This function is the entry for
*     the PHDC Application
*
*END*--------------------------------------------------------------------*/
void Main_Task(uint_32 param)
{
    /* Initialize Global Variable Structure */
    PHDC_CONFIG_STRUCT phdc_config;
    phdc_config.phdc_callback.callback =  USB_App_Callback;
    phdc_config.phdc_callback.arg = (void*)&g_bridge.handle;
    phdc_config.vendor_callback.callback = NULL;
    phdc_config.vendor_callback.arg = NULL;
    phdc_config.desc_callback_ptr = &desc_callback;
    phdc_config.info = &usb_desc_ep;

    USB_mem_zero(&g_bridge, sizeof(BRIDGE_GLOBAL_VARIABLE_STRUCT));

    if (_lwevent_create(&lwevent,0) != MQX_OK)
    {
#if _DEBUG
        printf("\nMake event failed : Main_Task");
#endif
        _task_block();
    }

    g_usb_rx_buff_ptr = USB_mem_alloc_zero(PHDC_BULK_OUT_EP_SIZE);
    if(g_usb_rx_buff_ptr == NULL)
    {
#if _DEBUG
        printf("g_usb_rx_buff_ptr malloc failed\n");
#endif
    }

    g_bridge_rx_buff_ptr = USB_mem_alloc_zero(PHDC_BULK_IN_EP_SIZE);
    if(g_bridge_rx_buff_ptr == NULL)
    {
#if _DEBUG
        printf("g_bridge_rx_buff_ptr  malloc failed\n");
#endif
    }

    _int_disable();
    g_bridge.handle = USB_Class_PHDC_Init(&phdc_config);
    Bridge_Interface_Init(Bridge_Callback);
    _int_enable();

    while(TRUE)
    {
        /* Block the task untill USB Enumeration is completed */
        if(_lwevent_wait_for(&lwevent,USB_ENUM_COMPLETED,FALSE,NULL) !=
                MQX_OK)
        {
#if _DEBUG
            printf("USB_ENUM_COMPLETEDEvent Wait failed\n");
#endif
            _task_block();
        }

        if(_lwevent_clear(&lwevent,USB_ENUM_COMPLETED) != MQX_OK)
        {
#if _DEBUG
            printf("Enum Event Clear failed\n");
#endif
            _task_block();
        }

        Bridge_Interface_Open(param);
    }
}
Exemple #6
0
static void usb_host_mass_test_storage
   (
      void
   )
{ /* Body */
   USB_STATUS                                 status = USB_OK;
   uint_8                                     bLun = 0;
   INQUIRY_DATA_FORMAT                        inquiry;
   CAPACITY_LIST                              capacity_list;
   #if 0
   MODE_SELECT_PARAMETER_LIST                 md_list;
   #endif
   MASS_STORAGE_READ_CAPACITY_CMD_STRUCT_INFO read_capacity;
   REQ_SENSE_DATA_FORMAT                      req_sense;
   FORMAT_UNIT_PARAMETER_BLOCK                formatunit = { 0};
   _mqx_int                                   block_len;
   DEVICE_DESCRIPTOR_PTR                      pdd;
   CBW_STRUCT_PTR cbw_ptr = pCmd->CBW_PTR;
   CSW_STRUCT_PTR csw_ptr = pCmd->CSW_PTR;

   USB_mem_zero(buff_out,0x0F);
   USB_mem_zero(buff_in,0x400C);
   USB_mem_zero(pCmd->CSW_PTR,sizeof(CSW_STRUCT));
   USB_mem_zero(pCmd->CBW_PTR,sizeof(CBW_STRUCT));
   USB_mem_zero(pCmd,sizeof(COMMAND_OBJECT_STRUCT));
   
   pCmd->CBW_PTR  = cbw_ptr;
   pCmd->CSW_PTR  = csw_ptr;
   pCmd->LUN      = bLun;
   pCmd->CALL_PTR = (pointer)&mass_device.class_intf;
   pCmd->CALLBACK = usb_host_mass_bulk_callback;

   printf("\n =============START OF A NEW SESSION==================");

   if (USB_OK != _usb_hostdev_get_descriptor(
      mass_device.dev_handle,
      NULL,
      USB_DESC_TYPE_DEV,
      0,
      0,
      (pointer *) &pdd))
   {
      printf ("\nCould not retrieve device descriptor.");
      return;
   }
   else
      printf("\nVID = 0x%04x, PID = 0x%04x", SHORT_LE_TO_HOST(*(uint_16*)pdd->idVendor), SHORT_LE_TO_HOST(*(uint_16*)pdd->idProduct));

   /* Test the GET MAX LUN command */
   printf("\nTesting: GET MAX LUN Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_class_mass_getmaxlun_bulkonly(
      (pointer)&mass_device.class_intf, &bLun,
      usb_host_mass_ctrl_callback);

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack) {;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }

   /* Test the TEST UNIT READY command */
   printf("Testing: TEST UNIT READY Command");
   fflush(stdout);

   bCallBack = FALSE;

   status =  usb_mass_ufi_test_unit_ready(pCmd);
   
   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }

   /* Test the REQUEST SENSE command */
   printf("Testing: REQUEST SENSE Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_request_sense(pCmd, &req_sense,
      sizeof(REQ_SENSE_DATA_FORMAT));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }

   /* Test the INQUIRY command */
   printf("Testing: INQUIRY Command");
   fflush(stdout);

   bCallBack = FALSE;

   status = usb_mass_ufi_inquiry(pCmd, (uchar_ptr) &inquiry,
      sizeof(INQUIRY_DATA_FORMAT));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the REQUEST SENSE command */
   printf("Testing: REQUEST SENSE Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_request_sense(pCmd, &req_sense,
      sizeof(REQ_SENSE_DATA_FORMAT));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the READ FORMAT CAPACITY command */
   printf("Testing: READ FORMAT CAPACITIES Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_format_capacity(pCmd, (uchar_ptr)&capacity_list,
      sizeof(CAPACITY_LIST));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the REQUEST SENSE command */
   printf("Testing: REQUEST SENSE Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_request_sense(pCmd, &req_sense,
      sizeof(REQ_SENSE_DATA_FORMAT));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the READ CAPACITY command */
   printf("Testing: READ CAPACITY Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_read_capacity(pCmd, (uchar_ptr)&read_capacity,
      sizeof(MASS_STORAGE_READ_CAPACITY_CMD_STRUCT_INFO));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   block_len = HOST_TO_BE_LONG(* (uint_32 *) &read_capacity.BLENGTH);

#if 0
   /* Test the MODE SELECT command */
   printf("Testing: MODE SELECT Command");
   fflush(stdout);
   bCallBack = FALSE;

   //md_list. Fill parameters here
   USB_mem_zero (&md_list, sizeof (MODE_SELECT_PARAMETER_LIST));
   md_list.MODE_PARAM_HEADER.BLENGTH[1] = 0x06;
   
   status = usb_mass_ufi_mode_select(pCmd, &md_list, 8);

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
#endif

   /* Test the REQUEST SENSE command */
   printf("Testing: REQUEST SENSE Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_request_sense(pCmd, &req_sense,
      sizeof(REQ_SENSE_DATA_FORMAT));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the READ(10) command */
   printf("Testing: READ(10) Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_read_10(pCmd, 0, buff_in, block_len, 1);

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the MODE SENSE command */
   printf("Testing: MODE SENSE Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_mode_sense(pCmd,
      2, //PC
      0x3F, //page code
      buff_in,
      (uint_32)0x08);

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the PREVENT ALLOW command */
   printf("Testing: PREVENT-ALLOW MEDIUM REMOVAL Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_prevent_allow_medium_removal(
      pCmd,
      1 // prevent
      );

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the REQUEST SENSE command */
   printf("Testing: REQUEST SENSE Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_request_sense(pCmd, &req_sense,
      sizeof(REQ_SENSE_DATA_FORMAT));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the VERIFY command */
   printf("Testing: VERIFY Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_verify(
      pCmd,
      0x400, // block address
      1 //length to be verified
      );

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }
   
   /* Test the WRITE(10) command */
   printf("Testing: WRITE(10) Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_write_10(pCmd, 8, buff_out, block_len, 1);

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }

   /* Test the REQUEST SENSE command */
   printf("Testing: REQUEST SENSE Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_request_sense(pCmd, &req_sense,
      sizeof(REQ_SENSE_DATA_FORMAT));

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }

   /* Test the START-STOP UNIT command */
   printf("Testing: START-STOP UNIT Command");
   fflush(stdout);
   bCallBack = FALSE;

   status = usb_mass_ufi_start_stop(pCmd, 0, 1);

   if ((status != USB_OK) && (status != USB_STATUS_TRANSFER_QUEUED))
   {
      printf ("\n...ERROR");
      return;
   }
   else
   {
      /* Wait till command comes back */
      while (!bCallBack){;}
      if (!bStatus) {
         printf("...OK\n");
      }
      else {
         printf("...Unsupported by device (bStatus=0x%x)\n", bStatus);
      }
   }

   printf("\nTest done!");
   fflush(stdout);
} /* Endbody */
Exemple #7
0
/**************************************************************************//*!
 *
 * @name  USB_Class_CDC_Init
 *
 * @brief The funtion initializes the Device and Controller layer 
 *
 * @param *cdc_config_ptr[IN]:  This structure contians configuration parameter
 *                              send by APP to configure CDC class.
 *
 * @return status       
 *         USB_OK           : When Successfull 
 *         Others           : Errors
 ******************************************************************************
 *
 *This function initializes the CDC Class layer and layers it is dependednt on 
 *
 *****************************************************************************/
uint_32 USB_Class_CDC_Init
(
  CDC_CONFIG_STRUCT_PTR cdc_config_ptr
)
{   
#if IMPLEMENT_QUEUING
    uint_8 index;
#endif

    uint_8 error;
    CDC_HANDLE cdc_handle;
    CDC_DEVICE_STRUCT_PTR devicePtr = NULL;
    USB_ENDPOINTS *usb_ep_data;
    
    if (NULL == (void *)cdc_config_ptr)
        return USBERR_ERROR;
    
    devicePtr = (CDC_DEVICE_STRUCT_PTR)USB_mem_alloc_zero(sizeof(CDC_DEVICE_STRUCT));
    if (NULL == devicePtr) 
    {
        #if _DEBUG
            printf("memalloc failed in USB_Class_CDC_Init\n");
        #endif  
        return USBERR_ALLOC;    
    }
    
    cdc_handle = USB_Cdc_Allocate_Handle();
    if (USBERR_DEVICE_BUSY == cdc_handle) 
    {
        USB_mem_free(devicePtr);
        devicePtr = NULL;
        return USBERR_INIT_FAILED;
    }

        /* initialize the Global Variable Structure */
    USB_mem_zero(devicePtr, sizeof(CDC_DEVICE_STRUCT));

    devicePtr->ep = cdc_config_ptr->ep;
    usb_ep_data = cdc_config_ptr->usb_ep_data;
    devicePtr->max_supported_interfaces = 
        cdc_config_ptr->max_supported_interfaces;
    #if RNDIS_SUPPORT
        USB_mem_copy(cdc_config_ptr->mac_address, devicePtr->mac_address, 
            sizeof(_enet_address));
        devicePtr->ip_address = cdc_config_ptr->ip_address;
        devicePtr->rndis_max_frame_size = cdc_config_ptr->rndis_max_frame_size;
    #endif
    /* Initialize the device layer*/
    error = _usb_device_init(USBCFG_DEFAULT_DEVICE_CONTROLLER, &devicePtr->controller_handle, (uint_8)(usb_ep_data->count+1));
    /* +1 is for Control Endpoint */ 
    if(error != USB_OK)
    {
      goto error1;  
    }
    
    cdc_config_ptr->desc_callback_ptr->handle = cdc_handle;
    
    /* Initialize the generic class functions */
    devicePtr->class_handle = USB_Class_Init(devicePtr->controller_handle,
    USB_Class_CDC_Event,USB_CDC_Other_Requests,(void *)devicePtr,
    cdc_config_ptr->desc_callback_ptr);

    /* Initialize the generic class functions */
    #if PSTN_SUBCLASS_NOTIF_SUPPORT
    /* Initialize the pstn subclass functions */
    error = USB_Pstn_Init(devicePtr,&cdc_config_ptr->param_callback);
    if(error != USB_OK)
    {
      goto error2;  
    }
    #endif
     
    devicePtr->usb_ep_data = usb_ep_data;
    #if IMPLEMENT_QUEUING
     for(index = 0; index < usb_ep_data->count; index++) 
     {            
        devicePtr->ep[index].endpoint = usb_ep_data->ep[index].ep_num;
        devicePtr->ep[index].type = usb_ep_data->ep[index].type;        
        devicePtr->ep[index].bin_consumer = 0x00;         
        devicePtr->ep[index].bin_producer = 0x00;        
      }
    #endif
        
    /* save the callback pointer */
    devicePtr->cdc_class_cb.callback = cdc_config_ptr->cdc_class_cb.callback;
    devicePtr->cdc_class_cb.arg = cdc_config_ptr->cdc_class_cb.arg;         
    /* save the callback pointer */
    devicePtr->vendor_req_callback.callback = 
    cdc_config_ptr->vendor_req_callback.callback;
    devicePtr->vendor_req_callback.arg = cdc_config_ptr->vendor_req_callback.arg; 
    /* save the callback pointer */
    devicePtr->param_callback.callback = cdc_config_ptr->param_callback.callback;
    devicePtr->param_callback.arg = cdc_config_ptr->param_callback.arg; 
    devicePtr->comm_feature_data_size =  cdc_config_ptr->comm_feature_data_size;  
    devicePtr->cic_send_endpoint = cdc_config_ptr->cic_send_endpoint;
    devicePtr->cic_recv_endpoint = USB_CONTROL_ENDPOINT;
    devicePtr->dic_send_endpoint = cdc_config_ptr->dic_send_endpoint;
    devicePtr->dic_recv_endpoint = cdc_config_ptr->dic_recv_endpoint; 
    devicePtr->dic_recv_pkt_size = cdc_config_ptr->dic_recv_pkt_size;
    devicePtr->dic_send_pkt_size = cdc_config_ptr->dic_send_pkt_size;
    devicePtr->cic_send_pkt_size = cdc_config_ptr->cic_send_pkt_size;
     
      
    devicePtr->cdc_handle = cdc_handle;
   
   cdc_device_array[cdc_handle] = devicePtr;
   
   return cdc_handle;
 error2:
  /* Implement Denit class and invoke here*/    
 error1: 
     USB_Cdc_Free_Handle(cdc_handle);
     USB_mem_free(devicePtr);
     devicePtr = NULL;    
    return error;    
}
Exemple #8
0
void usb_class_mass_init
   (
      /* [IN] structure with USB pipe information on the interface */
      PIPE_BUNDLE_STRUCT_PTR      pbs_ptr,

      /* [IN] printer call struct pointer */
      CLASS_CALL_STRUCT_PTR       ccs_ptr
   )
{ /* Body */
   USB_MASS_CLASS_INTF_STRUCT_PTR   intf_ptr = ccs_ptr->class_intf_handle;

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

   /* Pointer validity-checking, clear memory, init header of intf_ptr */
   if (usb_host_class_intf_init(pbs_ptr, intf_ptr, &mass_anchor)) 
   {
      #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("usb_class_mass_init");
      #endif
      return;
   }

   USB_lock();
   ccs_ptr->code_key = 0;
   ccs_ptr->code_key = usb_host_class_intf_validate( ccs_ptr );
   if (ccs_ptr->code_key == 0) goto Bad_Exit;

   /* Start filling up the members of interface handle (general class already filled) */
   intf_ptr->CONTROL_PIPE = usb_hostdev_get_pipe_handle(pbs_ptr,
      USB_CONTROL_PIPE, 0);
   intf_ptr->BULK_IN_PIPE = usb_hostdev_get_pipe_handle(pbs_ptr,
      USB_BULK_PIPE, USB_RECV);
   intf_ptr->BULK_OUT_PIPE = usb_hostdev_get_pipe_handle(pbs_ptr,
      USB_BULK_PIPE, USB_SEND);

   if (intf_ptr->CONTROL_PIPE    &&
      intf_ptr->BULK_IN_PIPE     &&
      intf_ptr->BULK_OUT_PIPE)  
   {
      /* Initialize the queue for storing the local copy of interface handles */
      usb_class_mass_q_init(intf_ptr);

      /* Store application handle */
      intf_ptr->APP = ccs_ptr;

      USB_unlock();
      #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("usb_class_mass_init, SUCCESSFULL");
      #endif
      
      return;
   } /* Endif */

Bad_Exit:
   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_class_mass_init, bad exit");
   #endif
   USB_mem_zero(intf_ptr, sizeof(USB_MASS_CLASS_INTF_STRUCT_PTR));
   ccs_ptr->class_intf_handle = NULL;
   ccs_ptr->code_key = 0;
   USB_unlock();
} /* Endbody */
/*FUNCTION*-------------------------------------------------------------
*
*  Function Name  : _usb_host_close_pipe
*  Returned Value : None
*  Comments       :
*        _usb_host_close_pipe routine removes the pipe from the open pipe list
*
*END*-----------------------------------------------------------------*/
USB_STATUS _usb_host_close_pipe
   (
      /* [IN] the USB Host state structure */
      _usb_host_handle     handle,
      
      /* [IN] the pipe (handle) to close */
      _usb_pipe_handle     pipe_handle
   )
{ /* Body */
   USB_STATUS error;
   USB_HOST_STATE_STRUCT_PTR usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)handle;
   PIPE_STRUCT_PTR pipe_ptr = (PIPE_STRUCT_PTR)pipe_handle;
   PIPE_STRUCT_PTR pipe_bkp_ptr;
   TR_STRUCT_PTR tr_ptr, tr_ptr_next;
   
   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("_usb_host_close_pipe");
   #endif

   if (pipe_ptr->PIPE_ID > USBCFG_MAX_PIPES) {
      #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_close_pipe invalid pipe");
      #endif
      return USB_log_error(__FILE__,__LINE__,USBERR_INVALID_PIPE_HANDLE);
   } /* Endif */

   USB_lock();

   /* Call the low-level routine to free the controller specific resources */
   error = _usb_host_close_pipe_call_interface (handle, pipe_ptr);

   if (error != USB_OK)
   {
      USB_unlock();

      #ifdef _HOST_DEBUG_
         DEBUG_LOG_TRACE("_usb_host_close_pipe FAILED");
      #endif
         
      return USB_log_error(__FILE__,__LINE__,error);
   }

   /* Before cleaning pipe_ptr struct we have to make sure that structures in the circullar list are really deallocated */
   /* Before deallocating structures in the list call the callback about failed pending transaction */
   if (pipe_ptr->tr_list_ptr != NULL) {
      tr_ptr = pipe_ptr->tr_list_ptr;
      do {
         tr_ptr_next = tr_ptr->NEXT;
         if (tr_ptr->TR_INDEX !=0 && tr_ptr->CALLBACK != NULL) {
            if (tr_ptr->RX_BUFFER != NULL) {
                tr_ptr->CALLBACK((void *)pipe_ptr, tr_ptr->CALLBACK_PARAM, tr_ptr->RX_BUFFER, 0, USBERR_PIPE_CLOSED);
            }
            else {
                tr_ptr->CALLBACK((void *)pipe_ptr, tr_ptr->CALLBACK_PARAM, tr_ptr->TX_BUFFER, 0, USBERR_PIPE_CLOSED);
            }
         }	 
         /* free transaction belonging to this pipe */
         USB_mem_free(tr_ptr);
         tr_ptr = tr_ptr_next;
      } while (tr_ptr != pipe_ptr->tr_list_ptr);  

      //pipe_ptr->tr_list_ptr = NULL; //this will be done later by zeroing pipe_ptr
   }

   /* De-initialise the pipe descriptor, but preserve the chain */
   pipe_bkp_ptr = pipe_ptr->NEXT;

   USB_mem_zero(pipe_ptr, usb_host_ptr->PIPE_SIZE);
   /* restore the chain */
   pipe_ptr->NEXT = pipe_bkp_ptr;

   USB_unlock();

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

   return USB_OK;

} /* Endbody */