From 7400eb36406f1e26ae55751aaa4c175630969402 Mon Sep 17 00:00:00 2001 From: b14ckcat Date: Mon, 17 Oct 2022 01:22:54 -0400 Subject: Kernel/USB: Add support for async & interrupt transfers Add support for async transfers by using a separate kernel task to poll a list of active async transfers on a set time interval, and invoke their user-provided callback function when they are complete. Also add support for the interrupt class of transfers, building off of this async functionality. --- Kernel/Bus/USB/USBTransfer.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Kernel/Bus/USB/USBTransfer.h') diff --git a/Kernel/Bus/USB/USBTransfer.h b/Kernel/Bus/USB/USBTransfer.h index 5923542d6c..c506650d9e 100644 --- a/Kernel/Bus/USB/USBTransfer.h +++ b/Kernel/Bus/USB/USBTransfer.h @@ -20,7 +20,7 @@ namespace Kernel::USB { class Transfer final : public AtomicRefCounted { public: - static ErrorOr> try_create(Pipe&, u16 length, Memory::Region& dma_buffer); + static ErrorOr> create(Pipe&, u16 length, Memory::Region& dma_buffer, USBAsyncCallback callback = nullptr); Transfer() = delete; ~Transfer(); @@ -41,14 +41,17 @@ public: bool complete() const { return m_complete; } bool error_occurred() const { return m_error_occurred; } + void invoke_async_callback(); + private: - Transfer(Pipe& pipe, u16 len, Memory::Region& dma_buffer); + Transfer(Pipe& pipe, u16 len, Memory::Region& dma_buffer, USBAsyncCallback callback); Pipe& m_pipe; // Pipe that initiated this transfer Memory::Region& m_dma_buffer; // DMA buffer USBRequestData m_request; // USB request u16 m_transfer_data_size { 0 }; // Size of the transfer's data stage bool m_complete { false }; // Has this transfer been completed? bool m_error_occurred { false }; // Did an error occur during this transfer? + USBAsyncCallback m_callback { nullptr }; }; } -- cgit v1.2.3