Skip to content

Commit 8273c14

Browse files
committed
Added init function.
1 parent 4e4d483 commit 8273c14

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
//! extern crate alloc_cortex_m;
88
//! extern crate collections;
99
//!
10-
//! use alloc_cortex_m::HEAP;
10+
//! use alloc_cortex_m::init as alloc_init;
1111
//! use collections::Vec;
1212
//!
1313
//! #[no_mangle]
1414
//! pub fn main() -> ! {
1515
//! // Initialize the heap BEFORE you use the allocator
16-
//! unsafe { HEAP.init(0x2000_0000, 1024) }
16+
//! unsafe { alloc_init(0x2000_0000, 1024) }
1717
//!
1818
//! let mut xs = Vec::new();
1919
//! xs.push(1);
@@ -66,6 +66,14 @@ impl Heap {
6666
}
6767
}
6868

69+
/// Init function
70+
pub unsafe fn alloc_init(start_addr: *mut usize, end_addr: *mut usize) {
71+
let start = start_addr as usize;
72+
let end = end_addr as usize;
73+
let size = (end - start) - 1;
74+
HEAP.lock(|heap| heap.init(start, size));
75+
}
76+
6977
// Rust allocator interface
7078

7179
#[doc(hidden)]

0 commit comments

Comments
 (0)