rtlp-lib

Crates.iortlp-lib
lib.rsrtlp-lib
version0.2.2
sourcesrc
created_at2022-07-15 06:35:39.301337
updated_at2023-02-18 22:10:42.446546
descriptionThis create provide structures to parse PCI TLPs
homepage
repositoryhttps://github.com/gotoco/rust_tlplib
max_upload_size
id626049
size34,659
mgrochowski (gotoco)

documentation

README

Rust TLP lib

This crate provide structs and functions to parse PCI TLP packets.

Example

use rtlp_lib::TlpPacket;
use rtlp_lib::TlpFmt;
use rtlp_lib::TlpType;
use rtlp_lib::new_msg_req;
use rtlp_lib::new_conf_req;
use rtlp_lib::new_mem_req;
use rtlp_lib::new_cmpl_req;

// Bytes for full TLP Packet
//               <------- DW1 -------->  <------- DW2 -------->  <------- DW3 -------->  <------- DW4 -------->
let bytes = vec![0x00, 0x00, 0x20, 0x01, 0x04, 0x00, 0x00, 0x01, 0x20, 0x01, 0xFF, 0x00, 0xC2, 0x81, 0xFF, 0x10];
let packet = TlpPacket::new(bytes);

let header = packet.get_header();
// TLP Type tells us what is this packet
let tlp_type = header.get_tlp_type().unwrap();
let tlp_format = packet.get_tlp_format();

// Get requester_id field from this TLP (TLP can be of different types)
let requester_id;
match (tlp_type) {
     TlpType::MemReadReq |
     TlpType::MemReadLockReq |
     TlpType::MemWriteReq |
     TlpType::IOReadReq |
     TlpType::IOWriteReq |
     TlpType::FetchAddAtomicOpReq |
     TlpType::SwapAtomicOpReq |
     TlpType::CompareSwapAtomicOpReq => requester_id = new_mem_req(packet.get_data(), &tlp_format).req_id(),
     TlpType::ConfType0ReadReq |
     TlpType::ConfType0WriteReq |
     TlpType::ConfType1ReadReq |
     TlpType::ConfType1WriteReq => requester_id = new_conf_req(packet.get_data(), &tlp_format).req_id(),
     TlpType::MsgReq |
     TlpType::MsgReqData => requester_id = new_msg_req(packet.get_data(), &tlp_format).req_id(),
     TlpType::Cpl |
     TlpType::CplData |
     TlpType::CplLocked |
     TlpType::CplDataLocked => requester_id = new_cmpl_req(packet.get_data(), &tlp_format).req_id(),
     TlpType::LocalTlpPrefix |
     TlpType::EndToEndTlpPrefix => println!("I need to implement This Type: {:?}", tlp_type),
}

println!("Requester ID from This TLP Packet: {}", requester_id);

Documentation

The documentation of the released version is available on doc.rs. To generate current documentation please run cargo new docs --lib

License

Licensed under:

  • The 3-Clause BSD License
Commit count: 11

cargo fmt