Lines Matching refs:uhost

49 usb_sts_type usbh_ctrl_send_setup(usbh_core_type *uhost, uint8_t *buffer, uint8_t hc_num)  in usbh_ctrl_send_setup()  argument
51 uhost->hch[hc_num].dir = 0; in usbh_ctrl_send_setup()
52 uhost->hch[hc_num].data_pid = HCH_PID_SETUP; in usbh_ctrl_send_setup()
53 uhost->hch[hc_num].trans_buf = buffer; in usbh_ctrl_send_setup()
54 uhost->hch[hc_num].trans_len = 8; /*setup */ in usbh_ctrl_send_setup()
56 return usbh_in_out_request(uhost, hc_num); in usbh_ctrl_send_setup()
67 usb_sts_type usbh_ctrl_recv_data(usbh_core_type *uhost, uint8_t *buffer, in usbh_ctrl_recv_data() argument
70 uhost->hch[hc_num].dir = 1; in usbh_ctrl_recv_data()
71 uhost->hch[hc_num].data_pid = HCH_PID_DATA1; in usbh_ctrl_recv_data()
72 uhost->hch[hc_num].trans_buf = buffer; in usbh_ctrl_recv_data()
73 uhost->hch[hc_num].trans_len = length; in usbh_ctrl_recv_data()
75 return usbh_in_out_request(uhost, hc_num); in usbh_ctrl_recv_data()
86 usb_sts_type usbh_ctrl_send_data(usbh_core_type *uhost, uint8_t *buffer, in usbh_ctrl_send_data() argument
89 uhost->hch[hc_num].dir = 0; in usbh_ctrl_send_data()
90 uhost->hch[hc_num].trans_buf = buffer; in usbh_ctrl_send_data()
91 uhost->hch[hc_num].trans_len = length; in usbh_ctrl_send_data()
95 uhost->hch[uhost->ctrl.hch_out].toggle_out = 1; in usbh_ctrl_send_data()
97 if(uhost->hch[uhost->ctrl.hch_out].toggle_out == 0) in usbh_ctrl_send_data()
99 uhost->hch[hc_num].data_pid = HCH_PID_DATA0; in usbh_ctrl_send_data()
103 uhost->hch[hc_num].data_pid = HCH_PID_DATA1; in usbh_ctrl_send_data()
105 return usbh_in_out_request(uhost, hc_num); in usbh_ctrl_send_data()
113 usb_sts_type usbh_ctrl_setup_handler(usbh_core_type *uhost) in usbh_ctrl_setup_handler() argument
115 usbh_ctrl_send_setup(uhost, (uint8_t *)(&uhost->ctrl.setup), in usbh_ctrl_setup_handler()
116 uhost->ctrl.hch_out); in usbh_ctrl_setup_handler()
117 uhost->ctrl.state = CONTROL_SETUP_WAIT; in usbh_ctrl_setup_handler()
127 usb_sts_type usbh_ctrl_setup_wait_handler(usbh_core_type *uhost, uint32_t *timeout) in usbh_ctrl_setup_wait_handler() argument
132 urb_state = uhost->urb_state[uhost->ctrl.hch_out]; in usbh_ctrl_setup_wait_handler()
135 dir = uhost->ctrl.setup.bmRequestType & USB_REQUEST_DIR_MASK; in usbh_ctrl_setup_wait_handler()
136 if(uhost->ctrl.setup.wLength != 0) in usbh_ctrl_setup_wait_handler()
141 uhost->ctrl.state = CONTROL_DATA_IN; in usbh_ctrl_setup_wait_handler()
145 uhost->ctrl.state = CONTROL_DATA_OUT; in usbh_ctrl_setup_wait_handler()
153 uhost->ctrl.state = CONTROL_STATUS_OUT; in usbh_ctrl_setup_wait_handler()
157 uhost->ctrl.state = CONTROL_STATUS_IN; in usbh_ctrl_setup_wait_handler()
160 uhost->ctrl.timer = uhost->timer; in usbh_ctrl_setup_wait_handler()
165 uhost->ctrl.state = CONTROL_ERROR; in usbh_ctrl_setup_wait_handler()
166 uhost->ctrl.sts = CTRL_XACTERR; in usbh_ctrl_setup_wait_handler()
172 if(uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT) in usbh_ctrl_setup_wait_handler()
174 uhost->ctrl.state = CONTROL_ERROR; in usbh_ctrl_setup_wait_handler()
175 uhost->ctrl.sts = CTRL_XACTERR; in usbh_ctrl_setup_wait_handler()
187 usb_sts_type usbh_ctrl_data_in_handler(usbh_core_type *uhost) in usbh_ctrl_data_in_handler() argument
190 usbh_ctrl_recv_data(uhost, uhost->ctrl.buffer, in usbh_ctrl_data_in_handler()
191 uhost->ctrl.len, in usbh_ctrl_data_in_handler()
192 uhost->ctrl.hch_in); in usbh_ctrl_data_in_handler()
193 uhost->ctrl.state = CONTROL_DATA_IN_WAIT; in usbh_ctrl_data_in_handler()
204 usb_sts_type usbh_ctrl_data_in_wait_handler(usbh_core_type *uhost, uint32_t timeout) in usbh_ctrl_data_in_wait_handler() argument
208 urb_state = uhost->urb_state[uhost->ctrl.hch_in]; in usbh_ctrl_data_in_wait_handler()
212 uhost->ctrl.state = CONTROL_STATUS_OUT; in usbh_ctrl_data_in_wait_handler()
216 uhost->ctrl.state = CONTROL_STALL; in usbh_ctrl_data_in_wait_handler()
220 uhost->ctrl.state = CONTROL_ERROR; in usbh_ctrl_data_in_wait_handler()
225 if(uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT) in usbh_ctrl_data_in_wait_handler()
227 uhost->ctrl.state = CONTROL_ERROR; in usbh_ctrl_data_in_wait_handler()
228 uhost->ctrl.sts = CTRL_XACTERR; in usbh_ctrl_data_in_wait_handler()
241 usb_sts_type usbh_ctrl_data_out_handler(usbh_core_type *uhost) in usbh_ctrl_data_out_handler() argument
244 uhost->hch[uhost->ctrl.hch_out].toggle_out = 1; in usbh_ctrl_data_out_handler()
246 usbh_ctrl_send_data(uhost, uhost->ctrl.buffer, in usbh_ctrl_data_out_handler()
247 uhost->ctrl.len, in usbh_ctrl_data_out_handler()
248 uhost->ctrl.hch_out); in usbh_ctrl_data_out_handler()
249 uhost->ctrl.state = CONTROL_DATA_OUT_WAIT; in usbh_ctrl_data_out_handler()
260 usb_sts_type usbh_ctrl_data_out_wait_handler(usbh_core_type *uhost, uint32_t timeout) in usbh_ctrl_data_out_wait_handler() argument
264 urb_state = uhost->urb_state[uhost->ctrl.hch_out]; in usbh_ctrl_data_out_wait_handler()
267 uhost->ctrl.state = CONTROL_STATUS_IN; in usbh_ctrl_data_out_wait_handler()
271 uhost->ctrl.state = CONTROL_STALL; in usbh_ctrl_data_out_wait_handler()
275 uhost->ctrl.state = CONTROL_ERROR; in usbh_ctrl_data_out_wait_handler()
279 uhost->ctrl.state = CONTROL_DATA_OUT; in usbh_ctrl_data_out_wait_handler()
283 if((uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT) && (urb_state == URB_NOTREADY)) in usbh_ctrl_data_out_wait_handler()
285 uhost->ctrl.state = CONTROL_ERROR; in usbh_ctrl_data_out_wait_handler()
286 uhost->ctrl.sts = CTRL_XACTERR; in usbh_ctrl_data_out_wait_handler()
297 usb_sts_type usbh_ctrl_status_in_handler(usbh_core_type *uhost) in usbh_ctrl_status_in_handler() argument
300 usbh_ctrl_recv_data(uhost, 0, 0, in usbh_ctrl_status_in_handler()
301 uhost->ctrl.hch_in); in usbh_ctrl_status_in_handler()
302 uhost->ctrl.state = CONTROL_STATUS_IN_WAIT; in usbh_ctrl_status_in_handler()
314 usb_sts_type usbh_ctrl_status_in_wait_handler(usbh_core_type *uhost, uint32_t timeout) in usbh_ctrl_status_in_wait_handler() argument
318 urb_state = uhost->urb_state[uhost->ctrl.hch_in]; in usbh_ctrl_status_in_wait_handler()
321 uhost->ctrl.state = CONTROL_COMPLETE; in usbh_ctrl_status_in_wait_handler()
325 uhost->ctrl.state = CONTROL_STALL; in usbh_ctrl_status_in_wait_handler()
330 uhost->ctrl.state = CONTROL_ERROR; in usbh_ctrl_status_in_wait_handler()
335 if(uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT) in usbh_ctrl_status_in_wait_handler()
337 uhost->ctrl.state = CONTROL_ERROR; in usbh_ctrl_status_in_wait_handler()
338 uhost->ctrl.sts = CTRL_XACTERR; in usbh_ctrl_status_in_wait_handler()
350 usb_sts_type usbh_ctrl_status_out_handler(usbh_core_type *uhost) in usbh_ctrl_status_out_handler() argument
353 uhost->hch[uhost->ctrl.hch_out].toggle_out ^= 1; in usbh_ctrl_status_out_handler()
355 usbh_ctrl_send_data(uhost, 0, 0, uhost->ctrl.hch_out); in usbh_ctrl_status_out_handler()
356 uhost->ctrl.state = CONTROL_STATUS_OUT_WAIT; in usbh_ctrl_status_out_handler()
367 usb_sts_type usbh_ctrl_status_out_wait_handler(usbh_core_type *uhost, uint32_t timeout) in usbh_ctrl_status_out_wait_handler() argument
371 urb_state = uhost->urb_state[uhost->ctrl.hch_out]; in usbh_ctrl_status_out_wait_handler()
374 uhost->ctrl.state = CONTROL_COMPLETE; in usbh_ctrl_status_out_wait_handler()
378 uhost->ctrl.state = CONTROL_STALL; in usbh_ctrl_status_out_wait_handler()
382 uhost->ctrl.state = CONTROL_ERROR; in usbh_ctrl_status_out_wait_handler()
386 uhost->ctrl.state = CONTROL_STATUS_OUT; in usbh_ctrl_status_out_wait_handler()
389 if((uhost->timer - uhost->ctrl.timer > CTRL_TIMEOUT) && (urb_state == URB_NOTREADY)) in usbh_ctrl_status_out_wait_handler()
391 uhost->ctrl.state = CONTROL_ERROR; in usbh_ctrl_status_out_wait_handler()
392 uhost->ctrl.sts = CTRL_XACTERR; in usbh_ctrl_status_out_wait_handler()
403 usb_sts_type usbh_ctrl_error_handler(usbh_core_type *uhost) in usbh_ctrl_error_handler() argument
406 if(++ uhost->ctrl.err_cnt <= USBH_MAX_ERROR_COUNT) in usbh_ctrl_error_handler()
408 uhost->ctrl.state = CONTROL_SETUP; in usbh_ctrl_error_handler()
412 uhost->ctrl.sts = CTRL_FAIL; in usbh_ctrl_error_handler()
413 uhost->global_state = USBH_ERROR_STATE; in usbh_ctrl_error_handler()
414 uhost->ctrl.err_cnt = 0; in usbh_ctrl_error_handler()
425 usb_sts_type usbh_ctrl_stall_handler(usbh_core_type *uhost) in usbh_ctrl_stall_handler() argument
435 usb_sts_type usbh_ctrl_complete_handler(usbh_core_type *uhost) in usbh_ctrl_complete_handler() argument
445 usb_sts_type usbh_ctrl_transfer_loop(usbh_core_type *uhost) in usbh_ctrl_transfer_loop() argument
449 uhost->ctrl.sts = CTRL_START; in usbh_ctrl_transfer_loop()
451 switch(uhost->ctrl.state) in usbh_ctrl_transfer_loop()
454 usbh_ctrl_setup_handler(uhost); in usbh_ctrl_transfer_loop()
455 uhost->ctrl.timer = uhost->timer; in usbh_ctrl_transfer_loop()
459 usbh_ctrl_setup_wait_handler(uhost, &timeout); in usbh_ctrl_transfer_loop()
463 usbh_ctrl_data_in_handler(uhost); in usbh_ctrl_transfer_loop()
467 usbh_ctrl_data_in_wait_handler(uhost, timeout); in usbh_ctrl_transfer_loop()
471 usbh_ctrl_data_out_handler(uhost); in usbh_ctrl_transfer_loop()
475 usbh_ctrl_data_out_wait_handler(uhost, timeout); in usbh_ctrl_transfer_loop()
479 usbh_ctrl_status_in_handler(uhost); in usbh_ctrl_transfer_loop()
483 usbh_ctrl_status_in_wait_handler(uhost, timeout); in usbh_ctrl_transfer_loop()
487 usbh_ctrl_status_out_handler(uhost); in usbh_ctrl_transfer_loop()
491 usbh_ctrl_status_out_wait_handler(uhost, timeout); in usbh_ctrl_transfer_loop()
494 status = usbh_ctrl_stall_handler(uhost); in usbh_ctrl_transfer_loop()
497 status = usbh_ctrl_error_handler(uhost); in usbh_ctrl_transfer_loop()
500 status = usbh_ctrl_complete_handler(uhost); in usbh_ctrl_transfer_loop()
517 usb_sts_type usbh_ctrl_request(usbh_core_type *uhost, uint8_t *buffer, uint16_t length) in usbh_ctrl_request() argument
520 if(uhost->req_state == CMD_SEND) in usbh_ctrl_request()
522 uhost->req_state = CMD_WAIT; in usbh_ctrl_request()
523 uhost->ctrl.buffer = buffer; in usbh_ctrl_request()
524 uhost->ctrl.len = length; in usbh_ctrl_request()
525 uhost->ctrl.state = CONTROL_SETUP; in usbh_ctrl_request()
539 usb_sts_type usbh_get_descriptor(usbh_core_type *uhost, uint16_t length, in usbh_get_descriptor() argument
544 uhost->ctrl.setup.bmRequestType = USB_DIR_D2H | req_type; in usbh_get_descriptor()
545 uhost->ctrl.setup.bRequest = USB_STD_REQ_GET_DESCRIPTOR; in usbh_get_descriptor()
546 uhost->ctrl.setup.wValue = wvalue; in usbh_get_descriptor()
547 uhost->ctrl.setup.wLength = length; in usbh_get_descriptor()
551 uhost->ctrl.setup.wIndex = 0x0409; in usbh_get_descriptor()
555 uhost->ctrl.setup.wIndex = 0; in usbh_get_descriptor()
558 status = usbh_ctrl_request(uhost, buffer, length); in usbh_get_descriptor()
569 void usbh_parse_dev_desc(usbh_core_type *uhost, uint8_t *buffer, uint16_t length) in usbh_parse_dev_desc() argument
571 usbh_dev_desc_type *desc = &(uhost->dev); in usbh_parse_dev_desc()
648 usb_sts_type usbh_parse_configure_desc(usbh_core_type *uhost, in usbh_parse_configure_desc() argument
651 usb_cfg_desc_type *cfg_desc = &(uhost->dev.cfg_desc); in usbh_parse_configure_desc()
707 uint8_t usbh_find_interface(usbh_core_type *uhost, uint8_t class_code, uint8_t sub_class, uint8_t p… in usbh_find_interface() argument
711 for(idx = 0; idx < uhost->dev.cfg_desc.cfg.bNumInterfaces; idx ++) in usbh_find_interface()
713 usbitf = &uhost->dev.cfg_desc.interface[idx]; in usbh_find_interface()
756 usb_sts_type usbh_get_device_descriptor(usbh_core_type *uhost, uint16_t length) in usbh_get_device_descriptor() argument
765 status = usbh_get_descriptor(uhost, length, bm_req, in usbh_get_device_descriptor()
766 wvalue, uhost->rx_buffer); in usbh_get_device_descriptor()
776 usb_sts_type usbh_get_configure_descriptor(usbh_core_type *uhost, uint16_t length) in usbh_get_configure_descriptor() argument
785 status = usbh_get_descriptor(uhost, length, bm_req, in usbh_get_configure_descriptor()
786 wvalue, uhost->rx_buffer); in usbh_get_configure_descriptor()
799 usb_sts_type usbh_get_sting_descriptor(usbh_core_type *uhost, uint8_t string_id, in usbh_get_sting_descriptor() argument
809 status = usbh_get_descriptor(uhost, length, bm_req, in usbh_get_sting_descriptor()
810 wvalue, uhost->rx_buffer); in usbh_get_sting_descriptor()
821 usb_sts_type usbh_set_configuration(usbh_core_type *uhost, uint16_t config) in usbh_set_configuration() argument
827 uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; in usbh_set_configuration()
828 uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_CONFIGURATION; in usbh_set_configuration()
829 uhost->ctrl.setup.wValue = config; in usbh_set_configuration()
830 uhost->ctrl.setup.wLength = 0; in usbh_set_configuration()
831 uhost->ctrl.setup.wIndex = 0; in usbh_set_configuration()
832 status = usbh_ctrl_request(uhost, 0, 0); in usbh_set_configuration()
842 usb_sts_type usbh_set_address(usbh_core_type *uhost, uint8_t address) in usbh_set_address() argument
848 uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; in usbh_set_address()
849 uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_ADDRESS; in usbh_set_address()
850 uhost->ctrl.setup.wValue = (uint16_t)address; in usbh_set_address()
851 uhost->ctrl.setup.wLength = 0; in usbh_set_address()
852 uhost->ctrl.setup.wIndex = 0; in usbh_set_address()
853 status = usbh_ctrl_request(uhost, 0, 0); in usbh_set_address()
864 usb_sts_type usbh_set_interface(usbh_core_type *uhost, uint8_t ept_num, uint8_t altsetting) in usbh_set_interface() argument
870 uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; in usbh_set_interface()
871 uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_INTERFACE; in usbh_set_interface()
872 uhost->ctrl.setup.wValue = (uint16_t)altsetting; in usbh_set_interface()
873 uhost->ctrl.setup.wLength = 0; in usbh_set_interface()
874 uhost->ctrl.setup.wIndex = ept_num; in usbh_set_interface()
875 status = usbh_ctrl_request(uhost, 0, 0); in usbh_set_interface()
886 usb_sts_type usbh_set_feature(usbh_core_type *uhost, uint8_t feature, uint16_t index) in usbh_set_feature() argument
892 uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; in usbh_set_feature()
893 uhost->ctrl.setup.bRequest = USB_STD_REQ_SET_FEATURE; in usbh_set_feature()
894 uhost->ctrl.setup.wValue = (uint16_t)feature; in usbh_set_feature()
895 uhost->ctrl.setup.wLength = 0; in usbh_set_feature()
896 uhost->ctrl.setup.wIndex = index; in usbh_set_feature()
897 status = usbh_ctrl_request(uhost, 0, 0); in usbh_set_feature()
909 usb_sts_type usbh_clear_dev_feature(usbh_core_type *uhost, uint8_t feature, uint16_t index) in usbh_clear_dev_feature() argument
915 uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; in usbh_clear_dev_feature()
916 uhost->ctrl.setup.bRequest = USB_STD_REQ_CLEAR_FEATURE; in usbh_clear_dev_feature()
917 uhost->ctrl.setup.wValue = (uint16_t)feature; in usbh_clear_dev_feature()
918 uhost->ctrl.setup.wLength = 0; in usbh_clear_dev_feature()
919 uhost->ctrl.setup.wIndex = index; in usbh_clear_dev_feature()
920 status = usbh_ctrl_request(uhost, 0, 0); in usbh_clear_dev_feature()
931 usb_sts_type usbh_clear_ept_feature(usbh_core_type *uhost, uint8_t ept_num, uint8_t hc_num) in usbh_clear_ept_feature() argument
935 if(uhost->ctrl.state == CONTROL_IDLE ) in usbh_clear_ept_feature()
939 uhost->ctrl.setup.bmRequestType = USB_DIR_H2D | bm_req; in usbh_clear_ept_feature()
940 uhost->ctrl.setup.bRequest = USB_STD_REQ_CLEAR_FEATURE; in usbh_clear_ept_feature()
941 uhost->ctrl.setup.wValue = USB_FEATURE_EPT_HALT; in usbh_clear_ept_feature()
942 uhost->ctrl.setup.wLength = 0; in usbh_clear_ept_feature()
943 uhost->ctrl.setup.wIndex = ept_num; in usbh_clear_ept_feature()
944 usbh_ctrl_request(uhost, 0, 0); in usbh_clear_ept_feature()
946 if(usbh_ctrl_result_check(uhost, CONTROL_IDLE, ENUM_IDLE) == USB_OK) in usbh_clear_ept_feature()