@@ -18,8 +18,10 @@ pub mod stdio;
1818pub mod thread;
1919pub mod time;
2020
21- use crate :: { arch:: asm, ptr :: { self , addr_of_mut } } ;
21+ use crate :: arch:: asm;
2222use crate :: hash:: { DefaultHasher , Hasher } ;
23+ use crate :: ptr:: { self , addr_of_mut} ;
24+ use crate :: time:: { Duration , Instant } ;
2325
2426#[ cfg( not( test) ) ]
2527#[ no_mangle]
@@ -53,12 +55,8 @@ pub unsafe extern "C" fn _start() -> ! {
5355#[ link_section = ".code_signature" ]
5456#[ linkage = "weak" ]
5557#[ 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 } ;
6260
6361// This function is needed by the panic runtime. The symbol is named in
6462// 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 {
9492}
9593
9694pub fn abort_internal ( ) -> ! {
95+ let exit_time = Instant :: now ( ) ;
96+ const FLUSH_TIMEOUT : Duration = Duration :: from_millis ( 15 ) ;
97+
9798 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+ }
99108 vex_sdk:: vexSystemExitRequest ( ) ;
100109 }
101110
@@ -107,9 +116,7 @@ pub fn abort_internal() -> ! {
107116fn hash_time ( ) -> u64 {
108117 let mut hasher = DefaultHasher :: new ( ) ;
109118 // 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 ( ) } ;
113120 hasher. write_u64 ( time) ;
114121 hasher. finish ( )
115122}
0 commit comments