From 7d3ef78f2a712766b069756137c5f3b21bd46e3d Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 28 Jan 2021 02:56:00 +0800 Subject: [PATCH] about halfway through the API implementation --- services/llio/src/api.rs | 17 ++++-- services/llio/src/main.rs | 115 +++++++++++++++++++++++++++++++++++++- 2 files changed, 124 insertions(+), 8 deletions(-) diff --git a/services/llio/src/api.rs b/services/llio/src/api.rs index ec3b8ed1d..9a16c0ef4 100644 --- a/services/llio/src/api.rs +++ b/services/llio/src/api.rs @@ -109,7 +109,8 @@ impl Into for ClockMode { pub enum Opcode { /// not tested - reboot RebootRequest, - RebootConfirm, + RebootSocConfirm, // all peripherals + CPU + RebootCpuConfirm, // just the CPU, peripherals (in particular the USB debug bridge) keep state /// not tested - reboot address RebootVector(u32), @@ -169,7 +170,8 @@ impl core::convert::TryFrom<& Message> for Opcode { match message { Message::Scalar(m) => match m.id { 0 => Ok(Opcode::RebootRequest), - 1 => Ok(Opcode::RebootConfirm), + 1 => Ok(Opcode::RebootSocConfirm), + 21 => Ok(Opcode::RebootCpuConfirm), 2 => Ok(Opcode::RebootVector(m.arg1 as u32)), 3 => Ok(Opcode::CrgMode(m.arg1.into())), 4 => Ok(Opcode::GpioDataOut(m.arg1 as u32)), @@ -217,6 +219,7 @@ impl core::convert::TryFrom<& Message> for Opcode { 18 => Ok(Opcode::EcPowerOn), 19 => Ok(Opcode::SelfDestruct(m.arg1 as u32)), 20 => Ok(Opcode::Vibe(m.arg1.into())), + // note 21 is used for RebootCpuConfirm _ => Err("LLIO api: unknown Scalar ID"), }, Message::BlockingScalar(m) => match m.id { @@ -278,10 +281,14 @@ impl Into for Opcode { id: 0, arg1: 0, arg2: 0, arg3: 0, arg4: 0, }), - Opcode::RebootConfirm => Message::Scalar(ScalarMessage { + Opcode::RebootSocConfirm => Message::Scalar(ScalarMessage { id: 1, arg1: 0, arg2: 0, arg3: 0, arg4: 0, }), + Opcode::RebootCpuConfirm => Message::Scalar(ScalarMessage { + id: 21, + 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, @@ -404,10 +411,10 @@ impl Into for Opcode { arg1: code as usize, arg2: 0, arg3: 0, arg4: 0, }), Opcode::Vibe(pattern) => Message::Scalar(ScalarMessage { - id: 17, + id: 20, arg1: pattern as usize, arg2: 0, arg3: 0, arg4: 0, }), - + // note 21 is used by RebootCpuConfirm // blocking scalars Opcode::InfoLitexId => Message::BlockingScalar(ScalarMessage { diff --git a/services/llio/src/main.rs b/services/llio/src/main.rs index 0098af5a1..c4e9a4894 100644 --- a/services/llio/src/main.rs +++ b/services/llio/src/main.rs @@ -13,7 +13,7 @@ use xous::CID; #[cfg(target_os = "none")] mod implementation { use crate::api::*; - use log::error; + use log::{error, info}; use utralib::generated::*; use xous::CID; @@ -146,6 +146,45 @@ mod implementation { xl } + pub fn reboot(&mut self, reboot_soc: bool) { + if reboot_soc { + self.reboot_csr.wfo(utra::reboot::SOC_RESET_SOC_RESET, 0xAC); + } else { + self.reboot_csr.wfo(utra::reboot::CPU_RESET_CPU_RESET, 1); + } + } + pub fn set_reboot_vector(&mut self, vector: u32) { + self.reboot_csr.wfo(utra::reboot::ADDR_ADDR, vector); + } + pub fn gpio_dout(&mut self, d: u32) { + self.gpio_csr.wfo(utra::gpio::OUTPUT_OUTPUT, d); + } + pub fn gpio_din(&self) -> u32 { + self.gpio_csr.rf(utra::gpio::INPUT_INPUT) + } + pub fn gpio_drive(&mut self, d: u32) { + self.gpio_csr.wfo(utra::gpio::DRIVE_DRIVE, d); + } + pub fn gpio_int_mask(&mut self, d: u32) { + self.gpio_csr.wfo(utra::gpio::INTENA_INTENA, d); + } + pub fn gpio_int_as_falling(&mut self, d: u32) { + self.gpio_csr.wfo(utra::gpio::INTPOL_INTPOL, d); + } + pub fn gpio_int_pending(&self) -> u32 { + self.gpio_csr.r(utra::gpio::EV_PENDING) & 0xff + } + pub fn gpio_int_ena(&mut self, d: u32) { + self.gpio_csr.wo(utra::gpio::EV_ENABLE, d & 0xff); + } + pub fn set_uart_mux(&mut self, mux: UartType) { + match mux { + UartType::Kernel => self.gpio_csr.wfo(utra::gpio::UARTSEL_UARTSEL, 0), + UartType::Log => self.gpio_csr.wfo(utra::gpio::UARTSEL_UARTSEL, 1), + UartType::Application => self.gpio_csr.wfo(utra::gpio::UARTSEL_UARTSEL, 2), + _ => info!("LLIO: invalid UART type specified for mux, doing nothing."), + } + } } } @@ -163,6 +202,17 @@ mod implementation { Llio { } } + + pub fn reboot(_reboot_soc: bool) {} + pub fn set_rebot_vector(_vector: u32) {} + pub fn gpio_dout(_d: u32) {} + pub fn gpio_din() -> u32 { 0xDEAD_BEEF } + pub fn gpio_drive(_d: u32) {} + pub fn gpio_int_mask(_d: u32) {} + pub fn gpio_int_as_falling(_d: u32) {} + pub fn gpio_int_pending() -> u32 { 0x0 } + pub fn gpio_int_ena(_d: u32) {} + pub fn set_uart_mux(_mux: UartType) {} } } @@ -181,16 +231,75 @@ fn xmain() -> ! { let mut llio = Llio::new(); info!("LLIO: starting main loop"); + let mut reboot_requested: bool = false; 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); + // reset the reboot request if the very next opcode is not a confirm + if reboot_requested { + match opcode { + Opcode::RebootCpuConfirm => { + if reboot_requested { + llio.reboot(false); + } + }, + Opcode::RebootSocConfirm => { + if reboot_requested { + llio.reboot(true); + } + }, + _ => reboot_requested = false, + } + } match opcode { - _ => error!("unknown opcode"), + Opcode::RebootRequest => { + reboot_requested = true; + }, + Opcode::RebootCpuConfirm => { + info!("LLIO: RebootCpuConfirm, but no prior Request. Ignoring."); + }, + Opcode::RebootSocConfirm => { + info!("LLIO: RebootSocConfirm, but no prior Request. Ignoring."); + }, + Opcode::RebootVector(vector) => { + llio.set_reboot_vector(vector); + }, + Opcode::CrgMode(_mode) => { + todo!("LLIO: CrgMode opcode not yet implemented."); + }, + Opcode::GpioDataOut(d) => { + llio.gpio_dout(d); + }, + Opcode::GpioDataIn => { + xous::return_scalar(envelope.sender, llio.gpio_din() as usize).expect("LLIO: couldn't return gpio data in"); + }, + Opcode::GpioDataDrive(d) => { + llio.gpio_drive(d); + }, + Opcode::GpioIntMask(d) => { + llio.gpio_int_mask(d); + }, + Opcode::GpioIntAsFalling(d) => { + llio.gpio_int_as_falling(d); + }, + Opcode::GpioIntPending => { + xous::return_scalar(envelope.sender, llio.gpio_int_pending() as usize).expect("LLIO: couldn't return gpio pending vector"); + }, + Opcode::GpioIntEna(d) => { + llio.gpio_int_ena(d); + }, + Opcode::GpioIntSubscribe(_Registration) => { + todo!("LLIO: GPIO push interrupt events not yet implemented."); + }, + Opcode::UartMux(mux) => { + llio.set_uart_mux(mux); + }, + _ => error!("LLIO: no handler for opcode"), } } else { - error!("couldn't convert opcode"); + error!("LLIO: couldn't convert opcode"); } } }