mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:37:45 +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:
parent
1aa16b4dd4
commit
7400eb3640
8 changed files with 181 additions and 62 deletions
|
@ -9,15 +9,16 @@
|
|||
|
||||
namespace Kernel::USB {
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<Transfer>> Transfer::try_create(Pipe& pipe, u16 length, Memory::Region& dma_buffer)
|
||||
ErrorOr<NonnullLockRefPtr<Transfer>> Transfer::create(Pipe& pipe, u16 length, Memory::Region& dma_buffer, USBAsyncCallback callback)
|
||||
{
|
||||
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) Transfer(pipe, length, dma_buffer));
|
||||
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) Transfer(pipe, length, dma_buffer, move(callback)));
|
||||
}
|
||||
|
||||
Transfer::Transfer(Pipe& pipe, u16 len, Memory::Region& dma_buffer)
|
||||
Transfer::Transfer(Pipe& pipe, u16 len, Memory::Region& dma_buffer, USBAsyncCallback callback)
|
||||
: m_pipe(pipe)
|
||||
, m_dma_buffer(dma_buffer)
|
||||
, m_transfer_data_size(len)
|
||||
, m_callback(move(callback))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -49,4 +50,10 @@ ErrorOr<void> Transfer::write_buffer(u16 len, void* data)
|
|||
return {};
|
||||
}
|
||||
|
||||
void Transfer::invoke_async_callback()
|
||||
{
|
||||
if (m_callback)
|
||||
m_callback(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue