Skip to content

Commit 061496a

Browse files
committed
Final touches
1 parent 2bb0de8 commit 061496a

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/ptp/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ impl EthernetPTP {
225225
pub fn interrupt_handler(&mut self) -> bool {
226226
let is_tsint = self.eth_ptp.ptptssr.read().tsttr().bit_is_set();
227227
if is_tsint {
228+
self.eth_ptp.ptptscr.modify(|_, w| w.tsite().clear_bit());
228229
EthernetMAC::mask_timestamp_trigger_interrupt();
229230
}
230231
is_tsint

src/ptp/subseconds.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ impl Subseconds {
2828
///
2929
/// To obtain that representation in nanoseconds, see [`Subseconds::nanos`].
3030
///
31-
/// To approximate a [`Subseconds`] from nanoseconds, see [`Subseconds::new_from_nanos`]
31+
/// To approximate a [`Subseconds`] from nanoseconds, see [`Subseconds::new_from_nanos`].
32+
///
33+
/// Returns `None` if `value > SUBSECONDS_PER_SECOND`. (See [`SUBSECONDS_PER_SECOND`]).
3234
pub const fn new(value: u32) -> Option<Self> {
3335
if value > SUBSECONDS_PER_SECOND as u32 {
3436
None
@@ -45,12 +47,14 @@ impl Subseconds {
4547
/// To obtain that representation in nanoseconds, see [`Subseconds::nanos`].
4648
///
4749
/// To approximate a [`Subseconds`] from nanoseconds, see [`Subseconds::new_from_nanos`]
48-
pub const fn new_unchecked(value: u32) -> Self {
50+
pub(crate) const fn new_unchecked(value: u32) -> Self {
4951
Self(value)
5052
}
5153

5254
/// Create a new [`Subseconds`] from the given amount of nanoseconds,
53-
/// using a round-to-closest method.
55+
/// using a round-to-nearest method.
56+
///
57+
/// Returns [`None`] if `nanos >= NANOS_PER_SECOND`. (See [`NANOS_PER_SECOND`])
5458
pub const fn new_from_nanos(nanos: u32) -> Option<Self> {
5559
if nanos >= NANOS_PER_SECOND as u32 {
5660
return None;
@@ -61,7 +65,7 @@ impl Subseconds {
6165
Some(Subseconds::new_unchecked(subseconds as u32))
6266
}
6367

64-
/// Convert this [`Subseconds`] to nanoseconds, using a round-to-closest method.
68+
/// Convert this [`Subseconds`] to nanoseconds, using a round-to-nearest method.
6569
pub const fn nanos(&self) -> u32 {
6670
let nanos = ((self.0 as u64 * NS_PER_S) + (SUBS_PER_S / 2)) / SUBS_PER_S;
6771

@@ -118,7 +122,7 @@ mod test {
118122

119123
use super::*;
120124

121-
// Assert that values produced by [`Subseconds::nearest_increment`] for all
125+
// Assert that values produced by [`Subseconds::nearest_increment`] for some
122126
// valid frequencies are within the correct span for `stssi`
123127
#[test]
124128
fn correct_subsecond_increment() {
@@ -128,6 +132,17 @@ mod test {
128132
}
129133
}
130134

135+
#[test]
136+
fn from_nanos() {
137+
for i in [0, 1, 2, 3, NANOS_PER_SECOND - 1] {
138+
let subseconds = Subseconds::new_from_nanos(i).unwrap();
139+
assert!(subseconds.raw() < SUBSECONDS_PER_SECOND);
140+
}
141+
142+
assert!(Subseconds::new_from_nanos(NANOS_PER_SECOND).is_none());
143+
assert!(Subseconds::new_from_nanos(u32::MAX).is_none());
144+
}
145+
131146
#[test]
132147
fn subsecond_math() {
133148
let one = Subseconds::new(1).unwrap();

src/ptp/timestamp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ impl Timestamp {
7878
let mut subseconds = self.subseconds().raw();
7979

8080
if self.0.is_negative() {
81-
subseconds |= 0x8000_0000;
81+
subseconds |= Self::SIGN_BIT;
8282
}
8383

8484
subseconds

0 commit comments

Comments
 (0)