void usb_class_hub_init ( /* [IN] structure with USB pipe information on the interface */ PIPE_BUNDLE_STRUCT_PTR pbs_ptr, /* [IN] hub call struct pointer */ CLASS_CALL_STRUCT_PTR ccs_ptr ) { /* Body */ USB_STATUS status; USB_HUB_CLASS_INTF_STRUCT_PTR if_ptr = ccs_ptr->class_intf_handle; /* Make sure the device is still attached */ status = usb_host_class_intf_init(pbs_ptr, if_ptr, &hub_anchor); if (status == USB_OK) { /* ** We generate a code_key based on the attached device. This is used to ** verify that the device has not been detached and replaced with another. */ ccs_ptr->code_key = 0; ccs_ptr->code_key = usb_host_class_intf_validate(ccs_ptr); if_ptr->P_CONTROL = usb_hostdev_get_pipe_handle(pbs_ptr, USB_CONTROL_PIPE, 0); if_ptr->P_INT_IN = usb_hostdev_get_pipe_handle(pbs_ptr, USB_INTERRUPT_PIPE, USB_RECV); } /* Endif */ /* Signal that an error has occured by setting the "code_key" to 0 */ if (status || !if_ptr->P_INT_IN || !if_ptr->P_CONTROL) { ccs_ptr->code_key = 0; } /* Endif */ } /* Endbody */
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 /* pointer2 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); USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_init, Q init failed"); #endif return; } /* Endif */ Bad_Exit: #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_init, bad exit"); #endif memset(intf_ptr, 0, 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_class_audio_stream_init * Returned Value : None * Comments : * This function is called by common class to initialize the class driver * for audio stream interface. It is called in response to a select * interface call by application. * *END*--------------------------------------------------------------------*/ void usb_class_audio_stream_init ( /* [IN] structure with USB pipe information on the interface */ PIPE_BUNDLE_STRUCT_PTR pbs_ptr, /* [IN] stream call struct pointer */ CLASS_CALL_STRUCT_PTR ccs_ptr ) { /* Body */ AUDIO_STREAM_INTERFACE_STRUCT_PTR if_ptr = ccs_ptr->class_intf_handle; USB_STATUS status; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_audio_stream_init"); #endif /* Make sure the device is still attached */ USB_lock(); status = usb_host_class_intf_init(pbs_ptr, if_ptr, &audio_stream_anchor); if (status == USB_OK) { /* Check the audio stream interface alternating 1 */ if (0 != (((INTERFACE_DESCRIPTOR_PTR)if_ptr->AUDIO_G.G.intf_handle)->bNumEndpoints)) { /* ** We generate a code_key based on the attached device. This is used to ** verify that the device has not been detached and replaced with another. */ ccs_ptr->code_key = 0; ccs_ptr->code_key = usb_host_class_intf_validate(ccs_ptr); if_ptr->AUDIO_G.IFNUM = ((INTERFACE_DESCRIPTOR_PTR)if_ptr->AUDIO_G.G.intf_handle)->bInterfaceNumber; if_ptr->iso_in_pipe = usb_hostdev_get_pipe_handle(pbs_ptr, USB_ISOCHRONOUS_PIPE, USB_RECV); if_ptr->iso_out_pipe = usb_hostdev_get_pipe_handle(pbs_ptr, USB_ISOCHRONOUS_PIPE, USB_SEND); if ((if_ptr->iso_in_pipe == NULL) && (if_ptr->iso_out_pipe == NULL)) status = USBERR_OPEN_PIPE_FAILED; } else { status = USBERR_INIT_FAILED; } } /* Endif */ /* Signal that an error has occured by setting the "code_key" */ if (status) { ccs_ptr->code_key = 0; } /* Endif */ USB_unlock(); #ifdef _HOST_DEBUG_ if (status) DEBUG_LOG_TRACE("usb_class_audio_stream_init, SUCCESSFUL"); else DEBUG_LOG_TRACE("usb_class_audio_stream_init, FAILED"); #endif } /* Endbody */
void usb_class_audio_control_init ( /* [IN] structure with USB pipe information on the interface */ PIPE_BUNDLE_STRUCT_PTR pbs_ptr, /* [IN] audio call struct pointer */ CLASS_CALL_STRUCT_PTR ccs_ptr ) { /* Body */ AUDIO_CONTROL_INTERFACE_STRUCT_PTR if_ptr = ccs_ptr->class_intf_handle; USB_STATUS status; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_audio_control_init"); #endif /* Make sure the device is still attached */ USB_lock(); status = usb_host_class_intf_init(pbs_ptr, if_ptr, &audio_control_anchor); if (status == USB_OK) { /* ** We generate a code_key based on the attached device. This is used to ** verify that the device has not been detached and replaced with another. */ ccs_ptr->code_key = 0; ccs_ptr->code_key = usb_host_class_intf_validate(ccs_ptr); if_ptr->AUDIO_G.IFNUM = ((INTERFACE_DESCRIPTOR_PTR)if_ptr->AUDIO_G.G.intf_handle)->bInterfaceNumber; if_ptr->interrupt_pipe = usb_hostdev_get_pipe_handle(pbs_ptr, USB_INTERRUPT_PIPE, 0); if (MQX_OK != (status = _lwevent_create(&if_ptr->control_event, 0))) { status = USBERR_INIT_FAILED; } else { /* prepare events to be auto or manual */ _lwevent_set_auto_clear(&if_ptr->control_event, USB_AUDIO_CTRL_PIPE_FREE | USB_AUDIO_CTRL_INT_PIPE_FREE); /* pre-set events */ _lwevent_set(&if_ptr->control_event, USB_AUDIO_CTRL_PIPE_FREE | USB_AUDIO_CTRL_INT_PIPE_FREE); } } /* Endif */ /* Signal that an error has occured by setting the "code_key" */ if (status) { ccs_ptr->code_key = 0; } /* Endif */ USB_unlock(); #ifdef _HOST_DEBUG_ if (status) DEBUG_LOG_TRACE("usb_class_audio_control_init, SUCCESSFUL"); else DEBUG_LOG_TRACE("usb_class_audio_control_init, FAILED"); #endif } /* Endbody */
void usb_class_hid_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_HID_CLASS_INTF_STRUCT_PTR if_ptr = ccs_ptr->class_intf_handle; USB_STATUS status; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_hid_init"); #endif /* Make sure the device is still attached */ USB_lock(); status = usb_host_class_intf_init(pbs_ptr, if_ptr, &hid_anchor); if (status == USB_OK) { /* ** We generate a code_key based on the attached device. This is used to ** verify that the device has not been detached and replaced with another. */ ccs_ptr->code_key = 0; ccs_ptr->code_key = usb_host_class_intf_validate(ccs_ptr); // if_ptr->IFNUM = // ((INTERFACE_DESCRIPTOR_PTR)if_ptr->G.intf_handle)->bInterfaceNumber; // if_ptr->P_CONTROL = usb_hostdev_get_pipe_handle(pbs_ptr, USB_CONTROL_PIPE, // 0); // if_ptr->P_INT_IN = usb_hostdev_get_pipe_handle(pbs_ptr, // USB_INTERRUPT_PIPE, USB_RECV); } /* Endif */ /* Signal that an error has occured by setting the "code_key" to 0 */ // if (status || !if_ptr->P_INT_IN || !if_ptr->P_CONTROL) { // ccs_ptr->code_key = 0; // } /* Endif */ USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_hid_init, SUCCESSFUL"); #endif } /* Endbody */
void usb_class_cdc_acm_init ( /* [IN] structure with USB pipe information on the interface */ PIPE_BUNDLE_STRUCT_PTR pbs_ptr, /* [IN] acm call struct pointer2 */ CLASS_CALL_STRUCT_PTR ccs_ptr ) { /* Body */ USB_ACM_CLASS_INTF_STRUCT_PTR acm_anchor = NULL; USB_ACM_CLASS_INTF_STRUCT_PTR if_ptr = ccs_ptr->class_intf_handle; USB_STATUS status; /* Make sure the device is still attached */ USB_lock(); status = usb_host_class_intf_init(pbs_ptr, if_ptr, &acm_anchor_abstract); if (status == USB_OK) { /* ** We generate a code_key based on the attached device. This is used to ** verify that the device has not been detached and replaced with another. */ ccs_ptr->code_key = 0; ccs_ptr->code_key = usb_host_class_intf_validate(ccs_ptr); if_ptr->CDC_G.IFNUM = ((INTERFACE_DESCRIPTOR_PTR)if_ptr->CDC_G.G.intf_handle)->bInterfaceNumber; if_ptr->interrupt_pipe = usb_hostdev_get_pipe_handle(pbs_ptr, USB_INTERRUPT_PIPE, 0); if (USB_OK != (status = _usb_event_init(&if_ptr->acm_event))) { status = USBERR_INIT_FAILED; } else { /* prepare events to be auto or manual */ //_lwevent_set_auto_clear(&if_ptr->acm_event, USB_ACM_CTRL_PIPE_FREE | USB_ACM_INT_PIPE_FREE); /* pre-set events */ _usb_event_set(&if_ptr->acm_event, USB_ACM_CTRL_PIPE_FREE | USB_ACM_INT_PIPE_FREE); } } /* Endif */ /* Signal that an error has occured by setting the "code_key" */ if (status) { ccs_ptr->code_key = 0; } /* Endif */ USB_unlock(); } /* Endbody */
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 */
void usb_class_cdc_data_init ( /* [IN] structure with USB pipe information on the interface */ PIPE_BUNDLE_STRUCT_PTR pbs_ptr, /* [IN] acm call struct pointer */ CLASS_CALL_STRUCT_PTR ccs_ptr ) { /* Body */ USB_DATA_CLASS_INTF_STRUCT_PTR if_ptr = ccs_ptr->class_intf_handle; ENDPOINT_DESCRIPTOR_PTR in_endpt, out_endpt; USB_STATUS status; /* Make sure the device is still attached */ USB_lock(); status = usb_host_class_intf_init(pbs_ptr, if_ptr, &data_anchor_abstract); if (status == USB_OK) { /* ** We generate a code_key based on the attached device. This is used to ** verify that the device has not been detached and replaced with another. */ ccs_ptr->code_key = 0; ccs_ptr->code_key = usb_host_class_intf_validate(ccs_ptr); if_ptr->CDC_G.IFNUM = ((INTERFACE_DESCRIPTOR_PTR)if_ptr->CDC_G.G.intf_handle)->bInterfaceNumber; if_ptr->in_pipe = usb_hostdev_get_pipe_handle(pbs_ptr, USB_BULK_PIPE, USB_RECV); if_ptr->out_pipe = usb_hostdev_get_pipe_handle(pbs_ptr, USB_BULK_PIPE, USB_SEND); if ((if_ptr->in_pipe == NULL) && (if_ptr->out_pipe == NULL)) status = USBERR_OPEN_PIPE_FAILED; else if (USB_OK != (status = _usb_event_init(&if_ptr->data_event))) status = USBERR_INIT_FAILED; else { /* prepare events to be auto or manual */ //_lwevent_set_auto_clear(&if_ptr->data_event, USB_DATA_READ_PIPE_FREE | USB_DATA_SEND_PIPE_FREE); /* pre-set events */ _usb_event_set(&if_ptr->data_event, USB_DATA_READ_PIPE_FREE | USB_DATA_SEND_PIPE_FREE); if (if_ptr->out_pipe) { /* Don't use host - predefined constant for NAK_COUNT... ** NOTE!!! ** This hack is not very clean. We need to maximize number of retries to minimize the time of ** transaction (minimize task's time while waiting for 1 transaction to be done (with or without data)) ** The time depends on user expecatation of the read() latency, on the delay between 2 NAKs and on number ** of NAKs to be performed. ** The workaround is to limit amount of retries for the pipe maximally to 3. ** Number 3 is hard-coded here for now. */ if (((PIPE_DESCRIPTOR_STRUCT_PTR) if_ptr->in_pipe)->NAK_COUNT > 3) ((PIPE_DESCRIPTOR_STRUCT_PTR) if_ptr->in_pipe)->NAK_COUNT = 3; /* don't use host - predefined constant */ } if (if_ptr->in_pipe) { /* The same as for OUT pipe applies here */ if (((PIPE_DESCRIPTOR_STRUCT_PTR) if_ptr->out_pipe)->NAK_COUNT > 3) ((PIPE_DESCRIPTOR_STRUCT_PTR) if_ptr->out_pipe)->NAK_COUNT = 3; /* don't use host - predefined constant */ /* initialize buffer */ /* size of buffer equals to the size of endpoint data size */ if_ptr->RX_BUFFER_SIZE = ((PIPE_INIT_PARAM_STRUCT_PTR) (if_ptr->in_pipe))->MAX_PACKET_SIZE; if (NULL == (if_ptr->RX_BUFFER = USB_mem_alloc_zero(if_ptr->RX_BUFFER_SIZE))) { status = USBERR_ALLOC; } else { /* initialize members */ if_ptr->RX_BUFFER_APP = if_ptr->RX_BUFFER_DRV = if_ptr->RX_BUFFER; } } } } /* Endif */ /* Signal that an error has occured by setting the "code_key" */ if (status) { ccs_ptr->code_key = 0; } /* Endif */ USB_unlock(); } /* Endbody */