Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Android/hardware/hardware/nxp/nxp_mcu_loader/src/   (Android Betriebssystem Version 17©)  Datei vom 26.5.2026 mit Größe 1 kB image not shown  

Quelle  transport.rs

  Sprache: Rust
 

use crate::protocol::START_BYTE;
use downcast_rs::{impl_downcast, Downcast};
use std::io;
use std::time::{Duration, Instant};

/// Represents the transport by which a target device can be communicated with,
/// e.g. SPI, I2C, UART.
pub trait Transport: Downcast {
    /// Reads data from the target device.
    fn read(&mut self, buf: &mut [u8], deadline: Instant) -> io::Result<()>;

    /// Read the start of a packet.
    ///
    /// Performs any polling as necessary.
    ///
    /// The default implementation defers to read().
    ///
    /// # Arguments
    ///
    /// * `buf` - The packet buffer. Must be 2 as it includes
    ///   the start byte and packet type.
    fn read_start(&mut self, buf: &mut [u8], deadline: Instant) -> io::Result<()> {
        assert_eq!(buf.len(), 2);

        self.read(buf, deadline)?;

        let start_byte = buf[0];
        if start_byte != START_BYTE {
            return Err(io::Error::new(
                io::ErrorKind::Other,
                format!("Invalid start byte: 0x{start_byte:X}"),
            ));
        }

        Ok(())
    }

    /// Writes data to the target device.
    fn write(&mut self, buf: &[u8], deadline: Instant) -> io::Result<()>;

    fn set_irq_line(&mut self, line: &gpio_cdev::Line) -> io::Result<()> {
        let _ = line;
        Err(io::Error::new(
            io::ErrorKind::Other,
            "irq line not supported",
        ))
    }
}
impl_downcast!(Transport);

pub fn to_timeout(deadline: Instant) -> io::Result<Duration> {
    deadline
        .checked_duration_since(Instant::now())
        .ok_or_else(|| io::Error::new(io::ErrorKind::TimedOut, "Timed out"))
}

Messung V0.5 in Prozent
C=94 H=94 G=93

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet am  2026-06-28) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.