Skip to content

Commit

Permalink
Add constant for ethernet MTU
Browse files Browse the repository at this point in the history
  • Loading branch information
dtwood committed May 28, 2019
1 parent d404d7d commit 060af75
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions tm4c129x-hal/src/ethernet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ impl EphyReg {
}
}

const ETHERNET_MTU: usize = 1500;
const NUM_TX_DESCRIPTORS: usize = 2;
const NUM_RX_DESCRIPTORS: usize = 10;

static RX_DESCRIPTORS: [RDES; NUM_RX_DESCRIPTORS] = [
RDES::new(),
RDES::new(),
Expand All @@ -78,12 +80,10 @@ static RX_DESCRIPTORS: [RDES; NUM_RX_DESCRIPTORS] = [
];
static TX_DESCRIPTORS: [TDES; NUM_TX_DESCRIPTORS] = [TDES::new(), TDES::new()];

const RX_BUFFER_SIZE: usize = 1536;
static mut RX_BUFFERS: [[u8; RX_BUFFER_SIZE]; NUM_RX_DESCRIPTORS] =
[[0; RX_BUFFER_SIZE]; NUM_RX_DESCRIPTORS];
const TX_BUFFER_SIZE: usize = RX_BUFFER_SIZE;
static mut TX_BUFFERS: [[u8; TX_BUFFER_SIZE]; NUM_TX_DESCRIPTORS] =
[[0; TX_BUFFER_SIZE]; NUM_TX_DESCRIPTORS];
static mut RX_BUFFERS: [[u8; ETHERNET_MTU]; NUM_RX_DESCRIPTORS] =
[[0; ETHERNET_MTU]; NUM_RX_DESCRIPTORS];
static mut TX_BUFFERS: [[u8; ETHERNET_MTU]; NUM_TX_DESCRIPTORS] =
[[0; ETHERNET_MTU]; NUM_TX_DESCRIPTORS];

fn emac_reset(emac0: &EMAC0) {
emac0.dmabusmod.modify(|_, w| w.swr().set_bit());
Expand Down Expand Up @@ -338,8 +338,7 @@ impl EthernetDevice {
RX_DESCRIPTORS[i].rdes0.write(|w| w.own().set_bit());
RX_DESCRIPTORS[i].rdes1.write(|w| {
w.bits(
DES1_RX_CTRL_CHAINED
| ((RX_BUFFER_SIZE as u32) << DES1_RX_CTRL_BUFF1_SIZE_S),
DES1_RX_CTRL_CHAINED | ((ETHERNET_MTU as u32) << DES1_RX_CTRL_BUFF1_SIZE_S),
)
});
RX_DESCRIPTORS[i]
Expand Down Expand Up @@ -428,7 +427,7 @@ impl<'a> Device<'a> for EthernetDevice {
fn capabilities(&self) -> DeviceCapabilities {
let mut cap = DeviceCapabilities::default();

cap.max_transmission_unit = TX_BUFFER_SIZE;
cap.max_transmission_unit = ETHERNET_MTU;
cap.max_burst_size = Some(NUM_TX_DESCRIPTORS);

cap.checksum = ChecksumCapabilities::default();
Expand Down Expand Up @@ -471,7 +470,7 @@ impl<'a> phy::RxToken for RxToken<'a> {

let len = ((descriptor.rdes0.read().bits() & DES0_RX_STAT_FRAME_LENGTH_M)
>> DES0_RX_STAT_FRAME_LENGTH_S) as usize;
assert!(len <= RX_BUFFER_SIZE);
assert!(len <= ETHERNET_MTU);
let data =
unsafe { core::slice::from_raw_parts(descriptor.rdes2.read().bits() as *mut u8, len) };

Expand All @@ -496,7 +495,7 @@ impl<'a> phy::TxToken for TxToken<'a> {
{
let descriptor = *self.descriptor_pointer;

assert!(len <= TX_BUFFER_SIZE);
assert!(len <= ETHERNET_MTU);

let data = unsafe {
core::slice::from_raw_parts_mut(descriptor.tdes2.read().bits() as *mut u8, len)
Expand Down

0 comments on commit 060af75

Please sign in to comment.