mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
create a serializable version of Spim
this works by blowing apart the structure and re-assembling it on the other side. The reason we can't simply pass it is because the hardware pointer to the core register violates a Rust safety rule, but Rust doesn't know that this pointer points to a hardware register that's immutable and static versus a regular block of memory that can go away.
This commit is contained in:
parent
ff3138b72b
commit
a8518f7fa1
2 changed files with 67 additions and 4 deletions
|
|
@ -8,6 +8,7 @@ pub enum IframBank {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `IframRange` is a range of memory that is suitable for use as a DMA target.
|
/// `IframRange` is a range of memory that is suitable for use as a DMA target.
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct IframRange {
|
pub struct IframRange {
|
||||||
pub phys_range: MemoryRange,
|
pub phys_range: MemoryRange,
|
||||||
pub virt_range: MemoryRange,
|
pub virt_range: MemoryRange,
|
||||||
|
|
|
||||||
|
|
@ -203,7 +203,7 @@ impl Into<u32> for PeriphEventType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
#[derive(Copy, Clone, num_derive::FromPrimitive)]
|
#[derive(Debug, Copy, Clone, num_derive::FromPrimitive)]
|
||||||
pub enum EventChannel {
|
pub enum EventChannel {
|
||||||
Channel0 = 0,
|
Channel0 = 0,
|
||||||
Channel1 = 8,
|
Channel1 = 8,
|
||||||
|
|
@ -799,7 +799,7 @@ pub enum SpimClkPha {
|
||||||
CaptureOnTrailing = 1,
|
CaptureOnTrailing = 1,
|
||||||
}
|
}
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum SpimCs {
|
pub enum SpimCs {
|
||||||
Cs0 = 0,
|
Cs0 = 0,
|
||||||
Cs1 = 1,
|
Cs1 = 1,
|
||||||
|
|
@ -807,13 +807,13 @@ pub enum SpimCs {
|
||||||
Cs3 = 3,
|
Cs3 = 3,
|
||||||
}
|
}
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||||
pub enum SpimMode {
|
pub enum SpimMode {
|
||||||
Standard = 0,
|
Standard = 0,
|
||||||
Quad = 1,
|
Quad = 1,
|
||||||
}
|
}
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum SpimByteAlign {
|
pub enum SpimByteAlign {
|
||||||
Enable = 0,
|
Enable = 0,
|
||||||
Disable = 1,
|
Disable = 1,
|
||||||
|
|
@ -935,6 +935,7 @@ pub enum SpimChannel {
|
||||||
Channel2,
|
Channel2,
|
||||||
Channel3,
|
Channel3,
|
||||||
}
|
}
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Spim {
|
pub struct Spim {
|
||||||
csr: CSR<u32>,
|
csr: CSR<u32>,
|
||||||
cs: SpimCs,
|
cs: SpimCs,
|
||||||
|
|
@ -1113,6 +1114,67 @@ impl Spim {
|
||||||
spim
|
spim
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// For creating a clone to the current SPIM handle passed through a thread.
|
||||||
|
///
|
||||||
|
/// Safety: can only be used on devices that are static for the life of the OS. Also, does nothing
|
||||||
|
/// to prevent races/contention for the underlying device. The main reason this is introduced is
|
||||||
|
/// to facilitate a panic handler for the graphics frame buffer, where we're about to kill the OS
|
||||||
|
/// anyways: we don't care about soundness guarantees after this point.
|
||||||
|
pub unsafe fn from_raw_parts(
|
||||||
|
csr: usize,
|
||||||
|
cs: SpimCs,
|
||||||
|
sot_wait: u8,
|
||||||
|
eot_wait: u8,
|
||||||
|
event_channel: Option<EventChannel>,
|
||||||
|
mode: SpimMode,
|
||||||
|
_align: SpimByteAlign,
|
||||||
|
ifram: IframRange,
|
||||||
|
tx_buf_len_bytes: usize,
|
||||||
|
rx_buf_len_bytes: usize,
|
||||||
|
dummy_cycles: u8,
|
||||||
|
) -> Self {
|
||||||
|
Spim {
|
||||||
|
csr: CSR::new(csr as *mut u32),
|
||||||
|
cs,
|
||||||
|
sot_wait,
|
||||||
|
eot_wait,
|
||||||
|
event_channel,
|
||||||
|
_align,
|
||||||
|
mode,
|
||||||
|
ifram,
|
||||||
|
tx_buf_len_bytes,
|
||||||
|
rx_buf_len_bytes,
|
||||||
|
dummy_cycles,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Blows a SPIM structure into parts that can be sent across a thread boundary.
|
||||||
|
///
|
||||||
|
/// Safety: this is only safe because the *mut u32 for the CSR doesn't change, because it's tied to
|
||||||
|
/// a piece of hardware, not some arbitrary block of memory.
|
||||||
|
pub unsafe fn into_raw_parts(
|
||||||
|
&self,
|
||||||
|
) -> (usize, SpimCs, u8, u8, Option<EventChannel>, SpimMode, SpimByteAlign, IframRange, usize, usize, u8)
|
||||||
|
{
|
||||||
|
(
|
||||||
|
self.csr.base() as usize,
|
||||||
|
self.cs,
|
||||||
|
self.sot_wait,
|
||||||
|
self.eot_wait,
|
||||||
|
self.event_channel,
|
||||||
|
self.mode,
|
||||||
|
self._align,
|
||||||
|
IframRange {
|
||||||
|
phys_range: self.ifram.phys_range,
|
||||||
|
virt_range: self.ifram.virt_range,
|
||||||
|
conn: self.ifram.conn,
|
||||||
|
},
|
||||||
|
self.tx_buf_len_bytes,
|
||||||
|
self.rx_buf_len_bytes,
|
||||||
|
self.dummy_cycles,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// The command buf is *always* a `u32`; so tie the type down here.
|
/// The command buf is *always* a `u32`; so tie the type down here.
|
||||||
fn cmd_buf_mut(&mut self) -> &mut [u32] {
|
fn cmd_buf_mut(&mut self) -> &mut [u32] {
|
||||||
&mut self.ifram.as_slice_mut()[(self.tx_buf_len_bytes + self.rx_buf_len_bytes) / size_of::<u32>()
|
&mut self.ifram.as_slice_mut()[(self.tx_buf_len_bytes + self.rx_buf_len_bytes) / size_of::<u32>()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue