@@ -50,6 +50,16 @@ pub extern crate env_logger;
50
50
/// defined as `0..NUM_INTERRUPT_LINES`
51
51
pub const NUM_INTERRUPT_LINES : usize = 1024 ;
52
52
53
+ /// Implemented on a system type by [`use_port!`].
54
+ ///
55
+ /// # Safety
56
+ ///
57
+ /// Only meant to be implemented by [`use_port!`].
58
+ #[ doc( hidden) ]
59
+ pub unsafe trait PortInstance : Kernel + Port < PortTaskState = TaskState > {
60
+ fn port_state ( ) -> & ' static State ;
61
+ }
62
+
53
63
/// The internal state of the port.
54
64
///
55
65
/// # Safety
@@ -394,9 +404,8 @@ impl State {
394
404
self . dispatch_pending . store ( true , Ordering :: Relaxed ) ;
395
405
}
396
406
397
- pub unsafe fn dispatch_first_task < System : Kernel > ( & ' static self ) -> !
407
+ pub unsafe fn dispatch_first_task < System : PortInstance > ( & ' static self ) -> !
398
408
where
399
- System : Port < PortTaskState = TaskState > ,
400
409
// FIXME: Work-around for <https://github.com/rust-lang/rust/issues/43475>
401
410
System :: TaskReadyQueue : std:: borrow:: BorrowMut < [ StaticListHead < TaskCb < System > > ] > ,
402
411
{
@@ -429,9 +438,8 @@ impl State {
429
438
panic ! ( "the system has been shut down" ) ;
430
439
}
431
440
432
- fn dispatcher_loop < System : Kernel > ( & ' static self )
441
+ fn dispatcher_loop < System : PortInstance > ( & ' static self )
433
442
where
434
- System : Port < PortTaskState = TaskState > ,
435
443
// FIXME: Work-around for <https://github.com/rust-lang/rust/issues/43475>
436
444
System :: TaskReadyQueue : std:: borrow:: BorrowMut < [ StaticListHead < TaskCb < System > > ] > ,
437
445
{
@@ -742,10 +750,17 @@ macro_rules! use_port {
742
750
PendInterruptLineError , Port , QueryInterruptLineError , SetInterruptLinePriorityError ,
743
751
TaskCb , PortToKernel , PortInterrupts , PortThreading , UTicks , PortTimer ,
744
752
} ;
745
- use $crate:: { State , TaskState } ;
753
+ use $crate:: { State , TaskState , PortInstance } ;
746
754
747
755
pub ( super ) static PORT_STATE : State = State :: new( ) ;
748
756
757
+ unsafe impl PortInstance for $sys {
758
+ #[ inline]
759
+ fn port_state( ) -> & ' static State {
760
+ & PORT_STATE
761
+ }
762
+ }
763
+
749
764
// Assume `$sys: Kernel`
750
765
unsafe impl PortThreading for $sys {
751
766
type PortTaskState = TaskState ;
0 commit comments