delay: is unsafe

This commit is contained in:
Astro 2019-08-08 01:57:30 +02:00
parent 44f48f6e0f
commit 4437a4195e
3 changed files with 7 additions and 5 deletions

View File

@ -11,9 +11,9 @@ pub struct Delay {
} }
impl Delay { impl Delay {
pub fn new() -> Self { /// unsafe: must only be used once to avoid concurrent use of systick
let mut cp = unsafe { tm4c129x::CorePeripherals::steal() }; pub unsafe fn new() -> Self {
let mut syst = cp.SYST; let mut syst = CorePeripherals::steal().SYST;
// PIOSC // PIOSC
syst.set_clock_source(SystClkSource::External); syst.set_clock_source(SystClkSource::External);
syst.disable_interrupt(); syst.disable_interrupt();

View File

@ -137,6 +137,7 @@ impl<'d, SCK: OutputPin, MOSI: OutputPin, MISO: InputPin, D: FnMut()> SyncSoftSp
} }
impl<'d, SCK: OutputPin, MOSI: OutputPin, MISO: InputPin, D: FnMut()> Transfer<u8> for SyncSoftSpi<'d, SCK, MOSI, MISO, D> { impl<'d, SCK: OutputPin, MOSI: OutputPin, MISO: InputPin, D: FnMut()> Transfer<u8> for SyncSoftSpi<'d, SCK, MOSI, MISO, D> {
// TODO: proper type
type Error = (); type Error = ();
fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> { fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> {
for b in words.iter_mut() { for b in words.iter_mut() {

View File

@ -53,6 +53,7 @@ mod ethmac;
static ADC_IRQ_COUNT: Mutex<Cell<u64>> = Mutex::new(Cell::new(0)); static ADC_IRQ_COUNT: Mutex<Cell<u64>> = Mutex::new(Cell::new(0));
// TODO: remove
fn get_time_ms() -> u64 { fn get_time_ms() -> u64 {
let adc_irq_count = cortex_m::interrupt::free(|cs| { let adc_irq_count = cortex_m::interrupt::free(|cs| {
ADC_IRQ_COUNT.borrow(cs).get() ADC_IRQ_COUNT.borrow(cs).get()
@ -115,8 +116,8 @@ fn main() -> ! {
| | | |
|_| |_|
"#); "#);
let mut delay = board::delay::Delay::new(); let mut delay = unsafe { board::delay::Delay::new() };
// SCK // CSn
let pb4 = board::gpio::PB4.into_output(); let pb4 = board::gpio::PB4.into_output();
// SCLK // SCLK
let pb5 = board::gpio::PB5.into_output(); let pb5 = board::gpio::PB5.into_output();