Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn write_embassy_task_ready(task_id: u16, executor_id: u3) {
buffer[1..3].copy_from_slice(&task_id.to_le_bytes());

// Write to global buffer
let timestamp = TimeDelta::from_now();
let timestamp = critical_section::with(|cs| TimeDelta::from_now(cs));
let pos = timestamp.write_bytes_mut(&mut buffer[3..]);
unsafe { write_tracing_data(&buffer[..3 + pos]) };
}
Expand All @@ -36,7 +36,7 @@ pub fn write_embassy_task_exec_begin(task_id: u16, executor_id: u3) {
buffer[1..3].copy_from_slice(&task_id.to_le_bytes());

// Write to global buffer
let timestamp = TimeDelta::from_now();
let timestamp = critical_section::with(|cs| TimeDelta::from_now(cs));
let pos = timestamp.write_bytes_mut(&mut buffer[3..]);
unsafe { write_tracing_data(&buffer[..3 + pos]) };
}
Expand All @@ -48,7 +48,7 @@ pub fn write_embassy_task_exec_end(executor_id: u3) {
buffer[0] = (event_ids::EMBASSY_TASK_EXEC_END << 3) | executor_id.as_u8();

// Write to global buffer
let timestamp = TimeDelta::from_now();
let timestamp = critical_section::with(|cs| TimeDelta::from_now(cs));
let pos = timestamp.write_bytes_mut(&mut buffer[1..]);
unsafe { write_tracing_data(&buffer[..1 + pos]) };
}
Expand All @@ -60,7 +60,7 @@ pub fn write_embassy_executor_poll_start(executor_id: u3) {
buffer[0] = (event_ids::EMBASSY_EXECUTOR_POLL_START << 3) | executor_id.as_u8();

// Write to global buffer
let timestamp = TimeDelta::from_now();
let timestamp = critical_section::with(|cs| TimeDelta::from_now(cs));
let pos = timestamp.write_bytes_mut(&mut buffer[1..]);
unsafe { write_tracing_data(&buffer[..1 + pos]) };
}
Expand All @@ -72,7 +72,7 @@ pub fn write_embassy_executor_idle(executor_id: u3) {
buffer[0] = (event_ids::EMBASSY_EXECUTOR_IDLE << 3) | executor_id.as_u8();

// Write to global buffer
let timestamp = TimeDelta::from_now();
let timestamp = critical_section::with(|cs| TimeDelta::from_now(cs));
let pos = timestamp.write_bytes_mut(&mut buffer[1..]);
unsafe { write_tracing_data(&buffer[..1 + pos]) };
}
Expand All @@ -85,7 +85,7 @@ pub fn write_monitor_start(monitor_id: u8) {
buffer[1] = monitor_id;

// Write to global buffer
let timestamp = TimeDelta::from_now();
let timestamp = critical_section::with(|cs| TimeDelta::from_now(cs));
let pos = timestamp.write_bytes_mut(&mut buffer[2..]);
unsafe { write_tracing_data(&buffer[..2 + pos]) };
}
Expand All @@ -97,7 +97,7 @@ pub fn write_monitor_end() {
buffer[0] = event_ids::MONITOR_END << 3;

// Write to global buffer
let timestamp = TimeDelta::from_now();
let timestamp = critical_section::with(|cs| TimeDelta::from_now(cs));
let pos = timestamp.write_bytes_mut(&mut buffer[1..]);
unsafe { write_tracing_data(&buffer[..1 + pos]) };
}
Expand All @@ -120,7 +120,7 @@ pub fn write_defmt_data(data: &[u8]) {
let next_pos = 2 + chunk_size;

// Write to global buffer with timestamp
let timestamp = TimeDelta::from_now();
let timestamp = critical_section::with(|cs| TimeDelta::from_now(cs));
let pos = timestamp.write_bytes_mut(&mut buffer[next_pos..]);
unsafe { write_tracing_data(&buffer[..next_pos + pos]) };

Expand Down
5 changes: 3 additions & 2 deletions rustmeter-beacon/rustmeter-beacon-core/src/time_delta.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(unused)] // in test mode, things might be unused
use arbitrary_int::traits::Integer;
use critical_section::CriticalSection;

use crate::{
buffer::{BufferReader, BufferWriter},
Expand Down Expand Up @@ -85,7 +86,7 @@ impl TimeDelta {
/// This has to be called inside a critical section
#[inline(always)]
#[cfg(not(test))]
pub fn from_now() -> Self {
pub fn from_now<'cs>(_cs: CriticalSection<'cs>) -> Self {
let core_id = unsafe { crate::get_current_core_id() as usize };
if !CORE_CLOCK_REFERENCED[core_id].load(portable_atomic::Ordering::Relaxed) {
do_core_clock_referencing(core_id);
Expand All @@ -107,7 +108,7 @@ impl TimeDelta {
}

#[cfg(test)]
pub fn from_now() -> Self {
pub fn from_now<'cs>(_cs: CriticalSection<'cs>) -> Self {
let now = unsafe { get_tracing_raw_ticks() };
TimeDelta { delta: now }
}
Expand Down
2 changes: 1 addition & 1 deletion rustmeter-beacon/rustmeter-beacon-core/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn write_tracing_event(event: EventPayload) {
critical_section::with(|cs| {
let _lock = TRACE_WRITING.borrow(cs);

let timestamp = TimeDelta::from_now();
let timestamp = TimeDelta::from_now(cs);

// Write event data
let mut buffer = BufferWriter::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ fn write_tracing_data(data: &[u8]) {
let idx = if core_id > 1 { 0 } else { core_id as usize };

// Write to Buffer
cortex_m::interrupt::free(|_| {
critical_section::with(|cs| {
// Check for dropped events
let dropped_events = unsafe { DROPPED_EVENTS_COUNTER[idx] };
if dropped_events > 0 {
// Create dropped events event
let mut buffer = [0u8; 12];
buffer[0] = event_ids::DATA_LOSS_EVENT << 3;
buffer[1..5].copy_from_slice(&dropped_events.to_le_bytes());
let timestamp = TimeDelta::from_now();
let timestamp = TimeDelta::from_now(cs);
let pos = timestamp.write_bytes_mut(&mut buffer[5..]);

// Try to write dropped events data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn write_tracing_data(data: &[u8]) {
let mut buffer = [0u8; 12];
buffer[0] = event_ids::DATA_LOSS_EVENT << 3;
buffer[1..5].copy_from_slice(&dropped_events.to_le_bytes());
let timestamp = TimeDelta::from_now();
let timestamp = critical_section::with(|cs| TimeDelta::from_now(cs));
let pos = timestamp.write_bytes_mut(&mut buffer[5..]);

// Try to write dropped events data
Expand Down