format libs/xous-pl230

This commit is contained in:
bunnie 2024-01-14 19:24:12 +08:00
parent ee2c7ef140
commit 59c6d6ae77
3 changed files with 27 additions and 33 deletions

View file

@ -8,22 +8,21 @@ pub struct Uart {
impl Uart { impl Uart {
fn put_digit(&mut self, d: u8) { fn put_digit(&mut self, d: u8) {
let nyb = d & 0xF; let nyb = d & 0xF;
let c = if nyb < 10 { let c = if nyb < 10 { nyb + 0x30 } else { nyb + 0x61 - 10 };
nyb + 0x30
} else {
nyb + 0x61 - 10
};
assert!(c >= 0x30, "conversion failed!"); assert!(c >= 0x30, "conversion failed!");
self.putc(c); self.putc(c);
} }
pub fn put_hex(&mut self, c: u8) { pub fn put_hex(&mut self, c: u8) {
self.put_digit(c >> 4); self.put_digit(c >> 4);
self.put_digit(c & 0xF); self.put_digit(c & 0xF);
} }
pub fn newline(&mut self) { pub fn newline(&mut self) {
self.putc(0xa); self.putc(0xa);
self.putc(0xd); self.putc(0xd);
} }
pub fn print_hex_word(&mut self, word: u32) { pub fn print_hex_word(&mut self, word: u32) {
for &byte in word.to_be_bytes().iter() { for &byte in word.to_be_bytes().iter() {
self.put_hex(byte); self.put_hex(byte);
@ -42,7 +41,6 @@ impl Uart {
self.putc(c); self.putc(c);
} }
} }
} }
use core::fmt::{Error, Write}; use core::fmt::{Error, Write};
@ -74,9 +72,7 @@ mod debug_print_hardware {
#[macro_export] #[macro_export]
#[allow(unused_variables)] #[allow(unused_variables)]
macro_rules! print { macro_rules! print {
($($args:tt)+) => ({ ($($args:tt)+) => {{ () }};
()
});
} }
} }

View file

@ -6,8 +6,8 @@ mod debug;
#[cfg(feature = "tests")] #[cfg(feature = "tests")]
pub mod pl230_tests; pub mod pl230_tests;
use utralib::*;
use bitfield::bitfield; use bitfield::bitfield;
use utralib::*;
#[repr(C, align(16))] #[repr(C, align(16))]
#[derive(Default)] #[derive(Default)]
@ -24,7 +24,6 @@ struct ControlChannels {
pub channels: [ChannelControl; 8], pub channels: [ChannelControl; 8],
} }
pub struct Pl230 { pub struct Pl230 {
pub csr: CSR<u32>, pub csr: CSR<u32>,
pub mdma: CSR<u32>, pub mdma: CSR<u32>,
@ -38,6 +37,7 @@ impl Pl230 {
mdma: CSR::new(utralib::HW_MDMA_BASE as *mut u32), mdma: CSR::new(utralib::HW_MDMA_BASE as *mut u32),
} }
} }
#[cfg(target_os = "xous")] #[cfg(target_os = "xous")]
pub fn new() -> Self { pub fn new() -> Self {
let csr = xous::syscall::map_memory( let csr = xous::syscall::map_memory(
@ -55,10 +55,7 @@ impl Pl230 {
) )
.unwrap(); .unwrap();
Pl230 { Pl230 { csr: CSR::new(csr.as_mut_ptr() as *mut u32), mdma: CSR::new(mdma.as_mut_ptr() as *mut u32) }
csr: CSR::new(csr.as_mut_ptr() as *mut u32),
mdma: CSR::new(mdma.as_mut_ptr() as *mut u32),
}
} }
} }
@ -70,6 +67,7 @@ pub enum DmaWidth {
NoInc = 0b11, NoInc = 0b11,
} }
#[repr(u32)] #[repr(u32)]
#[rustfmt::skip]
pub enum ArbitrateAfter { pub enum ArbitrateAfter {
XferEach = 0b0000, XferEach = 0b0000,
Xfer2 = 0b0001, Xfer2 = 0b0001,