@@ -18,8 +18,10 @@ pub mod stdio;
18
18
pub mod thread;
19
19
pub mod time;
20
20
21
- use crate :: { arch:: asm, ptr :: { self , addr_of_mut } } ;
21
+ use crate :: arch:: asm;
22
22
use crate :: hash:: { DefaultHasher , Hasher } ;
23
+ use crate :: ptr:: { self , addr_of_mut} ;
24
+ use crate :: time:: { Duration , Instant } ;
23
25
24
26
#[ cfg( not( test) ) ]
25
27
#[ no_mangle]
@@ -53,12 +55,8 @@ pub unsafe extern "C" fn _start() -> ! {
53
55
#[ link_section = ".code_signature" ]
54
56
#[ linkage = "weak" ]
55
57
#[ used]
56
- static CODE_SIGNATURE : vex_sdk:: vcodesig = vex_sdk:: vcodesig {
57
- magic : u32:: from_le_bytes ( * b"XVX5" ) ,
58
- r#type : 0 ,
59
- owner : 2 ,
60
- options : 0 ,
61
- } ;
58
+ static CODE_SIGNATURE : vex_sdk:: vcodesig =
59
+ vex_sdk:: vcodesig { magic : u32:: from_le_bytes ( * b"XVX5" ) , r#type : 0 , owner : 2 , options : 0 } ;
62
60
63
61
// This function is needed by the panic runtime. The symbol is named in
64
62
// pre-link args for the target specification, so keep that in sync.
@@ -94,8 +92,19 @@ pub fn decode_error_kind(_code: i32) -> crate::io::ErrorKind {
94
92
}
95
93
96
94
pub fn abort_internal ( ) -> ! {
95
+ let exit_time = Instant :: now ( ) ;
96
+ const FLUSH_TIMEOUT : Duration = Duration :: from_millis ( 15 ) ;
97
+
97
98
unsafe {
98
- vex_sdk:: vexTasksRun ( ) ;
99
+ // Force the serial buffer to flush
100
+ while exit_time. elapsed ( ) < FLUSH_TIMEOUT {
101
+ // If the buffer has been fully flushed, exit the loop
102
+ if vex_sdk:: vexSerialWriteFree ( stdio:: STDIO_CHANNEL ) == ( stdio:: STDOUT_BUF_SIZE as i32 )
103
+ {
104
+ break ;
105
+ }
106
+ vex_sdk:: vexTasksRun ( ) ;
107
+ }
99
108
vex_sdk:: vexSystemExitRequest ( ) ;
100
109
}
101
110
@@ -107,9 +116,7 @@ pub fn abort_internal() -> ! {
107
116
fn hash_time ( ) -> u64 {
108
117
let mut hasher = DefaultHasher :: new ( ) ;
109
118
// The closest we can get to a random number is the time since program start
110
- let time = unsafe {
111
- vex_sdk:: vexSystemHighResTimeGet ( )
112
- } ;
119
+ let time = unsafe { vex_sdk:: vexSystemHighResTimeGet ( ) } ;
113
120
hasher. write_u64 ( time) ;
114
121
hasher. finish ( )
115
122
}
0 commit comments