add dummy syncro

master
histausse 2 years ago
parent a01b2dff60
commit 571a2c995e
Signed by: histausse
GPG Key ID: 67486F107F62E9E9

@ -88,6 +88,16 @@ def task_install_dep():
], ],
} }
def task_check():
""" Run a compiler check on the code.
"""
task = {
'file_dep': get_build_dep(),
'actions': [f'RUSTFLAGS="{consts.RUSTC_FLAGS}" cargo check --target={consts.TARGET} {consts.CARGO_COMPILE_FLAGS}'],
}
print(task)
return task
def task_compile(): def task_compile():
""" Compile the sources. """ Compile the sources.
""" """

@ -0,0 +1,5 @@
#!/usr/bin/sh
udisksctl mount -b /dev/disk/by-label/BOOT
cp kernel8.img /run/media/me/BOOT/kernel8.img
udisksctl unmount -b /dev/disk/by-label/BOOT

@ -4,24 +4,27 @@ use core::arch::asm;
use core::fmt; use core::fmt;
use crate::traits::console::{Write, Console}; use crate::traits::console::{Write, Console};
use crate::traits::synchronization::{DummyMutex, Mutex};
use super::memory_map::uart as mm; use super::memory_map::uart as mm;
pub struct Uart<'a> { pub struct Uart<'a> {
inner: DummyMutex<UartInner<'a>>,
}
pub struct UartInner<'a> {
initialized: bool, initialized: bool,
memory_map: &'a mm::UartMemoryMap, memory_map: &'a mm::UartMemoryMap,
} }
impl<'a> Uart<'a> { impl<'a> UartInner<'a> {
// TODO: not sure this should be public outside of bsp.
/// Constructor for [`Uart`]. /// Constructor for [`Uart`].
pub const fn new(memory_map: &'a mm::UartMemoryMap) -> Self { const fn new(memory_map: &'a mm::UartMemoryMap) -> Self {
Uart { initialized: false, memory_map } Self { initialized: false, memory_map }
} }
/// Initialise the UART. /// Initialise the UART.
pub fn init(&mut self) { fn init(&mut self) {
// TODO: Recover from possible previous test. // TODO: Recover from possible previous test.
self.flush(); self.flush();
@ -68,55 +71,80 @@ impl<'a> Uart<'a> {
fn is_tx_full(&self) -> bool { fn is_tx_full(&self) -> bool {
self.memory_map.fr_txff.read() != 0 self.memory_map.fr_txff.read() != 0
} }
/// Write a character to the Uart
fn write_char(&self, c: char) {
if !self.initialized {
panic!("Cannot write to a non initialized UART");
}
while self.is_tx_full() {
use super::gpio;
let _ = gpio::set_pin_output_state(20, gpio::PinOutputState::High);
unsafe { asm!("nop") };
}
self.memory_map.dr_data.write_without_read(c as u32);
}
/// Flush the uart
fn flush(&self) {
while self.is_busy() {
unsafe { asm!("nop") };
}
}
} }
// Allow the use of uart for fmt::Write::write_fmt. // Allow the use of uart for fmt::Write::write_fmt.
impl fmt::Write for Uart<'_> { impl fmt::Write for UartInner<'_> {
fn write_str(&mut self, s: &str) -> fmt::Result { fn write_str(&mut self, s: &str) -> fmt::Result {
for c in s.chars() { for c in s.chars() {
if c == '\n' { if c == '\n' {
Write::write_char(self, '\r'); UartInner::write_char(self, '\r');
} }
Write::write_char(self, c); UartInner::write_char(self, c);
} }
Ok(()) Ok(())
} }
} }
// TODO: add sync
impl Write for Uart<'_> { impl Write for Uart<'_> {
fn write_char(&self, c: char) { fn write_char(&self, c: char) {
if !self.initialized { self.inner.lock(|uart| uart.write_char(c))
//panic!("Cannot write to a non initialized UART");
}
while self.is_tx_full() {
use super::gpio;
let _ = gpio::set_pin_output_state(20, gpio::PinOutputState::High);
unsafe { asm!("nop") };
}
self.memory_map.dr_data.write_without_read(c as u32);
} }
fn write_fmt(&self, args: fmt::Arguments) -> fmt::Result { fn write_fmt(&self, args: fmt::Arguments) -> fmt::Result {
// TODO: use syncronisation here self.inner.lock(|uart| fmt::Write::write_fmt(uart, args))
let mut new_uart = Uart { initialized: self.initialized, memory_map: self.memory_map};
fmt::Write::write_fmt(&mut new_uart, args)
} }
fn flush(&self) { fn flush(&self) {
while self.is_busy() { self.inner.lock(|uart| uart.flush())
unsafe { asm!("nop") }; }
}
impl<'a> Uart<'a> {
// TODO: not sure this should be public? public in bsp only?
/// Create a new UART object
const fn new(memory_map: &'a mm::UartMemoryMap) -> Self {
Self {
inner: DummyMutex::new(
UartInner::new(memory_map)
)
} }
} }
/// Initialize the UART.
fn init(&self) {
self.inner.lock(|uart| uart.init())
}
} }
impl Console for Uart<'_> {} impl Console for Uart<'_> {}
static UART: Uart = Uart { initialized: true, memory_map: &mm::UART }; // TODO: use sync /// The UART object
static UART: Uart = Uart::new(&mm::UART);
pub fn init() { pub fn init() {
let mut uart = Uart::new(&mm::UART); UART.init();
uart.init();
} }
// TODO: move? // TODO: move?

Loading…
Cancel
Save