Example #1
0
/**************************************************************************//*!
 *
 * @name  USB_Class_CDC_Event
 *
 * @brief The function initializes CDC endpoints
 *
 * @param handle   handle to Identify the controller
 * @param event           pointer to event structure
 * @param val             gives the configuration value
 *
 * @return None
 *
 *****************************************************************************/
void USB_Class_CDC_Event(uint8_t event, void* val, void* arg)
{
    usb_interfaces_struct_t usb_interfaces = {0, NULL};
    cdc_device_struct_t * cdc_obj_ptr = NULL;
    cdc_obj_ptr = (cdc_device_struct_t *)arg;
    uint8_t index;
    
    if (event == USB_DEV_EVENT_CONFIG_CHANGED)
    {
#if CDC_RNDIS_SUPPORT
        uint32_t max_if_count;
#endif
        usb_ep_struct_t* ep_struct_ptr = NULL;
        /* Get class info */
        if(USB_UNINITIALIZED_VAL_32 != USB_Class_Get_Class_Handle(cdc_obj_ptr->controller_id))
        {
            usb_composite_info_struct_t* usbcompinfoPtr;
            uint32_t interface_index = 0xFF;
            
            cdc_obj_ptr->desc_callback.get_desc_entity((uint32_t)cdc_obj_ptr,
                    USB_COMPOSITE_INFO,
                    (uint32_t*)&usbcompinfoPtr);
            cdc_obj_ptr->desc_callback.get_desc_entity((uint32_t)cdc_obj_ptr,
                    USB_CLASS_INTERFACE_INDEX_INFO, (uint32_t *)&interface_index);

            if ((interface_index < usbcompinfoPtr->count) && (usbcompinfoPtr->class_handle[interface_index].type == USB_CLASS_COMMUNICATION))
            {
                usb_interfaces = usbcompinfoPtr->class_handle[interface_index].interfaces;
            }
            else
            {
                return;
            }
        }
        else
        {
            usb_class_struct_t* usbclassPtr;
            cdc_obj_ptr->desc_callback.get_desc_entity((uint32_t)cdc_obj_ptr,
                    USB_CLASS_INFO,
                    (uint32_t*)&usbclassPtr);
            usb_interfaces = usbclassPtr->interfaces;
        }
#if CDC_RNDIS_SUPPORT
        /* Get count of interfaces for a specific configuration */
        USB_Cdc_Get_Desc_Info(cdc_obj_ptr, USB_CDC_INTERFACE_COUNT, &max_if_count);
        cdc_obj_ptr->max_supported_interfaces = max_if_count;
#endif
        if (NULL != cdc_obj_ptr->ep)
        {
             index = 0;
                 
            for (int inter_index =0; inter_index < usb_interfaces.count; inter_index++)
            {
                for (int ep_index = 0; ep_index < usb_interfaces.interface[inter_index].endpoints.count; ep_index++)
                {
                    ep_struct_ptr = &usb_interfaces.interface[inter_index].endpoints.ep[ep_index];

                    cdc_obj_ptr->ep[index].endpoint = ep_struct_ptr->ep_num;
                    cdc_obj_ptr->ep[index].type = ep_struct_ptr->type;
                    cdc_obj_ptr->ep[index].direction = ep_struct_ptr->direction;
#if CDC_IMPLEMENT_QUEUING
                    cdc_obj_ptr->ep[index].bin_consumer = 0x00;
                    cdc_obj_ptr->ep[index].bin_producer = 0x00;
#endif
                    index++;
               }
            }

        }
        /* Initialize all non control endpoints */
        for (int inter_index =0; inter_index < usb_interfaces.count; inter_index++)
        {
            for (int ep_index = 0; ep_index < usb_interfaces.interface[inter_index].endpoints.count; ep_index++)
            {
                ep_struct_ptr = &usb_interfaces.interface[inter_index].endpoints.ep[ep_index];
                (void)usb_device_init_endpoint(cdc_obj_ptr->controller_handle,ep_struct_ptr, TRUE);

                /* register callback service for Non Control EndPoints */
                switch(ep_struct_ptr->type)
                {
                case USB_INTERRUPT_PIPE:
                    (void)usb_device_register_service(cdc_obj_ptr->controller_handle,
                                                      (uint8_t)((uint8_t)(USB_SERVICE_EP0 + ep_struct_ptr->ep_num) | ((uint8_t)(ep_struct_ptr->direction << 7))),
                                                      USB_Service_Cdc_Notif, (void *)cdc_obj_ptr);
                    cdc_obj_ptr->cic_recv_endpoint = USB_CONTROL_ENDPOINT;
                    cdc_obj_ptr->cic_send_endpoint = ep_struct_ptr->ep_num;
                    cdc_obj_ptr->cic_send_pkt_size = ep_struct_ptr->size;
                    break;
                case USB_BULK_PIPE:
                    if (ep_struct_ptr->direction == USB_RECV)
                    {
                        (void)usb_device_register_service(cdc_obj_ptr->controller_handle,
                                                          (uint8_t)((uint8_t)(USB_SERVICE_EP0 + ep_struct_ptr->ep_num) | ((uint8_t)(ep_struct_ptr->direction << 7))),
                                                          USB_Service_Dic_Bulk_Out, (void *)cdc_obj_ptr);
                        cdc_obj_ptr->dic_recv_endpoint = ep_struct_ptr->ep_num;
                        cdc_obj_ptr->dic_recv_pkt_size = ep_struct_ptr->size;
                    }
                    else
                    {
                        (void)usb_device_register_service(cdc_obj_ptr->controller_handle,
                                                          (uint8_t)((uint8_t)(USB_SERVICE_EP0 + ep_struct_ptr->ep_num) | ((uint8_t)(ep_struct_ptr->direction << 7))),
                                                          USB_Service_Dic_Bulk_In, (void *)cdc_obj_ptr);
                        cdc_obj_ptr->dic_send_endpoint = ep_struct_ptr->ep_num;
                        cdc_obj_ptr->dic_send_pkt_size = ep_struct_ptr->size;
                    }
                    break;
                default:
                    break;
                }
            }
         }

    }
    else if (event == USB_DEV_EVENT_ENUM_COMPLETE)
    {
        /* To Do */
    }
    else if(event == USB_DEV_EVENT_TYPE_CLR_EP_HALT)
    {
        uint8_t value;
        value = *((uint8_t *)val);
        if (cdc_obj_ptr->ep != NULL)
        {
            for (index = 0; index < MAX_CDC_EP_NUM; index++)
            {
                if((value & 0x0F) == (cdc_obj_ptr->ep[index].endpoint &0x0F))
                {
                    usb_device_unstall_endpoint(cdc_obj_ptr->controller_handle,(value & 0x0F), ((uint8_t)(value & 0x80)) >> 7);
                }
            }
        }
Example #2
0
/**************************************************************************//*!
 *
 * @name  USB_Class_PHDC_Event
 *
 * @brief Initializes non control endpoints
 *
 * @param handle         
 * @param event          : event notified by the layer below
 * @param value          : additional parameter used by the event
 *
 * @return               : None
 ******************************************************************************
 * Initializes non control endpoints when Enumeration complete event is 
 * received.
 *****************************************************************************/
void USB_Class_PHDC_Event
(
uint8_t event,
void* val,
void* arg
)
{
    uint8_t count_rx = 0;
    uint8_t count_tx = 0;
    uint8_t index;
    usb_ep_struct_t* ep_struct_ptr;
    phdc_device_struct_t* devicePtr;
    uint8_t * phdc_qos;
    usb_interfaces_struct_t usb_interfaces;

    devicePtr = (phdc_device_struct_t *)arg;

    /* if enum is complete initialize non-control endpoints */
    if (event == USB_DEV_EVENT_CONFIG_CHANGED)
    {
        uint8_t count = 0;
        if(USB_UNINITIALIZED_VAL_32 != USB_Class_Get_Class_Handle(devicePtr->controller_id))
        {
            uint8_t type_sel;
            usb_composite_info_struct_t* usb_composite_info;
            uint32_t interface_index = 0xFF;
            devicePtr->desc_callback.get_desc_entity((uint32_t)devicePtr,
            USB_COMPOSITE_INFO,
            (uint32_t *)&usb_composite_info);

            devicePtr->desc_callback.get_desc_entity((uint32_t)devicePtr,
            USB_PHDC_QOS_INFO,
            (uint32_t *)&phdc_qos);

            devicePtr->desc_callback.get_desc_entity((uint32_t)devicePtr,
            USB_CLASS_INTERFACE_INDEX_INFO, (uint32_t *)&interface_index);
            if(interface_index == 0xFF)
            {
#if _DEBUG
                USB_PRINTF("not find interface index\n");
#endif  
                return;
            }

            for (type_sel = 0;type_sel < usb_composite_info->count;type_sel++)
            {
                if ((usb_composite_info->class_handle[type_sel].type == USB_CLASS_PHDC) && (type_sel == interface_index))
                {
                    break;
                }
            }
            if(type_sel >= usb_composite_info->count)
            {
#if _DEBUG
                USB_PRINTF("not find phdc interface\n");
#endif 
                return;
            }

            devicePtr->ep_desc_data = (usb_endpoints_t *) &usb_composite_info->class_handle[type_sel].interfaces.interface->endpoints;
            usb_interfaces = usb_composite_info->class_handle[type_sel].interfaces;

          } 
        else
        {
            usb_class_struct_t* usbclass = NULL;
            devicePtr->desc_callback.get_desc_entity((uint32_t)devicePtr->handle,
            USB_CLASS_INFO, (uint32_t *)&usbclass);
            devicePtr->desc_callback.get_desc_entity((uint32_t)devicePtr->handle,
            USB_PHDC_QOS_INFO, (uint32_t *)&phdc_qos);
            devicePtr->ep_desc_data = (usb_endpoints_t *) &usbclass->interfaces.interface->endpoints;
            usb_interfaces = usbclass->interfaces;
        }

        devicePtr->phdc_endpoint_data.count_rx = 0; /* init the count_rx */
        devicePtr->phdc_endpoint_data.count_tx = 0; /* init the count_tx */
        /* calculate the rx and tx endpoint counts */
        for (index = 0; index < usb_interfaces.interface->endpoints.count; index++)
        {
            if ((usb_interfaces.interface->endpoints.ep[index].direction == USB_RECV) &
            (devicePtr->phdc_endpoint_data.count_rx < PHDC_RX_ENDPOINTS))
            {
                devicePtr->phdc_endpoint_data.count_rx++;
            }
            else if ((usb_interfaces.interface->endpoints.ep[index].direction == USB_SEND) &
            (devicePtr->phdc_endpoint_data.count_tx < PHDC_TX_ENDPOINTS))
            {
                devicePtr->phdc_endpoint_data.count_tx++;
            }
        }
        
        /* initialize endpoint data structure for all endpoints */
        for (index = 0; index < usb_interfaces.interface->endpoints.count; index++)
        {
            if ((usb_interfaces.interface->endpoints.ep[index].direction == USB_RECV) &
            (count_rx < PHDC_RX_ENDPOINTS))
            {
                /* initialize endpoint data structure for recv endpoint */
                devicePtr->phdc_endpoint_data.ep_rx[count_rx].endpoint =
                usb_interfaces.interface->endpoints.ep[index].ep_num;
                devicePtr->phdc_endpoint_data.ep_rx[count_rx].type =
                usb_interfaces.interface->endpoints.ep[index].type;
                devicePtr->phdc_endpoint_data.ep_rx[count_rx].size =
                usb_interfaces.interface->endpoints.ep[index].size;
                devicePtr->phdc_endpoint_data.ep_rx[count_rx].qos = phdc_qos[index];
                devicePtr->phdc_endpoint_data.ep_rx[count_rx].current_qos = INVALID_VAL;
                devicePtr->phdc_endpoint_data.ep_rx[count_rx].buff_ptr = NULL;
                devicePtr->phdc_endpoint_data.ep_rx[count_rx].buffer_size = 0;
                /* increment count_rx by 1 */
                count_rx++;
            }
            else if ((usb_interfaces.interface->endpoints.ep[index].direction == USB_SEND) &
            (count_tx < PHDC_TX_ENDPOINTS))
            {
                /* initialize endpoint data structure for send endpoint */
                devicePtr->phdc_endpoint_data.ep_tx[count_tx].endpoint =
                usb_interfaces.interface->endpoints.ep[index].ep_num;
                devicePtr->phdc_endpoint_data.ep_tx[count_tx].type =
                usb_interfaces.interface->endpoints.ep[index].type;
                devicePtr->phdc_endpoint_data.ep_tx[count_tx].size =
                usb_interfaces.interface->endpoints.ep[index].size;
                devicePtr->phdc_endpoint_data.ep_tx[count_tx].qos = phdc_qos[index];
                devicePtr->phdc_endpoint_data.ep_tx[count_tx].current_qos = INVALID_VAL;
                devicePtr->phdc_endpoint_data.ep_tx[count_tx].bin_consumer = 0x00;
                devicePtr->phdc_endpoint_data.ep_tx[count_tx].bin_producer = 0x00;
                /* increment count_tx by 1 */
                count_tx++;
            }
        }

        
        usb_endpoints_t *ep_desc_data = devicePtr->ep_desc_data;
        /* initialize all non control endpoints */
        count = 0;
        while (count < ep_desc_data->count)
        {
            ep_struct_ptr= (usb_ep_struct_t*) &ep_desc_data->ep[count];
            (void)usb_device_init_endpoint(devicePtr->handle, ep_struct_ptr, TRUE);

            /* register callback service for endpoint 1 */
            (void)usb_device_register_service(devicePtr->handle,
            (uint8_t)((uint8_t)(USB_SERVICE_EP0+ep_struct_ptr->ep_num) | ((uint8_t)(ep_struct_ptr->direction << 7))),
            USB_PHDC_Endpoint_Service, arg);
            count++;
        }
    }
    else if (event == USB_DEV_EVENT_ENUM_COMPLETE)
    {

    }
    else if (event == USB_DEV_EVENT_BUS_RESET)
    {

    }

    if (devicePtr->phdc_application_callback.callback != NULL)
    {
        devicePtr->phdc_application_callback.callback(event,val,devicePtr->phdc_application_callback.arg);
    }
}
Example #3
0
/*************************************************************************//*!
 *
 * @name  USB_Cdc_Get_Desc_Info
 *
 * @brief The function gets the info of the descriptors. .
 *
 * @param handle  index in device array.
 * @param type     descriptor type.
 * @param object   store the returned value.
 * @return returns USB_OK if successful.
 *
 *****************************************************************************/
usb_status USB_Cdc_Get_Desc_Info(cdc_device_struct_t * cdc_obj_ptr, USB_DESC_INFO_T type, uint32_t * object)
{
    usb_class_struct_t* usbclassPtr;
    usb_interfaces_struct_t * ifs_ptr;
    /* Get class info */
    usb_composite_info_struct_t* usbcompinfoPtr;
    uint32_t interface_index;
    if(USB_UNINITIALIZED_VAL_32 != USB_Class_Get_Class_Handle(cdc_obj_ptr->controller_id))
    {
        cdc_obj_ptr->desc_callback.get_desc_entity((uint32_t)cdc_obj_ptr,
                USB_COMPOSITE_INFO,
                (uint32_t *)&usbcompinfoPtr);
        cdc_obj_ptr->desc_callback.get_desc_entity((uint32_t)cdc_obj_ptr,
                USB_CLASS_INTERFACE_INDEX_INFO,
                (uint32_t *)&interface_index);
    }
    else
    {
        cdc_obj_ptr->desc_callback.get_desc_entity((uint32_t)cdc_obj_ptr,
                USB_CLASS_INFO,
                (uint32_t *)&usbclassPtr);
    }
    switch(type)
    {
    case USB_EP_COUNT:
    case USB_CDC_EP_COUNT:
    {
        uint32_t ep_cnt = 0;
        if(USB_UNINITIALIZED_VAL_32 != USB_Class_Get_Class_Handle(cdc_obj_ptr->controller_id))
        {
            if ((interface_index < usbcompinfoPtr->count) && (usbcompinfoPtr->class_handle[interface_index].type == USB_CLASS_COMMUNICATION))
            {
                usbclassPtr = &(usbcompinfoPtr->class_handle[interface_index]);
            }
            else
            {
                *object = 0;
                break;
            }
        }
        ifs_ptr = &usbclassPtr->interfaces;
        for (uint8_t if_index = 0; if_index < ifs_ptr->count; if_index++)
        {
            ep_cnt += ifs_ptr->interface[if_index].endpoints.count;
        }
        *object = ep_cnt;
        break;
    }
    case USB_INTERFACE_COUNT:
    case USB_CDC_INTERFACE_COUNT:
    {
        if(USB_UNINITIALIZED_VAL_32 != USB_Class_Get_Class_Handle(cdc_obj_ptr->controller_id))
        {
            if ((interface_index < usbcompinfoPtr->count) && (usbcompinfoPtr->class_handle[interface_index].type == USB_CLASS_COMMUNICATION))
            {
                usbclassPtr = &(usbcompinfoPtr->class_handle[interface_index]);
            }
            else
            {
                *object = 0;
                break;
            }
         }
        ifs_ptr = &usbclassPtr->interfaces;
        *object = ifs_ptr->count;
        break;
    }
    default:
        break;
    }
    return USB_OK;
}