Maintain size assumptions held by openocd (and probably JLink tools)
* Buffer sizes are not prescribed exactly in Segger's implementation, but reference is made to "int" being 32 bits. * 24 bytes size assumption is hardcoded in openocd RTT implementation.
This commit is contained in:
parent
963a1a2bbf
commit
2a8dc7eb33
|
@ -38,6 +38,7 @@ register = "0.3.2"
|
||||||
cortex-a = "2.4"
|
cortex-a = "2.4"
|
||||||
#embedded-serial = "0.5.0"
|
#embedded-serial = "0.5.0"
|
||||||
# jlink_rtt = { version = "0.1.0", optional = true }
|
# jlink_rtt = { version = "0.1.0", optional = true }
|
||||||
|
static_assertions = { version = "0.3.1", features = ["nightly"] }
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
panic = "abort" # @todo try panic_rtt when feature jlink
|
panic = "abort" # @todo try panic_rtt when feature jlink
|
||||||
|
|
|
@ -15,7 +15,9 @@
|
||||||
/// The cost of logging data to RTT is the cost of formatting
|
/// The cost of logging data to RTT is the cost of formatting
|
||||||
/// and writing it to the ring buffer in memory.
|
/// and writing it to the ring buffer in memory.
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
use core::mem::size_of;
|
||||||
use core::ptr;
|
use core::ptr;
|
||||||
|
use static_assertions::const_assert_eq;
|
||||||
|
|
||||||
static mut UP_BUF: [u8; 1024] = [0u8; 1024];
|
static mut UP_BUF: [u8; 1024] = [0u8; 1024];
|
||||||
static mut DOWN_BUF: [u8; 16] = [0u8; 16];
|
static mut DOWN_BUF: [u8; 16] = [0u8; 16];
|
||||||
|
@ -25,8 +27,8 @@ static mut DOWN_BUF: [u8; 16] = [0u8; 16];
|
||||||
/// in the JLINK device.
|
/// in the JLINK device.
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
struct Buffer {
|
struct Buffer {
|
||||||
name: *const u8,
|
name: u32, //*const u8,
|
||||||
buf_start: *mut u8,
|
buf_start: u32, // *mut u8,
|
||||||
size_of_buffer: u32,
|
size_of_buffer: u32,
|
||||||
/// Position of next item to be written
|
/// Position of next item to be written
|
||||||
/// Volatile as the host may change it.
|
/// Volatile as the host may change it.
|
||||||
|
@ -35,15 +37,17 @@ struct Buffer {
|
||||||
/// Volatile as the host may change it.
|
/// Volatile as the host may change it.
|
||||||
read_offset: u32,
|
read_offset: u32,
|
||||||
/// In the segger library these flags control blocking
|
/// In the segger library these flags control blocking
|
||||||
/// or non-blocking behavior. Those functions are
|
/// or non-blocking behavior.
|
||||||
/// implemented differently here.
|
|
||||||
flags: u32,
|
flags: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Assumed by OpenOCD and probably JLink too...
|
||||||
|
const_assert_eq!(size_of::<Buffer>(), 24);
|
||||||
|
|
||||||
impl Buffer {
|
impl Buffer {
|
||||||
fn init(&mut self, buf: &mut [u8]) {
|
fn init(&mut self, buf: &mut [u8]) {
|
||||||
self.name = b"Terminal\0".as_ptr();
|
self.name = b"Terminal\0".as_ptr() as u32;
|
||||||
self.buf_start = buf.as_mut_ptr();
|
self.buf_start = buf.as_mut_ptr() as u32;
|
||||||
self.size_of_buffer = buf.len() as u32;
|
self.size_of_buffer = buf.len() as u32;
|
||||||
self.write_offset = 0;
|
self.write_offset = 0;
|
||||||
self.read_offset = 0;
|
self.read_offset = 0;
|
||||||
|
@ -104,7 +108,7 @@ impl Buffer {
|
||||||
unsafe {
|
unsafe {
|
||||||
ptr::copy(
|
ptr::copy(
|
||||||
buf.as_ptr(),
|
buf.as_ptr(),
|
||||||
self.buf_start.offset(write_off as isize),
|
(self.buf_start as *mut u8).offset(write_off as isize),
|
||||||
to_copy,
|
to_copy,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -142,6 +146,8 @@ pub struct ControlBlock {
|
||||||
down: Buffer,
|
down: Buffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const_assert_eq!(size_of::<ControlBlock>(), 24 + 24 + 24);
|
||||||
|
|
||||||
unsafe impl Sync for ControlBlock {}
|
unsafe impl Sync for ControlBlock {}
|
||||||
|
|
||||||
impl ControlBlock {
|
impl ControlBlock {
|
||||||
|
@ -172,16 +178,16 @@ pub static mut _SEGGER_RTT: ControlBlock = ControlBlock {
|
||||||
max_up_buffers: 1,
|
max_up_buffers: 1,
|
||||||
max_down_buffers: 1,
|
max_down_buffers: 1,
|
||||||
up: Buffer {
|
up: Buffer {
|
||||||
name: 0 as *const u8,
|
name: 0,
|
||||||
buf_start: 0 as *mut u8,
|
buf_start: 0,
|
||||||
read_offset: 0,
|
read_offset: 0,
|
||||||
write_offset: 0,
|
write_offset: 0,
|
||||||
flags: 0,
|
flags: 0,
|
||||||
size_of_buffer: 0,
|
size_of_buffer: 0,
|
||||||
},
|
},
|
||||||
down: Buffer {
|
down: Buffer {
|
||||||
name: 0 as *const u8,
|
name: 0,
|
||||||
buf_start: 0 as *mut u8,
|
buf_start: 0,
|
||||||
write_offset: 0,
|
write_offset: 0,
|
||||||
read_offset: 0,
|
read_offset: 0,
|
||||||
flags: 0,
|
flags: 0,
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
#![feature(range_contains)]
|
#![feature(range_contains)]
|
||||||
#![feature(try_from)]
|
#![feature(try_from)]
|
||||||
|
#![feature(underscore_const_names)]
|
||||||
#![doc(html_root_url = "https://docs.metta.systems/")]
|
#![doc(html_root_url = "https://docs.metta.systems/")]
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![allow(unused_assignments)]
|
#![allow(unused_assignments)]
|
||||||
|
|
Loading…
Reference in New Issue