net: maintain NET_PENDING flag
This commit is contained in:
parent
689f33304d
commit
384b537555
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -4,6 +4,7 @@
|
|||||||
name = "adc2tcp"
|
name = "adc2tcp"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"bare-metal 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"cortex-m 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cortex-m 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"cortex-m-log 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cortex-m-log 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"cortex-m-rt 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cortex-m-rt 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -22,6 +22,7 @@ default-target = "thumbv7em-none-eabihf"
|
|||||||
panic-abort = { version = "0.3.1" }
|
panic-abort = { version = "0.3.1" }
|
||||||
panic-semihosting = { version = "0.5.1", optional = true }
|
panic-semihosting = { version = "0.5.1", optional = true }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
bare-metal = "0.2"
|
||||||
cortex-m = "0.5"
|
cortex-m = "0.5"
|
||||||
cortex-m-rt = { version = "0.6", features = ["device"] }
|
cortex-m-rt = { version = "0.6", features = ["device"] }
|
||||||
cortex-m-log = { version = "0.4", features = ["log-integration"] }
|
cortex-m-log = { version = "0.4", features = ["log-integration"] }
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -122,14 +122,16 @@ fn main() -> ! {
|
|||||||
|
|
||||||
// Update watchdog
|
// Update watchdog
|
||||||
wd.feed();
|
wd.feed();
|
||||||
led_red.off();
|
|
||||||
|
|
||||||
|
led_red.on();
|
||||||
|
cortex_m::interrupt::free(|cs| {
|
||||||
|
if !net::is_pending(cs) {
|
||||||
// Wait for interrupts
|
// Wait for interrupts
|
||||||
// if net.is_pending() {
|
|
||||||
led_green.on();
|
|
||||||
wfi();
|
wfi();
|
||||||
led_green.off();
|
net::clear_pending(cs);
|
||||||
// }
|
}
|
||||||
|
});
|
||||||
|
led_red.off();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
19
src/net.rs
19
src/net.rs
@ -1,6 +1,9 @@
|
|||||||
//! As there is only one peripheral, supporting data structures are
|
//! As there is only one peripheral, supporting data structures are
|
||||||
//! declared once and globally.
|
//! declared once and globally.
|
||||||
|
|
||||||
|
use core::cell::RefCell;
|
||||||
|
use cortex_m::interrupt::Mutex;
|
||||||
|
use bare_metal::CriticalSection;
|
||||||
use stm32f4xx_hal::{
|
use stm32f4xx_hal::{
|
||||||
stm32::{interrupt, Peripherals, NVIC, ETHERNET_MAC, ETHERNET_DMA},
|
stm32::{interrupt, Peripherals, NVIC, ETHERNET_MAC, ETHERNET_DMA},
|
||||||
};
|
};
|
||||||
@ -17,6 +20,7 @@ static mut TX_RING: Option<[RingEntry<TxDescriptor>; 2]> = None;
|
|||||||
// TODO: generate one from device id
|
// TODO: generate one from device id
|
||||||
const SRC_MAC: [u8; 6] = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
|
const SRC_MAC: [u8; 6] = [0x00, 0x00, 0xDE, 0xAD, 0xBE, 0xEF];
|
||||||
|
|
||||||
|
static NET_PENDING: Mutex<RefCell<bool>> = Mutex::new(RefCell::new(false));
|
||||||
|
|
||||||
pub fn run<F>(nvic: &mut NVIC, ethernet_mac: ETHERNET_MAC, ethernet_dma: ETHERNET_DMA, f: F) -> !
|
pub fn run<F>(nvic: &mut NVIC, ethernet_mac: ETHERNET_MAC, ethernet_dma: ETHERNET_DMA, f: F) -> !
|
||||||
where
|
where
|
||||||
@ -79,6 +83,21 @@ impl<'a> NetInterface<'a> {
|
|||||||
/// and TODO: set pending flag
|
/// and TODO: set pending flag
|
||||||
#[interrupt]
|
#[interrupt]
|
||||||
fn ETH() {
|
fn ETH() {
|
||||||
|
cortex_m::interrupt::free(|cs| {
|
||||||
|
*NET_PENDING.borrow(cs)
|
||||||
|
.borrow_mut() = true;
|
||||||
|
});
|
||||||
|
|
||||||
let p = unsafe { Peripherals::steal() };
|
let p = unsafe { Peripherals::steal() };
|
||||||
stm32_eth::eth_interrupt_handler(&p.ETHERNET_DMA);
|
stm32_eth::eth_interrupt_handler(&p.ETHERNET_DMA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_pending(cs: &CriticalSection) -> bool {
|
||||||
|
*NET_PENDING.borrow(cs)
|
||||||
|
.borrow()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear_pending(cs: &CriticalSection) {
|
||||||
|
*NET_PENDING.borrow(cs)
|
||||||
|
.borrow_mut() = false;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user