File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,52 @@ pub fn wdr() {
39
39
}
40
40
}
41
41
42
+ /// Get the stack size in bytes, for debbuging.
43
+ #[ inline( always) ]
44
+ pub fn get_stack_size ( ) -> usize {
45
+ extern "C" {
46
+ static __DATA_REGION_ORIGIN__: usize ;
47
+ static __DATA_REGION_LENGTH__: usize ;
48
+ }
49
+ use core:: ptr:: addr_of;
50
+
51
+ cfg_if:: cfg_if! {
52
+ if #[ cfg( target_arch = "avr" ) ] {
53
+ unsafe {
54
+ let data_region_end = addr_of!( __DATA_REGION_ORIGIN__) as usize + addr_of!( __DATA_REGION_LENGTH__) as usize ;
55
+ let sp: usize ;
56
+ if data_region_end > u8 :: MAX as usize {
57
+ // Here the stack pointer is 2 bytes.
58
+
59
+ let spl: u8 ;
60
+ let sph: u8 ;
61
+ core:: arch:: asm!(
62
+ "in {}, 0x3d" ,
63
+ "in {}, 0x3e" ,
64
+ out( reg) spl,
65
+ out( reg) sph,
66
+ options( nostack, nomem, pure) ,
67
+ ) ;
68
+ sp = usize :: from_le_bytes( [ spl, sph] ) ;
69
+ } else {
70
+ // Here the stack pointer is 1 byte.
71
+
72
+ let spl: u8 ;
73
+ core:: arch:: asm!(
74
+ "in {}, 0x3d" ,
75
+ out( reg) spl,
76
+ options( nostack, nomem, pure) ,
77
+ ) ;
78
+ sp = spl as usize ;
79
+ }
80
+ data_region_end - sp
81
+ }
82
+ } else {
83
+ unimplemented!( )
84
+ }
85
+ }
86
+ }
87
+
42
88
/// Blocks the program for at least `cycles` CPU cycles.
43
89
///
44
90
/// This is intended for very simple delays in low-level drivers, but it
You can’t perform that action at this time.
0 commit comments