Compare commits
2 Commits
embassy-ne
...
embassy-ne
Author | SHA1 | Date | |
---|---|---|---|
73f8cd7ade | |||
afb01e3fc5 |
@ -6,6 +6,7 @@ keywords = ["embedded", "tuntap", "embassy-net", "embedded-hal-async", "ethernet
|
|||||||
categories = ["embedded", "hardware-support", "no-std", "network-programming", "async"]
|
categories = ["embedded", "hardware-support", "no-std", "network-programming", "async"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
repository = "https://github.com/embassy-rs/embassy"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
embassy-net-driver = { version = "0.2.0", path = "../embassy-net-driver" }
|
embassy-net-driver = { version = "0.2.0", path = "../embassy-net-driver" }
|
||||||
@ -16,4 +17,4 @@ libc = "0.2.101"
|
|||||||
[package.metadata.embassy_docs]
|
[package.metadata.embassy_docs]
|
||||||
src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-tuntap-v$VERSION/embassy-net-tuntap/src/"
|
src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-tuntap-v$VERSION/embassy-net-tuntap/src/"
|
||||||
src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net-tuntap/src/"
|
src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net-tuntap/src/"
|
||||||
target = "thumbv7em-none-eabi"
|
target = "thumbv7em-none-eabi"
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![warn(missing_docs)]
|
||||||
|
#![doc = include_str!("../README.md")]
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::os::unix::io::{AsRawFd, RawFd};
|
use std::os::unix::io::{AsRawFd, RawFd};
|
||||||
@ -7,12 +9,19 @@ use async_io::Async;
|
|||||||
use embassy_net_driver::{self, Capabilities, Driver, HardwareAddress, LinkState};
|
use embassy_net_driver::{self, Capabilities, Driver, HardwareAddress, LinkState};
|
||||||
use log::*;
|
use log::*;
|
||||||
|
|
||||||
|
/// Get the MTU of the given interface.
|
||||||
pub const SIOCGIFMTU: libc::c_ulong = 0x8921;
|
pub const SIOCGIFMTU: libc::c_ulong = 0x8921;
|
||||||
|
/// Get the index of the given interface.
|
||||||
pub const _SIOCGIFINDEX: libc::c_ulong = 0x8933;
|
pub const _SIOCGIFINDEX: libc::c_ulong = 0x8933;
|
||||||
|
/// Capture all packages.
|
||||||
pub const _ETH_P_ALL: libc::c_short = 0x0003;
|
pub const _ETH_P_ALL: libc::c_short = 0x0003;
|
||||||
|
/// Set the interface flags.
|
||||||
pub const TUNSETIFF: libc::c_ulong = 0x400454CA;
|
pub const TUNSETIFF: libc::c_ulong = 0x400454CA;
|
||||||
|
/// TUN device.
|
||||||
pub const _IFF_TUN: libc::c_int = 0x0001;
|
pub const _IFF_TUN: libc::c_int = 0x0001;
|
||||||
|
/// TAP device.
|
||||||
pub const IFF_TAP: libc::c_int = 0x0002;
|
pub const IFF_TAP: libc::c_int = 0x0002;
|
||||||
|
/// No packet information.
|
||||||
pub const IFF_NO_PI: libc::c_int = 0x1000;
|
pub const IFF_NO_PI: libc::c_int = 0x1000;
|
||||||
|
|
||||||
const ETHERNET_HEADER_LEN: usize = 14;
|
const ETHERNET_HEADER_LEN: usize = 14;
|
||||||
@ -47,6 +56,7 @@ fn ifreq_ioctl(lower: libc::c_int, ifreq: &mut ifreq, cmd: libc::c_ulong) -> io:
|
|||||||
Ok(ifreq.ifr_data)
|
Ok(ifreq.ifr_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A TUN/TAP device.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TunTap {
|
pub struct TunTap {
|
||||||
fd: libc::c_int,
|
fd: libc::c_int,
|
||||||
@ -60,6 +70,7 @@ impl AsRawFd for TunTap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TunTap {
|
impl TunTap {
|
||||||
|
/// Create a new TUN/TAP device.
|
||||||
pub fn new(name: &str) -> io::Result<TunTap> {
|
pub fn new(name: &str) -> io::Result<TunTap> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let fd = libc::open(
|
let fd = libc::open(
|
||||||
@ -126,11 +137,13 @@ impl io::Write for TunTap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A TUN/TAP device, wrapped in an async interface.
|
||||||
pub struct TunTapDevice {
|
pub struct TunTapDevice {
|
||||||
device: Async<TunTap>,
|
device: Async<TunTap>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TunTapDevice {
|
impl TunTapDevice {
|
||||||
|
/// Create a new TUN/TAP device.
|
||||||
pub fn new(name: &str) -> io::Result<TunTapDevice> {
|
pub fn new(name: &str) -> io::Result<TunTapDevice> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
device: Async::new(TunTap::new(name)?)?,
|
device: Async::new(TunTap::new(name)?)?,
|
||||||
|
@ -6,7 +6,6 @@ keywords = ["embedded", "wiznet", "embassy-net", "embedded-hal-async", "ethernet
|
|||||||
categories = ["embedded", "hardware-support", "no-std", "network-programming", "async"]
|
categories = ["embedded", "hardware-support", "no-std", "network-programming", "async"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
repository = "https://github.com/embassy-rs/embassy"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
embedded-hal = { version = "1.0.0-rc.3" }
|
embedded-hal = { version = "1.0.0-rc.3" }
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
//! Wiznet W5100s and W5500 family driver.
|
|
||||||
mod w5500;
|
mod w5500;
|
||||||
pub use w5500::W5500;
|
pub use w5500::W5500;
|
||||||
mod w5100s;
|
mod w5100s;
|
||||||
@ -46,5 +45,4 @@ pub(crate) mod sealed {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait for Wiznet chips.
|
|
||||||
pub trait Chip: sealed::Chip {}
|
pub trait Chip: sealed::Chip {}
|
||||||
|
@ -4,7 +4,6 @@ const SOCKET_BASE: u16 = 0x400;
|
|||||||
const TX_BASE: u16 = 0x4000;
|
const TX_BASE: u16 = 0x4000;
|
||||||
const RX_BASE: u16 = 0x6000;
|
const RX_BASE: u16 = 0x6000;
|
||||||
|
|
||||||
/// Wizard W5100S chip.
|
|
||||||
pub enum W5100S {}
|
pub enum W5100S {}
|
||||||
|
|
||||||
impl super::Chip for W5100S {}
|
impl super::Chip for W5100S {}
|
||||||
|
@ -8,7 +8,6 @@ pub enum RegisterBlock {
|
|||||||
RxBuf = 0x03,
|
RxBuf = 0x03,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wiznet W5500 chip.
|
|
||||||
pub enum W5500 {}
|
pub enum W5500 {}
|
||||||
|
|
||||||
impl super::Chip for W5500 {}
|
impl super::Chip for W5500 {}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![allow(async_fn_in_trait)]
|
#![allow(async_fn_in_trait)]
|
||||||
#![doc = include_str!("../README.md")]
|
#![doc = include_str!("../README.md")]
|
||||||
#![warn(missing_docs)]
|
|
||||||
|
|
||||||
pub mod chip;
|
pub mod chip;
|
||||||
mod device;
|
mod device;
|
||||||
@ -48,7 +47,6 @@ pub struct Runner<'d, C: Chip, SPI: SpiDevice, INT: Wait, RST: OutputPin> {
|
|||||||
|
|
||||||
/// You must call this in a background task for the driver to operate.
|
/// You must call this in a background task for the driver to operate.
|
||||||
impl<'d, C: Chip, SPI: SpiDevice, INT: Wait, RST: OutputPin> Runner<'d, C, SPI, INT, RST> {
|
impl<'d, C: Chip, SPI: SpiDevice, INT: Wait, RST: OutputPin> Runner<'d, C, SPI, INT, RST> {
|
||||||
/// Run the driver.
|
|
||||||
pub async fn run(mut self) -> ! {
|
pub async fn run(mut self) -> ! {
|
||||||
let (state_chan, mut rx_chan, mut tx_chan) = self.ch.split();
|
let (state_chan, mut rx_chan, mut tx_chan) = self.ch.split();
|
||||||
let mut tick = Ticker::every(Duration::from_millis(500));
|
let mut tick = Ticker::every(Duration::from_millis(500));
|
||||||
|
Reference in New Issue
Block a user