Skip to content

Commit 7cb9fd7

Browse files
committed
Remove transmit buffer references
1 parent d068281 commit 7cb9fd7

File tree

1 file changed

+33
-47
lines changed

1 file changed

+33
-47
lines changed

tm4c129x-hal/src/ethernet.rs

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,6 @@ impl EthernetDevice {
371371
w
372372
});
373373

374-
// unsafe {
375-
// EMACIntClear(emac0_base, EMACIntStatus(emac0_base, false));
376-
// }
377374
unsafe {
378375
emac0.dmaim.write(|w| w.bits(0xffff_ffff));
379376
emac0.ephyim.write(|w| w.bits(0xffff_ffff));
@@ -396,41 +393,37 @@ impl<'a> Device<'a> for EthernetDevice {
396393
.iter()
397394
.find(|rxd| rxd.rdes0.read().own().bit_is_clear())?;
398395

399-
let (tx_descriptor, tx_buffer) = TX_DESCRIPTORS
396+
let tx_descriptor = TX_DESCRIPTORS
400397
.iter()
401-
.zip(unsafe { TX_BUFFERS.iter_mut() })
402-
.find(|(txd, _)| txd.tdes0.read().own().bit_is_clear())?;
398+
.find(|txd| txd.tdes0.read().own().bit_is_clear())?;
403399

404400
Some((
405401
RxToken {
406402
descriptor: rx_descriptor,
407403
},
408404
TxToken {
409-
descriptor: tx_descriptor,
410-
buffer: tx_buffer,
411405
emac0: &self.emac0,
406+
descriptor: tx_descriptor,
412407
},
413408
))
414409
}
415410

416411
fn transmit(&'a mut self) -> Option<Self::TxToken> {
417-
let (tx_descriptor, tx_buffer) = TX_DESCRIPTORS
412+
let tx_descriptor = TX_DESCRIPTORS
418413
.iter()
419-
.zip(unsafe { TX_BUFFERS.iter_mut() })
420-
.find(|(txd, _)| txd.tdes0.read().own().bit_is_clear())?;
414+
.find(|txd| txd.tdes0.read().own().bit_is_clear())?;
421415

422416
Some(TxToken {
423-
descriptor: tx_descriptor,
424-
buffer: tx_buffer,
425417
emac0: &self.emac0,
418+
descriptor: tx_descriptor,
426419
})
427420
}
428421

429422
fn capabilities(&self) -> DeviceCapabilities {
430423
let mut cap = DeviceCapabilities::default();
431424

432-
cap.max_transmission_unit = RX_BUFFER_SIZE;
433-
cap.max_burst_size = Some(1);
425+
cap.max_transmission_unit = TX_BUFFER_SIZE;
426+
cap.max_burst_size = Some(NUM_TX_DESCRIPTORS);
434427

435428
cap.checksum = ChecksumCapabilities::ignored();
436429
cap.checksum.ipv4 = Checksum::None;
@@ -453,56 +446,49 @@ impl<'a> phy::RxToken for RxToken<'a> {
453446
where
454447
F: FnOnce(&[u8]) -> smoltcp::Result<R>,
455448
{
456-
let result;
449+
// We own the receive descriptor so check to see if it contains a valid frame.
450+
if self.descriptor.rdes0.read().bits() & DES0_RX_STAT_ERR == DES0_RX_STAT_ERR {
451+
self.descriptor.rdes0.write(|w| w.own().set_bit());
452+
return Err(smoltcp::Error::Checksum);
453+
}
457454

458-
unsafe {
459-
// We own the receive descriptor so check to see if it contains a valid frame.
460-
if self.descriptor.rdes0.read().bits() & DES0_RX_STAT_ERR != DES0_RX_STAT_ERR {
461-
// We have a valid frame. First check that the "last descriptor" flag is set. We
462-
// sized the receive buffer such that it can always hold a valid frame so this
463-
// flag should never be clear at this point but...
464-
if self.descriptor.rdes0.read().bits() & DES0_RX_STAT_LAST_DESC
465-
== DES0_RX_STAT_LAST_DESC
466-
{
467-
// What size is the received frame?
468-
let frame_len = (self.descriptor.rdes0.read().bits()
469-
& DES0_RX_STAT_FRAME_LENGTH_M)
470-
>> DES0_RX_STAT_FRAME_LENGTH_S;
471-
let data = core::slice::from_raw_parts(
472-
self.descriptor.rdes2.read().bits() as *mut u8,
473-
frame_len as usize,
474-
);
475-
result = f(data);
476-
} else {
477-
result = Err(smoltcp::Error::Truncated);
478-
}
479-
} else {
480-
result = Err(smoltcp::Error::Checksum);
481-
}
455+
// We have a valid frame. First check that the "last descriptor" flag is set. We
456+
// sized the receive buffer such that it can always hold a valid frame so this
457+
// flag should never be clear at this point but...
458+
if self.descriptor.rdes0.read().bits() & DES0_RX_STAT_LAST_DESC != DES0_RX_STAT_LAST_DESC {
482459
self.descriptor.rdes0.write(|w| w.own().set_bit());
460+
return Err(smoltcp::Error::Truncated);
483461
}
484462

463+
let len = ((self.descriptor.rdes0.read().bits() & DES0_RX_STAT_FRAME_LENGTH_M)
464+
>> DES0_RX_STAT_FRAME_LENGTH_S) as usize;
465+
assert!(len <= RX_BUFFER_SIZE);
466+
let data = unsafe {
467+
core::slice::from_raw_parts(self.descriptor.rdes2.read().bits() as *mut u8, len)
468+
};
469+
470+
let result = f(data);
471+
self.descriptor.rdes0.write(|w| w.own().set_bit());
485472
result
486473
}
487474
}
488475

489476
pub struct TxToken<'a> {
490-
descriptor: &'a TDES,
491-
buffer: &'a mut [u8],
492477
emac0: &'a EMAC0,
478+
descriptor: &'a TDES,
493479
}
494480

495481
impl<'a> phy::TxToken for TxToken<'a> {
496482
fn consume<R, F>(self, _timestamp: Instant, len: usize, f: F) -> smoltcp::Result<R>
497483
where
498484
F: FnOnce(&mut [u8]) -> smoltcp::Result<R>,
499485
{
500-
assert!(self.descriptor.tdes0.read().own().bit_is_clear());
501-
502-
assert!(len <= self.buffer.len());
503-
let result = f(self.buffer);
486+
assert!(len <= TX_BUFFER_SIZE);
487+
let data = unsafe {
488+
core::slice::from_raw_parts_mut(self.descriptor.tdes2.read().bits() as *mut u8, len)
489+
};
490+
let result = f(data);
504491

505-
// Fill in the packet size and pointer, and tell the transmitter to start work.
506492
unsafe {
507493
self.descriptor
508494
.tdes1

0 commit comments

Comments
 (0)