xvc_protocol/
protocol.rs

1use std::fmt::Display;
2
3/// The version of the protocol.
4/// A version always consists of a major and a minor part.
5#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
6pub struct Version {
7    major: usize,
8    minor: usize,
9}
10
11impl Version {
12    /// Version 1.0 of the protocol
13    pub const V1_0: Version = Version { major: 1, minor: 0 };
14
15    /// Returns the latest supported version
16    pub fn latest() -> Version {
17        Version::V1_0
18    }
19
20    /// The major part of the version
21    pub fn major(&self) -> usize {
22        self.major
23    }
24
25    /// The minor part of the version
26    pub fn minor(&self) -> usize {
27        self.minor
28    }
29}
30
31#[test]
32fn version_ordering() {
33    assert!(Version { major: 1, minor: 0 } < Version { major: 1, minor: 1 });
34    assert!(Version { major: 2, minor: 0 } > Version { major: 1, minor: 0 });
35}
36
37impl Default for Version {
38    fn default() -> Self {
39        Self::V1_0
40    }
41}
42
43impl Display for Version {
44    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45        write!(f, "{}.{}", self.major, self.minor)
46    }
47}
48
49/// A Message is transfered from the client to the server.
50/// For each message, the client is expected to send the message and wait for a response from the server.
51/// The server needs to process each message in the order received and promptly provide a response.
52/// For the XVC 1.0 protocol, only one connection is assumed.
53#[derive(Clone, Debug, Eq, PartialEq)]
54pub enum Message {
55    /// Requests info from the server. This is used to determine protocol capabilities of the server.
56    GetInfo,
57    /// Configures the TCK period. When sending JTAG vectors the TCK rate may need to be varied to accomodate cable and board signal integrity conditions.
58    /// This command is used by clients to adjust the TCK rate in order to slow down or speed up the shifting of JTAG vectors.
59    SetTck { period_ns: u32 },
60    /// Used to shift JTAG vectors in-and out of a device.
61    Shift {
62        /// represents the number of TCK clk toggles needed to shift the vectors out
63        num_bits: u32,
64        /// a byte sized vector with all the TMS data.
65        /// The vector is num_bits and rounds up to the nearest byte.
66        tms: Box<[u8]>,
67        /// a byte sized vector with all the TDI data.
68        /// The vector is num_bits and rounds up to the nearest byte.
69        tdi: Box<[u8]>,
70    },
71}
72
73/// Contains static information about the server capabilities that are transfered between
74/// client and server in the beginning.
75#[derive(Clone, Debug, Eq, PartialEq)]
76pub struct XvcInfo {
77    version: Version,
78    max_vector_len: u32,
79}
80
81impl XvcInfo {
82    /// Creates a new info object from version and the maximum receivable vector length.
83    pub fn new(version: Version, max_vector_len: u32) -> XvcInfo {
84        XvcInfo {
85            version,
86            max_vector_len,
87        }
88    }
89
90    /// The version of the protocol
91    pub fn version(&self) -> Version {
92        self.version
93    }
94
95    /// the max width of the vector that can be shifted into the server
96    pub fn max_vector_len(&self) -> u32 {
97        self.max_vector_len
98    }
99}
100
101impl Default for XvcInfo {
102    fn default() -> XvcInfo {
103        XvcInfo {
104            version: Version::default(),
105            max_vector_len: 10 * 1024 * 1024, // 10 MiB default
106        }
107    }
108}