forked from M-Labs/ionpak-thermostat
move systick under board/
This commit is contained in:
parent
e5529a8b94
commit
225f3754a1
|
@ -3,6 +3,7 @@ use tm4c129x;
|
||||||
|
|
||||||
pub mod gpio;
|
pub mod gpio;
|
||||||
pub mod softspi;
|
pub mod softspi;
|
||||||
|
pub mod systick;
|
||||||
|
|
||||||
|
|
||||||
const UART_DIV: u32 = (((/*sysclk*/120_000_000 * 8) / /*baud*/115200) + 1) / 2;
|
const UART_DIV: u32 = (((/*sysclk*/120_000_000 * 8) / /*baud*/115200) + 1) / 2;
|
||||||
|
@ -168,6 +169,8 @@ pub fn init() {
|
||||||
setup_timer_pwm!(TIMER3);
|
setup_timer_pwm!(TIMER3);
|
||||||
setup_timer_pwm!(TIMER4);
|
setup_timer_pwm!(TIMER4);
|
||||||
setup_timer_pwm!(TIMER5);
|
setup_timer_pwm!(TIMER5);
|
||||||
|
|
||||||
|
systick::init();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
use cortex_m_rt::exception;
|
||||||
|
use cortex_m::peripheral::{SYST, syst::SystClkSource};
|
||||||
|
|
||||||
|
const SYSTICK_RATE: u32 = 1000;
|
||||||
|
|
||||||
|
static mut TIME: u64 = 0;
|
||||||
|
|
||||||
|
pub fn init() {
|
||||||
|
unsafe { TIME = 0 };
|
||||||
|
|
||||||
|
#[allow(mutable_transmutes)]
|
||||||
|
let syst: &mut SYST = unsafe { core::mem::transmute(&*SYST::ptr()) };
|
||||||
|
syst.set_clock_source(SystClkSource::Core);
|
||||||
|
syst.set_reload(100 * SYST::get_ticks_per_10ms() / SYSTICK_RATE);
|
||||||
|
syst.clear_current();
|
||||||
|
syst.enable_interrupt();
|
||||||
|
syst.enable_counter();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[exception]
|
||||||
|
unsafe fn SysTick() {
|
||||||
|
TIME += u64::from(1000 / SYSTICK_RATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_time() -> u64 {
|
||||||
|
unsafe { TIME }
|
||||||
|
}
|
|
@ -2,9 +2,8 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use cortex_m_rt::{entry, exception};
|
use cortex_m_rt::entry;
|
||||||
use core::fmt::{self, Write};
|
use core::fmt::{self, Write};
|
||||||
use cortex_m::peripheral::{SYST, syst::SystClkSource};
|
|
||||||
use smoltcp::time::Instant;
|
use smoltcp::time::Instant;
|
||||||
use smoltcp::wire::{IpCidr, IpAddress, EthernetAddress};
|
use smoltcp::wire::{IpCidr, IpAddress, EthernetAddress};
|
||||||
use smoltcp::iface::{NeighborCache, EthernetInterfaceBuilder};
|
use smoltcp::iface::{NeighborCache, EthernetInterfaceBuilder};
|
||||||
|
@ -33,7 +32,7 @@ pub fn panic_fmt(info: &core::panic::PanicInfo) -> ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod board;
|
mod board;
|
||||||
use self::board::gpio::Gpio;
|
use self::board::{gpio::Gpio, systick::get_time};
|
||||||
mod ethmac;
|
mod ethmac;
|
||||||
mod ad7172;
|
mod ad7172;
|
||||||
|
|
||||||
|
@ -76,7 +75,6 @@ fn main() -> ! {
|
||||||
writeln!(stdout, "ionpak boot").unwrap();
|
writeln!(stdout, "ionpak boot").unwrap();
|
||||||
board::init();
|
board::init();
|
||||||
writeln!(stdout, "board initialized").unwrap();
|
writeln!(stdout, "board initialized").unwrap();
|
||||||
init_systick();
|
|
||||||
|
|
||||||
println!(r#"
|
println!(r#"
|
||||||
_ _
|
_ _
|
||||||
|
@ -179,7 +177,6 @@ fn main() -> ! {
|
||||||
tcp_handle7,
|
tcp_handle7,
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut time = 0i64;
|
|
||||||
let mut data = None;
|
let mut data = None;
|
||||||
// if a socket has sent the latest data
|
// if a socket has sent the latest data
|
||||||
let mut socket_pending = [false; 8];
|
let mut socket_pending = [false; 8];
|
||||||
|
@ -226,32 +223,9 @@ fn main() -> ! {
|
||||||
*pending = false;
|
*pending = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match iface.poll(&mut sockets, Instant::from_millis(time)) {
|
match iface.poll(&mut sockets, Instant::from_millis(get_time() as i64)) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => println!("poll error: {}", e)
|
Err(e) => println!("poll error: {}", e)
|
||||||
}
|
}
|
||||||
time += 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const SYSTICK_RATE: u32 = 1000;
|
|
||||||
static mut TIME: u32 = 0;
|
|
||||||
|
|
||||||
pub fn get_time() -> u32 {
|
|
||||||
unsafe { TIME }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[exception]
|
|
||||||
fn SysTick() {
|
|
||||||
unsafe { TIME += 1000 / SYSTICK_RATE; }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn init_systick() {
|
|
||||||
#[allow(mutable_transmutes)]
|
|
||||||
let syst: &mut SYST = unsafe { core::mem::transmute(&*SYST::ptr()) };
|
|
||||||
syst.set_clock_source(SystClkSource::Core);
|
|
||||||
syst.set_reload(100 * SYST::get_ticks_per_10ms() / SYSTICK_RATE);
|
|
||||||
syst.clear_current();
|
|
||||||
syst.enable_interrupt();
|
|
||||||
syst.enable_counter();
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue