2022-10-11 23:53:12 +02:00
|
|
|
//! The Judas kernel for raspberry pi.
|
|
|
|
//!
|
|
|
|
//! This is a kernel written in rust for raspberry pi 3 and 4.
|
|
|
|
//! This project is heavily inspired by https://github.com/rust-embedded/rust-raspberrypi-OS-tutorials,
|
|
|
|
//! but it's a project for discovering rust on embedded, so its architecture is less generic and
|
|
|
|
//! I'm trying to reuse knowledge from Telecom-Paris SE203 class as much as I can.
|
|
|
|
|
2022-10-14 23:43:30 +02:00
|
|
|
#![cfg_attr(not(test), no_main)]
|
|
|
|
#![cfg_attr(not(test), no_std)]
|
2022-10-11 23:53:12 +02:00
|
|
|
#![feature(format_args_nl)]
|
|
|
|
#![feature(panic_info_message)]
|
|
|
|
|
2022-10-14 13:21:36 +02:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2022-10-11 23:53:12 +02:00
|
|
|
mod traits;
|
|
|
|
mod bsp;
|
|
|
|
mod utils;
|
|
|
|
|
2022-10-14 23:43:30 +02:00
|
|
|
#[cfg(not(test))]
|
2022-10-11 23:53:12 +02:00
|
|
|
mod panic;
|
2022-10-14 23:43:30 +02:00
|
|
|
#[cfg(not(test))]
|
2022-10-11 23:53:12 +02:00
|
|
|
mod print;
|
|
|
|
|
2022-10-14 23:43:30 +02:00
|
|
|
#[cfg(not(test))]
|
2022-10-11 23:53:12 +02:00
|
|
|
use core::arch::global_asm;
|
2022-10-14 23:43:30 +02:00
|
|
|
#[cfg(not(test))]
|
2022-10-11 23:53:12 +02:00
|
|
|
use core::arch::asm;
|
|
|
|
|
|
|
|
// TODO: handle this with features
|
2022-11-15 23:37:52 +01:00
|
|
|
use crate::bsp::qemu::console::console;
|
|
|
|
//#[cfg(not(test))]
|
|
|
|
//use crate::bsp::rpi3::uart::console;
|
2022-10-14 23:43:30 +02:00
|
|
|
#[cfg(not(test))]
|
2022-10-11 23:53:12 +02:00
|
|
|
use crate::bsp::rpi3::gpio;
|
|
|
|
|
|
|
|
// TODO: move this to BSP
|
|
|
|
/// Pause the core with a infinit loop
|
2022-10-14 23:43:30 +02:00
|
|
|
#[cfg(not(test))]
|
2022-10-11 23:53:12 +02:00
|
|
|
#[inline(always)]
|
|
|
|
pub fn wait_forever() -> ! {
|
|
|
|
loop {
|
|
|
|
unsafe { asm!("wfe"); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: move this to BSP
|
2022-10-14 23:43:30 +02:00
|
|
|
#[cfg(not(test))]
|
2022-10-11 23:53:12 +02:00
|
|
|
global_asm!(include_str!("boot.s"));
|
|
|
|
|
|
|
|
/// Start the rust part of the kernel
|
2022-10-14 23:43:30 +02:00
|
|
|
#[cfg(not(test))]
|
2022-10-11 23:53:12 +02:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe fn _start_rust() -> ! {
|
2022-10-14 13:21:36 +02:00
|
|
|
|
|
|
|
// Set TX and RX function for pin 14 and 15
|
|
|
|
match gpio::set_pin_fonction(14, gpio::PinFunction::AltFunc0) {
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
match gpio::set_pin_fonction(15, gpio::PinFunction::AltFunc0) {
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
// Debut led
|
|
|
|
match gpio::set_pin_fonction(20, gpio::PinFunction::Output) {
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
match gpio::set_pin_output_state(20, gpio::PinOutputState::Low) {
|
|
|
|
_ => (),
|
|
|
|
}
|
2022-11-15 23:37:52 +01:00
|
|
|
//bsp::rpi3::uart::init();
|
2022-10-14 13:21:36 +02:00
|
|
|
println!("Hello there");
|
|
|
|
|
2022-11-15 23:37:52 +01:00
|
|
|
let mut buffer = ['X'; 200];
|
|
|
|
let mut i = 0;
|
|
|
|
let mut c = console().read_char();
|
|
|
|
console().write_char(c);
|
|
|
|
while c != '\r' && i < 199 {
|
|
|
|
buffer[i] = c;
|
|
|
|
c = console().read_char();
|
|
|
|
console().write_char(c);
|
|
|
|
i += 1;
|
|
|
|
}
|
|
|
|
buffer[i] = c;
|
|
|
|
i += 1;
|
|
|
|
let mut j = 0;
|
|
|
|
print!("Received: ");
|
|
|
|
while j < i {
|
|
|
|
print!("{}", buffer[j]);
|
|
|
|
j += 1;
|
|
|
|
}
|
|
|
|
println!("");
|
|
|
|
|
2022-10-11 23:53:12 +02:00
|
|
|
match gpio::set_pin_fonction(21, gpio::PinFunction::Output) {
|
|
|
|
Ok(()) => println!("Successfully set pin to output"),
|
|
|
|
Err(err) => println!("Failled to set pin: {err}"),
|
|
|
|
}
|
|
|
|
loop {
|
|
|
|
match gpio::set_pin_output_state(21, gpio::PinOutputState::High) {
|
2022-10-14 13:21:36 +02:00
|
|
|
Ok(()) => (),
|
|
|
|
Err(_err) => println!("Failled to set pin 21 to High"),
|
2022-10-11 23:53:12 +02:00
|
|
|
}
|
|
|
|
for _ in 0..5000000 {
|
|
|
|
asm!("nop");
|
|
|
|
}
|
|
|
|
match gpio::set_pin_output_state(21, gpio::PinOutputState::Low) {
|
2022-10-14 13:21:36 +02:00
|
|
|
Ok(()) => (),
|
|
|
|
Err(_err) => println!("Failled to set pin 21 to Low"),
|
2022-10-11 23:53:12 +02:00
|
|
|
}
|
|
|
|
for _ in 0..5000000 {
|
|
|
|
asm!("nop");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
println!("Hello there");
|
|
|
|
panic!("Paniccccccc")
|
|
|
|
*/
|
|
|
|
}
|
2022-10-14 23:43:30 +02:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
fn main() {}
|