oh god interrupt data sharing
Some checks failed
ci / Check build (push) Has been cancelled
ci / Check formatting (push) Has been cancelled
ci / Check Documentation Build (push) Has been cancelled
ci / Clippy (push) Has been cancelled
ci / Check build (pull_request) Has been cancelled
ci / Check formatting (pull_request) Has been cancelled
ci / Check Documentation Build (pull_request) Has been cancelled
ci / Clippy (pull_request) Has been cancelled
Some checks failed
ci / Check build (push) Has been cancelled
ci / Check formatting (push) Has been cancelled
ci / Check Documentation Build (push) Has been cancelled
ci / Clippy (push) Has been cancelled
ci / Check build (pull_request) Has been cancelled
ci / Check formatting (pull_request) Has been cancelled
ci / Check Documentation Build (pull_request) Has been cancelled
ci / Clippy (pull_request) Has been cancelled
This commit is contained in:
@@ -43,6 +43,7 @@ embassy-executor = { path = "../../../../Rust/embassy/embassy-executor", feature
|
|||||||
# embassy-time = { git = "https://github.com/us-irs/embassy", branch = "local-cortex-ar", version = "0.4", features = ["tick-hz-1_000_000"] }
|
# embassy-time = { git = "https://github.com/us-irs/embassy", branch = "local-cortex-ar", version = "0.4", features = ["tick-hz-1_000_000"] }
|
||||||
embassy-time = { path = "../../../../Rust/embassy/embassy-time", version = "0.4", features = ["tick-hz-1_000_000"] }
|
embassy-time = { path = "../../../../Rust/embassy/embassy-time", version = "0.4", features = ["tick-hz-1_000_000"] }
|
||||||
embassy-net = { path = "../../../../Rust/embassy/embassy-net", version = "0.7", features = ["dhcpv4"] }
|
embassy-net = { path = "../../../../Rust/embassy/embassy-net", version = "0.7", features = ["dhcpv4"] }
|
||||||
|
embassy-sync = { path = "../../../../Rust/embassy/embassy-sync", version = "0.7" }
|
||||||
heapless = "0.8"
|
heapless = "0.8"
|
||||||
axi-uartlite = { git = "https://egit.irs.uni-stuttgart.de/rust/axi-uartlite.git" }
|
axi-uartlite = { git = "https://egit.irs.uni-stuttgart.de/rust/axi-uartlite.git" }
|
||||||
axi-uart16550 = { git = "https://egit.irs.uni-stuttgart.de/rust/axi-uart16550.git" }
|
axi-uart16550 = { git = "https://egit.irs.uni-stuttgart.de/rust/axi-uart16550.git" }
|
||||||
|
|||||||
@@ -1,20 +1,23 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use core::{mem::MaybeUninit, panic::PanicInfo};
|
use core::{cell::RefCell, mem::MaybeUninit, panic::PanicInfo};
|
||||||
use cortex_ar::asm::nop;
|
use cortex_ar::asm::nop;
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_time::{Duration, Ticker, WithTimeout};
|
use embassy_time::{Duration, Ticker, Timer};
|
||||||
use embedded_hal::digital::StatefulOutputPin;
|
use embedded_hal::digital::StatefulOutputPin;
|
||||||
use embedded_io::Write;
|
use embedded_io::Write;
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use rand::{RngCore, SeedableRng};
|
use rand::{RngCore, SeedableRng};
|
||||||
use zedboard::PS_CLOCK_FREQUENCY;
|
use zedboard::{PS_CLOCK_FREQUENCY, phy_marvell::LatchingLinkStatus};
|
||||||
use zynq7000_hal::{
|
use zynq7000_hal::{
|
||||||
BootMode,
|
BootMode,
|
||||||
clocks::Clocks,
|
clocks::Clocks,
|
||||||
configure_level_shifter,
|
configure_level_shifter,
|
||||||
eth::{AlignedBuffer, ClkConfigCollection, EthernetConfig, EthernetLowLevel},
|
eth::{
|
||||||
|
AlignedBuffer, ClkConfigCollection, EthernetConfig, EthernetLowLevel,
|
||||||
|
embassy_net::InterruptResult,
|
||||||
|
},
|
||||||
gic::{GicConfigurator, GicInterruptHelper, Interrupt},
|
gic::{GicConfigurator, GicInterruptHelper, Interrupt},
|
||||||
gpio::{GpioPins, Output, PinState},
|
gpio::{GpioPins, Output, PinState},
|
||||||
gtc::Gtc,
|
gtc::Gtc,
|
||||||
@@ -45,6 +48,26 @@ static ETH_RX_BUFS: static_cell::ConstStaticCell<[AlignedBuffer; NUM_RX_BUFS]> =
|
|||||||
static ETH_TX_BUFS: static_cell::ConstStaticCell<[AlignedBuffer; NUM_TX_BUFS]> =
|
static ETH_TX_BUFS: static_cell::ConstStaticCell<[AlignedBuffer; NUM_TX_BUFS]> =
|
||||||
static_cell::ConstStaticCell::new([AlignedBuffer([0; zynq7000_hal::eth::MTU]); NUM_TX_BUFS]);
|
static_cell::ConstStaticCell::new([AlignedBuffer([0; zynq7000_hal::eth::MTU]); NUM_TX_BUFS]);
|
||||||
|
|
||||||
|
static ETH_ERR_QUEUE: static_cell::ConstStaticCell<
|
||||||
|
embassy_sync::channel::Channel<
|
||||||
|
embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex,
|
||||||
|
InterruptResult,
|
||||||
|
8,
|
||||||
|
>,
|
||||||
|
> = static_cell::ConstStaticCell::new(embassy_sync::channel::Channel::new());
|
||||||
|
static ETH_ERR_SENDER: critical_section::Mutex<
|
||||||
|
RefCell<
|
||||||
|
Option<
|
||||||
|
embassy_sync::channel::Sender<
|
||||||
|
'static,
|
||||||
|
embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex,
|
||||||
|
InterruptResult,
|
||||||
|
8,
|
||||||
|
>,
|
||||||
|
>,
|
||||||
|
>,
|
||||||
|
> = critical_section::Mutex::new(RefCell::new(None));
|
||||||
|
|
||||||
/// See memory.x file. 1 MB starting at this address will be configured as uncached memory using the
|
/// See memory.x file. 1 MB starting at this address will be configured as uncached memory using the
|
||||||
/// MMU.
|
/// MMU.
|
||||||
const UNCACHED_ADDR: u32 = 0x4000000;
|
const UNCACHED_ADDR: u32 = 0x4000000;
|
||||||
@@ -74,6 +97,14 @@ async fn led_task(mut mio_led: Output) -> ! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub enum IpMode {
|
||||||
|
LinkDown,
|
||||||
|
AutoNegotiating,
|
||||||
|
AwaitingIpConfig,
|
||||||
|
StackReady,
|
||||||
|
}
|
||||||
|
|
||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
#[unsafe(export_name = "main")]
|
#[unsafe(export_name = "main")]
|
||||||
async fn main(spawner: Spawner) -> ! {
|
async fn main(spawner: Spawner) -> ! {
|
||||||
@@ -215,11 +246,18 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
RESOURCES.init(embassy_net::StackResources::new()),
|
RESOURCES.init(embassy_net::StackResources::new()),
|
||||||
rng.next_u64(),
|
rng.next_u64(),
|
||||||
);
|
);
|
||||||
|
let eth_err_queue = ETH_ERR_QUEUE.take();
|
||||||
|
let sender = eth_err_queue.sender();
|
||||||
|
let receiver = eth_err_queue.receiver();
|
||||||
|
critical_section::with(|cs| {
|
||||||
|
let mut sender_ref = ETH_ERR_SENDER.borrow(cs).borrow_mut();
|
||||||
|
sender_ref.replace(sender);
|
||||||
|
});
|
||||||
spawner.spawn(embassy_net_task(runner)).unwrap();
|
spawner.spawn(embassy_net_task(runner)).unwrap();
|
||||||
|
|
||||||
let mut mio_led = Output::new_for_mio(gpio_pins.mio.mio7, PinState::Low);
|
let mut mio_led = Output::new_for_mio(gpio_pins.mio.mio7, PinState::Low);
|
||||||
|
|
||||||
spawner.spawn(led_task(mio_led)).unwrap();
|
//spawner.spawn(led_task(mio_led)).unwrap();
|
||||||
|
|
||||||
let mut _emio_leds: [Output; 8] = [
|
let mut _emio_leds: [Output; 8] = [
|
||||||
Output::new_for_emio(gpio_pins.emio.take(0).unwrap(), PinState::Low),
|
Output::new_for_emio(gpio_pins.emio.take(0).unwrap(), PinState::Low),
|
||||||
@@ -231,23 +269,20 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
Output::new_for_emio(gpio_pins.emio.take(6).unwrap(), PinState::Low),
|
Output::new_for_emio(gpio_pins.emio.take(6).unwrap(), PinState::Low),
|
||||||
Output::new_for_emio(gpio_pins.emio.take(7).unwrap(), PinState::Low),
|
Output::new_for_emio(gpio_pins.emio.take(7).unwrap(), PinState::Low),
|
||||||
];
|
];
|
||||||
|
let mut ip_mode = IpMode::LinkDown;
|
||||||
loop {
|
loop {
|
||||||
// TODO: We have to check our own link state boolean/atomic here instead of the stack
|
while let Ok(msg) = receiver.try_receive() {}
|
||||||
// link. We have to periodically monitor the phy link state, and update the atomic from
|
match ip_mode {
|
||||||
// that value.
|
// Assuming that auto-negotiation is performed automatically.
|
||||||
//
|
IpMode::LinkDown => {
|
||||||
// If the link goes from up to down, we update the atomic and have to periodically check
|
mio_led.set_low();
|
||||||
// whether the link is up again.
|
zynq7000_hal::eth::embassy_net::update_link_state(
|
||||||
//
|
embassy_net::driver::LinkState::Down,
|
||||||
// If it does from down to up, wait for auto-negotiation to complete, and update the
|
);
|
||||||
// atomic from that value.
|
ip_mode = IpMode::AutoNegotiating;
|
||||||
if !stack.is_link_up() {
|
}
|
||||||
loop {
|
IpMode::AutoNegotiating => {
|
||||||
let config_up_fut = stack.wait_config_up();
|
|
||||||
let status = phy.read_copper_status();
|
let status = phy.read_copper_status();
|
||||||
// TODO: How is this related to the ethernet stack link state? Should we only
|
|
||||||
// update the link state to up once auto-negotiation is complete and the clock
|
|
||||||
// was configured correctly?
|
|
||||||
if status.auto_negotiation_complete() {
|
if status.auto_negotiation_complete() {
|
||||||
let extended_status = phy.read_copper_specific_status_register_1();
|
let extended_status = phy.read_copper_specific_status_register_1();
|
||||||
eth.configure_clock_and_speed_duplex(
|
eth.configure_clock_and_speed_duplex(
|
||||||
@@ -257,18 +292,33 @@ async fn main(spawner: Spawner) -> ! {
|
|||||||
extended_status.duplex().as_zynq7000_eth_duplex(),
|
extended_status.duplex().as_zynq7000_eth_duplex(),
|
||||||
&clk_collection,
|
&clk_collection,
|
||||||
);
|
);
|
||||||
eth.set_tx_rx_enable(true, true);
|
zynq7000_hal::eth::embassy_net::update_link_state(
|
||||||
}
|
embassy_net::driver::LinkState::Up,
|
||||||
match config_up_fut.with_timeout(Duration::from_millis(100)).await {
|
);
|
||||||
Ok(_) => break,
|
ip_mode = IpMode::AwaitingIpConfig;
|
||||||
Err(e) => todo!(),
|
} else {
|
||||||
|
Timer::after_millis(100).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
IpMode::AwaitingIpConfig => {
|
||||||
|
// TODO: Timeout, check for link down periodically.
|
||||||
|
stack.wait_config_up().await;
|
||||||
|
let network_config = stack.config_v4();
|
||||||
|
info!("Network configuration is up: DHCP config: {network_config:?}!",);
|
||||||
|
ip_mode = IpMode::StackReady;
|
||||||
|
mio_led.set_high();
|
||||||
|
}
|
||||||
|
IpMode::StackReady => {
|
||||||
|
let status = phy.read_copper_status();
|
||||||
|
if status.copper_link_status() == LatchingLinkStatus::DownSinceLastRead {
|
||||||
|
ip_mode = IpMode::LinkDown;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Now what? maybe UDP Server?
|
||||||
|
info!("stack is ready");
|
||||||
|
Timer::after_millis(100).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let network_config = stack.config_v4();
|
|
||||||
info!("Network configuration is up: DHCP config: {network_config:?}!",);
|
|
||||||
//mio_led.toggle().unwrap();
|
|
||||||
//ticker.next().await; // Wait for the next cycle of the ticker
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,6 +340,13 @@ pub extern "C" fn _irq_handler() {
|
|||||||
let result = zynq7000_hal::eth::embassy_net::on_interrupt(
|
let result = zynq7000_hal::eth::embassy_net::on_interrupt(
|
||||||
zynq7000_hal::eth::EthernetId::Eth0,
|
zynq7000_hal::eth::EthernetId::Eth0,
|
||||||
);
|
);
|
||||||
|
if result.has_anomalies() || result.has_errors() {
|
||||||
|
critical_section::with(|cs| {
|
||||||
|
let sender_ref = ETH_ERR_SENDER.borrow(cs).borrow_mut();
|
||||||
|
let sender_mut = sender_ref.unwrap();
|
||||||
|
sender_mut.try_send(result).ok();
|
||||||
|
})
|
||||||
|
}
|
||||||
// TODO: Send the result structure back to the main thread.
|
// TODO: Send the result structure back to the main thread.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ pub struct CopperControlRegister {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[bitbybit::bitenum(u1, exhaustive = true)]
|
#[bitbybit::bitenum(u1, exhaustive = true)]
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum LatchingLinkStatus {
|
pub enum LatchingLinkStatus {
|
||||||
Up = 1,
|
Up = 1,
|
||||||
DownSinceLastRead = 0,
|
DownSinceLastRead = 0,
|
||||||
|
|||||||
@@ -269,6 +269,8 @@ impl EthernetConfig {
|
|||||||
pub struct Ethernet {
|
pub struct Ethernet {
|
||||||
ll: ll::EthernetLowLevel,
|
ll: ll::EthernetLowLevel,
|
||||||
mdio: mdio::Mdio,
|
mdio: mdio::Mdio,
|
||||||
|
current_speed: Speed,
|
||||||
|
current_duplex: Duplex,
|
||||||
}
|
}
|
||||||
|
|
||||||
const IRQ_CONTROL: InterruptControl = InterruptControl::builder()
|
const IRQ_CONTROL: InterruptControl = InterruptControl::builder()
|
||||||
@@ -438,7 +440,12 @@ impl Ethernet {
|
|||||||
ll.configure_clock(config.init_clk_config, true);
|
ll.configure_clock(config.init_clk_config, true);
|
||||||
let mut mdio = mdio::Mdio::new(&ll, true);
|
let mut mdio = mdio::Mdio::new(&ll, true);
|
||||||
mdio.configure_clock_div(config.mdc_clk_div);
|
mdio.configure_clock_div(config.mdc_clk_div);
|
||||||
let mut eth = Ethernet { ll, mdio };
|
let mut eth = Ethernet {
|
||||||
|
ll,
|
||||||
|
mdio,
|
||||||
|
current_speed: Speed::Mbps1000,
|
||||||
|
current_duplex: Duplex::Full,
|
||||||
|
};
|
||||||
eth.set_rx_buf_descriptor_base_address(0);
|
eth.set_rx_buf_descriptor_base_address(0);
|
||||||
eth.set_tx_buf_descriptor_base_address(0);
|
eth.set_tx_buf_descriptor_base_address(0);
|
||||||
eth
|
eth
|
||||||
@@ -449,7 +456,22 @@ impl Ethernet {
|
|||||||
ll.configure_clock(config.init_clk_config, true);
|
ll.configure_clock(config.init_clk_config, true);
|
||||||
let mut mdio = mdio::Mdio::new(&ll, true);
|
let mut mdio = mdio::Mdio::new(&ll, true);
|
||||||
mdio.configure_clock_div(config.mdc_clk_div);
|
mdio.configure_clock_div(config.mdc_clk_div);
|
||||||
Ethernet { ll, mdio }
|
Ethernet {
|
||||||
|
ll,
|
||||||
|
mdio,
|
||||||
|
current_speed: Speed::Mbps1000,
|
||||||
|
current_duplex: Duplex::Full,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn speed(&self) -> Speed {
|
||||||
|
self.current_speed
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn duplex(&self) -> Duplex {
|
||||||
|
self.current_duplex
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset(&mut self) {
|
pub fn reset(&mut self) {
|
||||||
@@ -462,14 +484,9 @@ impl Ethernet {
|
|||||||
ll.enable_peripheral_clock();
|
ll.enable_peripheral_clock();
|
||||||
ll.reset(3);
|
ll.reset(3);
|
||||||
ll.initialize(true);
|
ll.initialize(true);
|
||||||
// Set these to sensible values, but these probably need to be set again after
|
// Set speed and duplex to sensible values, but these probably need to be set again after
|
||||||
// auto-negotiation has completed.
|
// auto-negotiation has completed.
|
||||||
ll.regs.modify_net_cfg(|mut net_cfg| {
|
ll.set_speed_and_duplex(Speed::Mbps1000, Duplex::Full);
|
||||||
net_cfg.set_full_duplex(true);
|
|
||||||
net_cfg.set_gigabit_enable(true);
|
|
||||||
net_cfg.set_speed_mode(SpeedMode::High100Mbps);
|
|
||||||
net_cfg
|
|
||||||
});
|
|
||||||
let macaddr_msbs = (u32::from(mac_address[5]) << 8) | u32::from(mac_address[4]);
|
let macaddr_msbs = (u32::from(mac_address[5]) << 8) | u32::from(mac_address[4]);
|
||||||
let macaddr_lsbs = (u32::from(mac_address[3]) << 24)
|
let macaddr_lsbs = (u32::from(mac_address[3]) << 24)
|
||||||
| (u32::from(mac_address[2]) << 16)
|
| (u32::from(mac_address[2]) << 16)
|
||||||
@@ -526,6 +543,24 @@ impl Ethernet {
|
|||||||
&mut self.ll.regs
|
&mut self.ll.regs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This function checks whether new auto-negotiated settings require driver settings
|
||||||
|
/// updates and perform them if necessary.
|
||||||
|
pub fn configure_clock_and_speed_duplex(
|
||||||
|
&mut self,
|
||||||
|
speed: Speed,
|
||||||
|
duplex: Duplex,
|
||||||
|
clk_collection: &ClkConfigCollection,
|
||||||
|
) {
|
||||||
|
if speed == self.current_speed && duplex == self.current_duplex {
|
||||||
|
// No change, do nothing.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.ll.set_tx_rx_enable(false, false);
|
||||||
|
self.ll
|
||||||
|
.configure_clock_and_speed_duplex(speed, duplex, clk_collection);
|
||||||
|
self.ll.set_tx_rx_enable(true, true);
|
||||||
|
}
|
||||||
|
|
||||||
delegate::delegate! {
|
delegate::delegate! {
|
||||||
to self.ll {
|
to self.ll {
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -537,21 +572,6 @@ impl Ethernet {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_tx_buf_descriptor_base_address(&mut self, addr: u32);
|
pub fn set_tx_buf_descriptor_base_address(&mut self, addr: u32);
|
||||||
|
|
||||||
pub fn configure_clock_and_speed_duplex(
|
|
||||||
&mut self,
|
|
||||||
speed: Speed,
|
|
||||||
duplex: Duplex,
|
|
||||||
clk_collection: &ClkConfigCollection
|
|
||||||
);
|
|
||||||
|
|
||||||
pub fn configure_clock_for_speed(
|
|
||||||
&mut self,
|
|
||||||
speed: Speed,
|
|
||||||
clk_collection: &ClkConfigCollection,
|
|
||||||
);
|
|
||||||
|
|
||||||
pub fn set_speed_and_duplex(&mut self, speed: Speed, duplex: Duplex);
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_tx_rx_enable(&mut self, tx_enable: bool, rx_enable: bool);
|
pub fn set_tx_rx_enable(&mut self, tx_enable: bool, rx_enable: bool);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user