1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 07:47:35 +00:00

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.
This commit is contained in:
b14ckcat 2022-10-17 01:22:54 -04:00 committed by Andrew Kaster
parent 1aa16b4dd4
commit 7400eb3640
8 changed files with 181 additions and 62 deletions

View file

@ -20,7 +20,7 @@ namespace Kernel::USB {
class Transfer final : public AtomicRefCounted<Transfer> {
public:
static ErrorOr<NonnullLockRefPtr<Transfer>> try_create(Pipe&, u16 length, Memory::Region& dma_buffer);
static ErrorOr<NonnullLockRefPtr<Transfer>> 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 };
};
}