dedicated folder for generating bindings
This commit is contained in:
parent
a29ff4e041
commit
564a8f498d
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
/target
|
/target
|
||||||
|
/libcsp
|
||||||
|
9
Cargo.lock
generated
9
Cargo.lock
generated
@ -142,9 +142,18 @@ name = "libcsp-rust"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
|
"bitflags",
|
||||||
"libcsp-cargo-build",
|
"libcsp-cargo-build",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libcsp-rust-examples"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"libcsp-cargo-build",
|
||||||
|
"libcsp-rust",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libloading"
|
name = "libloading"
|
||||||
version = "0.8.3"
|
version = "0.8.3"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
|
|
||||||
members = [
|
members = [
|
||||||
"libcsp-cargo-build", "libcsp-rust",
|
"libcsp-cargo-build", "libcsp-rust", "examples"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
10
examples/Cargo.toml
Normal file
10
examples/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "libcsp-rust-examples"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
libcsp-rust = { path = "../libcsp-rust" }
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
libcsp-cargo-build = { path = "../libcsp-cargo-build" }
|
32
examples/build.rs
Normal file
32
examples/build.rs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
use std::{env, path::PathBuf};
|
||||||
|
|
||||||
|
use libcsp_cargo_build::Builder;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
|
// Pass some important build script environment variables to the binary/library.
|
||||||
|
// Remove this at a later stage, this belongs in a concrete example app.
|
||||||
|
/*
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-env=TARGET={}",
|
||||||
|
std::env::var("TARGET").unwrap()
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-env=OUT_DIR={}",
|
||||||
|
std::env::var("OUT_DIR").unwrap()
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-env=OPT_LEVEL={}",
|
||||||
|
std::env::var("OPT_LEVEL").unwrap()
|
||||||
|
);
|
||||||
|
println!("cargo:rustc-env=HOST={}", std::env::var("HOST").unwrap());
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Tell cargo to tell rustc to link our `csp` library. Cargo will
|
||||||
|
// automatically know it must look for a `libcsp.a` file.
|
||||||
|
// println!("cargo:rustc-link-lib=csp");
|
||||||
|
// println!("cargo:rustc-link-search={}/csp", project_dir);
|
||||||
|
|
||||||
|
let mut csp_builder = Builder::new();
|
||||||
|
csp_builder.compile();
|
||||||
|
}
|
12
examples/src/main.rs
Normal file
12
examples/src/main.rs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
use std::ffi::CString;
|
||||||
|
|
||||||
|
use libcsp_rust::{csp_init, csp_print_func};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
unsafe {
|
||||||
|
csp_init();
|
||||||
|
let c_str = CString::new("hello world\n").unwrap();
|
||||||
|
csp_print_func(c_str.as_ptr());
|
||||||
|
}
|
||||||
|
}
|
2
lib/.gitignore
vendored
Normal file
2
lib/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/libcsp
|
||||||
|
/cfg/csp/autoconfig.h
|
2418
lib/bindings.rs
Normal file
2418
lib/bindings.rs
Normal file
File diff suppressed because it is too large
Load Diff
2418
lib/bindings.sh
Normal file
2418
lib/bindings.sh
Normal file
File diff suppressed because it is too large
Load Diff
2
lib/gen-bindings.sh
Executable file
2
lib/gen-bindings.sh
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
bindgen --use-core wrapper.h -- "-I./libcsp/include" "-I./cfg" > bindings.rs
|
@ -1,3 +1 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "csp/csp.h"
|
#include "csp/csp.h"
|
@ -56,7 +56,11 @@ impl Builder {
|
|||||||
.file("libcsp/src/csp_promisc.c")
|
.file("libcsp/src/csp_promisc.c")
|
||||||
.file("libcsp/src/csp_qfifo.c")
|
.file("libcsp/src/csp_qfifo.c")
|
||||||
.file("libcsp/src/csp_port.c")
|
.file("libcsp/src/csp_port.c")
|
||||||
.file("libcsp/src/csp_route.c");
|
.file("libcsp/src/csp_route.c")
|
||||||
|
.file("libcsp/src/interfaces/csp_if_lo.c")
|
||||||
|
.file("libcsp/src/interfaces/csp_if_kiss.c")
|
||||||
|
.file("libcsp/src/interfaces/csp_if_tun.c")
|
||||||
|
.file("libcsp/src/interfaces/csp_if_udp.c");
|
||||||
if self.opts.rdp {
|
if self.opts.rdp {
|
||||||
self.build.file("libcsp/src/csp_rdp.c");
|
self.build.file("libcsp/src/csp_rdp.c");
|
||||||
self.build.file("libcsp/src/csp_rdp_queue.c");
|
self.build.file("libcsp/src/csp_rdp_queue.c");
|
||||||
|
@ -5,6 +5,7 @@ edition = "2021"
|
|||||||
links = "csp"
|
links = "csp"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
bitflags = "2"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
bindgen = "0.69"
|
bindgen = "0.69"
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
use std::{env, path::PathBuf};
|
use std::{env, path::PathBuf};
|
||||||
|
|
||||||
use libcsp_cargo_build::Builder;
|
|
||||||
|
|
||||||
const GENERATE_BINDINGS_IN_PROJ_ROOT: bool = true;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
// Pass some important build script environment variables to the binary/library.
|
// Pass some important build script environment variables to the binary/library.
|
||||||
@ -27,36 +23,38 @@ fn main() {
|
|||||||
// Tell cargo to tell rustc to link our `csp` library. Cargo will
|
// Tell cargo to tell rustc to link our `csp` library. Cargo will
|
||||||
// automatically know it must look for a `libcsp.a` file.
|
// automatically know it must look for a `libcsp.a` file.
|
||||||
println!("cargo:rustc-link-lib=csp");
|
println!("cargo:rustc-link-lib=csp");
|
||||||
println!("cargo:rustc-link-lib=csp");
|
|
||||||
// println!("cargo:rustc-link-search={}/csp", project_dir);
|
// println!("cargo:rustc-link-search={}/csp", project_dir);
|
||||||
|
|
||||||
let mut csp_builder = Builder::new();
|
// let mut csp_builder = Builder::new();
|
||||||
csp_builder.compile();
|
// csp_builder.compile();
|
||||||
|
|
||||||
// The bindgen::Builder is the main entry point
|
// The bindgen::Builder is the main entry point
|
||||||
// to bindgen, and lets you build up options for
|
// to bindgen, and lets you build up options for
|
||||||
// the resulting bindings.
|
// the resulting bindings.
|
||||||
let bindings = bindgen::Builder::default()
|
|
||||||
// The input header we would like to generate
|
|
||||||
// bindings for.
|
|
||||||
.clang_arg("-Ilibcsp/include")
|
|
||||||
.clang_arg("-Icfg")
|
|
||||||
.header("wrapper.h")
|
|
||||||
// Tell cargo to invalidate the built crate whenever any of the
|
|
||||||
// included header files changed.
|
|
||||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
|
||||||
// Finish the builder and generate the bindings.
|
|
||||||
.generate()
|
|
||||||
// Unwrap the Result and panic on failure.
|
|
||||||
.expect("Unable to generate bindings");
|
|
||||||
|
|
||||||
|
|
||||||
// Write the bindings to the $OUT_DIR/bindings.rs file.
|
// Write the bindings to the $OUT_DIR/bindings.rs file.
|
||||||
|
/*
|
||||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");
|
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");
|
||||||
bindings
|
bindings
|
||||||
.write_to_file(out_path)
|
.write_to_file(out_path)
|
||||||
.expect("Couldn't write bindings!");
|
.expect("Couldn't write bindings!");
|
||||||
if GENERATE_BINDINGS_IN_PROJ_ROOT {
|
*/
|
||||||
|
if let Ok(_str) = env::var("GEN_BINDINGS") {
|
||||||
|
let bindings = bindgen::Builder::default()
|
||||||
|
// The input header we would like to generate
|
||||||
|
// bindings for.
|
||||||
|
.clang_arg("-Ilibcsp/include")
|
||||||
|
.clang_arg("-Icfg")
|
||||||
|
.header("wrapper.h")
|
||||||
|
.use_core()
|
||||||
|
// Tell cargo to invalidate the built crate whenever any of the
|
||||||
|
// included header files changed.
|
||||||
|
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
||||||
|
// Finish the builder and generate the bindings.
|
||||||
|
.generate()
|
||||||
|
// Unwrap the Result and panic on failure.
|
||||||
|
.expect("Unable to generate bindings");
|
||||||
|
|
||||||
let local_path = PathBuf::from("./bindings.rs");
|
let local_path = PathBuf::from("./bindings.rs");
|
||||||
bindings
|
bindings
|
||||||
.write_to_file(local_path)
|
.write_to_file(local_path)
|
||||||
|
0
libcsp-rust/csp_types.h
Normal file
0
libcsp-rust/csp_types.h
Normal file
@ -1 +0,0 @@
|
|||||||
Subproject commit 447cc38f2106a15290358dc8c128ad553a415568
|
|
@ -1,15 +1,704 @@
|
|||||||
#![allow(non_upper_case_globals)]
|
#![allow(non_upper_case_globals)]
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
#![allow(non_snake_case)]
|
#![allow(non_snake_case)]
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
// include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
#[cfg(feature = "alloc")]
|
||||||
extern "C" {
|
extern crate alloc;
|
||||||
pub fn csp_print_func(fmt: *const ::std::os::raw::c_char, ...);
|
#[cfg(any(feature = "std", test))]
|
||||||
#[doc = " Initialize CSP.\n This will configure basic structures."]
|
extern crate std;
|
||||||
pub fn csp_init();
|
|
||||||
|
use bitflags::bitflags;
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||||
|
pub enum ReservedPorts {
|
||||||
|
Cmp = 0,
|
||||||
|
Ping = 1,
|
||||||
|
Ps = 2,
|
||||||
|
Memfree = 3,
|
||||||
|
Reboot = 4,
|
||||||
|
BufFree = 5,
|
||||||
|
Uptime = 6,
|
||||||
}
|
}
|
||||||
|
|
||||||
// include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||||
// extern "C" {
|
#[repr(i32)]
|
||||||
// pub fn csp_print_func(fmt: *const ::std::os::raw::c_char, ...);
|
pub enum CspError {
|
||||||
//}
|
None = 0,
|
||||||
|
NoMem = -1,
|
||||||
|
Inval = -2,
|
||||||
|
TimedOut = -3,
|
||||||
|
Used = -4,
|
||||||
|
NotSup = -5,
|
||||||
|
Busy = -6,
|
||||||
|
Already = -7,
|
||||||
|
Reset = -8,
|
||||||
|
NoBufs = -9,
|
||||||
|
Tx = -10,
|
||||||
|
Driver = -11,
|
||||||
|
Again = -12,
|
||||||
|
NoSys = -38,
|
||||||
|
Hmac = -100,
|
||||||
|
Crc32 = -102,
|
||||||
|
Sfp = -103,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Listen on all ports, primarily used with [csp_bind]
|
||||||
|
pub const CSP_ANY: u32 = 255;
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct csp_timestamp_t {
|
||||||
|
pub tv_sec: u32,
|
||||||
|
pub tv_nsec: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
pub struct SocketFlags: u32 {
|
||||||
|
const NONE = 0x0000;
|
||||||
|
/// RDP required.
|
||||||
|
const RDPREQ = 0x0001;
|
||||||
|
/// RDP prohibited.
|
||||||
|
const RDPPROHIB = 0x0002;
|
||||||
|
/// HMAC required
|
||||||
|
const HMACREQ = 0x0004;
|
||||||
|
/// HMAC prohibited.
|
||||||
|
const HMACPROHIB = 0x0008;
|
||||||
|
/// CRC32 required.
|
||||||
|
const CRC32REQ = 0x0040;
|
||||||
|
const CRC32PROHIB = 0x0080;
|
||||||
|
const CONN_LESS = 0x0100;
|
||||||
|
/// Copy opts from incoming packets. Only applies to [csp_sendto_reply]
|
||||||
|
const SAME = 0x8000;
|
||||||
|
|
||||||
|
// The source may set any bits
|
||||||
|
const _ = !0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
pub struct ConnectOpts: u32 {
|
||||||
|
const NONE = SocketFlags::NONE.bits();
|
||||||
|
|
||||||
|
const RDP = SocketFlags::RDPREQ.bits();
|
||||||
|
const NORDP = SocketFlags::RDPPROHIB.bits();
|
||||||
|
const HMAC = SocketFlags::HMACREQ.bits();
|
||||||
|
const NOHMAC = SocketFlags::HMACPROHIB.bits();
|
||||||
|
const CRC32 = SocketFlags::CRC32REQ.bits();
|
||||||
|
const NOCRC32 = SocketFlags::CRC32PROHIB.bits();
|
||||||
|
const SAME = SocketFlags::SAME.bits();
|
||||||
|
|
||||||
|
// The source may set any bits
|
||||||
|
const _ = !0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc = "CSP identifier/header."]
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone, Default)]
|
||||||
|
pub struct csp_id_t {
|
||||||
|
pub pri: u8,
|
||||||
|
pub flags: u8,
|
||||||
|
pub src: u16,
|
||||||
|
pub dst: u16,
|
||||||
|
pub dport: u8,
|
||||||
|
pub sport: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
|
||||||
|
pub enum MsgPriority {
|
||||||
|
Critical = 0,
|
||||||
|
High = 1,
|
||||||
|
Normal = 2,
|
||||||
|
Low = 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct csp_conn_s {
|
||||||
|
pub _address: u8,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc = " CSP Packet.\n\n This structure is constructed to fit with all interface and protocols to prevent the\n need to copy data (zero copy).\n\n .. note:: In most cases a CSP packet cannot be reused in case of send failure, because the\n \t\t\t lower layers may add additional data causing increased length (e.g. CRC32), convert\n \t\t\t the CSP id to different endian (e.g. I2C), etc.\n"]
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub struct csp_packet_s {
|
||||||
|
pub __bindgen_anon_1: csp_packet_s_anon_union,
|
||||||
|
pub length: u16,
|
||||||
|
pub id: csp_id_t,
|
||||||
|
pub next: *mut csp_packet_s,
|
||||||
|
#[doc = " Additional header bytes, to prepend packed data before transmission\n This must be minimum 6 bytes to accomodate CSP 2.0. But some implementations\n require much more scratch working area for encryption for example.\n\n Ultimately after csp_id_pack() this area will be filled with the CSP header"]
|
||||||
|
pub header: [u8; 8usize],
|
||||||
|
pub __bindgen_anon_2: csp_packet_s_data_union,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub union csp_packet_s_anon_union {
|
||||||
|
pub rdp_only: csp_packet_s_anon_union_field_rdp_only,
|
||||||
|
pub rx_tx_only: csp_packet_s_anon_union_field_rx_tx_only,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for csp_packet_s_anon_union {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
rdp_only: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct csp_packet_s_anon_union_field_rdp_only {
|
||||||
|
pub rdp_quarantine: u32,
|
||||||
|
pub timestamp_tx: u32,
|
||||||
|
pub timestamp_rx: u32,
|
||||||
|
pub conn: *mut csp_conn_s,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for csp_packet_s_anon_union_field_rdp_only {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
rdp_quarantine: Default::default(),
|
||||||
|
timestamp_tx: Default::default(),
|
||||||
|
timestamp_rx: Default::default(),
|
||||||
|
conn: core::ptr::null_mut(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct csp_packet_s_anon_union_field_rx_tx_only {
|
||||||
|
pub rx_count: u16,
|
||||||
|
pub remain: u16,
|
||||||
|
pub cfpid: u32,
|
||||||
|
pub last_used: u32,
|
||||||
|
pub frame_begin: *mut u8,
|
||||||
|
pub frame_length: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for csp_packet_s_anon_union_field_rx_tx_only {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
rx_count: Default::default(),
|
||||||
|
remain: Default::default(),
|
||||||
|
cfpid: Default::default(),
|
||||||
|
last_used: Default::default(),
|
||||||
|
frame_begin: core::ptr::null_mut(),
|
||||||
|
frame_length: Default::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc = " Data part of packet:"]
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub union csp_packet_s_data_union {
|
||||||
|
pub data: [u8; 256usize],
|
||||||
|
pub data16: [u16; 128usize],
|
||||||
|
pub data32: [u32; 64usize],
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for csp_packet_s_data_union {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
data: [0; 256usize],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc = " CSP Packet.\n\n This structure is constructed to fit with all interface and protocols to prevent the\n need to copy data (zero copy).\n\n .. note:: In most cases a CSP packet cannot be reused in case of send failure, because the\n \t\t\t lower layers may add additional data causing increased length (e.g. CRC32), convert\n \t\t\t the CSP id to different endian (e.g. I2C), etc.\n"]
|
||||||
|
pub type csp_packet_t = csp_packet_s;
|
||||||
|
|
||||||
|
pub struct CspPacket(pub csp_packet_s);
|
||||||
|
|
||||||
|
impl CspPacket {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for CspPacket {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self(csp_packet_s {
|
||||||
|
__bindgen_anon_1: Default::default(),
|
||||||
|
length: Default::default(),
|
||||||
|
id: Default::default(),
|
||||||
|
next: core::ptr::null_mut(),
|
||||||
|
header: Default::default(),
|
||||||
|
__bindgen_anon_2: Default::default(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type csp_queue_handle_t = *mut core::ffi::c_void;
|
||||||
|
pub type csp_static_queue_t = *mut core::ffi::c_void;
|
||||||
|
|
||||||
|
#[doc = " @brief Connection struct"]
|
||||||
|
#[repr(C)]
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct csp_socket_s {
|
||||||
|
pub rx_queue: csp_queue_handle_t,
|
||||||
|
pub rx_queue_static: csp_static_queue_t,
|
||||||
|
pub rx_queue_static_data: [core::ffi::c_char; 128usize],
|
||||||
|
pub opts: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_csp_socket_s() {
|
||||||
|
const UNINIT: ::std::mem::MaybeUninit<csp_socket_s> = ::std::mem::MaybeUninit::uninit();
|
||||||
|
let ptr = UNINIT.as_ptr();
|
||||||
|
assert_eq!(
|
||||||
|
::std::mem::size_of::<csp_socket_s>(),
|
||||||
|
152usize,
|
||||||
|
concat!("Size of: ", stringify!(csp_socket_s))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
::std::mem::align_of::<csp_socket_s>(),
|
||||||
|
8usize,
|
||||||
|
concat!("Alignment of ", stringify!(csp_socket_s))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).rx_queue) as usize - ptr as usize },
|
||||||
|
0usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_socket_s),
|
||||||
|
"::",
|
||||||
|
stringify!(rx_queue)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).rx_queue_static) as usize - ptr as usize },
|
||||||
|
8usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_socket_s),
|
||||||
|
"::",
|
||||||
|
stringify!(rx_queue_static)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).rx_queue_static_data) as usize - ptr as usize },
|
||||||
|
16usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_socket_s),
|
||||||
|
"::",
|
||||||
|
stringify!(rx_queue_static_data)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).opts) as usize - ptr as usize },
|
||||||
|
144usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_socket_s),
|
||||||
|
"::",
|
||||||
|
stringify!(opts)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#[doc = " Forward declaration of socket structure"]
|
||||||
|
pub type csp_socket_t = csp_socket_s;
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#[doc = " Error counters"]
|
||||||
|
pub static mut csp_dbg_buffer_out: u8;
|
||||||
|
pub static mut csp_dbg_conn_out: u8;
|
||||||
|
pub static mut csp_dbg_conn_ovf: u8;
|
||||||
|
pub static mut csp_dbg_conn_noroute: u8;
|
||||||
|
pub static mut csp_dbg_inval_reply: u8;
|
||||||
|
pub static mut csp_dbg_errno: u8;
|
||||||
|
pub static mut csp_dbg_can_errno: u8;
|
||||||
|
pub static mut csp_dbg_eth_errno: u8;
|
||||||
|
pub static mut csp_dbg_rdp_print: u8;
|
||||||
|
pub static mut csp_dbg_packet_print: u8;
|
||||||
|
|
||||||
|
#[doc = " Initialize CSP.\n This will configure basic structures."]
|
||||||
|
pub fn csp_init();
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
pub fn csp_print_func(fmt: *const ::std::os::raw::c_char, ...);
|
||||||
|
|
||||||
|
#[doc = " Bind port to socket.\n\n @param[in] socket socket to bind port to\n @param[in] port port number to bind, use #CSP_ANY for all ports. Bindnig to a specific will take precedence over #CSP_ANY.\n @return #CSP_ERR_NONE on success, otherwise an error code."]
|
||||||
|
pub fn csp_bind(socket: *mut csp_socket_t, port: u8) -> core::ffi::c_int;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use core::mem::{align_of, size_of};
|
||||||
|
use std::mem::MaybeUninit;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_csp_timestamp_t() {
|
||||||
|
const UNINIT: MaybeUninit<csp_timestamp_t> = MaybeUninit::uninit();
|
||||||
|
let ptr = UNINIT.as_ptr();
|
||||||
|
assert_eq!(
|
||||||
|
::core::mem::size_of::<csp_timestamp_t>(),
|
||||||
|
8usize,
|
||||||
|
concat!("Size of: ", stringify!(csp_timestamp_t))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
std::mem::align_of::<csp_timestamp_t>(),
|
||||||
|
4usize,
|
||||||
|
concat!("Alignment of ", stringify!(csp_timestamp_t))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).tv_sec) as usize - ptr as usize },
|
||||||
|
0usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_timestamp_t),
|
||||||
|
"::",
|
||||||
|
stringify!(tv_sec)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).tv_nsec) as usize - ptr as usize },
|
||||||
|
4usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_timestamp_t),
|
||||||
|
"::",
|
||||||
|
stringify!(tv_nsec)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_csp_id() {
|
||||||
|
const UNINIT: MaybeUninit<csp_id_t> = MaybeUninit::uninit();
|
||||||
|
let ptr = UNINIT.as_ptr();
|
||||||
|
assert_eq!(
|
||||||
|
size_of::<csp_id_t>(),
|
||||||
|
8usize,
|
||||||
|
concat!("Size of: ", stringify!(__packed))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
align_of::<csp_id_t>(),
|
||||||
|
2usize,
|
||||||
|
concat!("Alignment of ", stringify!(__packed))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).pri) as usize - ptr as usize },
|
||||||
|
0usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(__packed),
|
||||||
|
"::",
|
||||||
|
stringify!(pri)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).flags) as usize - ptr as usize },
|
||||||
|
1usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(__packed),
|
||||||
|
"::",
|
||||||
|
stringify!(flags)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).src) as usize - ptr as usize },
|
||||||
|
2usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(__packed),
|
||||||
|
"::",
|
||||||
|
stringify!(src)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).dst) as usize - ptr as usize },
|
||||||
|
4usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(__packed),
|
||||||
|
"::",
|
||||||
|
stringify!(dst)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).dport) as usize - ptr as usize },
|
||||||
|
6usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(__packed),
|
||||||
|
"::",
|
||||||
|
stringify!(dport)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).sport) as usize - ptr as usize },
|
||||||
|
7usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(__packed),
|
||||||
|
"::",
|
||||||
|
stringify!(sport)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_csp_packet_s__bindgen_ty_1__bindgen_ty_1() {
|
||||||
|
const UNINIT: MaybeUninit<csp_packet_s_anon_union_field_rdp_only> = MaybeUninit::uninit();
|
||||||
|
let ptr = UNINIT.as_ptr();
|
||||||
|
assert_eq!(
|
||||||
|
size_of::<csp_packet_s_anon_union_field_rdp_only>(),
|
||||||
|
24usize,
|
||||||
|
concat!(
|
||||||
|
"Size of: ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_1__bindgen_ty_1)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
align_of::<csp_packet_s_anon_union_field_rdp_only>(),
|
||||||
|
8usize,
|
||||||
|
concat!(
|
||||||
|
"Alignment of ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_1__bindgen_ty_1)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).rdp_quarantine) as usize - ptr as usize },
|
||||||
|
0usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_1__bindgen_ty_1),
|
||||||
|
"::",
|
||||||
|
stringify!(rdp_quarantine)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).timestamp_tx) as usize - ptr as usize },
|
||||||
|
4usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_1__bindgen_ty_1),
|
||||||
|
"::",
|
||||||
|
stringify!(timestamp_tx)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).timestamp_rx) as usize - ptr as usize },
|
||||||
|
8usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_1__bindgen_ty_1),
|
||||||
|
"::",
|
||||||
|
stringify!(timestamp_rx)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).conn) as usize - ptr as usize },
|
||||||
|
16usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_1__bindgen_ty_1),
|
||||||
|
"::",
|
||||||
|
stringify!(conn)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_csp_packet_s__bindgen_ty_1__bindgen_ty_2() {
|
||||||
|
const UNINIT: MaybeUninit<csp_packet_s_anon_union_field_rx_tx_only> = MaybeUninit::uninit();
|
||||||
|
let ptr = UNINIT.as_ptr();
|
||||||
|
assert_eq!(
|
||||||
|
size_of::<csp_packet_s_anon_union_field_rx_tx_only>(),
|
||||||
|
32usize,
|
||||||
|
concat!(
|
||||||
|
"Size of: ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_1__bindgen_ty_2)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
align_of::<csp_packet_s_anon_union_field_rx_tx_only>(),
|
||||||
|
8usize,
|
||||||
|
concat!(
|
||||||
|
"Alignment of ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_1__bindgen_ty_2)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).rx_count) as usize - ptr as usize },
|
||||||
|
0usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_1__bindgen_ty_2),
|
||||||
|
"::",
|
||||||
|
stringify!(rx_count)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).remain) as usize - ptr as usize },
|
||||||
|
2usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_1__bindgen_ty_2),
|
||||||
|
"::",
|
||||||
|
stringify!(remain)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).cfpid) as usize - ptr as usize },
|
||||||
|
4usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_1__bindgen_ty_2),
|
||||||
|
"::",
|
||||||
|
stringify!(cfpid)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).last_used) as usize - ptr as usize },
|
||||||
|
8usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_1__bindgen_ty_2),
|
||||||
|
"::",
|
||||||
|
stringify!(last_used)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).frame_begin) as usize - ptr as usize },
|
||||||
|
16usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_1__bindgen_ty_2),
|
||||||
|
"::",
|
||||||
|
stringify!(frame_begin)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).frame_length) as usize - ptr as usize },
|
||||||
|
24usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_1__bindgen_ty_2),
|
||||||
|
"::",
|
||||||
|
stringify!(frame_length)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_csp_packet_s__bindgen_ty_1() {
|
||||||
|
assert_eq!(
|
||||||
|
size_of::<csp_packet_s_anon_union>(),
|
||||||
|
32usize,
|
||||||
|
concat!("Size of: ", stringify!(csp_packet_s_anon_union))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
align_of::<csp_packet_s_anon_union>(),
|
||||||
|
8usize,
|
||||||
|
concat!("Alignment of ", stringify!(csp_packet_s_anon_union))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_csp_packet_s__bindgen_ty_2() {
|
||||||
|
const UNINIT: MaybeUninit<csp_packet_s_data_union> = MaybeUninit::uninit();
|
||||||
|
let ptr = UNINIT.as_ptr();
|
||||||
|
assert_eq!(
|
||||||
|
size_of::<csp_packet_s_data_union>(),
|
||||||
|
256usize,
|
||||||
|
concat!("Size of: ", stringify!(csp_packet_s__bindgen_ty_2))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
align_of::<csp_packet_s_data_union>(),
|
||||||
|
4usize,
|
||||||
|
concat!("Alignment of ", stringify!(csp_packet_s__bindgen_ty_2))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).data) as usize - ptr as usize },
|
||||||
|
0usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_2),
|
||||||
|
"::",
|
||||||
|
stringify!(data)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).data16) as usize - ptr as usize },
|
||||||
|
0usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_2),
|
||||||
|
"::",
|
||||||
|
stringify!(data16)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).data32) as usize - ptr as usize },
|
||||||
|
0usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s__bindgen_ty_2),
|
||||||
|
"::",
|
||||||
|
stringify!(data32)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn bindgen_test_layout_csp_packet_s() {
|
||||||
|
const UNINIT: MaybeUninit<csp_packet_s> = MaybeUninit::uninit();
|
||||||
|
let ptr = UNINIT.as_ptr();
|
||||||
|
assert_eq!(
|
||||||
|
size_of::<csp_packet_s>(),
|
||||||
|
320usize,
|
||||||
|
concat!("Size of: ", stringify!(csp_packet_s))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
align_of::<csp_packet_s>(),
|
||||||
|
8usize,
|
||||||
|
concat!("Alignment of ", stringify!(csp_packet_s))
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).length) as usize - ptr as usize },
|
||||||
|
32usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s),
|
||||||
|
"::",
|
||||||
|
stringify!(length)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).id) as usize - ptr as usize },
|
||||||
|
34usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s),
|
||||||
|
"::",
|
||||||
|
stringify!(id)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).next) as usize - ptr as usize },
|
||||||
|
48usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s),
|
||||||
|
"::",
|
||||||
|
stringify!(next)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
unsafe { ::std::ptr::addr_of!((*ptr).header) as usize - ptr as usize },
|
||||||
|
56usize,
|
||||||
|
concat!(
|
||||||
|
"Offset of field: ",
|
||||||
|
stringify!(csp_packet_s),
|
||||||
|
"::",
|
||||||
|
stringify!(header)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
use libcsp_rust::csp_init;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
println!("Hello, world!");
|
|
||||||
unsafe {
|
|
||||||
csp_init();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user