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

View file

@ -1,13 +1,13 @@
#![cfg_attr(target_os = "none", no_std)]
#[cfg(not(any(target_os="xous")))]
#[cfg(not(any(target_os = "xous")))]
mod debug;
#[cfg(feature="tests")]
#[cfg(feature = "tests")]
pub mod pl230_tests;
use utralib::*;
use bitfield::bitfield;
use utralib::*;
#[repr(C, align(16))]
#[derive(Default)]
@ -24,21 +24,21 @@ struct ControlChannels {
pub channels: [ChannelControl; 8],
}
pub struct Pl230 {
pub csr: CSR<u32>,
pub mdma: CSR<u32>,
}
impl Pl230 {
#[cfg(not(any(target_os="xous")))]
#[cfg(not(any(target_os = "xous")))]
pub fn new() -> Self {
Pl230 {
csr: CSR::new(utralib::HW_PL230_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 {
let csr = xous::syscall::map_memory(
xous::MemoryAddress::new(utralib::HW_PL230_BASE),
@ -47,18 +47,15 @@ impl Pl230 {
xous::MemoryFlags::R | xous::MemoryFlags::W,
)
.unwrap();
let mdma = xous::syscall::map_memory(
xous::MemoryAddress::new(utralib::HW_MDMA_BASE),
None,
4096,
xous::MemoryFlags::R | xous::MemoryFlags::W,
)
.unwrap();
let mdma = xous::syscall::map_memory(
xous::MemoryAddress::new(utralib::HW_MDMA_BASE),
None,
4096,
xous::MemoryFlags::R | xous::MemoryFlags::W,
)
.unwrap();
Pl230 {
csr: CSR::new(csr.as_mut_ptr() as *mut u32),
mdma: CSR::new(mdma.as_mut_ptr() as *mut u32),
}
Pl230 { 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,
}
#[repr(u32)]
#[rustfmt::skip]
pub enum ArbitrateAfter {
XferEach = 0b0000,
Xfer2 = 0b0001,
@ -88,11 +86,11 @@ pub enum DmaCycleControl {
Stop = 0b000,
Basic = 0b001,
AutoRequest = 0b010,
PingPong = 0b011,
PingPong = 0b011,
MemoryScatterGatherPrimary = 0b100,
MemoryScatterGatherAlt = 0b101,
MemoryScatterGatherAlt = 0b101,
PeripheralScatterGatherPrimary = 0b110,
PeripheralScatterGatherAlt = 0b111,
PeripheralScatterGatherAlt = 0b111,
}
bitfield! {

View file

@ -1,19 +1,19 @@
pub mod units;
pub fn report_api(desc: &str, d: u32) {
#[cfg(not(any(target_os="xous")))]
#[cfg(not(any(target_os = "xous")))]
{
use core::fmt::Write;
let mut uart = crate::debug::Uart{};
let mut uart = crate::debug::Uart {};
writeln!(uart, "pl230: [{}] 0x{:x}", desc, d).ok();
}
#[cfg(target_os="xous")]
#[cfg(target_os = "xous")]
log::info!("pl230: [{}] 0x{:x}", desc, d);
}
pub fn pl230_tests() {
let mut pl230 = crate::Pl230::new();
units::basic_tests(&mut pl230);
#[cfg(feature="pio")]
#[cfg(feature = "pio")]
units::pio_test(&mut pl230);
}