-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathhooks.rs
46 lines (36 loc) · 1.19 KB
/
hooks.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::base::*;
use crate::prelude::v1::String;
use crate::utils::*;
use core::cell::OnceCell;
type Callback = fn();
pub struct FreeRtosHooks {
on_assert: OnceCell<Callback>,
}
impl FreeRtosHooks {
pub fn set_on_assert(&self, c: Callback) -> Result<(), Callback> {
self.on_assert.set(c)
}
pub fn do_on_assert(&self) {
if let Some (cb) = self.on_assert.get() {
cb()
}
}
}
// SAFETY: must only be set before the scheduler starts and accessed after the
// kernel has asserted, both being single threaded situations.
unsafe impl Sync for FreeRtosHooks {}
pub static FREERTOS_HOOKS: FreeRtosHooks = FreeRtosHooks { on_assert: OnceCell::new() };
#[allow(unused_doc_comments)]
#[no_mangle]
pub extern "C" fn vAssertCalled(file_name_ptr: FreeRtosCharPtr, line: FreeRtosUBaseType) {
let file_name: String;
unsafe {
file_name = str_from_c_string(file_name_ptr).unwrap();
}
FREERTOS_HOOKS.do_on_assert();
// we can't print without std yet.
// TODO: make the macro work for debug UART? Or use Panic here?
// println!("ASSERT: {} {}", line, file_name);
panic!("FreeRTOS ASSERT: {}:{}", file_name, line);
//loop {}
}