Readme and cleanup

This commit is contained in:
2025-05-30 08:42:43 +02:00
parent 20808a7992
commit a289dcfd17
6 changed files with 35 additions and 31 deletions

View File

@@ -1,9 +1,9 @@
use core::ptr::{read_volatile, write_volatile};
use core::result::Result;
use core::result::Result::Err;
use core::result::Result::Ok;
use crate::{
timer::delay_nops,
uart::{self},
};
use crate::timer::delay_nops;
const GPFSEL_BASE: u32 = 0x3F20_0000;
const GPSET_BASE: u32 = 0x3F20_001C;

View File

@@ -1,7 +1,4 @@
use core::{
arch::asm,
ptr::{read_volatile, write_volatile},
};
use core::ptr::{read_volatile, write_volatile};
use crate::uart::print;

6
src/lib.rs Normal file
View File

@@ -0,0 +1,6 @@
#![no_std]
pub mod gpio;
pub mod interrupt;
pub mod timer;
pub mod uart;

View File

@@ -7,17 +7,15 @@ use core::{
panic::PanicInfo,
};
use gpio::{
gpio_enable_low_detect, gpio_get_state, gpio_high, gpio_low, gpio_pull_up, set_gpio_state,
use nova::{
gpio::{
gpio_enable_low_detect, gpio_get_state, gpio_high, gpio_low, gpio_pull_up, set_gpio_state,
GPIOState,
},
interrupt::enable_iqr_source,
timer::{delay_nops, sleep},
uart::{print, uart_init},
};
use interrupt::enable_iqr_source;
use timer::{delay_nops, sleep};
use uart::print;
mod gpio;
mod interrupt;
mod timer;
mod uart;
global_asm!(include_str!("vector.S"));
@@ -28,7 +26,7 @@ extern "C" {
#[panic_handler]
fn panic(_panic: &PanicInfo) -> ! {
loop {
uart::print("Panic\r\n");
print("Panic\r\n");
}
}
@@ -46,19 +44,19 @@ pub unsafe extern "C" fn _start() {
#[no_mangle]
pub extern "C" fn main() -> ! {
uart::uart_init();
uart_init();
// Set ACT Led to Outout
let _ = set_gpio_state(21, gpio::GPIOState::Output);
let _ = set_gpio_state(21, GPIOState::Output);
// Set GPIO Pins to UART
let _ = set_gpio_state(14, gpio::GPIOState::Alternative0);
let _ = set_gpio_state(15, gpio::GPIOState::Alternative0);
let _ = set_gpio_state(14, GPIOState::Alternative0);
let _ = set_gpio_state(15, GPIOState::Alternative0);
print_current_el_str();
// Delay so clock speed can stabilize
delay_nops(50000);
uart::print("Hello World!\r\n");
print("Hello World!\r\n");
unsafe {
el2_to_el1();
@@ -69,14 +67,13 @@ pub extern "C" fn main() -> ! {
#[no_mangle]
pub extern "C" fn kernel_main() -> ! {
let el = get_current_el();
print_current_el_str();
sleep(500_000);
// Set GPIO 21 to Input
enable_iqr_source(49); //21 is on the first GPIO bank
let _ = set_gpio_state(21, gpio::GPIOState::Input);
let _ = set_gpio_state(21, GPIOState::Input);
gpio_pull_up(21);
gpio_enable_low_detect(21, true);

View File

@@ -16,6 +16,8 @@ vector_table:
ventry .
ventry irq_handler // IRQ(Interrupt Request) 0x280
ventry .
ventry .
.align 4
@@ -25,26 +27,23 @@ el2_to_el1:
mov x0, #(1 << 31)
msr HCR_EL2, x0
isb
// Set SPSR_EL2: return to EL1h (EL1, using SP_EL1)
// Set SPSR_EL2: return to EL1h
mov x0, #(0b0101)
msr SPSR_EL2, x0
isb
// Set return address to ELR_EL2
ldr x0, =kernel_main
msr ELR_EL2, x0
isb
// Set SP_EL1 to stack base
ldr x0, =__stack_end
msr SP_EL1, x0
isb
// Set VBAR_EL1 to vector table
adr x0, vector_table
msr VBAR_EL1, x0
isb
// Return to EL1