Skip to content

Commit 8f6a13b

Browse files
hnezEmantor
authored andcommitted
dut_power: make GPIOs open drain
This improves EMI performance of the TAC a tiny bit, by not driving the pins on the flat flex using the somewhat noisy VCC_IO power supply. Signals on the flat flex are prone to coupling to one another due to missing GND reference plane. We _think_ we see this kind of noise on the IOBus lines, which are are present on the flat-flex, as well as on the external IOBus connector. Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
1 parent f3e9eda commit 8f6a13b

File tree

3 files changed

+73
-14
lines changed

3 files changed

+73
-14
lines changed

src/digital_io/gpio/demo_mode.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// with this program; if not, write to the Free Software Foundation, Inc.,
1616
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1717

18+
use std::ops::BitOr;
19+
1820
use anyhow::Result;
1921
use async_std::task::block_on;
2022

@@ -60,9 +62,30 @@ impl LineHandle {
6062
}
6163
}
6264

63-
#[allow(clippy::upper_case_acronyms)]
65+
#[allow(clippy::upper_case_acronyms, non_camel_case_types)]
66+
#[derive(Clone, Copy)]
6467
pub enum LineRequestFlags {
6568
OUTPUT,
69+
OPEN_DRAIN,
70+
}
71+
72+
impl BitOr for LineRequestFlags {
73+
type Output = Self;
74+
75+
fn bitor(self, rhs: Self) -> Self::Output {
76+
match (self, rhs) {
77+
(Self::OPEN_DRAIN, res) | (res, Self::OPEN_DRAIN) => res,
78+
_ => unimplemented!(),
79+
}
80+
}
81+
}
82+
83+
pub struct ChipDecoy;
84+
85+
impl ChipDecoy {
86+
pub fn label(&self) -> &'static str {
87+
"demo_mode"
88+
}
6689
}
6790

6891
pub struct FindDecoy {
@@ -79,6 +102,10 @@ impl FindDecoy {
79102

80103
Ok(line_handle)
81104
}
105+
106+
pub fn chip(&self) -> ChipDecoy {
107+
ChipDecoy
108+
}
82109
}
83110

84111
pub fn find_line(name: &str) -> Option<FindDecoy> {

src/digital_io/gpio/test.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1717

1818
use std::iter::Iterator;
19+
use std::ops::BitOr;
1920
use std::sync::atomic::{AtomicU8, Ordering};
2021
use std::thread::sleep;
2122
use std::time::Duration;
@@ -63,9 +64,30 @@ impl Iterator for LineEventHandle {
6364
}
6465
}
6566

66-
#[allow(clippy::upper_case_acronyms)]
67+
#[allow(clippy::upper_case_acronyms, non_camel_case_types)]
68+
#[derive(Clone, Copy)]
6769
pub enum LineRequestFlags {
6870
OUTPUT,
71+
OPEN_DRAIN,
72+
}
73+
74+
impl BitOr for LineRequestFlags {
75+
type Output = Self;
76+
77+
fn bitor(self, rhs: Self) -> Self::Output {
78+
match (self, rhs) {
79+
(Self::OPEN_DRAIN, res) | (res, Self::OPEN_DRAIN) => res,
80+
_ => unimplemented!(),
81+
}
82+
}
83+
}
84+
85+
pub struct ChipDecoy;
86+
87+
impl ChipDecoy {
88+
pub fn label(&self) -> &'static str {
89+
"test"
90+
}
6991
}
7092

7193
pub struct FindDecoy {
@@ -83,6 +105,10 @@ impl FindDecoy {
83105
})
84106
}
85107

108+
pub fn chip(&self) -> ChipDecoy {
109+
ChipDecoy
110+
}
111+
86112
pub fn stub_get(&self) -> u8 {
87113
self.val.load(Ordering::Relaxed)
88114
}

src/dut_power.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::sync::atomic::{AtomicU32, AtomicU8, Ordering};
1919
use std::thread;
2020
use std::time::{Duration, Instant};
2121

22-
use anyhow::Result;
22+
use anyhow::{anyhow, Result};
2323
use async_std::channel::bounded;
2424
use async_std::prelude::*;
2525
use async_std::sync::{Arc, Weak};
@@ -286,17 +286,23 @@ impl DutPwrThread {
286286
pwr_curr: AdcChannel,
287287
pwr_led: Arc<Topic<BlinkPattern>>,
288288
) -> Result<Self> {
289-
let pwr_line = find_line("DUT_PWR_EN").unwrap().request(
290-
LineRequestFlags::OUTPUT,
291-
1 - PWR_LINE_ASSERTED,
292-
"tacd",
293-
)?;
294-
295-
let discharge_line = find_line("DUT_PWR_DISCH").unwrap().request(
296-
LineRequestFlags::OUTPUT,
297-
DISCHARGE_LINE_ASSERTED,
298-
"tacd",
299-
)?;
289+
let pwr_line = find_line("DUT_PWR_EN")
290+
.ok_or_else(|| anyhow!("Could not find GPIO line DUT_PWR_EN"))?;
291+
let discharge_line = find_line("DUT_PWR_DISCH")
292+
.ok_or_else(|| anyhow!("Could not find GPIO line DUT_PWR_DISCH"))?;
293+
294+
// Early TACs have a i2c port expander on the power board.
295+
// This port expander is output only and can not be configured as
296+
// open drain.
297+
// The outputs on later TACs should however be driven open drain
298+
// for EMI reasons.
299+
let flags = match pwr_line.chip().label() {
300+
"pca9570" => LineRequestFlags::OUTPUT,
301+
_ => LineRequestFlags::OUTPUT | LineRequestFlags::OPEN_DRAIN,
302+
};
303+
304+
let pwr_line = pwr_line.request(flags, 1 - PWR_LINE_ASSERTED, "tacd")?;
305+
let discharge_line = discharge_line.request(flags, DISCHARGE_LINE_ASSERTED, "tacd")?;
300306

301307
// The realtime priority must be set up inside the tread, but
302308
// the operation may fail, in which case we want new() to fail

0 commit comments

Comments
 (0)