@@ -10,7 +10,92 @@ mod executor;
10
10
pub mod task;
11
11
pub mod unsync;
12
12
13
- use cortex_m_udf:: udf as abort;
13
+ #[ cfg( feature = "isa-cortex-m" ) ]
14
+ use cortex_m:: asm;
15
+
16
+ #[ cfg( feature = "isa-cortex-m" ) ]
17
+ pub use cortex_m_udf:: udf as abort;
18
+
19
+ #[ cfg( all( feature = "isa-cortex-m" ) ) ]
20
+ #[ inline]
21
+ /// Prevent next `wait_for_interrupt` from sleeping, wake up other harts if needed.
22
+ /// This particular implementation does nothing, since `wait_for_interrupt` never sleeps
23
+ pub ( crate ) unsafe fn signal_event_ready ( ) {
24
+ asm:: sev ( ) ;
25
+ }
26
+
27
+ #[ cfg( all( feature = "isa-cortex-m" ) ) ]
28
+ #[ inline]
29
+ /// Wait for an interrupt or until notified by other hart via `signal_task_ready`
30
+ /// This particular implementation does nothing
31
+ pub ( crate ) unsafe fn wait_for_event ( ) {
32
+ asm:: wfe ( ) ;
33
+ }
34
+
35
+ #[ cfg( feature = "isa-riscv" ) ]
36
+ /// This keeps dropping into the debugger and never returns
37
+ pub fn abort ( ) -> ! {
38
+ loop {
39
+ unsafe { riscv:: asm:: ebreak ( ) }
40
+ }
41
+ }
42
+
43
+ #[ cfg( all( feature = "isa-riscv" , feature = "riscv-wait-nop" ) ) ]
44
+ #[ inline]
45
+ /// Prevent next `wait_for_interrupt` from sleeping, wake up other harts if needed.
46
+ /// This particular implementation does nothing, since `wait_for_interrupt` never sleeps
47
+ pub ( crate ) unsafe fn signal_event_ready ( ) { }
48
+
49
+ #[ cfg( all( feature = "isa-riscv" , feature = "riscv-wait-nop" ) ) ]
50
+ #[ inline]
51
+ /// Wait for an interrupt or until notified by other hart via `signal_task_ready`
52
+ /// This particular implementation does nothing
53
+ pub ( crate ) unsafe fn wait_for_event ( ) { }
54
+
55
+ #[ cfg( all( feature = "isa-riscv" , feature = "riscv-wait-extern" ) ) ]
56
+ extern "C" {
57
+ /// Prevent next `wait_for_interrupt` from sleeping, wake up other harts if needed.
58
+ /// User is expected to provide an actual implementation, like the one shown below.
59
+ ///
60
+ /// #[no_mangle]
61
+ /// pub extern "C" fn signal_event_ready() {
62
+ /// unimplemented!();
63
+ /// }
64
+ pub ( crate ) fn signal_event_ready ( ) ;
65
+
66
+ /// Wait for an interrupt or until notified by other hart via `signal_task_ready`
67
+ /// User is expected to provide an actual implementation, like the one shown below.
68
+ ///
69
+ /// #[no_mangle]
70
+ /// pub extern "C" fn wait_for_event() {
71
+ /// unimplemented!();
72
+ /// }
73
+ pub ( crate ) fn wait_for_event ( ) ;
74
+ }
75
+
76
+ #[ cfg( all( feature = "isa-riscv" , feature = "riscv-wait-wfi-single-hart" ) ) ]
77
+ static mut TASK_READY : bool = false ;
78
+
79
+ #[ cfg( all( feature = "isa-riscv" , feature = "riscv-wait-wfi-single-hart" ) ) ]
80
+ #[ inline]
81
+ /// Prevent next `wait_for_interrupt` from sleeping, wake up other harts if needed.
82
+ /// This particular implementation prevents `wait_for_interrupt` from sleeping by setting
83
+ /// a global mutable flag
84
+ pub ( crate ) unsafe fn signal_event_ready ( ) {
85
+ TASK_READY = true ;
86
+ }
87
+
88
+ #[ cfg( all( feature = "isa-riscv" , feature = "riscv-wait-wfi-single-hart" ) ) ]
89
+ #[ inline]
90
+ /// Wait for an interrupt or until notified by other hart via `signal_task_ready`
91
+ /// This particular implementation decides whether to sleep or not by checking
92
+ /// a global mutable flag that's set by `signal_task_ready`
93
+ pub ( crate ) unsafe fn wait_for_event ( ) {
94
+ if !TASK_READY {
95
+ riscv:: asm:: wfi ( ) ;
96
+ TASK_READY = false ;
97
+ }
98
+ }
14
99
15
100
/// Maximum number of tasks (TODO this could be user configurable)
16
101
type NTASKS = typenum:: consts:: U8 ;
0 commit comments