opentitanlib/test_utils/
lc.rs1use std::time::Duration;
6
7use anyhow::Result;
8use arrayvec::ArrayVec;
9
10use ot_hal::dif::lc_ctrl::{DifLcCtrlState, LcCtrlReg, LcCtrlStatus};
11
12use crate::app::{TransportWrapper, UartRx};
13use crate::io::jtag::{JtagParams, JtagTap};
14use crate::test_utils::lc_transition::wait_for_status;
15
16pub fn read_lc_state(
17 transport: &TransportWrapper,
18 jtag_params: &JtagParams,
19) -> Result<DifLcCtrlState> {
20 transport.pin_strapping("PINMUX_TAP_LC")?.apply()?;
21
22 transport.pin_strapping("ROM_BOOTSTRAP")?.apply()?;
25 transport.reset(UartRx::Clear)?;
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) -> Result<ArrayVec<u32, 8>> {
44 transport.pin_strapping("PINMUX_TAP_LC")?.apply()?;
45
46 transport.pin_strapping("ROM_BOOTSTRAP")?.apply()?;
49 transport.reset(UartRx::Clear)?;
50 let mut jtag = jtag_params.create(transport)?.connect(JtagTap::LcTap)?;
51 wait_for_status(
53 &mut *jtag,
54 Duration::from_secs(1),
55 LcCtrlStatus::INITIALIZED,
56 )?;
57
58 let mut device_id = ArrayVec::<u32, 8>::new();
59 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId0)?);
60 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId1)?);
61 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId2)?);
62 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId3)?);
63 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId4)?);
64 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId5)?);
65 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId6)?);
66 device_id.push(jtag.read_lc_ctrl_reg(&LcCtrlReg::DeviceId7)?);
67
68 jtag.disconnect()?;
69 transport.pin_strapping("PINMUX_TAP_LC")?.remove()?;
70 transport.pin_strapping("ROM_BOOTSTRAP")?.remove()?;
71
72 Ok(device_id)
73}