Fix silliness in docs.
This commit is contained in:
parent
c29d3c2804
commit
716a1cf7fe
|
@ -8,7 +8,8 @@
|
||||||
//! It also provides the _middleware interfaces_ [Tracer](struct.Tracer.html) and
|
//! It also provides the _middleware interfaces_ [Tracer](struct.Tracer.html) and
|
||||||
//! [FaultInjector](struct.FaultInjector.html), to facilitate debugging.
|
//! [FaultInjector](struct.FaultInjector.html), to facilitate debugging.
|
||||||
//!
|
//!
|
||||||
//! # Examples
|
// https://github.com/rust-lang/rust/issues/38740
|
||||||
|
//! <h1 id="examples" class="section-header"><a href="#examples">Examples</a></h1>
|
||||||
//!
|
//!
|
||||||
//! An implementation of the [Device](trait.Device.html) trait for a simple hardware
|
//! An implementation of the [Device](trait.Device.html) trait for a simple hardware
|
||||||
//! Ethernet controller could look as follows:
|
//! Ethernet controller could look as follows:
|
||||||
|
@ -19,7 +20,6 @@ use std::slice;
|
||||||
use smoltcp::Error;
|
use smoltcp::Error;
|
||||||
use smoltcp::phy::Device;
|
use smoltcp::phy::Device;
|
||||||
|
|
||||||
const MTU: usize = 1536;
|
|
||||||
const TX_BUFFERS: [*mut u8; 2] = [0x10000000 as *mut u8, 0x10001000 as *mut u8];
|
const TX_BUFFERS: [*mut u8; 2] = [0x10000000 as *mut u8, 0x10001000 as *mut u8];
|
||||||
const RX_BUFFERS: [*mut u8; 2] = [0x10002000 as *mut u8, 0x10003000 as *mut u8];
|
const RX_BUFFERS: [*mut u8; 2] = [0x10002000 as *mut u8, 0x10003000 as *mut u8];
|
||||||
|
|
||||||
|
@ -28,6 +28,11 @@ fn rx_full() -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rx_length() -> usize {
|
||||||
|
/* platform-specific code to determine the length of an incoming packet */
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
fn rx_setup(buf: *mut u8) {
|
fn rx_setup(buf: *mut u8) {
|
||||||
/* platform-specific code to receive a packet into a buffer */
|
/* platform-specific code to receive a packet into a buffer */
|
||||||
}
|
}
|
||||||
|
@ -42,22 +47,23 @@ fn tx_setup(buf: *const u8) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct EthernetDevice {
|
struct EthernetDevice {
|
||||||
tx_next: usize,
|
tx_next: usize,
|
||||||
rx_next: usize
|
rx_next: usize
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Device for EthernetDevice {
|
impl Device for EthernetDevice {
|
||||||
type RxBuffer = &'static [u8];
|
type RxBuffer = &'static [u8];
|
||||||
type TxBuffer = EthernetTxBuffer;
|
type TxBuffer = EthernetTxBuffer;
|
||||||
|
|
||||||
fn mtu(&self) -> usize { MTU }
|
fn mtu(&self) -> usize { 1536 }
|
||||||
|
|
||||||
fn receive(&mut self) -> Result<Self::RxBuffer, Error> {
|
fn receive(&mut self) -> Result<Self::RxBuffer, Error> {
|
||||||
if rx_full() {
|
if rx_full() {
|
||||||
let index = self.rx_next;
|
let length = rx_length();
|
||||||
|
let index = self.rx_next;
|
||||||
self.rx_next = (self.rx_next + 1) % RX_BUFFERS.len();
|
self.rx_next = (self.rx_next + 1) % RX_BUFFERS.len();
|
||||||
rx_setup(RX_BUFFERS[self.rx_next]);
|
rx_setup(RX_BUFFERS[self.rx_next]);
|
||||||
Ok(unsafe { slice::from_raw_parts(RX_BUFFERS[index], MTU) })
|
Ok(unsafe { slice::from_raw_parts(RX_BUFFERS[index], length) })
|
||||||
} else {
|
} else {
|
||||||
Err(Error::Exhausted)
|
Err(Error::Exhausted)
|
||||||
}
|
}
|
||||||
|
@ -67,33 +73,25 @@ impl Device for EthernetDevice {
|
||||||
if tx_empty() {
|
if tx_empty() {
|
||||||
let index = self.tx_next;
|
let index = self.tx_next;
|
||||||
self.tx_next = (self.tx_next + 1) % TX_BUFFERS.len();
|
self.tx_next = (self.tx_next + 1) % TX_BUFFERS.len();
|
||||||
Ok(EthernetTxBuffer {
|
Ok(EthernetTxBuffer(unsafe { slice::from_raw_parts_mut(TX_BUFFERS[index], length) }))
|
||||||
buffer: unsafe { slice::from_raw_parts_mut(TX_BUFFERS[index], length) },
|
|
||||||
length: length,
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
Err(Error::Exhausted)
|
Err(Error::Exhausted)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct EthernetTxBuffer {
|
struct EthernetTxBuffer(&'static mut [u8]);
|
||||||
buffer: &'static mut [u8],
|
|
||||||
length: usize
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsRef<[u8]> for EthernetTxBuffer {
|
impl AsRef<[u8]> for EthernetTxBuffer {
|
||||||
fn as_ref(&self) -> &[u8] { &self.buffer[..self.length] }
|
fn as_ref(&self) -> &[u8] { self.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsMut<[u8]> for EthernetTxBuffer {
|
impl AsMut<[u8]> for EthernetTxBuffer {
|
||||||
fn as_mut(&mut self) -> &mut [u8] { &mut self.buffer[..self.length] }
|
fn as_mut(&mut self) -> &mut [u8] { self.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for EthernetTxBuffer {
|
impl Drop for EthernetTxBuffer {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) { tx_setup(self.0.as_ptr()) }
|
||||||
tx_setup(self.buffer.as_ptr())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
//! of possible field values, it provides a compact, high-level representation
|
//! of possible field values, it provides a compact, high-level representation
|
||||||
//! of packet data that can be parsed from and emitted into a sequence of octets.
|
//! of packet data that can be parsed from and emitted into a sequence of octets.
|
||||||
//! This happens through the `Repr` family of enums, e.g. [ArpRepr](enum.ArpRepr.html).
|
//! This happens through the `Repr` family of enums, e.g. [ArpRepr](enum.ArpRepr.html).
|
||||||
|
// https://github.com/rust-lang/rust/issues/38739
|
||||||
//! </ul>
|
//! </ul>
|
||||||
//!
|
//!
|
||||||
//! The functions in the `wire` module are designed for robustness and use together with
|
//! The functions in the `wire` module are designed for robustness and use together with
|
||||||
|
|
Loading…
Reference in New Issue