Skip to content

Commit 9b7dc07

Browse files
committed
Also timestamp target time interrupt
1 parent 64a44b1 commit 9b7dc07

File tree

3 files changed

+58
-16
lines changed

3 files changed

+58
-16
lines changed

examples/rtic-timestamp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ mod app {
161161
// incorrect, but works well enough in low-activity systems (such as this example).
162162
let now = (cx.shared.ptp, cx.shared.scheduled_time).lock(|ptp, sched_time| {
163163
let now = ptp.get_time();
164-
#[cfg(not(any(feature = "stm32f107", feature = "stm32h7xx-hal")))]
164+
#[cfg(not(feature = "stm32f107"))]
165165
{
166166
let in_half_sec = now
167167
+ Timestamp::new(
@@ -212,7 +212,7 @@ mod app {
212212
.lock(|dma, tx_id, ptp, _sched_time| {
213213
dma.interrupt_handler();
214214

215-
#[cfg(not(any(feature = "stm32f107", feature = "stm32h7xx-hal")))]
215+
#[cfg(not(feature = "stm32f107"))]
216216
{
217217
if ptp.interrupt_handler() {
218218
if let Some(sched_time) = _sched_time.take() {

src/mac/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ impl EthernetMAC {
223223
parts.enable_promicious_mode();
224224
parts.disable_mmc_interrupts();
225225

226+
#[cfg(feature = "stm32h7xx-hal")]
227+
// On H7 parts, the target timestamp interrupt
228+
// is not broken, so we can enable it unconditionally.
229+
{
230+
parts.eth_mac.macier.modify(|_, w| w.tsie().set_bit());
231+
}
232+
226233
let mut me = Self {
227234
eth_mac: parts.eth_mac,
228235
};

src/ptp/mod.rs

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,34 @@ impl EthernetPTP {
343343
/// Setting and configuring target time interrupts on the STM32F107 does not
344344
/// make any sense: we can generate the interrupt, but it is impossible to
345345
/// clear the flag as the register required to do so does not exist.
346-
#[cfg(all(not(feature = "stm32f1xx-hal"), not(feature = "stm32h7xx-hal")))]
346+
#[cfg(all(not(feature = "stm32f1xx-hal")))]
347347
impl EthernetPTP {
348348
/// Configure the target time.
349349
fn set_target_time(&mut self, timestamp: Timestamp) {
350350
let (high, low) = (timestamp.seconds(), timestamp.subseconds_signed());
351-
self.eth_ptp
352-
.ptptthr
353-
.write(|w| unsafe { w.ttsh().bits(high) });
354-
self.eth_ptp
355-
.ptpttlr
356-
.write(|w| unsafe { w.ttsl().bits(low) });
351+
352+
#[cfg(feature = "f-series")]
353+
{
354+
self.eth_ptp
355+
.ptptthr
356+
.write(|w| unsafe { w.ttsh().bits(high) });
357+
self.eth_ptp
358+
.ptpttlr
359+
.write(|w| unsafe { w.ttsl().bits(low) });
360+
}
361+
362+
#[cfg(feature = "stm32h7xx-hal")]
363+
{
364+
// SAFETY: we only write to `ppsttsr` (PPS target time seconds register) and
365+
// `ppsttnr` (PPS target time subseconds register)
366+
let (ppsttsr, ppsttnr) = unsafe {
367+
let mac = self.mac();
368+
(&mac.macppsttsr, &mac.macppsttnr)
369+
};
370+
371+
ppsttsr.write(|w| unsafe { w.bits(high) });
372+
ppsttnr.write(|w| unsafe { w.bits(low) });
373+
}
357374
}
358375

359376
/// Configure the target time interrupt.
@@ -362,22 +379,40 @@ impl EthernetPTP {
362379
/// interrupt to detect (and clear) the correct status bits.
363380
pub fn configure_target_time_interrupt(&mut self, timestamp: Timestamp) {
364381
self.set_target_time(timestamp);
365-
self.eth_ptp.ptptscr.modify(|_, w| w.tsite().set_bit());
366-
EthernetMAC::unmask_timestamp_trigger_interrupt();
382+
#[cfg(feature = "f-series")]
383+
{
384+
self.eth_ptp.ptptscr.modify(|_, w| w.tsite().set_bit());
385+
EthernetMAC::unmask_timestamp_trigger_interrupt();
386+
}
367387
}
368388

369389
/// Returns a boolean indicating whether or not the interrupt
370390
/// was caused by a Timestamp trigger and clears the interrupt
371391
/// flag.
372392
pub fn interrupt_handler(&mut self) -> bool {
373-
let is_tsint = self.eth_ptp.ptptssr.read().tsttr().bit_is_set();
374-
if is_tsint {
375-
self.eth_ptp.ptptscr.modify(|_, w| w.tsite().clear_bit());
376-
EthernetMAC::mask_timestamp_trigger_interrupt();
377-
}
393+
#[cfg(feature = "f-series")]
394+
let is_tsint = {
395+
let is_tsint = self.eth_ptp.ptptssr.read().tsttr().bit_is_set();
396+
if is_tsint {
397+
self.eth_ptp.ptptscr.modify(|_, w| w.tsite().clear_bit());
398+
EthernetMAC::mask_timestamp_trigger_interrupt();
399+
}
400+
is_tsint
401+
};
402+
403+
#[cfg(feature = "stm32h7xx-hal")]
404+
let is_tsint = {
405+
// SAFETY: we only write to `mactssr` (Timestamp Status register)
406+
let mactssr = unsafe { &self.mac().mactssr };
407+
408+
// Reading the bit clears it, and deasserts the interrupt.
409+
mactssr.read().tstargt0().bit_is_set()
410+
};
411+
378412
is_tsint
379413
}
380414

415+
#[cfg(feature = "f-series")]
381416
/// Configure the PPS output frequency.
382417
///
383418
/// The PPS output frequency becomes `2 ^ pps_freq`. `pps_freq` is

0 commit comments

Comments
 (0)