opentitanlib/test_utils/
lc.rs1use std::time::Duration;
6
7use anyhow::Result;
8use arrayvec::ArrayVec;
9
10use crate::app::TransportWrapper;
11use crate::dif::lc_ctrl::{DifLcCtrlState, LcCtrlReg, LcCtrlStatus};
12use crate::io::jtag::{JtagParams, JtagTap};
13use crate::test_utils::lc_transition::wait_for_status;
14
15pub fn read_lc_state(
16 transport: &TransportWrapper,
17 jtag_params: &JtagParams,
18 reset_delay: Duration,
19) -> Result<DifLcCtrlState> {
20 transport.pin_strapping("PINMUX_TAP_LC")?.apply()?;
21
22 transport.pin_strapping("ROM_BOOTSTRAP")?.apply()?;
25 transport.reset_target(reset_delay, true)?;
26 let mut jtag = jtag_params.create(transport)?.connect(JtagTap::LcTap)?;
27 wait_for_status(
29 &mut *jtag,
30 Duration::from_secs(1),
31 LcCtrlStatus::INITIALIZED,
32 )?;
33 let raw_lc_state = jtag.read_lc_ctrl_reg(&LcCtrlReg::LcState)?;
34 jtag.disconnect()?;
35 transport.pin_strapping("PINMUX_TAP_LC")?.remove()?;
36 transport.pin_strapping("ROM_BOOTSTRAP")?.remove()?;
37 DifLcCtrlState::from_redundant_encoding(raw_lc_state)
38}
39
40pub fn read_device_id(
41 transport: &TransportWrapper,
42 jtag_params: &JtagParams,
43 reset_delay: Duration,
44) -> Result<ArrayVec<u32, 8>> {
45 transport.pin_strapping("PINMUX_TAP_LC")?.apply()?;
46
47 transport.pin_strapping("ROM_BOOTSTRAP")?.apply()?;
50 transport.reset_target(reset_delay, true)?;
51 let mut jtag = jtag_params.create(transport)?.connect(JtagTap::LcTap)?;
52 wait_for_status(
54 &mut *jtag,
55 Duration::from_secs(1),
56 LcCtrlStatus::INITIALIZED,
57 )?;
58
59 let mut device_id = ArrayVec::<u32, 8>::new();
60 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId0)?);
61 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId1)?);
62 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId2)?);
63 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId3)?);
64 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId4)?);
65 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId5)?);
66 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId6)?);
67 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId7)?);
68
69 jtag.disconnect()?;
70 transport.pin_strapping("PINMUX_TAP_LC")?.remove()?;
71 transport.pin_strapping("ROM_BOOTSTRAP")?.remove()?;
72
73 Ok(device_id)
74}