Skip to content

Commit

Permalink
zephyr: keep the endpoint queues free during suspend
Browse files Browse the repository at this point in the history
  • Loading branch information
benedekkupper committed Oct 3, 2024
1 parent cf1a73e commit c1677e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 16 additions & 1 deletion c2usb/port/zephyr/udc_mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,15 @@ int udc_mac::process_event(const udc_event& event)
process_ep_event(event.buf);
break;
case UDC_EVT_RESET:
cancel_all_transfers();
bus_reset();
break;
case UDC_EVT_SUSPEND:
set_power_state(power::state::L2_SUSPEND);
break;
case UDC_EVT_RESUME:
case UDC_EVT_VBUS_READY:
cancel_all_transfers();
set_power_state(power::state::L0_ON);
break;
case UDC_EVT_VBUS_REMOVED:
Expand Down Expand Up @@ -583,6 +585,19 @@ usb::endpoint::address udc_mac::ep_handle_to_address(ep_handle eph) const
return endpoint::address(udc_get_buf_info(ep_handle_to_buf(eph))->ep);
}

void udc_mac::cancel_all_transfers()
{
for (auto* buf : ep_bufs_)
{
endpoint::address addr{udc_get_buf_info(buf)->ep};
if (busy_flags_.test(addr))
{
[[maybe_unused]] auto ret = udc_ep_dequeue(dev_, addr);
busy_flags_.clear(addr);
}
}
}

usb::df::ep_handle udc_mac::ep_open(const usb::df::config::endpoint& ep)
{
auto ret = udc_ep_enable(dev_, ep.address(), ep.bmAttributes, ep.wMaxPacketSize, ep.bInterval);
Expand Down Expand Up @@ -611,7 +626,7 @@ usb::result udc_mac::ep_transfer(usb::df::ep_handle eph, const transfer& t, usb:
return result::BUSY;
}
#endif
if (busy_flags_.test_and_set(addr))
if ((power_state() != power::state::L0_ON) or busy_flags_.test_and_set(addr))
{
return result::BUSY;
}
Expand Down
1 change: 1 addition & 0 deletions c2usb/port/zephyr/udc_mac.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class udc_mac : public df::mac
usb::result ep_clear_stall(endpoint::address addr);
usb::result ep_transfer(usb::df::ep_handle eph, const usb::df::transfer& t, usb::direction dir);

void cancel_all_transfers();
usb::df::ep_handle ep_open(const usb::df::config::endpoint& ep) override;
usb::result ep_send(usb::df::ep_handle eph, const std::span<const uint8_t>& data) override;
usb::result ep_receive(usb::df::ep_handle eph, const std::span<uint8_t>& data) override;
Expand Down

0 comments on commit c1677e0

Please sign in to comment.