add dummy syncro

This commit is contained in:
histausse 2022-11-07 19:58:09 +01:00
parent a01b2dff60
commit 571a2c995e
Signed by: histausse
GPG key ID: 67486F107F62E9E9
3 changed files with 75 additions and 32 deletions

10
dodo.py
View file

@ -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.
""" """

5
flash.sh Executable file
View file

@ -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

View file

@ -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,26 +71,11 @@ 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
} }
}
// Allow the use of uart for fmt::Write::write_fmt. /// Write a character to the Uart
impl fmt::Write for Uart<'_> {
fn write_str(&mut self, s: &str) -> fmt::Result {
for c in s.chars() {
if c == '\n' {
Write::write_char(self, '\r');
}
Write::write_char(self, c);
}
Ok(())
}
}
// TODO: add sync
impl Write for Uart<'_> {
fn write_char(&self, c: char) { fn write_char(&self, c: char) {
if !self.initialized { if !self.initialized {
//panic!("Cannot write to a non initialized UART"); panic!("Cannot write to a non initialized UART");
} }
while self.is_tx_full() { while self.is_tx_full() {
use super::gpio; use super::gpio;
@ -97,12 +85,7 @@ impl Write for Uart<'_> {
self.memory_map.dr_data.write_without_read(c as u32); self.memory_map.dr_data.write_without_read(c as u32);
} }
fn write_fmt(&self, args: fmt::Arguments) -> fmt::Result { /// Flush the uart
// TODO: use syncronisation here
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() { while self.is_busy() {
unsafe { asm!("nop") }; unsafe { asm!("nop") };
@ -110,13 +93,58 @@ impl Write for Uart<'_> {
} }
} }
// Allow the use of uart for fmt::Write::write_fmt.
impl fmt::Write for UartInner<'_> {
fn write_str(&mut self, s: &str) -> fmt::Result {
for c in s.chars() {
if c == '\n' {
UartInner::write_char(self, '\r');
}
UartInner::write_char(self, c);
}
Ok(())
}
}
impl Write for Uart<'_> {
fn write_char(&self, c: char) {
self.inner.lock(|uart| uart.write_char(c))
}
fn write_fmt(&self, args: fmt::Arguments) -> fmt::Result {
self.inner.lock(|uart| fmt::Write::write_fmt(uart, args))
}
fn flush(&self) {
self.inner.lock(|uart| uart.flush())
}
}
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?