Commit 0cb4cf61 authored by Per's avatar Per

itm packaging according to CMSIS

parent 4eb02a2c
......@@ -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 {
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)));
for d in buffer {
while !port.is_fifo_ready() {}
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`
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment