/**************************************************************************//*! * * @name USB_Composite_Init * * @brief The funtion initializes the Device and Controller layer * * @param controller_ID : Controller ID * @param composite_callback_ptr : Pointer to app callback * * @return status: * USB_OK : When Successfull * Others : When Error * ****************************************************************************** *This function initializes the Composite layer *****************************************************************************/ uint_8 USB_Composite_Init( uint_8 controller_ID, /* [IN] Controller ID */ COMPOSITE_CALLBACK_STRUCT * composite_callback_ptr /* [IN] Pointer to class info */ ) { uint_8 count,status; DEV_ARCHITECTURE_STRUCT_PTR dev_arc_ptr; CLASS_ARC_STRUCT_PTR dev_class_ptr; /* Get device architecture */ dev_arc_ptr = (DEV_ARCHITECTURE_STRUCT *)USB_Desc_Get_Class_Architecture(controller_ID); /* Device init */ status = _usb_device_init(controller_ID, NULL, (uint_8)(dev_arc_ptr->ep_count+1), TRUE); if(status == USB_OK) { /* Initialize the generic class functions */ status = USB_Class_Init(controller_ID,USB_Composite_Event, USB_Composite_Other_Requests); if(status == USB_OK) { for(count = 0; count < dev_arc_ptr->cl_count; count++) { dev_class_ptr = (CLASS_ARC_STRUCT_PTR)dev_arc_ptr->value[count]; /* Initializes sub_classes */ switch(dev_class_ptr->class_type) { #ifdef USE_HID_CLASS case HID_COMP_CC: (void)USB_Class_HID_Init( controller_ID,composite_callback_ptr->class_app_callback[count]->composite_class_callback, composite_callback_ptr->class_app_callback[count]->vendor_req_callback, composite_callback_ptr->class_app_callback[count]->param_specific_callback); break; #endif #ifdef USE_AUDIO_CLASS case AUDIO_COMP_CC: (void)USB_Class_Audio_Init( controller_ID,composite_callback_ptr->class_app_callback[count]->composite_class_callback, composite_callback_ptr->class_app_callback[count]->vendor_req_callback, composite_callback_ptr->class_app_callback[count]->param_callback); break; #endif #ifdef USE_VIDEO_CLASS case VIDEO_COMP_CC: (void)USB_Class_Video_Init( controller_ID,composite_callback_ptr->class_app_callback[count]->composite_class_callback, composite_callback_ptr->class_app_callback[count]->vendor_req_callback, composite_callback_ptr->class_app_callback[count]->param_callback); break; #endif #ifdef USE_CDC_CLASS case CDC_COMP_CC: (void)USB_Class_CDC_Init( controller_ID,composite_callback_ptr->class_app_callback[count]->composite_class_callback, composite_callback_ptr->class_app_callback[count]->vendor_req_callback, composite_callback_ptr->class_app_callback[count]->param_callback, TRUE); break; #endif #ifdef USE_MSD_CLASS case MSD_COMP_CC: (void)USB_Class_MSC_Init( controller_ID,composite_callback_ptr->class_app_callback[count]->composite_class_callback, composite_callback_ptr->class_app_callback[count]->vendor_req_callback, composite_callback_ptr->class_app_callback[count]->param_callback); break; #endif #ifdef USE_PHDC_CLASS case PHDC_COMP_CC: (void)USB_Class_PHDC_Init( controller_ID,composite_callback_ptr->class_app_callback[count]->composite_class_callback, composite_callback_ptr->class_app_callback[count]->vendor_req_callback); break; #endif #ifdef USE_DFU_CLASS case DFU_COMP_CC: (void)USB_Class_Dfu_Init( controller_ID,composite_callback_ptr->class_app_callback[count]->composite_class_callback, composite_callback_ptr->class_app_callback[count]->vendor_req_callback, composite_callback_ptr->class_app_callback[count]->param_callback); break; #endif default: break; } } } } return status; }
/*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); } }