-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmain.rs
86 lines (72 loc) · 2.23 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#![no_std]
#![no_main]
// Needed for embassy macros
#![feature(type_alias_impl_trait)]
mod globals;
use crate::globals::println;
use embassy_executor::{task, Executor};
use embassy_futures::yield_now;
use riscv_rt::entry;
use static_cell::StaticCell;
#[entry]
fn main() -> ! {
// self::globals::setup();
let p = esp32c3_hal::pac::Peripherals::take().unwrap();
// Disable the RTC and TIMG watchdog timers
// Technically, the error still occurs even without this, but I've included it
// for completeness.
{
use esp32c3_hal::{clock::ClockControl, prelude::*, timer::TimerGroup, Rtc};
let system = p.SYSTEM.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let mut rtc = Rtc::new(p.RTC_CNTL);
let timer_group0 = TimerGroup::new(p.TIMG0, &clocks);
let mut wdt0 = timer_group0.wdt;
let timer_group1 = TimerGroup::new(p.TIMG1, &clocks);
let mut wdt1 = timer_group1.wdt;
rtc.rwdt.disable();
rtc.swd.disable();
wdt0.disable();
wdt1.disable();
}
println!("Booted");
static EXECUTOR: StaticCell<Executor> = StaticCell::new();
EXECUTOR.init(Executor::new()).run(move |spawner| {
spawner.spawn(network_task()).unwrap();
spawner.spawn(sensor_task()).unwrap();
});
}
#[task]
async fn network_task() {
println!("Started network_task");
let mut i = 0;
loop {
println!("In main(), i was {}", i);
i += 1;
yield_now().await; // Yield to ensure fairness
println!("After network yield");
}
}
#[task]
async fn sensor_task() {
println!("Started sensor_task");
let mut i = 0;
loop {
println!("In data(), i was {}", i);
i += 1;
yield_now().await; // Yield to ensure fairness
println!("after sensor yield");
}
}
#[export_name = "ExceptionHandler"]
fn custom_exception_handler(trap_frame: &riscv_rt::TrapFrame) -> ! {
let mcause = riscv::register::mcause::read();
println!(
"mcause bits: {:#b}, mcause cause: {:?}",
mcause.bits(),
mcause.cause(),
);
println!("return address register (ra): {:#x}", trap_frame.ra);
println!("trap_frame: {:?}", trap_frame);
loop {}
}