-
-
Save Azorlogh/334e212c61b414358f8c7d25daa44cdb to your computer and use it in GitHub Desktop.
nrf52840 timer attempt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![no_main] | |
#![no_std] | |
use core::cell::RefCell; | |
use cortex_m::{interrupt::Mutex, peripheral::NVIC, prelude::_embedded_hal_timer_CountDown}; | |
use cortex_m_rt::entry; | |
use hal::{ | |
pac::{interrupt, Interrupt, Peripherals, TIMER0}, | |
timer::Periodic, | |
Timer, | |
}; | |
use nrf52840_hal as hal; | |
static TIMER: Mutex<RefCell<Option<Timer<TIMER0, Periodic>>>> = Mutex::new(RefCell::new(None)); | |
#[entry] | |
fn main() -> ! { | |
let periph = Peripherals::take().unwrap(); | |
unsafe { | |
NVIC::unmask(Interrupt::TIMER0); | |
} | |
let mut timer = Timer::periodic(periph.TIMER0); | |
timer.enable_interrupt(); | |
timer.start(2_000_000u32); | |
cortex_m::interrupt::free(move |cs| { | |
*TIMER.borrow(cs).borrow_mut() = Some(timer); | |
}); | |
loop {} | |
} | |
#[interrupt] | |
fn TIMER0() { | |
cortex_m::interrupt::free(move |cs| { | |
let mut timer_cell = TIMER.borrow(cs).borrow_mut(); | |
let timer = timer_cell.as_mut().unwrap(); | |
timer.event_compare_cc0().reset(); | |
}) | |
} | |
#[panic_handler] | |
fn panic(_: &core::panic::PanicInfo) -> ! { | |
loop { | |
cortex_m::asm::bkpt(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment