xous-core/services/spinor/src/api.rs

71 lines
2.3 KiB
Rust
Raw Normal View History

pub(crate) const SERVER_NAME_SPINOR: &str = "_SPINOR Hardware Interface Server_";
pub const SPINOR_SIZE_BYTES: u32 = 128 * 1024 * 1024; // physical size of the device, used for hardware sanity checks on requests
pub const SPINOR_ERASE_SIZE: u32 = 0x1000; // this is the smallest sector size. 64k sectors also exist, but this implementation does not use them.
// note: logical lengths of regions are in xous::definitions
2021-07-13 14:28:46 +00:00
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
pub(crate) enum Opcode {
2021-07-13 14:28:46 +00:00
/// writes are split into multiple transactions. Must acquire exclusive rights before initiation
AcquireExclusive,
ReleaseExclusive,
/// a special token is reserved for writing to the SoC region, only one service is allowed to do that
RegisterSocToken,
/// program a region. Erase is accomplished by calling WriteRegion with all 0xFF's as data.
WriteRegion,
2021-07-13 14:28:46 +00:00
/// allow the susres manager to prevent new ops from happening during a suspend
AcquireSuspendLock,
ReleaseSuspendLock,
2021-07-13 16:01:09 +00:00
/// intra-thread messages for suspend and resume
SuspendInner,
ResumeInner,
2021-07-13 16:01:09 +00:00
/// internal interrupt handler ops
EccError,
2021-07-13 14:28:46 +00:00
}
// Erase/Write are uninterruptable operations. Split suspend/resume
// into a separate server to asynchronously manage this.
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
pub(crate) enum SusResOps {
/// Suspend/resume callback
SuspendResume,
2021-07-13 14:28:46 +00:00
/// exit the thread
Quit,
}
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone, Copy)]
pub(crate) struct WriteRegion {
2021-07-13 14:28:46 +00:00
/// the exclusive access ID
pub id: [u32; 4],
/// start address for the write; address 0 is start of FLASH.
pub start: u32,
/// set if the sector was checked to be erased already
pub clean_patch: bool,
2021-07-13 14:28:46 +00:00
/// length of data to write
pub len: u32,
/// return code
pub result: Option<SpinorError>,
/// data to write - up to one page
pub data: [u8; 4096],
2021-07-13 14:28:46 +00:00
}
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone, Copy, num_derive::FromPrimitive, num_derive::ToPrimitive)]
2021-07-13 14:28:46 +00:00
pub enum SpinorError {
NoError,
AbortNotErased,
EraseFailed,
WriteFailed,
VerifyFailed,
InvalidRequest,
ImplementationError,
AlignmentError,
2021-07-13 14:28:46 +00:00
IpcError,
BusyTryAgain,
IdMismatch,
NoId,
AccessDenied,
}