@@ -26,11 +26,13 @@ fn to_stack_units(size: usize) usize {
2626/// Downside: Performance (may be mitigated once https://github.com/ziglang/zig/issues/23367 is implemeted).
2727pub const PauseReason = union (enum ) {
2828 const OnStack = [to_stack_units (@sizeOf (@This ()))]StackUint ;
29+ const PtrMask = struct { ptr : * const usize , mask : usize };
2930
3031 /// Task volutarily gave up execution, but is ready to continue.
3132 yield ,
3233 sleep_until : time .Absolute align (@alignOf (StackUint )),
33- bits_mask_any_high : struct { ptr : * const usize , mask : usize },
34+ bits_mask_all_low : PtrMask ,
35+ bits_mask_any_high : PtrMask ,
3436 /// This value means there is no context stored on this stack
3537 /// so it can be used to launch a new task.
3638 no_task ,
@@ -48,6 +50,9 @@ pub const PauseReason = union(enum) {
4850 .bits_mask_any_high = > | info | {
4951 return @atomicLoad (usize , info .ptr , .acquire ) & info .mask != 0 ;
5052 },
53+ .bits_mask_all_low = > | info | {
54+ return @atomicLoad (usize , info .ptr , .acquire ) & info .mask == 0 ;
55+ },
5156 .sleep_until = > | t | t .is_reached_by (io .monotonic_clock ()),
5257 };
5358 }
@@ -303,11 +308,24 @@ pub const RoundRobin = struct {
303308 pub fn monotonic_clock (this : * @This ()) time.Absolute {
304309 return this .vtable .monotonic_clock ();
305310 }
311+
312+ /// Perform memcpy with DMA. `dst` and `src` must have the same length.
313+ pub fn dma_memcpy (this : * @This (), T : type , dst : []T , src : []const T ) ! DmaResult {
314+ assert (dst .len == src .len );
315+ return this .vtable .dma_memcpy (dst .ptr , src .ptr , dst .len * @sizeOf (T ));
316+ }
317+ };
318+
319+ /// TODO: I hate this
320+ pub const DmaResult = struct {
321+ await : * const fn (* @This (), * RoundRobin ) void ,
322+ channel : u32 ,
306323};
307324
308325/// Common functionality between all implementations.
309326/// Needs to be specified by every port.
310327pub const VTable = struct {
311328 /// A clock source that only ever goes up, not synchronized with epoch.
312329 monotonic_clock : * const fn () time.Absolute ,
330+ dma_memcpy : * const fn (* anyopaque , * const anyopaque , usize ) anyerror ! DmaResult ,
313331};
0 commit comments