Skip to content
Snippets Groups Projects
Commit 0cb4cf61 authored by Per's avatar Per
Browse files

itm packaging according to CMSIS

parent 4eb02a2c
Branches itm
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@ keywords = ["arm", "cortex-m", "register", "peripheral"]
license = "MIT OR Apache-2.0"
name = "cortex-m"
repository = "https://github.com/japaric/cortex-m"
version = "0.3.1"
version = "0.3.2"
[dependencies]
aligned = "0.1.1"
......
//! Instrumentation Trace Macrocell
use core::{fmt, mem, ptr, slice};
use core::{fmt, ptr, slice};
use aligned::Aligned;
......@@ -27,47 +27,52 @@ impl<'p> fmt::Write for Port<'p> {
/// Writes a `buffer` to the ITM `port`
pub fn write_all(port: &Stim, buffer: &[u8]) {
unsafe {
let mut len = buffer.len();
let mut ptr = buffer.as_ptr();
if len == 0 {
return;
}
// 0x01 OR 0x03
if ptr as usize % 2 == 1 {
for d in buffer {
while !port.is_fifo_ready() {}
port.write_u8(*ptr);
// 0x02 OR 0x04
ptr = ptr.offset(1);
len -= 1;
}
// 0x02
if ptr as usize % 4 == 2 {
if len > 1 {
// at least 2 bytes
while !port.is_fifo_ready() {}
port.write_u16(ptr::read(ptr as *const u16));
// 0x04
ptr = ptr.offset(2);
len -= 2;
} else {
if len == 1 {
// last byte
while !port.is_fifo_ready() {}
port.write_u8(*ptr);
}
return;
}
}
write_aligned(port, mem::transmute(slice::from_raw_parts(ptr, len)));
}
port.write_u32(*d as u32);
}
// unsafe {
// let mut len = buffer.len();
// let mut ptr = buffer.as_ptr();
//
// if len == 0 {
// return;
// }
//
//
// // 0x01 OR 0x03
// if ptr as usize % 2 == 1 {
// while !port.is_fifo_ready() {}
// port.write_u8(*ptr);
//
// // 0x02 OR 0x04
// ptr = ptr.offset(1);
// len -= 1;
// }
//
// // 0x02
// if ptr as usize % 4 == 2 {
// if len > 1 {
// // at least 2 bytes
// while !port.is_fifo_ready() {}
// port.write_u16(ptr::read(ptr as *const u16));
//
// // 0x04
// ptr = ptr.offset(2);
// len -= 2;
// } else {
// if len == 1 {
// // last byte
// while !port.is_fifo_ready() {}
// port.write_u8(*ptr);
// }
//
// return;
// }
// }
//
// write_aligned(port, mem::transmute(slice::from_raw_parts(ptr, len)));
// }
}
/// Writes a 4-byte aligned `buffer` to the ITM `port`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment