mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
parent
72859d18dd
commit
6cf5135a7d
5 changed files with 9 additions and 164 deletions
|
|
@ -106,16 +106,16 @@ pub(crate) enum Opcode {
|
|||
|
||||
/// partially tested -- events
|
||||
EventComSubscribe, //(String<64>),
|
||||
EventRtcSubscribe, //(String<64>),
|
||||
//EventRtcSubscribe, //(String<64>),
|
||||
EventUsbAttachSubscribe, //(String<64>),
|
||||
EventComEnable, //(bool),
|
||||
EventRtcEnable, //(bool),
|
||||
//EventRtcEnable, //(bool),
|
||||
EventUsbAttachEnable, //(bool),
|
||||
EventActivityHappened,
|
||||
|
||||
/// internal from handler to main loop
|
||||
EventComHappened,
|
||||
EventRtcHappened,
|
||||
//EventRtcHappened,
|
||||
EventUsbHappened,
|
||||
|
||||
/// SuspendResume callback
|
||||
|
|
@ -127,9 +127,9 @@ pub(crate) enum Opcode {
|
|||
/// clear any wakeup alarms that have been set
|
||||
ClearWakeupAlarm,
|
||||
/// sets an RTC alarm. This just triggers a regular interrupt, no other side-effect
|
||||
SetRtcAlarm,
|
||||
//SetRtcAlarm,
|
||||
/// clears any RTC alarms that have been set
|
||||
ClearRtcAlarm,
|
||||
//ClearRtcAlarm,
|
||||
/// reads the current RTC count as a value in seconds
|
||||
GetRtcValue,
|
||||
|
||||
|
|
|
|||
|
|
@ -72,8 +72,6 @@ impl Llio {
|
|||
0
|
||||
}
|
||||
|
||||
pub fn rtc_int_ena(self, _ena: bool) {
|
||||
}
|
||||
pub fn com_int_ena(self, _ena: bool) {
|
||||
}
|
||||
pub fn usb_int_ena(self, _ena: bool) {
|
||||
|
|
|
|||
|
|
@ -34,14 +34,6 @@ fn handle_event_irq(_irq_no: usize, arg: *mut usize) {
|
|||
log::error!("|handle_event_irq: COM interrupt, but no connection for notification!")
|
||||
}
|
||||
}
|
||||
if xl.event_csr.rf(utra::btevents::EV_PENDING_RTC_INT) != 0 {
|
||||
if let Some(conn) = xl.handler_conn {
|
||||
xous::try_send_message(conn,
|
||||
xous::Message::new_scalar(Opcode::EventRtcHappened.to_usize().unwrap(), 0, 0, 0, 0)).map(|_|()).unwrap();
|
||||
} else {
|
||||
log::error!("|handle_event_irq: RTC interrupt, but no connection for notification!")
|
||||
}
|
||||
}
|
||||
xl.event_csr
|
||||
.wo(utra::btevents::EV_PENDING, xl.event_csr.r(utra::btevents::EV_PENDING));
|
||||
}
|
||||
|
|
@ -459,10 +451,6 @@ impl Llio {
|
|||
pub fn xadc_gpio2(&self) -> u16 {
|
||||
self.xadc_csr.rf(utra::trng::XADC_GPIO2_XADC_GPIO2) as u16
|
||||
}
|
||||
pub fn rtc_int_ena(&mut self, ena: bool) {
|
||||
let value = if ena {1} else {0};
|
||||
self.event_csr.rmwf(utra::btevents::EV_ENABLE_RTC_INT, value);
|
||||
}
|
||||
pub fn com_int_ena(&mut self, ena: bool) {
|
||||
let value = if ena {1} else {0};
|
||||
self.event_csr.rmwf(utra::btevents::EV_ENABLE_COM_INT, value);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ pub struct Llio {
|
|||
com_sid: Option<xous::SID>,
|
||||
usb_sid: Option<xous::SID>,
|
||||
gpio_sid: Option<xous::SID>,
|
||||
rtc_sid: Option<xous::SID>,
|
||||
}
|
||||
impl Llio {
|
||||
pub fn new(xns: &xous_names::XousNames) -> Self {
|
||||
|
|
@ -24,36 +23,8 @@ impl Llio {
|
|||
com_sid: None,
|
||||
usb_sid: None,
|
||||
gpio_sid: None,
|
||||
rtc_sid: None,
|
||||
}
|
||||
}
|
||||
/// RTC alarm hooks -- even though it's physically associated with the RTC, all the async interrupts get
|
||||
/// routed through the LLIO block through a single event register, and so, RTC event registration counter-intuitively
|
||||
/// must be done through the LLIO, and not the RTC block.
|
||||
pub fn hook_rtc_alarm_callback(&mut self, id: u32, cid: CID) -> Result<(), xous::Error> {
|
||||
if self.rtc_sid.is_none() {
|
||||
let sid = xous::create_server().unwrap();
|
||||
self.rtc_sid = Some(sid);
|
||||
let sid_tuple = sid.to_u32();
|
||||
xous::create_thread_4(rtc_cb_server, sid_tuple.0 as usize, sid_tuple.1 as usize, sid_tuple.2 as usize, sid_tuple.3 as usize).unwrap();
|
||||
let hookdata = ScalarHook {
|
||||
sid: sid_tuple,
|
||||
id,
|
||||
cid,
|
||||
};
|
||||
let buf = Buffer::into_buf(hookdata).or(Err(xous::Error::InternalError))?;
|
||||
buf.lend(self.conn, Opcode::EventRtcSubscribe.to_u32().unwrap()).map(|_|())
|
||||
} else {
|
||||
Err(xous::Error::MemoryInUse) // can't hook it twice
|
||||
}
|
||||
}
|
||||
pub fn rtc_alarm_enable(&self, ena: bool) -> Result<(), xous::Error> {
|
||||
let arg = if ena { 1 } else { 0 };
|
||||
send_message(self.conn,
|
||||
Message::new_scalar(Opcode::EventRtcEnable.to_usize().unwrap(), arg, 0, 0, 0)
|
||||
).map(|_| ())
|
||||
}
|
||||
|
||||
pub fn vibe(&self, pattern: VibePattern) -> Result<(), xous::Error> {
|
||||
send_message(self.conn,
|
||||
Message::new_scalar(Opcode::Vibe.to_usize().unwrap(), pattern.into(), 0, 0, 0)
|
||||
|
|
@ -366,17 +337,6 @@ impl Llio {
|
|||
Message::new_blocking_scalar(Opcode::ClearWakeupAlarm.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).map(|_|())
|
||||
}
|
||||
/// the rtc alarm will not turn the system on, but it will trigger an interrupt on the CPU
|
||||
pub fn set_rtc_alarm(&self, seconds_from_now: u8) -> Result<(), xous::Error> {
|
||||
send_message(self.conn,
|
||||
Message::new_blocking_scalar(Opcode::SetRtcAlarm.to_usize().unwrap(), seconds_from_now as _, 0, 0, 0)
|
||||
).map(|_|())
|
||||
}
|
||||
pub fn clear_rtc_alarm(&self) -> Result<(), xous::Error> {
|
||||
send_message(self.conn,
|
||||
Message::new_blocking_scalar(Opcode::ClearRtcAlarm.to_usize().unwrap(), 0, 0, 0, 0)
|
||||
).map(|_|())
|
||||
}
|
||||
/// This returns the elapsed seconds on the RTC since an arbitrary start point in the past.
|
||||
/// The translation of this is handled by `libstd::SystemTime`; you may use this call, but
|
||||
/// the interpretation is not terribly meaningful on its own.
|
||||
|
|
@ -416,9 +376,6 @@ impl Drop for Llio {
|
|||
if let Some(sid) = self.gpio_sid.take() {
|
||||
drop_conn(sid);
|
||||
}
|
||||
if let Some(sid) = self.rtc_sid.take() {
|
||||
drop_conn(sid);
|
||||
}
|
||||
if REFCOUNT.fetch_sub(1, Ordering::Relaxed) == 1 {
|
||||
unsafe{xous::disconnect(self.conn).unwrap();}
|
||||
}
|
||||
|
|
@ -488,24 +445,3 @@ fn gpio_cb_server(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
|||
}
|
||||
xous::destroy_server(sid).unwrap();
|
||||
}
|
||||
|
||||
/// handles callback messages that indicate a RTC interrupt has happened, in the library user's process space.
|
||||
fn rtc_cb_server(sid0: usize, sid1: usize, sid2: usize, sid3: usize) {
|
||||
let sid = xous::SID::from_u32(sid0 as u32, sid1 as u32, sid2 as u32, sid3 as u32);
|
||||
loop {
|
||||
let msg = xous::receive_message(sid).unwrap();
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(EventCallback::Event) => msg_scalar_unpack!(msg, cid, id, _, _, {
|
||||
// directly pass the scalar message onto the CID with the ID memorized in the original hook
|
||||
send_message(cid as u32,
|
||||
Message::new_scalar(id, 0, 0, 0, 0)
|
||||
).unwrap();
|
||||
}),
|
||||
Some(EventCallback::Drop) => {
|
||||
break; // this exits the loop and kills the thread
|
||||
}
|
||||
None => (),
|
||||
}
|
||||
}
|
||||
xous::destroy_server(sid).unwrap();
|
||||
}
|
||||
|
|
@ -154,13 +154,10 @@ fn main() -> ! {
|
|||
|
||||
let mut usb_cb_conns: [Option<ScalarCallback>; 32] = [None; 32];
|
||||
let mut com_cb_conns: [Option<ScalarCallback>; 32] = [None; 32];
|
||||
let mut rtc_cb_conns: [Option<ScalarCallback>; 32] = [None; 32];
|
||||
let mut gpio_cb_conns: [Option<ScalarCallback>; 32] = [None; 32];
|
||||
|
||||
// create a self-connection to I2C to handle the public, non-security sensitive RTC API calls
|
||||
let mut i2c = llio::I2c::new(&xns);
|
||||
let mut rtc_alarm_enabled = false;
|
||||
let mut wakeup_alarm_enabled = false;
|
||||
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
||||
|
||||
log::trace!("starting main loop");
|
||||
|
|
@ -330,11 +327,6 @@ fn main() -> ! {
|
|||
let hookdata = buffer.to_original::<ScalarHook, _>().unwrap();
|
||||
do_hook(hookdata, &mut com_cb_conns);
|
||||
}
|
||||
Some(Opcode::EventRtcSubscribe) => {
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let hookdata = buffer.to_original::<ScalarHook, _>().unwrap();
|
||||
do_hook(hookdata, &mut rtc_cb_conns);
|
||||
}
|
||||
Some(Opcode::GpioIntSubscribe) => {
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let hookdata = buffer.to_original::<ScalarHook, _>().unwrap();
|
||||
|
|
@ -347,13 +339,6 @@ fn main() -> ! {
|
|||
llio.com_int_ena(true);
|
||||
}
|
||||
}),
|
||||
Some(Opcode::EventRtcEnable) => msg_scalar_unpack!(msg, ena, _, _, _, {
|
||||
if ena == 0 {
|
||||
llio.rtc_int_ena(false);
|
||||
} else {
|
||||
llio.rtc_int_ena(true);
|
||||
}
|
||||
}),
|
||||
Some(Opcode::EventUsbAttachEnable) => msg_scalar_unpack!(msg, ena, _, _, _, {
|
||||
if ena == 0 {
|
||||
llio.usb_int_ena(false);
|
||||
|
|
@ -364,9 +349,6 @@ fn main() -> ! {
|
|||
Some(Opcode::EventComHappened) => {
|
||||
send_event(&com_cb_conns, 0);
|
||||
},
|
||||
Some(Opcode::EventRtcHappened) => {
|
||||
send_event(&rtc_cb_conns, 0);
|
||||
},
|
||||
Some(Opcode::EventUsbHappened) => {
|
||||
send_event(&usb_cb_conns, 0);
|
||||
},
|
||||
|
|
@ -399,7 +381,6 @@ fn main() -> ! {
|
|||
continue;
|
||||
}
|
||||
let seconds = delay as u8;
|
||||
wakeup_alarm_enabled = true;
|
||||
// make sure battery switchover is enabled, otherwise we won't keep time when power goes off
|
||||
i2c.i2c_write(ABRTCMC_I2C_ADR, ABRTCMC_CONTROL3, &[(Control3::BATT_STD_BL_EN).bits()]).expect("RTC access error");
|
||||
// set clock units to 1 second, output pulse length to ~218ms
|
||||
|
|
@ -407,78 +388,21 @@ fn main() -> ! {
|
|||
// program elapsed time
|
||||
i2c.i2c_write(ABRTCMC_I2C_ADR, ABRTCMC_TIMERB, &[seconds]).expect("RTC access error");
|
||||
// enable timerb countdown interrupt, also clears any prior interrupt flag
|
||||
let mut control2 = (Control2::COUNTDOWN_B_INT).bits();
|
||||
if rtc_alarm_enabled {
|
||||
control2 |= Control2::COUNTDOWN_A_INT.bits();
|
||||
}
|
||||
let control2 = (Control2::COUNTDOWN_B_INT).bits();
|
||||
i2c.i2c_write(ABRTCMC_I2C_ADR, ABRTCMC_CONTROL2, &[control2]).expect("RTC access error");
|
||||
// turn on the timer proper -- the system will wakeup in 5..4..3....
|
||||
let mut config = (Config::CLKOUT_DISABLE | Config::TIMER_B_ENABLE).bits();
|
||||
if rtc_alarm_enabled {
|
||||
config |= (Config::TIMER_A_COUNTDWN | Config::TIMERA_SECONDS_INT_PULSED).bits();
|
||||
}
|
||||
let config = (Config::CLKOUT_DISABLE | Config::TIMER_B_ENABLE).bits();
|
||||
i2c.i2c_write(ABRTCMC_I2C_ADR, ABRTCMC_CONFIG, &[config]).expect("RTC access error");
|
||||
xous::return_scalar(msg.sender, 0).expect("couldn't return to caller");
|
||||
}),
|
||||
Some(Opcode::ClearWakeupAlarm) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
wakeup_alarm_enabled = false;
|
||||
// make sure battery switchover is enabled, otherwise we won't keep time when power goes off
|
||||
i2c.i2c_write(ABRTCMC_I2C_ADR, ABRTCMC_CONTROL3, &[(Control3::BATT_STD_BL_EN).bits()]).expect("RTC access error");
|
||||
let mut config = Config::CLKOUT_DISABLE.bits();
|
||||
if rtc_alarm_enabled {
|
||||
config |= (Config::TIMER_A_COUNTDWN | Config::TIMERA_SECONDS_INT_PULSED).bits();
|
||||
}
|
||||
let config = Config::CLKOUT_DISABLE.bits();
|
||||
// turn off RTC wakeup timer, in case previously set
|
||||
i2c.i2c_write(ABRTCMC_I2C_ADR, ABRTCMC_CONFIG, &[config]).expect("RTC access error");
|
||||
// clear my interrupts and flags
|
||||
let mut control2 = 0;
|
||||
if rtc_alarm_enabled {
|
||||
control2 |= Control2::COUNTDOWN_A_INT.bits();
|
||||
}
|
||||
i2c.i2c_write(ABRTCMC_I2C_ADR, ABRTCMC_CONTROL2, &[control2]).expect("RTC access error");
|
||||
xous::return_scalar(msg.sender, 0).expect("couldn't return to caller");
|
||||
}),
|
||||
Some(Opcode::SetRtcAlarm) => msg_blocking_scalar_unpack!(msg, delay, _, _, _, {
|
||||
if delay > u8::MAX as usize {
|
||||
log::error!("Alarm must be no longer than {} secs in the future", u8::MAX);
|
||||
xous::return_scalar(msg.sender, 1).expect("couldn't return to caller");
|
||||
continue;
|
||||
}
|
||||
let seconds = delay as u8;
|
||||
rtc_alarm_enabled = true;
|
||||
// make sure battery switchover is enabled, otherwise we won't keep time when power goes off
|
||||
i2c.i2c_write(ABRTCMC_I2C_ADR, ABRTCMC_CONTROL3, &[(Control3::BATT_STD_BL_EN).bits()]).expect("RTC access error");
|
||||
// set clock units to 1 second, output pulse length to ~218ms
|
||||
i2c.i2c_write(ABRTCMC_I2C_ADR, ABRTCMC_TIMERA_CLK, &[(TimerClk::CLK_1_S | TimerClk::PULSE_218_MS).bits()]).expect("RTC access error");
|
||||
// program elapsed time
|
||||
i2c.i2c_write(ABRTCMC_I2C_ADR, ABRTCMC_TIMERA, &[seconds]).expect("RTC access error");
|
||||
// enable timerb countdown interrupt, also clears any prior interrupt flag
|
||||
let mut control2 = (Control2::COUNTDOWN_A_INT).bits();
|
||||
if wakeup_alarm_enabled {
|
||||
control2 |= Control2::COUNTDOWN_B_INT.bits();
|
||||
}
|
||||
i2c.i2c_write(ABRTCMC_I2C_ADR, ABRTCMC_CONTROL2, &[control2]).expect("RTC access error");
|
||||
// turn on the timer proper -- interrupt in 5..4..3....
|
||||
let mut config = (Config::CLKOUT_DISABLE | Config::TIMER_A_COUNTDWN | Config::TIMERA_SECONDS_INT_PULSED).bits();
|
||||
if wakeup_alarm_enabled {
|
||||
config |= (Config::TIMER_B_ENABLE).bits();
|
||||
}
|
||||
i2c.i2c_write(ABRTCMC_I2C_ADR, ABRTCMC_CONFIG, &[config]).expect("RTC access error");
|
||||
xous::return_scalar(msg.sender, 0).expect("couldn't return to caller");
|
||||
}),
|
||||
Some(Opcode::ClearRtcAlarm) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
|
||||
rtc_alarm_enabled = false;
|
||||
// turn off RTC wakeup timer, in case previously set
|
||||
let mut config = Config::CLKOUT_DISABLE.bits();
|
||||
if wakeup_alarm_enabled {
|
||||
config |= (Config::TIMER_B_ENABLE | Config::TIMERB_INT_PULSED).bits();
|
||||
}
|
||||
i2c.i2c_write(ABRTCMC_I2C_ADR, ABRTCMC_CONFIG, &[config]).expect("RTC access error");
|
||||
// clear my interrupts and flags
|
||||
let mut control2 = 0;
|
||||
if wakeup_alarm_enabled {
|
||||
control2 |= Control2::COUNTDOWN_B_INT.bits();
|
||||
}
|
||||
let control2 = 0;
|
||||
i2c.i2c_write(ABRTCMC_I2C_ADR, ABRTCMC_CONTROL2, &[control2]).expect("RTC access error");
|
||||
xous::return_scalar(msg.sender, 0).expect("couldn't return to caller");
|
||||
}),
|
||||
|
|
@ -553,7 +477,6 @@ fn main() -> ! {
|
|||
}
|
||||
log::trace!("main loop exit, destroying servers");
|
||||
unhook(&mut com_cb_conns);
|
||||
unhook(&mut rtc_cb_conns);
|
||||
unhook(&mut usb_cb_conns);
|
||||
unhook(&mut gpio_cb_conns);
|
||||
xns.unregister_server(llio_sid).unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue