HeavyX/firmware/testing/src/eth.rs

45 lines
1.1 KiB
Rust

use core::ptr::{read_volatile, write_volatile};
const ETH_FLAGS : *mut u32 = (0x02000200) as *mut u32;
const ETH_RXDATA: *mut u32 = (0x02000204) as *mut u32;
pub fn eth_get_rxready() -> u8 {
unsafe {
let full = read_volatile(ETH_FLAGS) as u32;
return (full & 0x0001) as u8;
}
}
pub fn eth_enable_rx_clear() {
unsafe {
let bitmasked = read_volatile(ETH_FLAGS) & (!0x0100) as u32;
write_volatile(ETH_FLAGS, (0x0100 | bitmasked) as u32);
}
}
pub fn eth_disable_rx_clear() {
unsafe {
let bitmasked = read_volatile(ETH_FLAGS) & (!0x0100) as u32;
write_volatile(ETH_FLAGS, (0x0000 | bitmasked) as u32);
}
}
pub fn eth_read_rxdat() -> u32 {
unsafe {
return read_volatile(ETH_RXDATA) as u32;
}
}
// Helper functions
pub fn eth_get_byte_from_dat(dat: u32) -> u8 {
unsafe {
return (dat & 0x00FF) as u8;
}
}
pub fn eth_get_eop_from_dat(dat: u32) -> u8 {
unsafe {
return ((dat & 0x0100) >> 8) as u8;
}
}
pub fn eth_get_nodat_from_dat(dat: u32) -> u8 {
unsafe {
return ((dat & 0x0200) >> 9) as u8;
}
}