/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_register_ch9_callback * Returned Value : USB_OK, or error status * Comments : * This function registers a callback function that will be called * to notify the user of a ch9 command completion. This should be used * only after enumeration is completed * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_register_ch9_callback ( /* usb device */ _usb_device_instance_handle dev_handle, /* Callback upon completion */ tr_callback callback, /* User provided callback param */ pointer callback_param ) { /* Body */ DEV_INSTANCE_PTR dev_inst_ptr; USB_STATUS error; /* Verify that device handle is valid */ USB_lock(); error = usb_hostdev_validate(dev_handle); if (error != USB_OK) { USB_unlock(); return USBERR_DEVICE_NOT_FOUND; } /* Endif */ dev_inst_ptr = (DEV_INSTANCE_PTR)dev_handle; /* This will be called if the device is already enumerated */ dev_inst_ptr->control_callback = callback; dev_inst_ptr->control_callback_param = callback_param; USB_unlock(); return USB_OK; } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_hostdev_cntrl_request * Returned Value : USB_OK, or error status * Comments : * Function to process class- or vendor-specific control pipe device * requests. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_hostdev_cntrl_request ( /* usb device */ _usb_device_instance_handle dev_handle, /* Device Request to send */ USB_SETUP_PTR devreq, /* buffer to send/receive */ uchar_ptr buff_ptr, /* callback upon completion */ tr_callback callback, /* [IN] the parameter to pass back to the callback function */ pointer callback_param ) { /* Body */ DEV_INSTANCE_PTR dev_ptr; _usb_pipe_handle pipe_handle; TR_INIT_PARAM_STRUCT tr; USB_STATUS error = USB_OK; /* Verify that device handle is valid */ USB_lock(); error = usb_hostdev_validate(dev_handle); if (error != USB_OK) { USB_unlock(); return USBERR_DEVICE_NOT_FOUND; } /* Endif */ dev_ptr = (DEV_INSTANCE_PTR)dev_handle; if (dev_ptr->state < DEVSTATE_ENUM_OK) { USB_unlock(); return USBERR_DEVICE_NOT_FOUND; } /* Endif */ pipe_handle = dev_ptr->control_pipe; usb_hostdev_tr_init(&tr, callback, callback_param); /* Set TR buffer length as required */ if ((REQ_TYPE_IN & devreq->BMREQUESTTYPE) != 0) { tr.RX_BUFFER = buff_ptr; tr.RX_LENGTH = utoh16(devreq->WLENGTH); } else { tr.TX_BUFFER = buff_ptr; tr.TX_LENGTH = utoh16(devreq->WLENGTH); } /* EndIf */ tr.DEV_REQ_PTR = (uchar_ptr)devreq; error = _usb_host_send_setup(dev_ptr->host, pipe_handle, &tr); USB_unlock(); return error; } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_device_call_service * Returned Value : USB_OK or error code * Comments : * Calls the appropriate service for the specified type, if one is * registered. Used internally only. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_device_call_service ( /* [IN] Type of service or endpoint */ uint_8 type, /* [IN] pointer to event structure */ PTR_USB_EVENT_STRUCT event ) { /* Body */ USB_DEV_STATE_STRUCT_PTR usb_dev_ptr; SERVICE_STRUCT _PTR_ service_ptr; usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)event->handle; /* Needs mutual exclusion */ USB_lock(); /* Search for an existing entry for type */ for (service_ptr = usb_dev_ptr->SERVICE_HEAD_PTR; service_ptr; service_ptr = service_ptr->NEXT) { if (service_ptr->TYPE == type) { service_ptr->SERVICE(event,service_ptr->arg); USB_unlock(); return USB_OK; } /* Endif */ } /* Endfor */ USB_unlock(); return USBERR_CLOSED_SERVICE; } /* 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_audio_recv_data * Returned Value : USB status * Comments : * Receive data on isochronous IN pipe. * *END*--------------------------------------------------------------------*/ USB_STATUS usb_audio_recv_data ( /* [IN] class-interface control pointer */ CLASS_CALL_STRUCT_PTR control_ptr, /* [IN] class-interface stream pointer */ CLASS_CALL_STRUCT_PTR stream_ptr, /* [IN] callback upon completion */ tr_callback callback, /* [IN] user parameter returned by callback */ void *call_parm, /* [IN] data length */ uint32_t buf_size, /* [IN] buffer pointer */ unsigned char *buffer ) { /* Body */ AUDIO_STREAM_INTERFACE_STRUCT_PTR stream_if_ptr; AUDIO_CONTROL_INTERFACE_STRUCT_PTR control_if_ptr; TR_INIT_PARAM_STRUCT tr; USB_STATUS status = USBERR_NO_INTERFACE; USB_lock(); /* Validity checking, always needed when passing data to lower API */ if (!usb_host_class_intf_validate(control_ptr)) { USB_unlock(); return USBERR_NO_INTERFACE; } stream_if_ptr = (AUDIO_STREAM_INTERFACE_STRUCT_PTR) stream_ptr->class_intf_handle; control_if_ptr = (AUDIO_CONTROL_INTERFACE_STRUCT_PTR) control_ptr->class_intf_handle; /* Do the device use OUT pipe? */ if (stream_if_ptr->iso_in_pipe == NULL) { USB_unlock(); return USBERR_OPEN_PIPE_FAILED; } /* Validity checking, always needed when passing data to lower API */ if (!usb_host_class_intf_validate(control_ptr)) { USB_unlock(); return USBERR_NO_INTERFACE; } usb_hostdev_tr_init(&tr, (tr_callback) callback, (void *) call_parm); tr.G.RX_BUFFER = (unsigned char *) buffer; tr.G.RX_LENGTH = buf_size; status = _usb_host_recv_data(control_if_ptr->AUDIO_G.G.host_handle, stream_if_ptr->iso_in_pipe, &tr); USB_unlock(); return status; } /* Endbody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_clear_feature * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_clear_feature ( /* usb device */ _usb_device_instance_handle dev_handle, /* request type device/interface/endpoint */ uint_8 req_type, /* device = 0, or interface/endpoint */ uint_8 intf_endpt, /* feature selection */ uint_16 feature ) { /* Body */ USB_SETUP request = req_prototype; USB_STATUS error = USB_OK; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_clear_feature"); #endif USB_lock(); switch (req_type) { case REQ_TYPE_DEVICE: break; case REQ_TYPE_INTERFACE: case REQ_TYPE_ENDPOINT: *(uint_16*)request.WINDEX = HOST_TO_LE_SHORT(intf_endpt); break; default: USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_clear_feature, invalid request"); #endif return USB_log_error(__FILE__,__LINE__,USBERR_INVALID_BMREQ_TYPE); } /* EndSwitch */ request.BMREQUESTTYPE = (uchar)(req_type | REQ_TYPE_OUT); request.BREQUEST = REQ_CLEAR_FEATURE; *(uint_16*)request.WVALUE = HOST_TO_LE_SHORT(feature); error = usb_host_ch9_dev_req(dev_handle, &request, NULL); USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_clear_feature, SUCCESSFUL"); #endif return USB_log_error(__FILE__,__LINE__,error); } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_device_register_service * Returned Value : USB_OK or error code * Comments : * Registers a callback routine for a specified event or endpoint. * *END*--------------------------------------------------------------------*/ uint_8 _usb_device_register_service ( /* [IN] Handle to the USB device */ _usb_device_handle handle, /* [IN] type of event or endpoint number to service */ uint_8 type, /* [IN] Pointer to the service's callback function */ void(_CODE_PTR_ service)(pointer, uint_8, boolean, uint_8, uint_8_ptr, uint_32, uint_8) ) { /* Body */ USB_DEV_STATE_STRUCT_PTR usb_dev_ptr; SERVICE_STRUCT_PTR service_ptr; SERVICE_STRUCT_PTR _PTR_ search_ptr; int lockKey; usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle; /* Needs mutual exclusion */ lockKey = USB_lock(); /* Search for an existing entry for type */ for (search_ptr = &usb_dev_ptr->SERVICE_HEAD_PTR; *search_ptr; search_ptr = &(*search_ptr)->NEXT) { if ((*search_ptr)->TYPE == type) { /* Found an existing entry */ USB_unlock(lockKey); USB_printf("_usb_device_register_service, service %d already opened\n"); return USBERR_OPEN_SERVICE; } /* Endif */ } /* Endfor */ /* No existing entry found - create a new one */ service_ptr = (SERVICE_STRUCT_PTR)USB_memalloc(sizeof(SERVICE_STRUCT)); if (!service_ptr) { USB_unlock(lockKey); USB_printf("_usb_device_register_service, malloc for %d bytes failed\n", sizeof(SERVICE_STRUCT)); return USBERR_ALLOC; } /* Endif */ service_ptr->TYPE = type; service_ptr->SERVICE = service; service_ptr->NEXT = NULL; *search_ptr = service_ptr; USB_unlock(lockKey); return USB_OK; } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_device_call_service * Returned Value : USB_OK or error code * Comments : * Calls the appropriate service for the specified type, if one is * registered. Used internally only. * *END*--------------------------------------------------------------------*/ uint_8 _usb_device_call_service ( /* [IN] Handle to the USB device */ _usb_device_handle handle, /* [OUT] Type of service or endpoint */ uint_8 type, /* [OUT] Is it a Setup transfer? */ boolean setup, /* [OUT] Direction of transmission; is it a Transmit? */ boolean direction, /* [OUT] Pointer to the data */ uint_8_ptr buffer_ptr, /* [OUT] Number of bytes in transmission */ uint_32 length, /* [OUT] Any errors */ uint_8 errors ) { /* Body */ USB_DEV_STATE_STRUCT_PTR usb_dev_ptr; SERVICE_STRUCT _PTR_ service_ptr; int lockKey; usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle; /* Needs mutual exclusion */ lockKey = USB_lock(); /* Search for an existing entry for type */ for (service_ptr = usb_dev_ptr->SERVICE_HEAD_PTR; service_ptr; service_ptr = service_ptr->NEXT) { if (service_ptr->TYPE == type) { service_ptr->SERVICE(handle, type, setup, direction, buffer_ptr, length, errors); USB_unlock(lockKey); return USB_OK; } /* Endif */ } /* Endfor */ USB_unlock(lockKey); ARC_DEBUG_TRACE(ARC_DEBUG_FLAG_CTRL, "_usb_device_call_service, service %d is closed\n", type); return USBERR_CLOSED_SERVICE; } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_unregister_service * Returned Value : USB_OK or error code * Comments : * Unregisters a callback routine for a specified event or endpoint. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_unregister_service ( /* [IN] Handle to the USB device */ _usb_host_handle handle, /* [IN] type of event or endpoint number to service */ uint_8 type ) { /* Body */ USB_HOST_STATE_STRUCT_PTR usb_host_ptr; USB_SERVICE_STRUCT_PTR service_ptr; USB_SERVICE_STRUCT_PTR _PTR_ search_ptr; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_unregister_service"); #endif usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)handle; /* Needs mutual exclusion */ USB_lock(); /* Search for an existing entry for type */ for (search_ptr = &usb_host_ptr->SERVICE_HEAD_PTR; *search_ptr; search_ptr = &(*search_ptr)->NEXT) { if ((*search_ptr)->TYPE == type) { /* Found an existing entry - delete it */ break; } /* Endif */ } /* Endfor */ /* No existing entry found */ if (!*search_ptr) { USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_unregister_service no service found"); #endif return USB_log_error(__FILE__,__LINE__,USBERR_CLOSED_SERVICE); } /* Endif */ service_ptr = *search_ptr; *search_ptr = service_ptr->NEXT; USB_unlock(); USB_mem_free((pointer)service_ptr); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_unregister_service SUCCESSFUL"); #endif return USB_OK; } /* EndBody */
/*FUNCTION*------------------------------------------------------------- * * Function Name : _usb_host_send_data * Returned Value : error or status of the transfer * Comments : * The Send Data routine is non-blocking routine that causes a block of data * to be made available for transmission to the USB host. * *END*-----------------------------------------------------------------*/ uint_32 _usb_host_send_data ( /* [IN] the USB Host state structure */ _usb_host_handle hci_handle, /* [IN] the pipe handle */ _usb_pipe_handle pipe_handle, /* [IN] transfer parameters */ TR_INIT_PARAM_STRUCT_PTR tr_params_ptr ) { /* Body */ PIPE_DESCRIPTOR_STRUCT_PTR pipe_descr_ptr; USB_HOST_STATE_STRUCT_PTR usb_host_ptr; uint_32 return_code; PIPE_TR_STRUCT_PTR pipe_tr_ptr; USB_lock(); return_code = _usb_host_set_up_TR(pipe_handle, tr_params_ptr, &pipe_tr_ptr); if (return_code != USB_STATUS_TRANSFER_QUEUED) { USB_unlock(); return return_code; } /* Endif */ usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)hci_handle; UNUSED(usb_host_ptr); pipe_descr_ptr = (PIPE_DESCRIPTOR_STRUCT_PTR)pipe_handle; /*Must Flush and Invalidate the buffer before sending /receiving the data in it */ USB_dcache_flush_mlines((void *)pipe_tr_ptr->TX_BUFFER, pipe_tr_ptr->TX_LENGTH); /* We have obtained the current TR on the Pipe's TR list ** from _usb_host_set_up_TR */ /* Call the low-level send routine */ return_code = _usb_host_send_call_interface (hci_handle, pipe_descr_ptr, pipe_tr_ptr); USB_unlock(); if(return_code == USB_OK) { return USB_STATUS_TRANSFER_QUEUED; } else { return return_code; } } /* Endbody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_get_status * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_get_status ( /* usb device */ _usb_device_instance_handle dev_handle, /* request type device/interface/endpoint */ uint_8 req_type, /* device = 0, or interface/endpoint */ uint_8 intf_endpt, /* returned status */ uchar_ptr buffer ) { /* Body */ USB_SETUP request = req_prototype; USB_STATUS error = USB_OK; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_get_status"); #endif USB_lock(); switch (req_type) { case REQ_TYPE_DEVICE: case REQ_TYPE_INTERFACE: case REQ_TYPE_ENDPOINT: break; default: USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_get_status, invalid parameter"); #endif return USB_log_error(__FILE__,__LINE__,USBERR_INVALID_BMREQ_TYPE); } /* EndSwitch */ request.BMREQUESTTYPE = (uchar)(req_type | REQ_TYPE_IN); request.BREQUEST = REQ_GET_STATUS; *(uint_16*)request.WINDEX = HOST_TO_LE_SHORT(intf_endpt); *(uint_16*)request.WLENGTH = HOST_TO_LE_SHORT_CONST(2); error = usb_host_ch9_dev_req(dev_handle, &request, buffer); USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_ch9_get_status, SUCCESSFUL"); #endif return USB_log_error(__FILE__,__LINE__,error); } /* EndBody */
USB_STATUS usb_class_mass_getmaxlun_bulkonly ( CLASS_CALL_STRUCT_PTR ccs_ptr, uint_8_ptr pLUN, tr_callback callback ) { /* Body */ USB_STATUS status = USBERR_NO_INTERFACE; USB_SETUP request; USB_MASS_CLASS_INTF_STRUCT_PTR intf_ptr; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_getmaxlun_bulkonly"); #endif /* Pointer validity-checking, clear memory, init header */ USB_lock(); if (usb_host_class_intf_validate(ccs_ptr)) { intf_ptr = (USB_MASS_CLASS_INTF_STRUCT_PTR) ccs_ptr->class_intf_handle; status = usb_hostdev_validate(intf_ptr->G.dev_handle); } /* Endif */ if (status) { USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_getmaxlun_bulkonly, error status"); #endif return status; } /* Endif */ /* Get the number of logical units on the device */ request.BMREQUESTTYPE = REQ_TYPE_CLASS | REQ_TYPE_INTERFACE | REQ_TYPE_IN; request.BREQUEST = GET_MAX_LUN; htou16(request.WVALUE, 0); htou16(request.WINDEX, ((INTERFACE_DESCRIPTOR_PTR)intf_ptr->G.intf_handle)->bInterfaceNumber); htou16(request.WLENGTH, 1); /* Send request */ status = _usb_hostdev_cntrl_request (intf_ptr->G.dev_handle, &request, (uchar_ptr)pLUN, callback, NULL); USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_getmaxlun_bulkonly, SUCCESSFUL"); #endif return status; } /* Endbody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_class_mass_get_app * Returned Value : CLASS_CALL_STRUCT_PTR if class found * Comments : * This function returns stored application handle as it was passed as * a param in select_interface. * *END*--------------------------------------------------------------------*/ USB_STATUS usb_class_mass_get_app ( /* [IN] handle of device */ _usb_device_instance_handle dev_ptr, /* [IN] pointer to interface descriptor */ _usb_interface_descriptor_handle intf_ptr, /* [OUT] pointer to CLASS_CALL_STRUCT to be filled in */ CLASS_CALL_STRUCT_PTR _PTR_ ccs_ptr ) { USB_STATUS error; GENERAL_CLASS_PTR parser; USB_lock(); error = usb_hostdev_validate (dev_ptr); if (error != USB_OK) { USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_hub_get_app, FAILED"); #endif return USB_log_error(__FILE__,__LINE__,error); } /* EndIf */ for (parser = (GENERAL_CLASS_PTR) mass_anchor; parser != NULL; parser = parser->next) { if (parser->dev_handle == dev_ptr && parser->intf_handle == intf_ptr) break; } if (parser != NULL) { USB_MASS_CLASS_INTF_STRUCT_PTR msd = (USB_MASS_CLASS_INTF_STRUCT_PTR) parser; *ccs_ptr = msd->APP; } else { USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_get_app, not found"); #endif return USB_log_error(__FILE__,__LINE__,USBERR_NOT_FOUND); } USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_get_app, SUCCESSFUL"); #endif return USB_OK; }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_device_unregister_service * Returned Value : USB_OK or error code * Comments : * Unregisters a callback routine for a specified event or endpoint. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_device_unregister_service ( /* [IN] Handle to the USB device */ _usb_device_handle handle, /* [IN] type of event or endpoint number to service */ uint_8 type ) { /* Body */ USB_DEV_STATE_STRUCT_PTR usb_dev_ptr; SERVICE_STRUCT_PTR service_ptr; SERVICE_STRUCT_PTR _PTR_ search_ptr; if (handle == NULL) { return USBERR_ERROR; } usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle; /* Needs mutual exclusion */ USB_lock(); /* Search for an existing entry for type */ for (search_ptr = &usb_dev_ptr->SERVICE_HEAD_PTR; *search_ptr; search_ptr = &(*search_ptr)->NEXT) { if ((*search_ptr)->TYPE == type) { /* Found an existing entry - delete it */ break; } /* Endif */ } /* Endfor */ /* No existing entry found */ if (!*search_ptr) { USB_unlock(); return USBERR_CLOSED_SERVICE; } /* Endif */ service_ptr = *search_ptr; *search_ptr = service_ptr->NEXT; USB_mem_free((pointer)service_ptr); USB_unlock(); return USB_OK; } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_call_service * Returned Value : USB_OK or error code * Comments : * Calls the appropriate service for the specified type, if one is * registered. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_call_service ( /* [IN] Handle to the USB device */ _usb_host_handle handle, /* [IN] Type of service or endpoint */ uint_8 type, /* [IN] Number of bytes in transmission */ uint_32 length ) { /* Body */ USB_HOST_STATE_STRUCT_PTR usb_host_ptr; USB_SERVICE_STRUCT_PTR service_ptr; usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)handle; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_call_service"); #endif /* Needs mutual exclusion */ USB_lock(); /* Search for an existing entry for type */ for (service_ptr = usb_host_ptr->SERVICE_HEAD_PTR; service_ptr; service_ptr = service_ptr->NEXT) { if (service_ptr->TYPE == type) { if (service_ptr->SERVICE) { service_ptr->SERVICE(handle, length); } USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_call_service, service exists"); #endif return USB_OK; } /* Endif */ } /* Endfor */ USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("_usb_host_call_service, service closed"); #endif return USB_log_error(__FILE__,__LINE__,USBERR_CLOSED_SERVICE); } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_get_descriptor * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_get_descriptor ( /* usb device */ _usb_device_instance_handle dev_handle, /* descriptor type & index */ uint_16 type_index, /* Language ID or 0 */ uint_16 lang_id, /* buffer length */ uint_16 buflen, /* descriptor buffer */ uchar_ptr buffer ) { /* Body */ USB_SETUP request; USB_STATUS error = USB_OK; USB_lock(); request.BMREQUESTTYPE = REQ_TYPE_DEVICE | REQ_TYPE_IN; request.BREQUEST = REQ_GET_DESCRIPTOR; htou16(request.WVALUE, type_index); htou16(request.WINDEX, lang_id); htou16(request.WLENGTH, buflen); error = usb_host_ch9_dev_req(dev_handle, &request, buffer); USB_unlock(); return error; } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_get_configuration * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_get_configuration ( /* [IN] usb device */ _usb_device_instance_handle dev_handle, /* [OUT] configuration value */ uchar_ptr buffer ) { /* Body */ USB_SETUP request = req_prototype; USB_STATUS error = USB_OK; USB_lock(); request.BMREQUESTTYPE = REQ_TYPE_DEVICE | REQ_TYPE_IN; request.BREQUEST = REQ_GET_CONFIGURATION; htou16(request.WLENGTH, 1); error = usb_host_ch9_dev_req(dev_handle, &request, buffer); USB_unlock(); return error; } /* EndBody */
void usb_class_mass_get_pending_request ( /* [IN] interface structure pointer */ USB_MASS_CLASS_INTF_STRUCT_PTR intf_ptr, /* [OUT] pointer to pointer which will hold the pending request */ COMMAND_OBJECT_PTR *cmd_ptr_ptr ) { /* Body */ MASS_QUEUE_STRUCT_PTR Q = &intf_ptr->QUEUE; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_get_pending_request"); #endif USB_lock(); if (Q->COUNT) { *cmd_ptr_ptr = (COMMAND_OBJECT_PTR)Q->ELEMENTS[Q->FIRST]; } else { *cmd_ptr_ptr = NULL; } /* Endif */ USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_get_pending_request, SUCCESSFUL"); #endif return; } /* Endbody */
int32_t usb_class_mass_q_insert ( /* [IN] interface structure pointer */ USB_MASS_CLASS_INTF_STRUCT_PTR intf_ptr, /* [IN] command object to be inserted in the queue*/ COMMAND_OBJECT_PTR pCmd ) { /* Body */ MASS_QUEUE_STRUCT_PTR Q = &intf_ptr->QUEUE; int32_t tmp = -1; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_q_insert"); #endif /* ** Insert into queue, update LAST, check if full and return queue position. ** If queue is full -1 will be returned */ USB_lock(); if (Q->COUNT < QUEUE_SIZE) { Q->ELEMENTS[Q->LAST] = pCmd; tmp = Q->LAST; Q->LAST = MASSQ_NEXT(Q->LAST); Q->COUNT++; } /* Endif */ USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_q_insert, SUCCESSFUL"); #endif return tmp; } /* Endbody */
void usb_class_mass_deleteq ( /* [IN] interface structure pointer */ USB_MASS_CLASS_INTF_STRUCT_PTR intf_ptr ) { /* Body */ MASS_QUEUE_STRUCT_PTR Q = &intf_ptr->QUEUE; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_deleteq"); #endif /* Remove current command and increment FIRST modulo the Q size */ USB_lock(); if (Q->COUNT) { Q->ELEMENTS[Q->FIRST] = NULL; Q->FIRST = MASSQ_NEXT(Q->FIRST); // Q->AVAILABLE = TRUE; Q->COUNT--; } USB_unlock(); //if (Q->COUNT >1) { // printf("\nMASS q size now %d", Q->COUNT ); //} #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_deleteq, SUCCESSFUL"); #endif } /* Endbody */
/*FUNCTION*------------------------------------------------------------- * * Function Name : _usb_device_unstall_endpoint * Returned Value : USB_OK or error code * Comments : * Unstalls the endpoint in specified direction * *END*-----------------------------------------------------------------*/ void _usb_device_unstall_endpoint ( /* [IN] the USB_USB_dev_initialize state structure */ _usb_device_handle handle, /* [IN] the Endpoint number */ uint_8 ep_num, /* [IN] direction */ uint_8 direction ) { /* Body */ /* uint_8 error = 0; */ USB_DEV_STATE_STRUCT_PTR usb_dev_ptr; usb_dev_ptr = (USB_DEV_STATE_STRUCT_PTR)handle; #ifdef _DEVICE_DEBUG_ DEBUG_LOG_TRACE("_usb_device_unstall_endpoint"); #endif USB_lock(); _usb_dci_vusb20_unstall_endpoint(handle, ep_num, direction); USB_unlock(); #ifdef _DEVICE_DEBUG_ DEBUG_LOG_TRACE("_usb_device_unstall_endpoint, SUCCESSFULL"); #endif } /* EndBody */
boolean usb_class_mass_storage_device_command_cancel ( /* Handle to class struct with the key */ CLASS_CALL_STRUCT_PTR ccs_ptr, /*Command */ COMMAND_OBJECT_PTR cmd_ptr ) { /* Body */ USB_MASS_CLASS_INTF_STRUCT_PTR intf_ptr; USB_STATUS error = USBERR_NO_INTERFACE; boolean result = FALSE; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_storage_device_command_cancel"); #endif /* Pointer validity-checking, clear memory, init header */ USB_lock(); if (usb_host_class_intf_validate(ccs_ptr)) { intf_ptr = (USB_MASS_CLASS_INTF_STRUCT_PTR) ccs_ptr->class_intf_handle; error = usb_hostdev_validate (intf_ptr->G.dev_handle); } /* Endif */ if ((error == USB_OK) || (error == USB_STATUS_TRANSFER_QUEUED)) { result = usb_class_mass_cancelq(intf_ptr, cmd_ptr); } USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_mass_storage_device_command_cancel, SUCCESSFUL"); #endif return result; } /* Endbody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_set_interface * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_set_interface ( /* usb device */ _usb_device_instance_handle dev_handle, /* alternate setting */ uint_8 alternate, /* interface */ uint_8 intf ) { /* Body */ USB_SETUP request = req_prototype; USB_STATUS error = USB_OK; USB_lock(); request.BMREQUESTTYPE = REQ_TYPE_INTERFACE | REQ_TYPE_OUT; request.BREQUEST = REQ_SET_INTERFACE; htou16(request.WVALUE, alternate); htou16(request.WINDEX, intf); error = usb_host_ch9_dev_req(dev_handle, &request, NULL); USB_unlock(); return error; } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_get_interface * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_get_interface ( /* usb device */ _usb_device_instance_handle dev_handle, /* interface index */ uint_8 interface, /* alternate setting buffer */ uchar_ptr buffer ) { /* Body */ USB_SETUP request = req_prototype; USB_STATUS error = USB_OK; USB_lock(); request.BMREQUESTTYPE = REQ_TYPE_INTERFACE | REQ_TYPE_IN; request.BREQUEST = REQ_GET_INTERFACE; htou16(request.WINDEX, interface); htou16(request.WLENGTH, 1); error = usb_host_ch9_dev_req(dev_handle, &request, buffer); USB_unlock(); return error; } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_set_configuration * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_set_configuration ( /* usb device */ _usb_device_instance_handle dev_handle, /* configuration value */ uint_16 config ) { /* Body */ USB_SETUP request = req_prototype; USB_STATUS error = USB_OK; USB_lock(); request.BMREQUESTTYPE = REQ_TYPE_DEVICE | REQ_TYPE_OUT; request.BREQUEST = REQ_SET_CONFIGURATION; htou16(request.WVALUE, config); error = usb_host_ch9_dev_req(dev_handle, &request, NULL); USB_unlock(); return error; } /* EndBody */
USB_STATUS usb_class_hub_get_descriptor ( /* [IN] The communication device common command structure */ HUB_COMMAND_PTR com_ptr, /* [IN] descriptor buffer */ uchar_ptr buffer, /* [IN] buffer length (or, better said, how many bytes to read) */ uchar len ) { /* Body */ USB_STATUS error = USB_OK; USB_lock(); error = usb_class_hub_cntrl_common( com_ptr, REQ_TYPE_DEVICE | REQ_TYPE_IN | REQ_TYPE_CLASS, REQ_GET_DESCRIPTOR, 0, 0, len, buffer ); USB_unlock(); return error; } /* EndBody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : _usb_host_ch9_synch_frame * Returned Value : USB_OK, or error status * Comments : * Function to process standard device request in Chapter 9. * See Table 9-3 p. 250 of USB 2.0 specification. * *END*--------------------------------------------------------------------*/ USB_STATUS _usb_host_ch9_synch_frame ( /* usb device */ _usb_device_instance_handle dev_handle, /* interface index */ uint_8 intf, /* configuration buffer */ uchar_ptr buffer ) { /* Body */ USB_SETUP request = req_prototype; USB_STATUS error = USB_OK; USB_lock(); request.BMREQUESTTYPE = REQ_TYPE_ENDPOINT | REQ_TYPE_IN; request.BREQUEST = REQ_SYNCH_FRAME; htou16(request.WINDEX, intf); htou16(request.WLENGTH, 2); error = usb_host_ch9_dev_req(dev_handle, &request, buffer); USB_unlock(); return error; } /* EndBody */
USB_STATUS usb_class_cdc_install_driver ( CLASS_CALL_STRUCT_PTR data_instance, char_ptr device_name ) { USB_DATA_CLASS_INTF_STRUCT_PTR if_ptr; USB_STATUS status = USB_OK; USB_lock(); /* Validity checking, always needed when passing data to lower API */ if (usb_host_class_intf_validate(data_instance)) { if_ptr = (USB_DATA_CLASS_INTF_STRUCT_PTR) data_instance->class_intf_handle; f_usb->DEV_PTR->DRIVER_INIT_PTR = data_instance; f_usb->DEV_PTR->IDENTIFIER = device_name; f_usb->DEV_PTR->IO_OPEN = _io_cdc_serial_open; f_usb->DEV_PTR->IO_CLOSE = _io_cdc_serial_close; f_usb->DEV_PTR->IO_READ = _io_cdc_serial_read; f_usb->DEV_PTR->IO_WRITE = _io_cdc_serial_write; f_usb->DEV_PTR->IO_IOCTL = _io_cdc_serial_ioctl; f_usb->DEV_PTR->IO_UNINSTALL = _io_cdc_serial_uninstall; f_usb->DEV_PTR->DRIVER_TYPE = 0; if (status == IO_OK) if_ptr->device_name = device_name; } USB_unlock(); return status; }
static USB_STATUS usb_class_hid_cntrl_common ( /* [IN] The communication device common command structure */ HID_COMMAND_PTR com_ptr, /* [IN] Bitmask of the request type */ uint_8 bmrequesttype, /* [IN] Request code */ uint_8 brequest, /* [IN] Value to copy into WVALUE field of the REQUEST */ uint_16 wvalue, /* [IN] Length of the data associated with REQUEST */ uint_16 wlength, /* [IN] Pointer to data buffer used to send/recv */ uchar_ptr data ) { /* Body */ USB_HID_CLASS_INTF_STRUCT_PTR if_ptr; USB_SETUP req; USB_STATUS status = USBERR_NO_INTERFACE; #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_hid_cntrl_common"); #endif USB_lock(); /* Validity checking */ if (usb_host_class_intf_validate(com_ptr->CLASS_PTR)) { if_ptr = (USB_HID_CLASS_INTF_STRUCT_PTR)com_ptr->CLASS_PTR->class_intf_handle; status = usb_hostdev_validate(if_ptr->G.dev_handle); } /* Endif */ if (!status && if_ptr->IN_SETUP) { status = USBERR_TRANSFER_IN_PROGRESS; } /* Endif */ if (!status) { /* Save the higher level callback and ID */ if_ptr->USER_CALLBACK = com_ptr->CALLBACK_FN; if_ptr->USER_PARAM = com_ptr->CALLBACK_PARAM; /* Setup the request */ req.BMREQUESTTYPE = bmrequesttype; req.BREQUEST = brequest; *(uint_16*)req.WVALUE = HOST_TO_LE_SHORT(wvalue); *(uint_16*)req.WINDEX = HOST_TO_LE_SHORT(((INTERFACE_DESCRIPTOR_PTR)if_ptr->G.intf_handle)->bInterfaceNumber); *(uint_16*)req.WLENGTH = HOST_TO_LE_SHORT(wlength); status = _usb_hostdev_cntrl_request(if_ptr->G.dev_handle, &req, data, usb_class_hid_cntrl_callback, if_ptr); if (status == USB_STATUS_TRANSFER_QUEUED) { if_ptr->IN_SETUP = TRUE; } /* Endif */ } /* Endif */ USB_unlock(); #ifdef _HOST_DEBUG_ DEBUG_LOG_TRACE("usb_class_hid_cntrl_common, SUCCESSFUL"); #endif return status; } /* Endbody */
/*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 */ int_16 i; USB_HOST_STATE_STRUCT_PTR usb_host_ptr; usb_host_ptr = (USB_HOST_STATE_STRUCT_PTR)handle; USB_lock(); for (i=0; i < USBCFG_MAX_PIPES; i++) { if (!(usb_host_ptr->PIPE_DESCRIPTOR_BASE_PTR[i].OPEN)) { break; } else { /* Call the low-level routine to free the controller specific ** resources for this pipe */ _usb_host_close_pipe_call_interface (handle, &usb_host_ptr->PIPE_DESCRIPTOR_BASE_PTR[i]); /* de-initialise the pipe descriptor */ memset(&usb_host_ptr->PIPE_DESCRIPTOR_BASE_PTR[i],0, sizeof(PIPE_DESCRIPTOR_STRUCT)); } /* Endif */ } /* Endfor */ USB_unlock(); } /* Endbody */