mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
add API framework for LLIO
This commit is contained in:
parent
3cd175fb49
commit
8ed37a0dcb
8 changed files with 702 additions and 1 deletions
13
Cargo.lock
generated
13
Cargo.lock
generated
|
|
@ -461,6 +461,19 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "llio"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"heapless",
|
||||
"log",
|
||||
"log-server",
|
||||
"ticktimer-server",
|
||||
"utralib",
|
||||
"xous",
|
||||
"xous-names",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.11"
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ members = [
|
|||
"services/log-server",
|
||||
"services/ticktimer-server",
|
||||
"services/com",
|
||||
"services/llio",
|
||||
"services/trng-tester",
|
||||
"services/fcc-agent",
|
||||
"services/xous-names",
|
||||
|
|
@ -31,6 +32,7 @@ default-members = [
|
|||
"services/xous-names",
|
||||
"services/keyboard",
|
||||
"services/com",
|
||||
"services/llio",
|
||||
"services/trng",
|
||||
"services/gam",
|
||||
"imports/blitstr-ref",
|
||||
|
|
|
|||
24
services/llio/Cargo.toml
Normal file
24
services/llio/Cargo.toml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
[package]
|
||||
name = "llio"
|
||||
version = "0.1.0"
|
||||
authors = ["bunnie <bunnie@kosagi.com>"]
|
||||
edition = "2018"
|
||||
description = "Low level IO"
|
||||
|
||||
[dependencies]
|
||||
xous = { path = "../../xous-rs" }
|
||||
heapless = "0.5"
|
||||
log-server = { path = "../log-server" }
|
||||
ticktimer-server = { path = "../ticktimer-server" }
|
||||
xous-names = { path = "../xous-names" }
|
||||
log = "0.4"
|
||||
|
||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||
utralib = { path = "../../utralib"}
|
||||
|
||||
[target.'cfg(any(windows,unix))'.dependencies]
|
||||
|
||||
[features]
|
||||
debugprint = []
|
||||
default = [] # "debugprint"
|
||||
#default = ["debugprint"] # , "fccagent"
|
||||
452
services/llio/src/api.rs
Normal file
452
services/llio/src/api.rs
Normal file
|
|
@ -0,0 +1,452 @@
|
|||
use xous::{Message, ScalarMessage};
|
||||
use xous_names::api::Registration;
|
||||
|
||||
pub const SUBTYPE_REGISTER_GPIO_LISTENER: u16 = 0;
|
||||
pub const SUBTYPE_REGISTER_COM_LISTENER: u16 = 1;
|
||||
pub const SUBTYPE_REGISTER_RTC_LISTENER: u16 = 2;
|
||||
pub const SUBTYPE_REGISTER_USB_LISTENER: u16 = 3;
|
||||
pub const SUBTYPE_I2C_WRITE: u16 = 4;
|
||||
pub const SUBTYPE_I2C_READ: u16 = 5;
|
||||
|
||||
#[derive(Debug)]
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct I2cTransaction {
|
||||
busAddr: u8,
|
||||
// write address and read address are encoded in the packet field below
|
||||
packet: [u8; 258], // up to 258 bytes total packet length; note cost is "same" b/c these are sent via 4kiB page remaps
|
||||
length: u8,
|
||||
// read or write type is encoded in the opcode
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum VibePattern {
|
||||
Short,
|
||||
Long,
|
||||
Double,
|
||||
}
|
||||
impl From<usize> for VibePattern {
|
||||
fn from(pattern: usize) -> Self {
|
||||
match pattern {
|
||||
_ => VibePattern::Short,
|
||||
0 => VibePattern::Long,
|
||||
1 => VibePattern::Double,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Into<usize> for VibePattern {
|
||||
fn into(self) -> usize {
|
||||
match self {
|
||||
VibePattern::Long => 0,
|
||||
VibePattern::Double => 1,
|
||||
VibePattern::Short => 0xffff_ffff,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub enum Opcode {
|
||||
/// not tested - reboot
|
||||
RebootRequest,
|
||||
RebootConfirm,
|
||||
|
||||
/// 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),
|
||||
GpioIntSubscribe(Registration),
|
||||
|
||||
/// not tested - set UART mux
|
||||
UartMux(UartType),
|
||||
|
||||
/// not tested - information about the SoC build and revision
|
||||
InfoLitexId, // returns the ASCII string baked into the FPGA that describes the FPGA build
|
||||
InfoDna,
|
||||
InfoGit,
|
||||
InfoPlatform,
|
||||
InfoTarget,
|
||||
InfoSeed,
|
||||
|
||||
/// not tested - I2C functions
|
||||
I2cWrite(I2cTransaction),
|
||||
I2cRead(I2cTransaction),
|
||||
|
||||
/// not tested -- events
|
||||
EventComSubscribe(Registration),
|
||||
EventRtcSubscribe(Registration),
|
||||
EventUsbAttachSubscribe(Registration),
|
||||
EventComEnable(bool),
|
||||
EventRtcEnable(bool),
|
||||
EventUsbAttachEnable(bool),
|
||||
|
||||
/// 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),
|
||||
}
|
||||
|
||||
impl core::convert::TryFrom<& Message> for Opcode {
|
||||
type Error = &'static str;
|
||||
fn try_from(message: & Message) -> Result<Self, Self::Error> {
|
||||
match message {
|
||||
Message::Scalar(m) => match m.id {
|
||||
0 => Ok(Opcode::RebootRequest),
|
||||
1 => Ok(Opcode::RebootConfirm),
|
||||
2 => Ok(Opcode::RebootVector(m.arg1 as u32)),
|
||||
3 => Ok(Opcode::CrgMode(m.arg1.into())),
|
||||
4 => Ok(Opcode::GpioDataOut(m.arg1 as u32)),
|
||||
5 => Ok(Opcode::GpioDataDrive(m.arg1 as u32)),
|
||||
6 => Ok(Opcode::GpioIntMask(m.arg1 as u32)),
|
||||
7 => Ok(Opcode::GpioIntAsFalling(m.arg1 as u32)),
|
||||
8 => Ok(Opcode::GpioIntEna(m.arg1 as u32)),
|
||||
9 => Ok(Opcode::UartMux(m.arg1.into())),
|
||||
10 => if m.arg1 == 0 {
|
||||
Ok(Opcode::EventComEnable(false))
|
||||
} else {
|
||||
Ok(Opcode::EventComEnable(true))
|
||||
},
|
||||
11 => if m.arg1 == 0 {
|
||||
Ok(Opcode::EventRtcEnable(false))
|
||||
} else {
|
||||
Ok(Opcode::EventRtcEnable(true))
|
||||
},
|
||||
12 => if m.arg1 == 0 {
|
||||
Ok(Opcode::EventUsbAttachEnable(false))
|
||||
} else {
|
||||
Ok(Opcode::EventUsbAttachEnable(true))
|
||||
},
|
||||
13 => if m.arg1 == 0 {
|
||||
Ok(Opcode::PowerAudio(false))
|
||||
} else {
|
||||
Ok(Opcode::PowerAudio(true))
|
||||
},
|
||||
14 => if m.arg1 == 0 {
|
||||
Ok(Opcode::PowerSelf(false))
|
||||
} else {
|
||||
Ok(Opcode::PowerSelf(true))
|
||||
},
|
||||
15 => if m.arg1 == 0 {
|
||||
Ok(Opcode::PowerBoostMode(false))
|
||||
} else {
|
||||
Ok(Opcode::PowerBoostMode(true))
|
||||
},
|
||||
16 => if m.arg1 == 0 {
|
||||
Ok(Opcode::EcSnoopAllow(false))
|
||||
} else {
|
||||
Ok(Opcode::EcSnoopAllow(true))
|
||||
},
|
||||
17 => Ok(Opcode::EcReset),
|
||||
18 => Ok(Opcode::EcPowerOn),
|
||||
19 => Ok(Opcode::SelfDestruct(m.arg1 as u32)),
|
||||
20 => Ok(Opcode::Vibe(m.arg1.into())),
|
||||
_ => Err("LLIO api: unknown Scalar ID"),
|
||||
},
|
||||
Message::BlockingScalar(m) => match m.id {
|
||||
0x100 => Ok(Opcode::InfoLitexId),
|
||||
0x101 => Ok(Opcode::GpioDataIn),
|
||||
0x102 => Ok(Opcode::GpioIntPending),
|
||||
0x103 => Ok(Opcode::InfoLitexId),
|
||||
0x104 => Ok(Opcode::InfoDna),
|
||||
0x105 => Ok(Opcode::InfoGit),
|
||||
0x106 => Ok(Opcode::InfoPlatform),
|
||||
0x107 => Ok(Opcode::InfoTarget),
|
||||
0x108 => Ok(Opcode::InfoSeed),
|
||||
_ => Err("LLIO api: unknown BlockingScalar ID"),
|
||||
},
|
||||
Message::Borrow(m) => {
|
||||
if xous_names::api::Registration::match_subtype(m.id, SUBTYPE_REGISTER_GPIO_LISTENER) {
|
||||
Ok(Opcode::GpioIntSubscribe({
|
||||
unsafe { *( (m.buf.as_mut_ptr()) as *mut xous_names::api::Registration) }
|
||||
}))
|
||||
} else if xous_names::api::Registration::match_subtype(m.id, SUBTYPE_REGISTER_COM_LISTENER) {
|
||||
Ok(Opcode::EventComSubscribe({
|
||||
unsafe { *( (m.buf.as_mut_ptr()) as *mut xous_names::api::Registration) }
|
||||
}))
|
||||
} else if xous_names::api::Registration::match_subtype(m.id, SUBTYPE_REGISTER_RTC_LISTENER) {
|
||||
Ok(Opcode::EventRtcSubscribe({
|
||||
unsafe { *( (m.buf.as_mut_ptr()) as *mut xous_names::api::Registration) }
|
||||
}))
|
||||
} else if xous_names::api::Registration::match_subtype(m.id, SUBTYPE_REGISTER_USB_LISTENER) {
|
||||
Ok(Opcode::EventUsbAttachSubscribe({
|
||||
unsafe { *( (m.buf.as_mut_ptr()) as *mut xous_names::api::Registration) }
|
||||
}))
|
||||
} else if m.id as u16 == SUBTYPE_I2C_WRITE {
|
||||
Ok(Opcode::I2cWrite({
|
||||
unsafe { *( (m.buf.as_mut_ptr()) as *mut I2cTransaction) }
|
||||
}))
|
||||
} else {
|
||||
Err("COM: unknown borrow ID")
|
||||
}
|
||||
},
|
||||
Message::MutableBorrow(m) => {
|
||||
if m.id as u16 == SUBTYPE_I2C_READ {
|
||||
Ok(Opcode::I2cRead({
|
||||
unsafe { *( (m.buf.as_mut_ptr()) as *mut I2cTransaction) }
|
||||
}))
|
||||
} else {
|
||||
Err("COM: unknown mutable borrow ID")
|
||||
}
|
||||
}
|
||||
_ => Err("unhandled message type"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Message> for Opcode {
|
||||
fn into(self) -> Message {
|
||||
match self {
|
||||
// scalars
|
||||
Opcode::RebootRequest => Message::Scalar(ScalarMessage {
|
||||
id: 0,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::RebootConfirm => Message::Scalar(ScalarMessage {
|
||||
id: 1,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::RebootVector(vector) => Message::Scalar(ScalarMessage {
|
||||
id: 2,
|
||||
arg1: vector as usize, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::CrgMode(mode) => Message::Scalar(ScalarMessage {
|
||||
id: 3,
|
||||
arg1: mode as usize, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::GpioDataOut(data) => Message::Scalar(ScalarMessage {
|
||||
id: 4,
|
||||
arg1: data as usize, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::GpioDataDrive(drive_bits) => Message::Scalar(ScalarMessage {
|
||||
id: 5,
|
||||
arg1: drive_bits as usize, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::GpioIntMask(mask) => Message::Scalar(ScalarMessage {
|
||||
id: 6,
|
||||
arg1: mask as usize, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::GpioIntAsFalling(falling) => Message::Scalar(ScalarMessage {
|
||||
id: 7,
|
||||
arg1: falling as usize, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::GpioIntEna(enable) => Message::Scalar(ScalarMessage {
|
||||
id: 8,
|
||||
arg1: enable as usize, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::UartMux(uarttype) => Message::Scalar(ScalarMessage {
|
||||
id: 9,
|
||||
arg1: uarttype as usize, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::EventComEnable(ena) => if ena {
|
||||
Message::Scalar(ScalarMessage {
|
||||
id: 10,
|
||||
arg1: 1, arg2: 0, arg3: 0, arg4: 0,
|
||||
})
|
||||
} else {
|
||||
Message::Scalar(ScalarMessage {
|
||||
id: 10,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
})
|
||||
},
|
||||
Opcode::EventRtcEnable(ena) => if ena {
|
||||
Message::Scalar(ScalarMessage {
|
||||
id: 11,
|
||||
arg1: 1, arg2: 0, arg3: 0, arg4: 0,
|
||||
})
|
||||
} else {
|
||||
Message::Scalar(ScalarMessage {
|
||||
id: 11,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
})
|
||||
},
|
||||
Opcode::EventUsbAttachEnable(ena) => if ena {
|
||||
Message::Scalar(ScalarMessage {
|
||||
id: 12,
|
||||
arg1: 1, arg2: 0, arg3: 0, arg4: 0,
|
||||
})
|
||||
} else {
|
||||
Message::Scalar(ScalarMessage {
|
||||
id: 12,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
})
|
||||
},
|
||||
Opcode::PowerAudio(ena) => if ena {
|
||||
Message::Scalar(ScalarMessage {
|
||||
id: 13,
|
||||
arg1: 1, arg2: 0, arg3: 0, arg4: 0,
|
||||
})
|
||||
} else {
|
||||
Message::Scalar(ScalarMessage {
|
||||
id: 13,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
})
|
||||
},
|
||||
Opcode::PowerSelf(ena) => if ena {
|
||||
Message::Scalar(ScalarMessage {
|
||||
id: 14,
|
||||
arg1: 1, arg2: 0, arg3: 0, arg4: 0,
|
||||
})
|
||||
} else {
|
||||
Message::Scalar(ScalarMessage {
|
||||
id: 14,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
})
|
||||
},
|
||||
Opcode::PowerBoostMode(ena) => if ena {
|
||||
Message::Scalar(ScalarMessage {
|
||||
id: 15,
|
||||
arg1: 1, arg2: 0, arg3: 0, arg4: 0,
|
||||
})
|
||||
} else {
|
||||
Message::Scalar(ScalarMessage {
|
||||
id: 15,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
})
|
||||
},
|
||||
Opcode::EcSnoopAllow(ena) => if ena {
|
||||
Message::Scalar(ScalarMessage {
|
||||
id: 16,
|
||||
arg1: 1, arg2: 0, arg3: 0, arg4: 0,
|
||||
})
|
||||
} else {
|
||||
Message::Scalar(ScalarMessage {
|
||||
id: 16,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
})
|
||||
},
|
||||
Opcode::EcReset => Message::Scalar(ScalarMessage {
|
||||
id: 17,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::EcPowerOn => Message::Scalar(ScalarMessage {
|
||||
id: 18,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::SelfDestruct(code) => Message::Scalar(ScalarMessage {
|
||||
id: 19,
|
||||
arg1: code as usize, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::Vibe(pattern) => Message::Scalar(ScalarMessage {
|
||||
id: 17,
|
||||
arg1: pattern as usize, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
|
||||
|
||||
// blocking scalars
|
||||
Opcode::InfoLitexId => Message::BlockingScalar(ScalarMessage {
|
||||
id: 0x100,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::GpioDataIn => Message::BlockingScalar(ScalarMessage {
|
||||
id: 0x101,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::GpioIntPending => Message::BlockingScalar(ScalarMessage {
|
||||
id: 0x102,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::InfoLitexId => Message::BlockingScalar(ScalarMessage {
|
||||
id: 0x103,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::InfoDna => Message::BlockingScalar(ScalarMessage {
|
||||
id: 0x104,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::InfoGit => Message::BlockingScalar(ScalarMessage {
|
||||
id: 0x105,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::InfoPlatform => Message::BlockingScalar(ScalarMessage {
|
||||
id: 0x106,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::InfoTarget => Message::BlockingScalar(ScalarMessage {
|
||||
id: 0x107,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
Opcode::InfoSeed => Message::BlockingScalar(ScalarMessage {
|
||||
id: 0x108,
|
||||
arg1: 0, arg2: 0, arg3: 0, arg4: 0,
|
||||
}),
|
||||
_ => panic!("opcode not handled -- maybe you meant to use one of the direct APIs")
|
||||
}
|
||||
}
|
||||
}
|
||||
9
services/llio/src/lib.rs
Normal file
9
services/llio/src/lib.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
|
||||
/// This is the API that other servers use to call the COM. Read this code as if you
|
||||
/// are calling these functions inside a different process.
|
||||
pub mod api;
|
||||
|
||||
use api::*;
|
||||
use xous::{send_message, Error, CID};
|
||||
|
||||
196
services/llio/src/main.rs
Normal file
196
services/llio/src/main.rs
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
#![cfg_attr(target_os = "none", no_main)]
|
||||
|
||||
mod api;
|
||||
use api::*;
|
||||
|
||||
use core::convert::TryFrom;
|
||||
|
||||
use log::{error, info};
|
||||
|
||||
use xous::CID;
|
||||
|
||||
#[cfg(target_os = "none")]
|
||||
mod implementation {
|
||||
use crate::api::*;
|
||||
use log::error;
|
||||
use utralib::generated::*;
|
||||
use xous::CID;
|
||||
|
||||
use heapless::Vec;
|
||||
use heapless::consts::*;
|
||||
|
||||
const STD_TIMEOUT: u32 = 100;
|
||||
|
||||
pub struct Llio {
|
||||
reboot_csr: utralib::CSR<u32>,
|
||||
crg_csr: utralib::CSR<u32>,
|
||||
gpio_csr: utralib::CSR<u32>,
|
||||
info_csr: utralib::CSR<u32>,
|
||||
identifier_csr: utralib::CSR<u32>,
|
||||
i2c_csr: utralib::CSR<u32>,
|
||||
event_csr: utralib::CSR<u32>,
|
||||
power_csr: utralib::CSR<u32>,
|
||||
}
|
||||
|
||||
fn handle_event_irq(_irq_no: usize, arg: *mut usize) {
|
||||
let xl = unsafe { &mut *(arg as *mut Llio) };
|
||||
// just clear the pending request for now and return
|
||||
xl.event_csr
|
||||
.wo(utra::btevents::EV_PENDING, xl.event_csr.r(utra::btevents::EV_PENDING));
|
||||
}
|
||||
fn handle_gpio_irq(_irq_no: usize, arg: *mut usize) {
|
||||
let xl = unsafe { &mut *(arg as *mut Llio) };
|
||||
// just clear the pending request for now and return
|
||||
xl.gpio_csr
|
||||
.wo(utra::gpio::EV_PENDING, xl.gpio_csr.r(utra::gpio::EV_PENDING));
|
||||
}
|
||||
fn handle_i2c_irq(_irq_no: usize, arg: *mut usize) {
|
||||
let xl = unsafe { &mut *(arg as *mut Llio) };
|
||||
// just clear the pending request for now and return
|
||||
xl.i2c_csr
|
||||
.wo(utra::i2c::EV_PENDING, xl.i2c_csr.r(utra::i2c::EV_PENDING));
|
||||
}
|
||||
|
||||
impl Llio {
|
||||
pub fn new() -> Llio {
|
||||
let reboot_csr = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utra::reboot::HW_REBOOT_BASE),
|
||||
None,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("couldn't map Reboot CSR range");
|
||||
let crg_csr = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utra::crg::HW_CRG_BASE),
|
||||
None,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("couldn't map CRG CSR range");
|
||||
let gpio_csr = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utra::gpio::HW_GPIO_BASE),
|
||||
None,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("couldn't map GPIO CSR range");
|
||||
let info_csr = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utra::info::HW_INFO_BASE),
|
||||
None,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("couldn't map Info CSR range");
|
||||
let identifier_csr = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utra::identifier_mem::HW_IDENTIFIER_MEM_BASE),
|
||||
None,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("couldn't map Identifier CSR range");
|
||||
let i2c_csr = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utra::i2c::HW_I2C_BASE),
|
||||
None,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("couldn't map I2C CSR range");
|
||||
let event_csr = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utra::btevents::HW_BTEVENTS_BASE),
|
||||
None,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("couldn't map BtEvents CSR range");
|
||||
let power_csr = xous::syscall::map_memory(
|
||||
xous::MemoryAddress::new(utra::power::HW_POWER_BASE),
|
||||
None,
|
||||
4096,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
)
|
||||
.expect("couldn't map Power CSR range");
|
||||
|
||||
let mut xl = Llio {
|
||||
reboot_csr: CSR::new(reboot_csr.as_mut_ptr() as *mut u32),
|
||||
crg_csr: CSR::new(crg_csr.as_mut_ptr() as *mut u32),
|
||||
gpio_csr: CSR::new(gpio_csr.as_mut_ptr() as *mut u32),
|
||||
info_csr: CSR::new(info_csr.as_mut_ptr() as *mut u32),
|
||||
identifier_csr: CSR::new(identifier_csr.as_mut_ptr() as *mut u32),
|
||||
i2c_csr: CSR::new(i2c_csr.as_mut_ptr() as *mut u32),
|
||||
event_csr: CSR::new(event_csr.as_mut_ptr() as *mut u32),
|
||||
power_csr: CSR::new(power_csr.as_mut_ptr() as *mut u32),
|
||||
};
|
||||
|
||||
xous::claim_interrupt(
|
||||
utra::btevents::BTEVENTS_IRQ,
|
||||
handle_event_irq,
|
||||
(&mut xl) as *mut Llio as *mut usize,
|
||||
)
|
||||
.expect("couldn't claim BtEvents irq");
|
||||
|
||||
xous::claim_interrupt(
|
||||
utra::gpio::GPIO_IRQ,
|
||||
handle_gpio_irq,
|
||||
(&mut xl) as *mut Llio as *mut usize,
|
||||
)
|
||||
.expect("couldn't claim GPIO irq");
|
||||
|
||||
xous::claim_interrupt(
|
||||
utra::i2c::I2C_IRQ,
|
||||
handle_i2c_irq,
|
||||
(&mut xl) as *mut Llio as *mut usize,
|
||||
)
|
||||
.expect("couldn't claim I2C irq");
|
||||
|
||||
xl
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// a stub to try to avoid breaking hosted mode for as long as possible.
|
||||
#[cfg(not(target_os = "none"))]
|
||||
mod implementation {
|
||||
use crate::api::*;
|
||||
use log::{error, info};
|
||||
|
||||
pub struct Llio {
|
||||
}
|
||||
|
||||
impl Llio {
|
||||
pub fn new() -> Llio {
|
||||
Llio {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
use crate::implementation::Llio;
|
||||
use heapless::Vec;
|
||||
use heapless::consts::*;
|
||||
|
||||
log_server::init_wait().unwrap();
|
||||
|
||||
let llio_sid = xous_names::register_name(xous::names::SERVER_NAME_LLIO).expect("LLIO: can't register server");
|
||||
info!("LLIO: registered with NS -- {:?}", llio_sid);
|
||||
|
||||
// Create a new com object
|
||||
let mut llio = Llio::new();
|
||||
|
||||
info!("LLIO: starting main loop");
|
||||
loop {
|
||||
let envelope = xous::receive_message(llio_sid).unwrap();
|
||||
// info!("LLIO: Message: {:?}", envelope);
|
||||
if let Ok(opcode) = Opcode::try_from(&envelope.body) {
|
||||
// info!("LLIO: Opcode: {:?}", opcode);
|
||||
match opcode {
|
||||
_ => error!("unknown opcode"),
|
||||
}
|
||||
} else {
|
||||
error!("couldn't convert opcode");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ for the core set of kernel services.
|
|||
*/
|
||||
|
||||
pub const SERVER_NAME_COM: &str = "_COM manager_";
|
||||
pub const SERVER_NAME_LLIO: &str = "_Low Level I/O manager_";
|
||||
pub const SERVER_NAME_SHELL: &str = "_Shell_";
|
||||
pub const SERVER_NAME_GFX: &str = "_Graphics_";
|
||||
pub const SERVER_NAME_KBD: &str = "_Matrix keyboard driver_";
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ fn try_main() -> Result<(), DynError> {
|
|||
"xous-names",
|
||||
"keyboard",
|
||||
"trng",
|
||||
"llio",
|
||||
];
|
||||
let fcc_pkgs = [
|
||||
"shell",
|
||||
|
|
@ -182,12 +183,15 @@ fn renode_image(debug: bool) -> Result<(), DynError> {
|
|||
let kernel = build_kernel(debug)?;
|
||||
let mut init = vec![];
|
||||
for pkg in &[
|
||||
"shell",
|
||||
"benchmark",
|
||||
"benchmark-target",
|
||||
// "shell",
|
||||
"log-server",
|
||||
"graphics-server",
|
||||
"ticktimer-server",
|
||||
"com",
|
||||
"xous-names",
|
||||
"trng",
|
||||
] {
|
||||
init.push(build(pkg, debug, Some(TARGET), None)?);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue