irq commit: this large commit gets interrupts working
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
57
src/main.rs
57
src/main.rs
@ -2,17 +2,68 @@
|
||||
#![no_main]
|
||||
|
||||
extern crate xous_riscv;
|
||||
mod syscalls;
|
||||
mod irq;
|
||||
|
||||
pub use irq::sys_interrupt_claim;
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
use xous_kernel_riscv_rt::xous_kernel_entry;
|
||||
use xous_riscv::register::{mcause, mstatus, mie, vmim, vmip};
|
||||
|
||||
|
||||
#[panic_handler]
|
||||
fn handle_panic(arg: &PanicInfo) -> ! {
|
||||
fn handle_panic(_arg: &PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
|
||||
use xous_riscv_rt::entry;
|
||||
#[entry]
|
||||
fn print_str(uart: *mut usize, s: &str) {
|
||||
for c in s.bytes() {
|
||||
unsafe { uart.write_volatile(c as usize) };
|
||||
}
|
||||
}
|
||||
|
||||
#[xous_kernel_entry]
|
||||
fn xous_main() -> ! {
|
||||
unsafe {
|
||||
vmim::write(0); // Disable all machine interrupts
|
||||
mie::set_msoft();
|
||||
mie::set_mtimer();
|
||||
mie::set_mext();
|
||||
mstatus::set_mie(); // Enable CPU interrupts
|
||||
}
|
||||
sys_interrupt_claim(2, |_| {
|
||||
let uart_ptr = 0xE000_1800 as *mut usize;
|
||||
print_str(uart_ptr, "hello, world!\r\n");
|
||||
// Acknowledge the IRQ
|
||||
unsafe {
|
||||
uart_ptr.add(0).read_volatile();
|
||||
|
||||
// Acknowledge the event
|
||||
uart_ptr.add(4).write_volatile(3);
|
||||
};
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
// Enable interrupts
|
||||
let uart_ptr = 0xE000_1800 as *mut usize;
|
||||
unsafe { uart_ptr.add(4).write_volatile(3) };
|
||||
unsafe { uart_ptr.add(5).write_volatile(3) };
|
||||
print_str(uart_ptr, "greetings!\r\n");
|
||||
|
||||
loop {
|
||||
unsafe { xous_riscv::asm::wfi() };
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn trap_handler() {
|
||||
let mc = mcause::read();
|
||||
let irqs_pending = vmip::read();
|
||||
|
||||
if mc.is_exception() {}
|
||||
|
||||
if irqs_pending != 0 {
|
||||
irq::handle(irqs_pending);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user