net: maintain NET_PENDING flag
This commit is contained in:
parent
689f33304d
commit
384b537555
|
@ -4,6 +4,7 @@
|
|||
name = "adc2tcp"
|
||||
version = "0.0.0"
|
||||
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-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)",
|
||||
|
|
|
@ -22,6 +22,7 @@ default-target = "thumbv7em-none-eabihf"
|
|||
panic-abort = { version = "0.3.1" }
|
||||
panic-semihosting = { version = "0.5.1", optional = true }
|
||||
log = "0.4"
|
||||
bare-metal = "0.2"
|
||||
cortex-m = "0.5"
|
||||
cortex-m-rt = { version = "0.6", features = ["device"] }
|
||||
cortex-m-log = { version = "0.4", features = ["log-integration"] }
|
||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -122,14 +122,16 @@ fn main() -> ! {
|
|||
|
||||
// Update watchdog
|
||||
wd.feed();
|
||||
led_red.off();
|
||||
|
||||
// Wait for interrupts
|
||||
// if net.is_pending() {
|
||||
led_green.on();
|
||||
wfi();
|
||||
led_green.off();
|
||||
// }
|
||||
led_red.on();
|
||||
cortex_m::interrupt::free(|cs| {
|
||||
if !net::is_pending(cs) {
|
||||
// Wait for interrupts
|
||||
wfi();
|
||||
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
|
||||
//! declared once and globally.
|
||||
|
||||
use core::cell::RefCell;
|
||||
use cortex_m::interrupt::Mutex;
|
||||
use bare_metal::CriticalSection;
|
||||
use stm32f4xx_hal::{
|
||||
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
|
||||
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) -> !
|
||||
where
|
||||
|
@ -79,6 +83,21 @@ impl<'a> NetInterface<'a> {
|
|||
/// and TODO: set pending flag
|
||||
#[interrupt]
|
||||
fn ETH() {
|
||||
cortex_m::interrupt::free(|cs| {
|
||||
*NET_PENDING.borrow(cs)
|
||||
.borrow_mut() = true;
|
||||
});
|
||||
|
||||
let p = unsafe { Peripherals::steal() };
|
||||
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