/////////////////////// UART TYPE #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] pub enum UartType { Kernel, Log, Application, Invalid, } // from/to for Xous messages impl From for UartType { fn from(code: usize) -> Self { match code { 0 => UartType::Kernel, 1 => UartType::Log, 2 => UartType::Application, _ => UartType::Invalid, } } } impl Into 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 for UartType { fn into(self) -> u32 { match self { UartType::Kernel => 0, UartType::Log => 1, UartType::Application => 2, UartType::Invalid => 3, } } } /////////////////////// I2C // a small book-keeping struct used to report back to I2C requestors as to the status of a transaction #[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Eq, PartialEq)] 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, } #[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] pub enum I2cCallback { Result, Drop, } #[derive(Debug, Copy, Clone, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] pub struct I2cTransaction { pub bus_addr: u8, // write address and read address are encoded in the packet field below pub txbuf: Option<[u8; 258]>, // long enough for a 256-byte operation + 2 bytes of "register address" pub txlen: u32, pub rxbuf: Option<[u8; 258]>, pub rxlen: u32, pub timeout_ms: u32, pub status: I2cStatus, } impl I2cTransaction { pub fn new() -> Self { I2cTransaction{ bus_addr: 0, txbuf: None, txlen: 0, rxbuf: None, rxlen: 0, timeout_ms: 100, status: I2cStatus::Uninitialized } } } ////////////////////////////////// VIBE #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] pub enum VibePattern { Short, Long, Double, } impl From for VibePattern { fn from(pattern: usize) -> Self { match pattern { 0 => VibePattern::Long, 1 => VibePattern::Double, _ => VibePattern::Short, } } } impl Into for VibePattern { fn into(self) -> usize { match self { VibePattern::Long => 0, VibePattern::Double => 1, VibePattern::Short => 0xffff_ffff, } } } //////////////////////////////// CLOCK GATING (placeholder) #[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] pub enum ClockMode { Low, AllOn, } impl From for ClockMode { fn from(mode: usize) -> Self { match mode { 0 => ClockMode::Low, _ => ClockMode::AllOn, } } } impl Into for ClockMode { fn into(self) -> usize { match self { ClockMode::Low => 0, ClockMode::AllOn => 0xffff_ffff, } } } pub(crate) const SERVER_NAME_LLIO: &str = "_Low Level I/O manager_"; //////////////////////////////////// OPCODES #[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] pub(crate) enum Opcode { /// not tested - reboot RebootRequest, RebootSocConfirm, // all peripherals + CPU RebootCpuConfirm, // just the CPU, peripherals (in particular the USB debug bridge) keep state /// not tested - reboot address RebootVector, //(u32), /// not tested - set CRG parameters CrgMode, //(ClockMode), /// not tested -- set GPIO GpioDataOut, //(u32), GpioDataIn, GpioDataDrive, //(u32), GpioIntMask, //(u32), GpioIntAsFalling, //(u32), GpioIntPending, GpioIntEna, //(u32), //TODO GpioIntSubscribe, //(String<64>), // TODO /// not tested - set UART mux UartMux, //(UartType), /// not tested - information about the SoC build and revision //TODO InfoLitexId, //(String<64>), // TODO: returns the ASCII string baked into the FPGA that describes the FPGA build, inside Registration InfoDna, InfoGit, InfoPlatform, InfoTarget, InfoSeed, /// not tested -- power PowerAudio, //(bool), PowerSelf, //(bool), // setting this to false allows the EC to turn off our power PowerBoostMode, //(bool), EcSnoopAllow, //(bool), EcReset, EcPowerOn, SelfDestruct, //(u32), // requires a series of writes to enable /// not tested -- vibe Vibe, //(VibePattern), /// not tested -- xadc AdcVbus, AdcVccInt, AdcVccAux, AdcVccBram, AdcUsbN, AdcUsbP, AdcTemperature, AdcGpio5, AdcGpio2, /// not tested - I2C functions 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 /// not tested -- events //TODO EventComSubscribe, //(String<64>), //TODO EventRtcSubscribe, //(String<64>), EventUsbAttachSubscribe, //(String<64>), //TODO EventComEnable, //(bool), //TODO EventRtcEnable, //(bool), //TODO EventUsbAttachEnable, //(bool), } #[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)] pub(crate) enum EventCallback { Event, Drop, } #[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. }