firewire_dice_protocols/tcat/extension/
peak_section.rs

1// SPDX-License-Identifier: LGPL-3.0-or-later
2// Copyright (c) 2020 Takashi Sakamoto
3
4//! Peak section in protocol extension defined by TCAT for ASICs of DICE.
5//!
6//! The module includes structure, enumeration, and trait and its implementation for peak section
7//! in protocol extension defined by TCAT for ASICs of DICE.
8use super::{caps_section::*, router_entry::*, *};
9
10/// Parameters of meter detections in peak section.
11#[derive(Default, Debug, Clone, PartialEq, Eq)]
12pub struct PeakParams(pub RouterParams);
13
14impl<O: TcatExtensionOperation> TcatExtensionSectionParamsOperation<PeakParams> for O {
15    fn cache_extension_whole_params(
16        req: &FwReq,
17        node: &FwNode,
18        sections: &ExtensionSections,
19        caps: &ExtensionCaps,
20        params: &mut PeakParams,
21        timeout_ms: u32,
22    ) -> Result<(), Error> {
23        if !caps.general.peak_avail {
24            Err(Error::new(
25                ProtocolExtensionError::Peak,
26                "Peak is not available",
27            ))?
28        }
29
30        params
31            .0
32             .0
33            .resize_with(caps.router.maximum_entry_count as usize, Default::default);
34        let size = calculate_router_entries_size(params.0 .0.len());
35        let mut raw = vec![0u8; size];
36
37        Self::read_extension(req, node, &sections.peak, 0, &mut raw, timeout_ms)?;
38
39        deserialize_router_entries(&mut params.0 .0, &raw)
40            .map_err(|cause| Error::new(ProtocolExtensionError::Peak, &cause))
41    }
42}