use core::num::NonZeroUsize;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct BlockRequestId(usize);
impl BlockRequestId {
pub const fn new(id: usize) -> Self {
Self(id)
}
}
impl From<BlockRequestId> for usize {
fn from(value: BlockRequestId) -> Self {
value.0
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum BlockTransferMode {
Fifo,
Dma,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct BlockBufferConfig {
pub block_size: NonZeroUsize,
pub align: usize,
pub dma_mask: Option<u64>,
}
impl BlockBufferConfig {
pub const fn new(block_size: NonZeroUsize, align: usize, dma_mask: Option<u64>) -> Self {
Self {
block_size,
align,
dma_mask,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum BlockTransferDirection {
Read,
Write,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum BlockTransferState {
#[default]
Idle,
Submitted {
id: BlockRequestId,
mode: BlockTransferMode,
direction: BlockTransferDirection,
},
Complete {
id: BlockRequestId,
mode: BlockTransferMode,
direction: BlockTransferDirection,
},
Failed {
id: BlockRequestId,
mode: BlockTransferMode,
direction: BlockTransferDirection,
},
}
impl BlockTransferState {
pub const fn id(self) -> Option<BlockRequestId> {
match self {
Self::Idle => None,
Self::Submitted { id, .. } | Self::Complete { id, .. } | Self::Failed { id, .. } => {
Some(id)
}
}
}
pub const fn mode(self) -> Option<BlockTransferMode> {
match self {
Self::Idle => None,
Self::Submitted { mode, .. }
| Self::Complete { mode, .. }
| Self::Failed { mode, .. } => Some(mode),
}
}
pub const fn direction(self) -> Option<BlockTransferDirection> {
match self {
Self::Idle => None,
Self::Submitted { direction, .. }
| Self::Complete { direction, .. }
| Self::Failed { direction, .. } => Some(direction),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum BlockPoll {
Pending,
Complete,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum DataCommandDirection {
Read,
Write,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum DataCommandState {
#[default]
Idle,
Submitted {
direction: DataCommandDirection,
cmd_index: u8,
block_size: u32,
block_count: u32,
},
}
#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub enum DataCommandPoll {
Pending,
Complete(crate::response::Response),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum CommandPoll {
Pending,
Complete,
}
#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub enum CommandResponsePoll {
Pending,
Complete(crate::response::Response),
}
#[derive(Clone, Copy, Debug)]
#[non_exhaustive]
pub enum OperationPoll<T> {
Pending,
Complete(T),
}
impl From<CommandResponsePoll> for OperationPoll<crate::response::Response> {
fn from(value: CommandResponsePoll) -> Self {
match value {
CommandResponsePoll::Pending => Self::Pending,
CommandResponsePoll::Complete(response) => Self::Complete(response),
}
}
}
impl From<DataCommandPoll> for OperationPoll<crate::response::Response> {
fn from(value: DataCommandPoll) -> Self {
match value {
DataCommandPoll::Pending => Self::Pending,
DataCommandPoll::Complete(response) => Self::Complete(response),
}
}
}
impl From<BlockPoll> for OperationPoll<()> {
fn from(value: BlockPoll) -> Self {
match value {
BlockPoll::Pending => Self::Pending,
BlockPoll::Complete => Self::Complete(()),
}
}
}