Lines Matching refs:dev_obj

132     device_t *dev_obj = heap_caps_calloc(1, sizeof(device_t), MALLOC_CAP_DEFAULT);  in device_alloc()  local
134 if (dev_obj == NULL || dev_desc == NULL) { in device_alloc()
142 .context = (void *)dev_obj, in device_alloc()
153 dev_obj->dynamic.state = USB_DEVICE_STATE_DEFAULT; in device_alloc()
154 dev_obj->constant.default_pipe = default_pipe_hdl; in device_alloc()
155 dev_obj->constant.port_hdl = port_hdl; in device_alloc()
157 dev_obj->constant.speed = speed; in device_alloc()
158 dev_obj->constant.desc = dev_desc; in device_alloc()
159 *dev_obj_ret = dev_obj; in device_alloc()
165 heap_caps_free(dev_obj); in device_alloc()
169 static void device_free(device_t *dev_obj) in device_free() argument
171 if (dev_obj == NULL) { in device_free()
175 if (dev_obj->constant.config_desc) { in device_free()
176 heap_caps_free((usb_config_desc_t *)dev_obj->constant.config_desc); in device_free()
179 if (dev_obj->constant.str_desc_manu) { in device_free()
180 heap_caps_free((usb_str_desc_t *)dev_obj->constant.str_desc_manu); in device_free()
182 if (dev_obj->constant.str_desc_product) { in device_free()
183 heap_caps_free((usb_str_desc_t *)dev_obj->constant.str_desc_product); in device_free()
185 if (dev_obj->constant.str_desc_ser_num) { in device_free()
186 heap_caps_free((usb_str_desc_t *)dev_obj->constant.str_desc_ser_num); in device_free()
188 heap_caps_free((usb_device_desc_t *)dev_obj->constant.desc); in device_free()
189 ESP_ERROR_CHECK(hcd_pipe_free(dev_obj->constant.default_pipe)); in device_free()
190 heap_caps_free(dev_obj); in device_free()
195 static bool _dev_set_actions(device_t *dev_obj, uint32_t action_flags) in _dev_set_actions() argument
202 if (!dev_obj->dynamic.flags.in_pending_list) { in _dev_set_actions()
204 TAILQ_REMOVE(&p_usbh_obj->dynamic.devs_idle_tailq, dev_obj, dynamic.tailq_entry); in _dev_set_actions()
205 TAILQ_INSERT_TAIL(&p_usbh_obj->dynamic.devs_pending_tailq, dev_obj, dynamic.tailq_entry); in _dev_set_actions()
206 dev_obj->dynamic.action_flags |= action_flags; in _dev_set_actions()
207 dev_obj->dynamic.flags.in_pending_list = 1; in _dev_set_actions()
218 device_t *dev_obj = (device_t *)user_arg; in default_pipe_callback() local
232 ESP_EARLY_LOGE(USBH_TAG, "Dev %d EP 0 Error", dev_obj->constant.address); in default_pipe_callback()
234 ESP_LOGE(USBH_TAG, "Dev %d EP 0 Error", dev_obj->constant.address); in default_pipe_callback()
241 ESP_EARLY_LOGE(USBH_TAG, "Dev %d EP 0 STALL", dev_obj->constant.address); in default_pipe_callback()
243 ESP_LOGE(USBH_TAG, "Dev %d EP 0 STALL", dev_obj->constant.address); in default_pipe_callback()
252 bool call_notif_cb = _dev_set_actions(dev_obj, action_flags); in default_pipe_callback()
262 static void handle_pipe_halt_and_flush(device_t *dev_obj) in handle_pipe_halt_and_flush() argument
268 if (dev_obj->mux_protected.ep_in[i] != NULL) { in handle_pipe_halt_and_flush()
269 ESP_ERROR_CHECK(hcd_pipe_command(dev_obj->mux_protected.ep_in[i], HCD_PIPE_CMD_HALT)); in handle_pipe_halt_and_flush()
270 ESP_ERROR_CHECK(hcd_pipe_command(dev_obj->mux_protected.ep_in[i], HCD_PIPE_CMD_FLUSH)); in handle_pipe_halt_and_flush()
272 if (dev_obj->mux_protected.ep_out[i] != NULL) { in handle_pipe_halt_and_flush()
273 ESP_ERROR_CHECK(hcd_pipe_command(dev_obj->mux_protected.ep_out[i], HCD_PIPE_CMD_HALT)); in handle_pipe_halt_and_flush()
274 ESP_ERROR_CHECK(hcd_pipe_command(dev_obj->mux_protected.ep_out[i], HCD_PIPE_CMD_FLUSH)); in handle_pipe_halt_and_flush()
280 static bool handle_dev_free(device_t *dev_obj) in handle_dev_free() argument
286 if (dev_obj->dynamic.flags.in_pending_list) { in handle_dev_free()
287 dev_obj->dynamic.flags.in_pending_list = 0; in handle_dev_free()
288 TAILQ_REMOVE(&p_usbh_obj->dynamic.devs_pending_tailq, dev_obj, dynamic.tailq_entry); in handle_dev_free()
290 TAILQ_REMOVE(&p_usbh_obj->dynamic.devs_idle_tailq, dev_obj, dynamic.tailq_entry); in handle_dev_free()
296 device_free(dev_obj); in handle_dev_free()
398 device_t *dev_obj = TAILQ_FIRST(&p_usbh_obj->dynamic.devs_pending_tailq); in usbh_process() local
399 TAILQ_REMOVE(&p_usbh_obj->dynamic.devs_pending_tailq, dev_obj, dynamic.tailq_entry); in usbh_process()
400 TAILQ_INSERT_TAIL(&p_usbh_obj->dynamic.devs_idle_tailq, dev_obj, dynamic.tailq_entry); in usbh_process()
402 uint32_t action_flags = dev_obj->dynamic.action_flags; in usbh_process()
403 dev_obj->dynamic.action_flags = 0; in usbh_process()
404 dev_obj->dynamic.flags.in_pending_list = 0; in usbh_process()
415 handle_pipe_halt_and_flush(dev_obj); in usbh_process()
418 ESP_ERROR_CHECK(hcd_pipe_command(dev_obj->constant.default_pipe, HCD_PIPE_CMD_HALT)); in usbh_process()
419 ESP_ERROR_CHECK(hcd_pipe_command(dev_obj->constant.default_pipe, HCD_PIPE_CMD_FLUSH)); in usbh_process()
423 ESP_LOGD(USBH_TAG, "Default pipe device %d", dev_obj->constant.address); in usbh_process()
425 urb_t *urb = hcd_urb_dequeue(dev_obj->constant.default_pipe); in usbh_process()
428 …p_usbh_obj->constant.ctrl_xfer_cb((usb_device_handle_t)dev_obj, urb, p_usbh_obj->constant.ctrl_xfe… in usbh_process()
429 urb = hcd_urb_dequeue(dev_obj->constant.default_pipe); in usbh_process()
432 dev_obj->dynamic.num_ctrl_xfers_inflight -= num_urbs; in usbh_process()
437 hcd_pipe_command(dev_obj->constant.default_pipe, HCD_PIPE_CMD_CLEAR); in usbh_process()
441 ESP_LOGE(USBH_TAG, "Device %d gone", dev_obj->constant.address); in usbh_process()
442 …p_usbh_obj->constant.event_cb((usb_device_handle_t)dev_obj, USBH_EVENT_DEV_GONE, p_usbh_obj->const… in usbh_process()
453 hcd_port_handle_t port_hdl = dev_obj->constant.port_hdl; in usbh_process()
454 ESP_LOGD(USBH_TAG, "Freeing device %d", dev_obj->constant.address); in usbh_process()
455 if (handle_dev_free(dev_obj)) { in usbh_process()
465 ESP_LOGD(USBH_TAG, "Disable device port %d", dev_obj->constant.address); in usbh_process()
466 …p_usbh_obj->constant.hub_req_cb(dev_obj->constant.port_hdl, USBH_HUB_REQ_PORT_DISABLE, p_usbh_obj-… in usbh_process()
468 ESP_LOGD(USBH_TAG, "New device %d", dev_obj->constant.address); in usbh_process()
469 …p_usbh_obj->constant.event_cb((usb_device_handle_t)dev_obj, USBH_EVENT_DEV_NEW, p_usbh_obj->consta… in usbh_process()
499 device_t *dev_obj; in usbh_dev_addr_list_fill() local
501 TAILQ_FOREACH(dev_obj, &p_usbh_obj->dynamic.devs_idle_tailq, dynamic.tailq_entry) { in usbh_dev_addr_list_fill()
503 dev_addr_list[num_filled] = dev_obj->constant.address; in usbh_dev_addr_list_fill()
510 TAILQ_FOREACH(dev_obj, &p_usbh_obj->dynamic.devs_pending_tailq, dynamic.tailq_entry) { in usbh_dev_addr_list_fill()
512 dev_addr_list[num_filled] = dev_obj->constant.address; in usbh_dev_addr_list_fill()
532 device_t *dev_obj; in usbh_dev_open() local
533 TAILQ_FOREACH(dev_obj, &p_usbh_obj->dynamic.devs_idle_tailq, dynamic.tailq_entry) { in usbh_dev_open()
534 if (dev_obj->constant.address == dev_addr) { in usbh_dev_open()
535 found_dev_obj = dev_obj; in usbh_dev_open()
539 TAILQ_FOREACH(dev_obj, &p_usbh_obj->dynamic.devs_idle_tailq, dynamic.tailq_entry) { in usbh_dev_open()
540 if (dev_obj->constant.address == dev_addr) { in usbh_dev_open()
541 found_dev_obj = dev_obj; in usbh_dev_open()
548 …if (dev_obj->dynamic.flags.is_gone || dev_obj->dynamic.flags.waiting_port_disable || dev_obj->dyna… in usbh_dev_open()
551 dev_obj->dynamic.ref_count++; in usbh_dev_open()
566 device_t *dev_obj = (device_t *)dev_hdl; in usbh_dev_close() local
569 dev_obj->dynamic.ref_count--; in usbh_dev_close()
571 if (dev_obj->dynamic.ref_count == 0) { in usbh_dev_close()
573 …assert(dev_obj->dynamic.num_ctrl_xfers_inflight == 0); //There cannot be any control transfer inf… in usbh_dev_close()
574 … assert(!dev_obj->dynamic.flags.waiting_free); //This can only be set when ref count reaches 0 in usbh_dev_close()
575 if (dev_obj->dynamic.flags.is_gone) { in usbh_dev_close()
577 dev_obj->dynamic.flags.waiting_free = 1; in usbh_dev_close()
578 …call_notif_cb = _dev_set_actions(dev_obj, DEV_FLAG_ACTION_FREE_AND_RECOVER); //Port error occurred… in usbh_dev_close()
579 } else if (dev_obj->dynamic.flags.waiting_close) { in usbh_dev_close()
581 dev_obj->dynamic.flags.waiting_port_disable = 1; in usbh_dev_close()
582 call_notif_cb = _dev_set_actions(dev_obj, DEV_FLAG_ACTION_PORT_DISABLE); in usbh_dev_close()
642 device_t *dev_obj = (device_t *)dev_hdl; in usbh_dev_get_addr() local
645 USBH_CHECK_FROM_CRIT(dev_obj->constant.address > 0, ESP_ERR_INVALID_STATE); in usbh_dev_get_addr()
646 *dev_addr = dev_obj->constant.address; in usbh_dev_get_addr()
655 device_t *dev_obj = (device_t *)dev_hdl; in usbh_dev_get_info() local
660 …if (!(dev_obj->dynamic.state == USB_DEVICE_STATE_CONFIGURED || dev_obj->dynamic.state == USB_DEVIC… in usbh_dev_get_info()
666 dev_info->speed = dev_obj->constant.speed; in usbh_dev_get_info()
667 dev_info->dev_addr = dev_obj->constant.address; in usbh_dev_get_info()
668 dev_info->bMaxPacketSize0 = dev_obj->constant.desc->bMaxPacketSize0; in usbh_dev_get_info()
670 assert(dev_obj->constant.config_desc); in usbh_dev_get_info()
671 dev_info->bConfigurationValue = dev_obj->constant.config_desc->bConfigurationValue; in usbh_dev_get_info()
673 dev_info->str_desc_manufacturer = dev_obj->constant.str_desc_manu; in usbh_dev_get_info()
674 dev_info->str_desc_product = dev_obj->constant.str_desc_product; in usbh_dev_get_info()
675 dev_info->str_desc_serial_num = dev_obj->constant.str_desc_ser_num; in usbh_dev_get_info()
684 device_t *dev_obj = (device_t *)dev_hdl; in usbh_dev_get_desc() local
687 …USBH_CHECK_FROM_CRIT(dev_obj->dynamic.state == USB_DEVICE_STATE_CONFIGURED, ESP_ERR_INVALID_STATE); in usbh_dev_get_desc()
690 *dev_desc_ret = dev_obj->constant.desc; in usbh_dev_get_desc()
697 device_t *dev_obj = (device_t *)dev_hdl; in usbh_dev_get_config_desc() local
702 if (dev_obj->dynamic.state != USB_DEVICE_STATE_CONFIGURED) { in usbh_dev_get_config_desc()
708 assert(dev_obj->constant.config_desc); in usbh_dev_get_config_desc()
709 *config_desc_ret = dev_obj->constant.config_desc; in usbh_dev_get_config_desc()
718 device_t *dev_obj = (device_t *)dev_hdl; in usbh_dev_submit_ctrl_urb() local
721 …USBH_CHECK_FROM_CRIT(dev_obj->dynamic.state == USB_DEVICE_STATE_CONFIGURED, ESP_ERR_INVALID_STATE); in usbh_dev_submit_ctrl_urb()
723 dev_obj->dynamic.num_ctrl_xfers_inflight++; in usbh_dev_submit_ctrl_urb()
727 if (hcd_pipe_get_state(dev_obj->constant.default_pipe) != HCD_PIPE_STATE_ACTIVE) { in usbh_dev_submit_ctrl_urb()
731 ret = hcd_urb_enqueue(dev_obj->constant.default_pipe, urb); in usbh_dev_submit_ctrl_urb()
740 dev_obj->dynamic.num_ctrl_xfers_inflight--; in usbh_dev_submit_ctrl_urb()
750 device_t *dev_obj = (device_t *)dev_hdl; in usbh_ep_alloc() local
759 .dev_speed = dev_obj->constant.speed, in usbh_ep_alloc()
760 .dev_addr = dev_obj->constant.address, in usbh_ep_alloc()
763 ret = hcd_pipe_alloc(dev_obj->constant.port_hdl, &pipe_config, &pipe_hdl); in usbh_ep_alloc()
776 if (dev_obj->dynamic.state != USB_DEVICE_STATE_CONFIGURED) { in usbh_ep_alloc()
783 if (is_in && dev_obj->mux_protected.ep_in[addr - 1] == NULL) { //Is an IN EP in usbh_ep_alloc()
784 dev_obj->mux_protected.ep_in[addr - 1] = pipe_hdl; in usbh_ep_alloc()
786 } else if (dev_obj->mux_protected.ep_out[addr - 1] == NULL) { //Is an OUT EP in usbh_ep_alloc()
787 dev_obj->mux_protected.ep_out[addr - 1] = pipe_hdl; in usbh_ep_alloc()
810 device_t *dev_obj = (device_t *)dev_hdl; in usbh_ep_free() local
821 if (dev_obj->mux_protected.ep_in[addr - 1] != NULL) { in usbh_ep_free()
822 pipe_hdl = dev_obj->mux_protected.ep_in[addr - 1]; in usbh_ep_free()
823 dev_obj->mux_protected.ep_in[addr - 1] = NULL; in usbh_ep_free()
830 if (dev_obj->mux_protected.ep_out[addr - 1] != NULL) { in usbh_ep_free()
831 pipe_hdl = dev_obj->mux_protected.ep_out[addr - 1]; in usbh_ep_free()
832 dev_obj->mux_protected.ep_out[addr - 1] = NULL; in usbh_ep_free()
857 device_t *dev_obj = (device_t *)dev_hdl; in usbh_ep_get_context() local
864 pipe_hdl = dev_obj->mux_protected.ep_in[addr - 1]; in usbh_ep_get_context()
866 pipe_hdl = dev_obj->mux_protected.ep_out[addr - 1]; in usbh_ep_get_context()
907 device_t *dev_obj; in usbh_hub_add_dev() local
908 ret = device_alloc(port_hdl, dev_speed, &dev_obj); in usbh_hub_add_dev()
913 *new_dev_hdl = (usb_device_handle_t)dev_obj; in usbh_hub_add_dev()
914 *default_pipe_hdl = dev_obj->constant.default_pipe; in usbh_hub_add_dev()
922 device_t *dev_obj = (device_t *)dev_hdl; in usbh_hub_pass_event() local
928 dev_obj->dynamic.flags.is_gone = 1; in usbh_hub_pass_event()
930 if (dev_obj->dynamic.ref_count == 0) { in usbh_hub_pass_event()
931 dev_obj->dynamic.flags.waiting_free = 1; in usbh_hub_pass_event()
933 …call_notif_cb = _dev_set_actions(dev_obj, DEV_FLAG_ACTION_FREE_AND_RECOVER); //Port error occurred… in usbh_hub_pass_event()
935 call_notif_cb = _dev_set_actions(dev_obj, DEV_FLAG_ACTION_PIPE_HALT_AND_FLUSH | in usbh_hub_pass_event()
945 …assert(dev_obj->dynamic.ref_count == 0); //At this stage, the device should have been closed by… in usbh_hub_pass_event()
946 dev_obj->dynamic.flags.waiting_free = 1; in usbh_hub_pass_event()
947 call_notif_cb = _dev_set_actions(dev_obj, DEV_FLAG_ACTION_FREE); in usbh_hub_pass_event()
966 device_t *dev_obj = (device_t *)dev_hdl; in usbh_hub_enum_fill_dev_addr() local
969 dev_obj->dynamic.state = USB_DEVICE_STATE_ADDRESS; in usbh_hub_enum_fill_dev_addr()
973 dev_obj->constant.address = dev_addr; in usbh_hub_enum_fill_dev_addr()
980 device_t *dev_obj = (device_t *)dev_hdl; in usbh_hub_enum_fill_dev_desc() local
982 memcpy((usb_device_desc_t *)dev_obj->constant.desc, device_desc, sizeof(usb_device_desc_t)); in usbh_hub_enum_fill_dev_desc()
989 device_t *dev_obj = (device_t *)dev_hdl; in usbh_hub_enum_fill_config_desc() local
998 assert(dev_obj->constant.config_desc == NULL); in usbh_hub_enum_fill_config_desc()
999 dev_obj->constant.config_desc = config_desc; in usbh_hub_enum_fill_config_desc()
1006 device_t *dev_obj = (device_t *)dev_hdl; in usbh_hub_enum_fill_str_desc() local
1017 assert(dev_obj->constant.str_desc_manu == NULL); in usbh_hub_enum_fill_str_desc()
1018 dev_obj->constant.str_desc_manu = str_desc_fill; in usbh_hub_enum_fill_str_desc()
1021 assert(dev_obj->constant.str_desc_product == NULL); in usbh_hub_enum_fill_str_desc()
1022 dev_obj->constant.str_desc_product = str_desc_fill; in usbh_hub_enum_fill_str_desc()
1025 assert(dev_obj->constant.str_desc_ser_num == NULL); in usbh_hub_enum_fill_str_desc()
1026 dev_obj->constant.str_desc_ser_num = str_desc_fill; in usbh_hub_enum_fill_str_desc()
1035 device_t *dev_obj = (device_t *)dev_hdl; in usbh_hub_enum_done() local
1040 dev_obj->dynamic.state = USB_DEVICE_STATE_CONFIGURED; in usbh_hub_enum_done()
1042 …TAILQ_INSERT_TAIL(&p_usbh_obj->dynamic.devs_idle_tailq, dev_obj, dynamic.tailq_entry); //Add it … in usbh_hub_enum_done()
1043 bool call_notif_cb = _dev_set_actions(dev_obj, DEV_FLAG_ACTION_SEND_NEW); in usbh_hub_enum_done()
1049 …ESP_ERROR_CHECK(hcd_pipe_update_callback(dev_obj->constant.default_pipe, default_pipe_callback, (v… in usbh_hub_enum_done()
1060 device_t *dev_obj = (device_t *)dev_hdl; in usbh_hub_enum_failed() local
1061 device_free(dev_obj); in usbh_hub_enum_failed()