2021-03-10 17:45:54 +00:00
|
|
|
/////////////////////// UART TYPE
|
2021-03-15 18:02:53 +00:00
|
|
|
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
2021-01-27 05:33:03 +00:00
|
|
|
pub enum UartType {
|
|
|
|
|
Kernel,
|
|
|
|
|
Log,
|
|
|
|
|
Application,
|
|
|
|
|
Invalid,
|
|
|
|
|
}
|
|
|
|
|
// from/to for Xous messages
|
|
|
|
|
impl From<usize> for UartType {
|
|
|
|
|
fn from(code: usize) -> Self {
|
|
|
|
|
match code {
|
|
|
|
|
0 => UartType::Kernel,
|
|
|
|
|
1 => UartType::Log,
|
|
|
|
|
2 => UartType::Application,
|
|
|
|
|
_ => UartType::Invalid,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl Into<usize> for UartType {
|
|
|
|
|
fn into(self) -> usize {
|
|
|
|
|
match self {
|
|
|
|
|
UartType::Kernel => 0,
|
|
|
|
|
UartType::Log => 1,
|
|
|
|
|
UartType::Application => 2,
|
|
|
|
|
UartType::Invalid => 3,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// for the actual bitmask going to hardware
|
|
|
|
|
impl Into<u32> for UartType {
|
|
|
|
|
fn into(self) -> u32 {
|
|
|
|
|
match self {
|
|
|
|
|
UartType::Kernel => 0,
|
|
|
|
|
UartType::Log => 1,
|
|
|
|
|
UartType::Application => 2,
|
|
|
|
|
UartType::Invalid => 3,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-10 17:45:54 +00:00
|
|
|
/////////////////////// I2C
|
2021-03-15 16:11:23 +00:00
|
|
|
// a small book-keeping struct used to report back to I2C requestors as to the status of a transaction
|
2021-03-17 08:06:06 +00:00
|
|
|
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Eq, PartialEq)]
|
2021-03-15 16:11:23 +00:00
|
|
|
pub enum I2cStatus {
|
|
|
|
|
/// used only as the default, should always be set to one of the below before sending
|
|
|
|
|
Uninitialized,
|
|
|
|
|
/// used by a managing process to indicate a request
|
|
|
|
|
RequestIncoming,
|
|
|
|
|
/// everything was OK, request in progress
|
|
|
|
|
ResponseInProgress,
|
|
|
|
|
/// we tried to process your request, but there was a timeout
|
|
|
|
|
ResponseTimeout,
|
|
|
|
|
/// I2C had a NACK on the request
|
|
|
|
|
ResponseNack,
|
|
|
|
|
/// the I2C bus is currently busy and your request was ignored
|
|
|
|
|
ResponseBusy,
|
|
|
|
|
/// the request was malformed
|
|
|
|
|
ResponseFormatError,
|
|
|
|
|
/// everything is OK, data here should be valid
|
|
|
|
|
ResponseReadOk,
|
|
|
|
|
/// everything is OK, write finished. data fields have no meaning
|
|
|
|
|
ResponseWriteOk,
|
|
|
|
|
}
|
2021-04-06 11:32:35 +00:00
|
|
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
|
|
|
|
pub enum I2cCallback {
|
|
|
|
|
Result,
|
|
|
|
|
Drop,
|
|
|
|
|
}
|
2021-03-15 18:02:53 +00:00
|
|
|
#[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
2021-01-27 05:33:03 +00:00
|
|
|
pub struct I2cTransaction {
|
2021-03-16 08:37:38 +00:00
|
|
|
pub bus_addr: u8,
|
2021-01-27 05:33:03 +00:00
|
|
|
// write address and read address are encoded in the packet field below
|
2021-03-17 20:00:38 +00:00
|
|
|
pub txbuf: Option<[u8; 258]>, // long enough for a 256-byte operation + 2 bytes of "register address"
|
2021-03-16 08:37:38 +00:00
|
|
|
pub txlen: u32,
|
2021-03-17 20:00:38 +00:00
|
|
|
pub rxbuf: Option<[u8; 258]>,
|
2021-03-16 08:37:38 +00:00
|
|
|
pub rxlen: u32,
|
|
|
|
|
pub timeout_ms: u32,
|
|
|
|
|
pub status: I2cStatus,
|
2021-01-27 05:33:03 +00:00
|
|
|
}
|
2021-03-10 17:45:54 +00:00
|
|
|
impl I2cTransaction {
|
|
|
|
|
pub fn new() -> Self {
|
2021-03-15 16:11:23 +00:00
|
|
|
I2cTransaction{ bus_addr: 0, txbuf: None, txlen: 0, rxbuf: None, rxlen: 0, timeout_ms: 100, status: I2cStatus::Uninitialized }
|
2021-03-10 17:45:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-01-27 05:33:03 +00:00
|
|
|
|
2021-03-10 17:45:54 +00:00
|
|
|
////////////////////////////////// VIBE
|
2021-03-15 18:02:53 +00:00
|
|
|
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
2021-01-27 05:33:03 +00:00
|
|
|
pub enum VibePattern {
|
|
|
|
|
Short,
|
|
|
|
|
Long,
|
|
|
|
|
Double,
|
|
|
|
|
}
|
|
|
|
|
impl From<usize> for VibePattern {
|
|
|
|
|
fn from(pattern: usize) -> Self {
|
|
|
|
|
match pattern {
|
|
|
|
|
0 => VibePattern::Long,
|
|
|
|
|
1 => VibePattern::Double,
|
2021-03-10 17:45:54 +00:00
|
|
|
_ => VibePattern::Short,
|
2021-01-27 05:33:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl Into<usize> for VibePattern {
|
|
|
|
|
fn into(self) -> usize {
|
|
|
|
|
match self {
|
|
|
|
|
VibePattern::Long => 0,
|
|
|
|
|
VibePattern::Double => 1,
|
|
|
|
|
VibePattern::Short => 0xffff_ffff,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-10 17:45:54 +00:00
|
|
|
//////////////////////////////// CLOCK GATING (placeholder)
|
2021-03-15 18:02:53 +00:00
|
|
|
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
2021-01-27 05:33:03 +00:00
|
|
|
pub enum ClockMode {
|
|
|
|
|
Low,
|
|
|
|
|
AllOn,
|
|
|
|
|
}
|
|
|
|
|
impl From<usize> for ClockMode {
|
|
|
|
|
fn from(mode: usize) -> Self {
|
|
|
|
|
match mode {
|
|
|
|
|
0 => ClockMode::Low,
|
|
|
|
|
_ => ClockMode::AllOn,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl Into<usize> for ClockMode {
|
|
|
|
|
fn into(self) -> usize {
|
|
|
|
|
match self {
|
|
|
|
|
ClockMode::Low => 0,
|
|
|
|
|
ClockMode::AllOn => 0xffff_ffff,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-06 11:32:35 +00:00
|
|
|
pub(crate) const SERVER_NAME_LLIO: &str = "_Low Level I/O manager_";
|
2021-03-10 17:45:54 +00:00
|
|
|
//////////////////////////////////// OPCODES
|
2021-04-06 11:32:35 +00:00
|
|
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
|
|
|
|
pub(crate) enum Opcode {
|
2021-01-27 05:33:03 +00:00
|
|
|
/// not tested - reboot
|
|
|
|
|
RebootRequest,
|
2021-01-27 18:56:00 +00:00
|
|
|
RebootSocConfirm, // all peripherals + CPU
|
|
|
|
|
RebootCpuConfirm, // just the CPU, peripherals (in particular the USB debug bridge) keep state
|
2021-01-27 05:33:03 +00:00
|
|
|
|
|
|
|
|
/// not tested - reboot address
|
2021-04-06 11:32:35 +00:00
|
|
|
RebootVector, //(u32),
|
2021-01-27 05:33:03 +00:00
|
|
|
|
|
|
|
|
/// not tested - set CRG parameters
|
2021-04-06 11:32:35 +00:00
|
|
|
CrgMode, //(ClockMode),
|
2021-01-27 05:33:03 +00:00
|
|
|
|
|
|
|
|
/// not tested -- set GPIO
|
2021-04-06 11:32:35 +00:00
|
|
|
GpioDataOut, //(u32),
|
2021-01-27 05:33:03 +00:00
|
|
|
GpioDataIn,
|
2021-04-06 11:32:35 +00:00
|
|
|
GpioDataDrive, //(u32),
|
|
|
|
|
GpioIntMask, //(u32),
|
|
|
|
|
GpioIntAsFalling, //(u32),
|
2021-01-27 05:33:03 +00:00
|
|
|
GpioIntPending,
|
2021-04-06 11:32:35 +00:00
|
|
|
GpioIntEna, //(u32),
|
|
|
|
|
//TODO GpioIntSubscribe, //(String<64>), // TODO
|
2021-01-27 05:33:03 +00:00
|
|
|
|
|
|
|
|
/// not tested - set UART mux
|
2021-04-06 11:32:35 +00:00
|
|
|
UartMux, //(UartType),
|
2021-01-27 05:33:03 +00:00
|
|
|
|
|
|
|
|
/// not tested - information about the SoC build and revision
|
2021-04-06 11:32:35 +00:00
|
|
|
//TODO InfoLitexId, //(String<64>), // TODO: returns the ASCII string baked into the FPGA that describes the FPGA build, inside Registration
|
2021-01-27 05:33:03 +00:00
|
|
|
InfoDna,
|
|
|
|
|
InfoGit,
|
|
|
|
|
InfoPlatform,
|
|
|
|
|
InfoTarget,
|
|
|
|
|
InfoSeed,
|
|
|
|
|
|
|
|
|
|
/// not tested -- power
|
2021-04-06 11:32:35 +00:00
|
|
|
PowerAudio, //(bool),
|
|
|
|
|
PowerSelf, //(bool), // setting this to false allows the EC to turn off our power
|
|
|
|
|
PowerBoostMode, //(bool),
|
|
|
|
|
EcSnoopAllow, //(bool),
|
2021-01-27 05:33:03 +00:00
|
|
|
EcReset,
|
|
|
|
|
EcPowerOn,
|
2021-04-06 11:32:35 +00:00
|
|
|
SelfDestruct, //(u32), // requires a series of writes to enable
|
2021-01-27 05:33:03 +00:00
|
|
|
|
|
|
|
|
/// not tested -- vibe
|
2021-04-06 11:32:35 +00:00
|
|
|
Vibe, //(VibePattern),
|
2021-01-27 20:03:30 +00:00
|
|
|
|
2021-03-10 18:57:58 +00:00
|
|
|
/// not tested -- xadc
|
|
|
|
|
AdcVbus,
|
|
|
|
|
AdcVccInt,
|
|
|
|
|
AdcVccAux,
|
|
|
|
|
AdcVccBram,
|
|
|
|
|
AdcUsbN,
|
|
|
|
|
AdcUsbP,
|
|
|
|
|
AdcTemperature,
|
|
|
|
|
AdcGpio5,
|
|
|
|
|
AdcGpio2,
|
|
|
|
|
|
2021-01-27 20:03:30 +00:00
|
|
|
/// not tested - I2C functions
|
2021-04-06 11:32:35 +00:00
|
|
|
I2cTxRx, //(I2cTransaction), // type (tx or rx) encoded in struct
|
|
|
|
|
/// callback repsonses from the I2C engine
|
|
|
|
|
I2cRegisterCallback, //(String<64>), // if TxRx is issued without first subscribing to responses, the read data is just "lost"
|
|
|
|
|
/// from i2c interrupt handler
|
|
|
|
|
IrqI2cTxrxDone, // internal API only
|
2021-01-27 20:03:30 +00:00
|
|
|
|
|
|
|
|
/// not tested -- events
|
2021-04-06 11:32:35 +00:00
|
|
|
//TODO EventComSubscribe, //(String<64>),
|
|
|
|
|
//TODO EventRtcSubscribe, //(String<64>),
|
|
|
|
|
EventUsbAttachSubscribe, //(String<64>),
|
|
|
|
|
//TODO EventComEnable, //(bool),
|
|
|
|
|
//TODO EventRtcEnable, //(bool),
|
|
|
|
|
//TODO EventUsbAttachEnable, //(bool),
|
2021-01-27 05:33:03 +00:00
|
|
|
}
|
2021-04-06 11:32:35 +00:00
|
|
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
|
|
|
|
pub(crate) enum EventCallback {
|
|
|
|
|
Event,
|
|
|
|
|
Drop,
|
2021-01-27 05:33:03 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-06 11:32:35 +00:00
|
|
|
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Copy, Clone)]
|
|
|
|
|
pub struct ScalarHook {
|
|
|
|
|
pub sid: (u32, u32, u32, u32),
|
|
|
|
|
pub id: u32, // ID of the scalar message to send through (e.g. the discriminant of the Enum on the caller's side API)
|
|
|
|
|
pub cid: xous::CID, // caller-side connection ID for the scalar message to route to. Created by the caller before hooking.
|
2021-01-27 05:33:03 +00:00
|
|
|
}
|
2021-04-06 11:32:35 +00:00
|
|
|
|