aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxoviat <[email protected]>2023-07-15 09:57:09 -0500
committerxoviat <[email protected]>2023-07-15 09:57:09 -0500
commit975a780efe73b20d3ba63a116792b28f9a6edada (patch)
treefc14fbe912903a8c8f5419c4cc3367b043f98d39
parentc3774607a55141ce55d8ba462a2ebe18f80056de (diff)
stm32/eth: impl. poll interval
-rw-r--r--embassy-stm32/src/eth/generic_smi.rs25
-rw-r--r--examples/stm32f4/src/bin/eth.rs2
-rw-r--r--examples/stm32f7/src/bin/eth.rs2
-rw-r--r--examples/stm32h5/src/bin/eth.rs2
-rw-r--r--examples/stm32h7/src/bin/eth.rs2
-rw-r--r--examples/stm32h7/src/bin/eth_client.rs2
6 files changed, 29 insertions, 6 deletions
diff --git a/embassy-stm32/src/eth/generic_smi.rs b/embassy-stm32/src/eth/generic_smi.rs
index 5c7856437..22631c2d1 100644
--- a/embassy-stm32/src/eth/generic_smi.rs
+++ b/embassy-stm32/src/eth/generic_smi.rs
@@ -1,6 +1,10 @@
1//! Generic SMI Ethernet PHY 1//! Generic SMI Ethernet PHY
2 2
3#[cfg(feature = "time")]
4use embassy_time::{Duration, Timer};
3use futures::task::Context; 5use futures::task::Context;
6#[cfg(feature = "time")]
7use futures::FutureExt;
4 8
5use super::{StationManagement, PHY}; 9use super::{StationManagement, PHY};
6 10
@@ -38,7 +42,22 @@ mod phy_consts {
38use self::phy_consts::*; 42use self::phy_consts::*;
39 43
40/// Generic SMI Ethernet PHY 44/// Generic SMI Ethernet PHY
41pub struct GenericSMI; 45pub struct GenericSMI {
46 #[cfg(feature = "time")]
47 poll_interval: Duration,
48}
49
50impl GenericSMI {
51 #[cfg(feature = "time")]
52 pub fn new(poll_interval: Duration) -> Self {
53 Self { poll_interval }
54 }
55
56 #[cfg(not(feature = "time"))]
57 pub fn new() -> Self {
58 Self {}
59 }
60}
42 61
43unsafe impl PHY for GenericSMI { 62unsafe impl PHY for GenericSMI {
44 /// Reset PHY and wait for it to come out of reset. 63 /// Reset PHY and wait for it to come out of reset.
@@ -57,8 +76,12 @@ unsafe impl PHY for GenericSMI {
57 } 76 }
58 77
59 fn poll_link<S: StationManagement>(&mut self, sm: &mut S, cx: &mut Context) -> bool { 78 fn poll_link<S: StationManagement>(&mut self, sm: &mut S, cx: &mut Context) -> bool {
79 #[cfg(not(feature = "time"))]
60 cx.waker().wake_by_ref(); 80 cx.waker().wake_by_ref();
61 81
82 #[cfg(feature = "time")]
83 let _ = Timer::after(self.poll_interval).poll_unpin(cx);
84
62 let bsr = sm.smi_read(PHY_REG_BSR); 85 let bsr = sm.smi_read(PHY_REG_BSR);
63 86
64 // No link without autonegotiate 87 // No link without autonegotiate
diff --git a/examples/stm32f4/src/bin/eth.rs b/examples/stm32f4/src/bin/eth.rs
index c32d886d0..15390592a 100644
--- a/examples/stm32f4/src/bin/eth.rs
+++ b/examples/stm32f4/src/bin/eth.rs
@@ -56,7 +56,7 @@ async fn main(spawner: Spawner) -> ! {
56 p.PG13, 56 p.PG13,
57 p.PB13, 57 p.PB13,
58 p.PG11, 58 p.PG11,
59 GenericSMI, 59 GenericSMI::new(Duration::from_millis(500)),
60 mac_addr, 60 mac_addr,
61 0, 61 0,
62 ); 62 );
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs
index fde6a7576..c1baa5848 100644
--- a/examples/stm32f7/src/bin/eth.rs
+++ b/examples/stm32f7/src/bin/eth.rs
@@ -57,7 +57,7 @@ async fn main(spawner: Spawner) -> ! {
57 p.PG13, 57 p.PG13,
58 p.PB13, 58 p.PB13,
59 p.PG11, 59 p.PG11,
60 GenericSMI, 60 GenericSMI::new(Duration::from_millis(500)),
61 mac_addr, 61 mac_addr,
62 0, 62 0,
63 ); 63 );
diff --git a/examples/stm32h5/src/bin/eth.rs b/examples/stm32h5/src/bin/eth.rs
index 78c8282a6..3b33265ac 100644
--- a/examples/stm32h5/src/bin/eth.rs
+++ b/examples/stm32h5/src/bin/eth.rs
@@ -76,7 +76,7 @@ async fn main(spawner: Spawner) -> ! {
76 p.PG13, 76 p.PG13,
77 p.PB15, 77 p.PB15,
78 p.PG11, 78 p.PG11,
79 GenericSMI, 79 GenericSMI::new(Duration::from_millis(500)),
80 mac_addr, 80 mac_addr,
81 0, 81 0,
82 ); 82 );
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs
index 12d37f7a4..9203708ad 100644
--- a/examples/stm32h7/src/bin/eth.rs
+++ b/examples/stm32h7/src/bin/eth.rs
@@ -58,7 +58,7 @@ async fn main(spawner: Spawner) -> ! {
58 p.PG13, 58 p.PG13,
59 p.PB13, 59 p.PB13,
60 p.PG11, 60 p.PG11,
61 GenericSMI, 61 GenericSMI::new(Duration::from_millis(500)),
62 mac_addr, 62 mac_addr,
63 0, 63 0,
64 ); 64 );
diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs
index 6078fc3fe..8abc41095 100644
--- a/examples/stm32h7/src/bin/eth_client.rs
+++ b/examples/stm32h7/src/bin/eth_client.rs
@@ -59,7 +59,7 @@ async fn main(spawner: Spawner) -> ! {
59 p.PG13, 59 p.PG13,
60 p.PB13, 60 p.PB13,
61 p.PG11, 61 p.PG11,
62 GenericSMI, 62 GenericSMI::new(Duration::from_millis(500)),
63 mac_addr, 63 mac_addr,
64 0, 64 0,
65 ); 65 );