interrupt compiled
This commit is contained in:
@@ -10,11 +10,7 @@ path = "./src/bin/main.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32"] }
|
esp-bootloader-esp-idf = { version = "0.2.0", features = ["esp32"] }
|
||||||
esp-hal = { version = "=1.0.0-rc.0", features = [
|
esp-hal = { version = "=1.0.0-rc.0", features = ["esp32", "log-04", "rt", "unstable"] }
|
||||||
"esp32",
|
|
||||||
"log-04",
|
|
||||||
"unstable",
|
|
||||||
] }
|
|
||||||
log = "0.4.27"
|
log = "0.4.27"
|
||||||
embedded-io = "0.6.1"
|
embedded-io = "0.6.1"
|
||||||
embedded-io-async = "0.6.1"
|
embedded-io-async = "0.6.1"
|
||||||
|
|||||||
@@ -12,9 +12,12 @@ use esp_hal::{
|
|||||||
clock::CpuClock,
|
clock::CpuClock,
|
||||||
gpio::{Level, Output, OutputConfig},
|
gpio::{Level, Output, OutputConfig},
|
||||||
timer::Timer,
|
timer::Timer,
|
||||||
|
interrupt,
|
||||||
|
peripherals,
|
||||||
timer::timg::TimerGroup,
|
timer::timg::TimerGroup,
|
||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
use esp_hal::handler;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
@@ -23,6 +26,8 @@ extern crate alloc;
|
|||||||
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
|
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
|
||||||
esp_bootloader_esp_idf::esp_app_desc!();
|
esp_bootloader_esp_idf::esp_app_desc!();
|
||||||
|
|
||||||
|
static mut INTERRUPT_FIRED: bool = false;
|
||||||
|
|
||||||
#[esp_hal_embassy::main]
|
#[esp_hal_embassy::main]
|
||||||
async fn main(spawner: Spawner) {
|
async fn main(spawner: Spawner) {
|
||||||
esp_println::logger::init_logger_from_env();
|
esp_println::logger::init_logger_from_env();
|
||||||
@@ -32,35 +37,53 @@ async fn main(spawner: Spawner) {
|
|||||||
|
|
||||||
esp_alloc::heap_allocator!(size: 64 * 1024);
|
esp_alloc::heap_allocator!(size: 64 * 1024);
|
||||||
|
|
||||||
let timer_group1 = TimerGroup::new(peripherals.TIMG1);
|
let mut timer_group1 = TimerGroup::new(peripherals.TIMG1);
|
||||||
let timer0 = timer_group1.timer0;
|
let mut timer0 = timer_group1.timer0;
|
||||||
|
|
||||||
|
// make it periodic, 1 s per tick, enable interrupt
|
||||||
|
timer0.enable_interrupt(true);
|
||||||
|
timer0.enable_auto_reload(true);
|
||||||
|
timer0.load_value(Duration::from_secs(1)).unwrap();
|
||||||
|
timer0.start();
|
||||||
|
|
||||||
|
// enable NVIC entry for this timer
|
||||||
|
unsafe {
|
||||||
|
interrupt::enable(
|
||||||
|
peripherals::Interrupt::TG1_T0_LEVEL,
|
||||||
|
interrupt::Priority::Priority2, // medium priority for now
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize GPIO4 as output (starts LOW)
|
// Initialize GPIO4 as output (starts LOW)
|
||||||
let mut gpio4 = Output::new(peripherals.GPIO4, Level::Low, OutputConfig::default());
|
let mut gpio4 = Output::new(peripherals.GPIO4, Level::Low, OutputConfig::default());
|
||||||
|
|
||||||
info!("Embassy initialized!");
|
info!("Embassy initialized!");
|
||||||
loop {
|
loop {
|
||||||
gpio4.set_high();
|
|
||||||
info!("GPIO4 ON");
|
|
||||||
|
|
||||||
// Start timer for 1 second and block until done
|
let mut counter = 0;
|
||||||
let duration = Duration::from_secs(1);
|
while counter < 10000000 {
|
||||||
timer0.load_value(duration).unwrap();
|
counter += 1;
|
||||||
timer0.start();
|
}
|
||||||
info!("{:?}", duration);
|
|
||||||
|
|
||||||
// Wait until timer completes
|
unsafe {
|
||||||
while !timer0.is_interrupt_set() {}
|
if INTERRUPT_FIRED {
|
||||||
timer0.clear_interrupt();
|
info!("Timer interrupt fired!");
|
||||||
|
INTERRUPT_FIRED = false;
|
||||||
gpio4.set_low();
|
|
||||||
info!("GPIO4 OFF");
|
|
||||||
|
|
||||||
// Start timer for 1 second and block until done
|
|
||||||
timer0.load_value(duration).unwrap();
|
|
||||||
timer0.start();
|
|
||||||
|
|
||||||
while !timer0.is_interrupt_set() {}
|
|
||||||
timer0.clear_interrupt();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[handler]
|
||||||
|
fn TG1_T0_LEVEL() {
|
||||||
|
// Clear the interrupt
|
||||||
|
critical_section::with(|_cs| {
|
||||||
|
unsafe {
|
||||||
|
let mut tg1 = TimerGroup::new(peripherals::TIMG1::steal());
|
||||||
|
tg1.timer0.clear_interrupt();
|
||||||
|
|
||||||
|
INTERRUPT_FIRED = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user