Skip to content

Commit 55676f2

Browse files
committed
Generate timestamps if available
1 parent 1ddbda8 commit 55676f2

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

src/dap.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ where
101101
}
102102
// Bit 4: Atomic commands not supported
103103
// Bit 5: Test Domain Timer not supported
104+
if dependencies.timer_available() {
105+
caps.insert(Capabilities::TEST_DOMAIN_TIMER);
106+
}
104107
// Bit 6: SWO Streaming Trace optional
105108
if swo.support().streaming {
106109
caps.insert(Capabilities::SWO_STREAMING);
@@ -705,7 +708,8 @@ where
705708
let a = swd::DPRegister::try_from((transfer_req & (3 << 2)) >> 2).unwrap();
706709
let vmatch = (transfer_req & (1 << 4)) != 0;
707710
let mmask = (transfer_req & (1 << 5)) != 0;
708-
let _ts = (transfer_req & (1 << 7)) != 0;
711+
// Bit 7 (Time Stamp) cannot be combined with Bit 4 (Value Match) or Bit 5 (Match Mask).
712+
let timestamp = (transfer_req & (1 << 7)) != 0;
709713

710714
if rnw == swd::RnW::R {
711715
// Issue register read
@@ -720,11 +724,20 @@ where
720724
if swd.read_ap(wait_retries, a).check(resp.mut_at(2)).is_none() {
721725
break;
722726
}
727+
if timestamp {
728+
// Store Timestamp of next AP read
729+
resp.write_u32(swd.timestamp());
730+
}
723731
match swd.read_dp(wait_retries, rdbuff).check(resp.mut_at(2)) {
724732
Some(v) => v,
725733
None => break,
726734
}
727735
} else {
736+
if timestamp {
737+
// Store Timestamp
738+
resp.write_u32(swd.timestamp());
739+
}
740+
728741
// Reads from DP are not posted, so directly read the register.
729742
match swd.read_dp(wait_retries, a).check(resp.mut_at(2)) {
730743
Some(v) => v,
@@ -781,6 +794,11 @@ where
781794
{
782795
break;
783796
}
797+
798+
if timestamp {
799+
// Store Timestamp
800+
resp.write_u32(swd.timestamp());
801+
}
784802
}
785803
}
786804
}
@@ -848,7 +866,7 @@ where
848866
}
849867

850868
if post_read && request_value.timestamp {
851-
resp.write_u32(0); // TODO real timestamp
869+
resp.write_u32(jtag.timestamp());
852870
}
853871
}
854872

@@ -906,7 +924,7 @@ where
906924
}
907925

908926
if request_value.timestamp {
909-
resp.write_u32(0); // TODO real timestamp
927+
resp.write_u32(jtag.timestamp());
910928
}
911929
post_read = true;
912930
}
@@ -951,7 +969,7 @@ where
951969
}
952970

953971
if request_value.timestamp {
954-
resp.write_u32(0); // TODO real timestamp
972+
resp.write_u32(jtag.timestamp());
955973
}
956974
}
957975
}

src/jtag.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ pub trait Jtag<DEPS>: From<DEPS> {
186186
/// Returns whether JTAG is available or not.
187187
fn available(deps: &DEPS) -> bool;
188188

189+
/// Returns the current timestamp.
190+
fn timestamp(&self) -> u32 {
191+
0
192+
}
193+
189194
/// Returns a mutable reference to the JTAG interface configuration.
190195
fn config(&mut self) -> &mut Config;
191196

src/mock_device.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use crate::{jtag, swd, swj};
22

33
#[mockall::automock]
44
pub trait SwdJtagDevice {
5+
fn timer_available(&self) -> bool;
6+
57
// swj
68
fn high_impedance_mode(&mut self);
79
fn process_swj_clock(&mut self, max_frequency: u32) -> bool;
@@ -25,6 +27,10 @@ pub trait SwdJtagDevice {
2527
}
2628

2729
impl swj::Dependencies<Self, Self> for MockSwdJtagDevice {
30+
fn timer_available(&self) -> bool {
31+
SwdJtagDevice::timer_available(self)
32+
}
33+
2834
fn high_impedance_mode(&mut self) {
2935
SwdJtagDevice::high_impedance_mode(self)
3036
}

src/swd.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ pub trait Swd<DEPS>: From<DEPS> {
114114
/// Returns whether SWD is available or not.
115115
fn available(deps: &DEPS) -> bool;
116116

117+
/// Returns the current timestamp.
118+
fn timestamp(&self) -> u32 {
119+
0
120+
}
121+
117122
/// Returns a mutable reference to the SWD interface configuration.
118123
fn config(&mut self) -> &mut Config;
119124

src/swj.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ bitflags! {
2626
///
2727
/// User has to provide implementations of SWJ_{Pins, Sequence, Clock} commands
2828
pub trait Dependencies<SWD, JTAG>: From<SWD> + From<JTAG> {
29+
/// Returns true if the device can generate timestamps.
30+
fn timer_available(&self) -> bool {
31+
false
32+
}
33+
2934
/// Runner for SWJ_Pins commands.
3035
fn process_swj_pins(&mut self, output: Pins, mask: Pins, wait_us: u32) -> Pins;
3136

0 commit comments

Comments
 (0)