forked from M-Labs/zynq-rs
1
0
Fork 0

eth: add safety asserts

This commit is contained in:
Astro 2019-06-09 02:23:37 +02:00
parent 824e91e6cb
commit 74bd81f87f
2 changed files with 3 additions and 0 deletions

View File

@ -277,6 +277,7 @@ impl<'rx> Eth<'rx> {
pub fn start_rx(&mut self, rx_buffers: [&'rx mut [u8]; rx::DESCS]) {
self.rx = Some(rx::DescList::new(rx_buffers));
let list_addr = self.rx.as_ref().unwrap() as *const _ as u32;
assert!(list_addr & 0b11 == 0);
self.regs.rx_qbar.write(
regs::RxQbar::zeroed()
.rx_q_baseaddr(list_addr >> 2)

View File

@ -45,7 +45,9 @@ impl<'a> DescList<'a> {
pub fn new(buffers: [&'a mut [u8]; DESCS]) -> Self {
let mut list: [DescEntry; DESCS] = unsafe { uninitialized() };
for i in 0..DESCS {
assert!(buffers[i].len() >= 1536);
let buffer_addr = &mut buffers[i][0] as *mut _ as u32;
assert!(buffer_addr & 0b11 == 0);
list[i].word0.write(
DescWord0::zeroed()
.used(false)