Ejemplo n.º 1
0
void usb_host_cdc_acm_event
   (
      /* [IN] pointer to device instance */
      _usb_device_instance_handle      dev_handle,

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

      /* [IN] code number for event causing callback */
      uint_32                          event_code
   )
{ /* Body */
   INTERFACE_DESCRIPTOR_PTR   intf_ptr = (INTERFACE_DESCRIPTOR_PTR)intf_handle;

   fflush(stdout);
   switch (event_code) {
      case USB_CONFIG_EVENT:
         /* Drop through into attach, same processing */
      case USB_ATTACH_EVENT: {
         USB_CDC_DESC_ACM_PTR    acm_desc = NULL;
         USB_CDC_DESC_CM_PTR     cm_desc = NULL;
         USB_CDC_DESC_HEADER_PTR header_desc = NULL;
         USB_CDC_DESC_UNION_PTR  union_desc = NULL;

         /* finds all the descriptors in the configuration */
         if (USB_OK != usb_class_cdc_get_acm_descriptors(dev_handle,
             intf_handle,
             &acm_desc,
             &cm_desc,
             &header_desc,
             &union_desc))
            break;

         /* initialize new interface members and select this interface */
         if (USB_OK != _usb_hostdev_select_interface(dev_handle,
            intf_handle, (pointer)&acm_device.CLASS_INTF))
         {
            break;
         }
         /* set all info got from descriptors to the class interface struct */
         usb_class_cdc_set_acm_descriptors((pointer)&acm_device.CLASS_INTF,
            acm_desc, cm_desc, header_desc, union_desc);

         /* link all already registered data interfaces to this ACM control, if needed */
         if (USB_OK != usb_class_cdc_bind_data_interfaces(dev_handle, (pointer)&acm_device.CLASS_INTF)) {
            break;
         }
         
         printf("----- CDC control interface attach Event -----\n");
         fflush(stdout);
         printf("State = attached");
         printf("  Class = %d", intf_ptr->bInterfaceClass);
         printf("  SubClass = %d", intf_ptr->bInterfaceSubClass);
         printf("  Protocol = %d\n", intf_ptr->bInterfaceProtocol);
         fflush(stdout);

         break;
      }
      case USB_INTF_EVENT: 
      {
         CLASS_CALL_STRUCT_PTR   acm_parser;
         USB_STATUS              status;
         
         if (NULL == (acm_parser = usb_class_cdc_get_ctrl_interface(intf_handle)))
             break;
         if (MQX_OK != usb_class_cdc_acm_use_lwevent(acm_parser, &acm_device.acm_event))
             break;
         status = usb_class_cdc_init_ipipe(acm_parser);
         if ((status != USB_OK) && (status != USBERR_OPEN_PIPE_FAILED))
             break;
         
         printf("----- CDC control interface selected -----\n");

         break;
      }
         
      case USB_DETACH_EVENT:
      {
         CLASS_CALL_STRUCT_PTR acm_parser;
         
         if (NULL == (acm_parser = usb_class_cdc_get_ctrl_interface(intf_handle)))
             break;
         
         /* Allow tasks waiting for acm to be finished...
         ** We will not wait here - in the interrupt context.
         ** For simplification, we dont use any semaphore to indicate that
         ** all tasks have finished its job with device. Instead, we are just
         ** informed them that device is detached and we rely on USB stack layer
         ** that its check of the available device returns false.
         ** The code that would synchronize tasks to be finished would look like:
         **
         **  _lwsem_wait(tasks_using_device_semaphore);
         **
         **  where the semaphore would be signalled from this interrupt.
         */

         usb_class_cdc_unbind_data_interfaces(acm_parser);

         /* Use only the interface with desired protocol */
         printf("----- CDC control interface detach event -----\n");
         fflush(stdout);
         printf("State = detached");
         printf("  Class = %d", intf_ptr->bInterfaceClass);
         printf("  SubClass = %d", intf_ptr->bInterfaceSubClass);
         printf("  Protocol = %d\n", intf_ptr->bInterfaceProtocol);
         fflush(stdout);

         break;
      }

      default:
         printf("CDC device: unknown control event\n");
         fflush(stdout);
         break;
   } /* EndSwitch */
} /* Endbody */
Ejemplo n.º 2
0
void usb_host_cdc_acm_event
   (
      /* [IN] pointer to device instance */
      _usb_device_instance_handle      dev_handle,

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

      /* [IN] code number for event causing callback */
      uint_32                          event_code
   )
{ /* Body */
   INTERFACE_DESCRIPTOR_PTR   intf_ptr = (INTERFACE_DESCRIPTOR_PTR)intf_handle;
   ACM_DEVICE_STRUCT_PTR      acm_device;

#if 0 /* << EST */
   fflush(stdout);
#endif
   switch (event_code) 
   {
      case USB_CONFIG_EVENT:
         /* Drop through into attach, same processing */
      case USB_ATTACH_EVENT: 
      {
         USB_CDC_DESC_ACM_PTR     	acm_desc = NULL; 
         USB_CDC_DESC_CM_PTR      	cm_desc = NULL;
         USB_CDC_DESC_HEADER_PTR 	header_desc = NULL;
         USB_CDC_DESC_UNION_PTR 	union_desc = NULL;
         int_32                     external_data = 0;

         /* finds all the descriptors in the configuration */
         if (USB_OK != usb_class_cdc_get_acm_descriptors(dev_handle,
             intf_handle,
             &acm_desc, 
             &cm_desc, 
             &header_desc, 
             &union_desc)) 
            break;
         /* we can allocate new acm device */
         if (NULL == (acm_device = USB_mem_alloc_zero(sizeof(ACM_DEVICE_STRUCT))))
            break;
         /* initialize new interface members and select this interface */
         if (USB_OK != _usb_hostdev_select_interface(dev_handle,
            intf_handle, (pointer)&acm_device->CLASS_INTF))
         {
            free(acm_device);
            break;
         }
         /* set all info got from descriptors to the class interface struct */
         usb_class_cdc_set_acm_descriptors((pointer)&acm_device->CLASS_INTF,
            acm_desc, cm_desc, header_desc, union_desc);

         /* link all already registered data interfaces to this ACM control, if needed */
         if (USB_OK != usb_class_cdc_bind_data_interfaces(dev_handle, (pointer)&acm_device->CLASS_INTF)) 
         {
            free(acm_device);
            break;
         }
#if 0 /* << EST */
         printf("----- CDC control interface attach Event -----\n");
         fflush(stdout);
         printf("State = attached");
         printf("  Class = %%d", intf_ptr->bInterfaceClass);
         printf("  SubClass = %%d", intf_ptr->bInterfaceSubClass);
         printf("  Protocol = %%d\n", intf_ptr->bInterfaceProtocol);
         fflush(stdout);
#endif
         check_open = 0;
         break;
      }
      case USB_INTF_EVENT: 
      {
         CLASS_CALL_STRUCT_PTR   acm_parser;
         USB_STATUS              status;
         
         if (NULL == (acm_parser = usb_class_cdc_get_ctrl_interface(intf_handle)))
             break;
         status = usb_class_cdc_init_ipipe(acm_parser);
         if ((status != USB_OK) && (status != USBERR_OPEN_PIPE_FAILED))
             break;
         
#if 0 /* << EST */
         printf("----- CDC control interface selected -----\n");
#endif
         
         break;
      }
         
      case USB_DETACH_EVENT:
      {
         CLASS_CALL_STRUCT_PTR acm_parser;
         USB_ACM_CLASS_INTF_STRUCT_PTR if_ptr;
         
         if (NULL == (acm_parser = usb_class_cdc_get_ctrl_interface(intf_handle)))
             break;
         if_ptr = (USB_ACM_CLASS_INTF_STRUCT_PTR) acm_parser->class_intf_handle;
         
         _usb_event_set(&if_ptr->acm_event, USB_ACM_DETACH); /* mark we are not using input pipe */

         /* Allow tasks waiting for acm to be finished...
         ** This does have sense only if this task will not be active
         ** or scheduler switches to another task.
         ** For simplification, we dont use any semaphore to indicate that
         ** all tasks have finished its job with device. Instead, we have just
         ** informed them that device is detached and we rely on USB stack layer
         ** that it checking if the device is available returns false.
         ** The code that would synchronize tasks to be finished would look like:
         **
         **  _lwsem_wait(if_ptr->device_using_tasks);
         */

         usb_class_cdc_unbind_data_interfaces(acm_parser);

         USB_unlock();
         
         free(acm_parser);
         /* Use only the interface with desired protocol */
#if 0 /* << EST */
         printf("----- CDC control interface detach event -----\n");
         fflush(stdout);
         printf("State = detached");
         printf("  Class = %%d", intf_ptr->bInterfaceClass);
         printf("  SubClass = %%d", intf_ptr->bInterfaceSubClass);
         printf("  Protocol = %%d\n", intf_ptr->bInterfaceProtocol);
         fflush(stdout);
#endif
         
         break;
      }

         break;
      default:
#if 0 /* << EST */
         printf("CDC device: unknown control event\n");
         fflush(stdout);
#endif
         break;
   } /* EndSwitch */
} /* Endbody */