kirdy/src/main.rs

89 lines
2.3 KiB
Rust
Raw Normal View History

2022-10-20 15:17:43 +08:00
#![no_main]
#![no_std]
2022-10-23 20:07:44 +08:00
use rtic::app;
2022-10-20 20:57:24 +08:00
mod device;
2022-10-21 12:05:55 +08:00
mod laser_diode;
2022-11-01 11:16:55 +08:00
mod network;
2022-10-22 21:00:17 +08:00
// If RTT is used, print panic info through RTT
#[cfg(feature = "RTT")]
use {core::panic::PanicInfo, rtt_target::rprintln};
2022-10-22 21:00:17 +08:00
#[cfg(feature = "RTT")]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
rprintln!("{}", info);
loop {}
}
// Otherwise use panic halt
#[cfg(not(feature = "RTT"))]
use panic_halt as _;
2022-10-20 15:17:43 +08:00
2022-10-23 20:07:44 +08:00
// #[entry]
2022-11-01 11:16:55 +08:00
#[app(device = stm32f4xx_hal::pac, peripherals = true, dispatchers = [TIM8_CC, TIM8_BRK_TIM12])]
2022-10-23 20:07:44 +08:00
mod app {
use crate::device::{boot::bootup, log_setup};
2022-11-01 11:16:55 +08:00
use crate::network::network;
use fugit::ExtU32;
use log::info;
use stm32f4xx_hal::watchdog::IndependentWatchdog;
use systick_monotonic::Systick;
2022-10-23 20:07:44 +08:00
#[monotonic(binds = SysTick, default = true)]
type SystickTimer = Systick<1000>;
#[shared]
struct Shared {}
2022-10-23 20:07:44 +08:00
#[local]
struct Local {
wd: IndependentWatchdog,
2022-11-01 11:16:55 +08:00
// server_storage: network::network::ServerStorage::new(),
server_handle: network::ServerHandle,
2022-10-23 20:07:44 +08:00
}
2022-10-22 21:00:17 +08:00
#[init( local = [server_storage: network::ServerStorage = network::ServerStorage::new()] )]
2022-10-23 20:07:44 +08:00
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
log_setup::init_log();
info!("Kirdy init");
2022-10-23 20:07:44 +08:00
let core_perif = cx.core;
let perif = cx.device;
2022-11-01 11:16:55 +08:00
let server_storage = cx.local.server_storage;
let (wd, systick, server_handle) = bootup(core_perif, perif, server_storage);
2022-10-23 20:07:44 +08:00
wd_feed::spawn().unwrap();
2022-11-01 11:16:55 +08:00
// server_poll::spawn().unwrap();
(
Shared {},
Local { wd, server_handle },
init::Monotonics(systick),
)
2022-10-23 20:07:44 +08:00
}
2022-10-20 20:57:24 +08:00
2022-10-23 20:07:44 +08:00
#[task(priority = 5, local = [wd])]
fn wd_feed(cx: wd_feed::Context) {
2022-10-23 20:07:44 +08:00
let start = monotonics::now();
let wd = cx.local.wd;
2022-11-01 11:16:55 +08:00
// info!("feed wd");
2022-10-20 20:57:24 +08:00
wd.feed();
2022-10-23 20:07:44 +08:00
wd_feed::spawn_at(start + 10_u32.millis()).unwrap();
2022-10-20 20:57:24 +08:00
}
2022-10-23 20:07:44 +08:00
2022-11-01 11:16:55 +08:00
#[task(binds = ETH, priority = 2, local = [server_handle, data: [u8; 512] = [0u8; 512]])]
fn server_poll(cx: server_poll::Context) {
2022-11-01 11:16:55 +08:00
let data = cx.local.data;
let server_handle = cx.local.server_handle;
server_handle.poll(data);
// server_poll::spawn_at(start + 10_u32.millis()).unwrap();
}
2022-10-23 20:07:44 +08:00
#[idle]
fn idle(_: idle::Context) -> ! {
loop {
cortex_m::asm::nop();
}
}
2022-10-22 15:49:01 +08:00
}