Commit 0096985 1 parent 9d6e613 commit 0096985 Copy full SHA for 0096985
File tree 3 files changed +27
-20
lines changed
3 files changed +27
-20
lines changed Original file line number Diff line number Diff line change 1
- use mcu_if:: { println, alloc:: boxed:: Box } ;
2
1
use embassy_executor:: { Spawner , raw:: Executor as RawExecutor } ;
2
+ use super :: { to_raw, static_from_raw} ;
3
3
4
4
// https://github.com/embassy-rs/embassy/blob/b6fc682117a41e8e63a9632e06da5a17f46d9ab0/embassy-executor/src/raw/mod.rs#L465
5
5
#[ export_name = "__pender" ]
6
6
fn pender ( context : * mut ( ) ) {
7
- let signaler: & ' static Signaler = unsafe { core:: mem:: transmute ( context) } ;
8
- if 0 == 1 { println ! ( "@@ pender(): signaler: {:?}" , signaler) ; }
7
+ //@@ let signaler: &'static Signaler = unsafe { core::mem::transmute(context) };
8
+ let signaler: & ' static Signaler = static_from_raw ( context) ;
9
+ if 0 == 1 { crate :: println!( "@@ pender(): signaler: {:?}" , signaler) ; }
9
10
}
10
11
11
12
pub struct Executor {
12
13
executor : RawExecutor ,
13
- _signaler : & ' static Signaler , // c.f. embassy/embassy-executor/src/arch/std.rs
14
+ //@@ _signaler: &'static Signaler, // c.f. embassy/embassy-executor/src/arch/std.rs
15
+ _signaler : Signaler ,
14
16
}
15
17
16
18
#[ derive( Debug ) ]
17
19
struct Signaler ( ( ) ) ; // TODO
18
20
19
21
impl Executor {
20
22
pub fn new ( ) -> Self {
21
- let signaler = Box :: leak ( Box :: new ( Signaler ( ( ) ) ) ) ;
23
+ //@@ let signaler = Box::leak(Box::new(Signaler(())));
24
+ let mut signaler = Signaler ( ( ) ) ;
22
25
23
26
Self {
24
- executor : RawExecutor :: new ( signaler as * mut _ as * mut ( ) ) ,
27
+ executor : RawExecutor :: new ( to_raw ( & mut signaler ) ) ,
25
28
_signaler : signaler,
26
29
}
27
30
}
Original file line number Diff line number Diff line change 1
- use mcu_if:: alloc:: boxed:: Box ;
2
1
use super :: xbd:: { self , Xbd } ;
3
2
4
3
mod executor;
@@ -30,19 +29,21 @@ async fn task_shell_stream() {
30
29
xbd:: process_shell_stream ( ) . await . unwrap ( ) ;
31
30
}
32
31
33
- pub struct Runtime ( & ' static mut Executor ) ;
34
-
35
- impl Runtime {
36
- pub fn new_static ( ) -> Result < & ' static mut Self , ( ) > {
37
- Ok ( Self :: get_static ( Self :: new ( ) ) )
38
- }
32
+ fn to_raw < T > ( x : & mut T ) -> * mut ( ) { x as * mut _ as _ }
33
+ fn static_from_raw < T > ( p : * mut ( ) ) -> & ' static mut T { unsafe { core:: mem:: transmute ( p) } }
34
+ pub fn get_static < T > ( x : & mut T ) -> & ' static mut T { static_from_raw ( to_raw ( x) ) }
35
+ /* deprecated
36
+ pub fn get_static<T>(x: &mut T) -> &'static mut T {
37
+ use mcu_if::alloc::boxed::Box;
38
+ Box::leak(Box::new(x))
39
+ }
40
+ */
39
41
40
- fn new ( ) -> Self {
41
- Self ( Self :: get_static ( Executor :: new ( ) ) )
42
- }
42
+ pub struct Runtime ( Executor ) ;
43
43
44
- fn get_static < T > ( x : T ) -> & ' static mut T {
45
- Box :: leak ( Box :: new ( x) )
44
+ impl Runtime {
45
+ pub fn new ( ) -> Self {
46
+ Self ( Executor :: new ( ) )
46
47
}
47
48
48
49
pub fn run ( & ' static mut self ) -> ! {
Original file line number Diff line number Diff line change @@ -47,12 +47,15 @@ pub extern fn rustmod_start(
47
47
if 0 == 1 { // debug
48
48
Xbd :: usleep ( 1_000_000 ) ;
49
49
blogos12:: test_misc ( ) ;
50
- return ;
50
+ panic ! ( "ok" ) ;
51
51
}
52
52
53
53
if 1 == 1 {
54
54
println ! ( "@@ [debug] `xbd_main()` with `embassy::Runtime` ..." ) ;
55
- embassy:: Runtime :: new_static ( ) . unwrap ( ) . run ( ) ;
55
+ embassy:: get_static ( & mut embassy:: Runtime :: new ( ) )
56
+ . run ( ) ; // -> !
57
+
58
+ // should be never reached
56
59
} else {
57
60
println ! ( "@@ [debug] `xbd_main()` with `blogos12::Runtime` ..." ) ;
58
61
let _ = blogos12:: Runtime :: new ( )
You can’t perform that action at this time.
0 commit comments