mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
allow changing fclk through susres server
This commit is contained in:
parent
19df2d3cf8
commit
d26b04f043
4 changed files with 32 additions and 16 deletions
|
|
@ -46,6 +46,19 @@ pub struct PmuControl {
|
|||
pmu_0p8v_dig_hv_ena: bool,
|
||||
}
|
||||
|
||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
pub enum ClockOp {
|
||||
GetVco,
|
||||
GetFclk,
|
||||
GetAclk,
|
||||
GetHclk,
|
||||
GetIclk,
|
||||
GetPclk,
|
||||
GetPer,
|
||||
SetFclk,
|
||||
DeepSleep,
|
||||
}
|
||||
|
||||
/// Requires:
|
||||
/// `freq_hz`: target frequency of PLL - generally it is 2x of the CPU clock frequency
|
||||
/// `daric_cgu`: Pointer to SYSCTL_BASE - for setting clocks
|
||||
|
|
|
|||
|
|
@ -20,15 +20,3 @@ pub enum TimeOp {
|
|||
/// Serialize the internal state for storage across reboots
|
||||
GetState = 1024,
|
||||
}
|
||||
|
||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
pub enum ClockOp {
|
||||
GetVco,
|
||||
GetFclk,
|
||||
GetAclk,
|
||||
GetHclk,
|
||||
GetIclk,
|
||||
GetPclk,
|
||||
GetPer,
|
||||
DeepSleep,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,12 +3,11 @@ pub mod trng;
|
|||
|
||||
use bao1x_api::*;
|
||||
use bao1x_hal::udma::{AdcExtChannel, AdcSource};
|
||||
use bao1x_hal::clocks::ClockOp;
|
||||
use num_traits::*;
|
||||
use xous::{Message, send_message};
|
||||
use xous_api_susres::api::Opcode as SusresOp;
|
||||
|
||||
use crate::api::ClockOp;
|
||||
|
||||
pub struct UdmaGlobal {
|
||||
conn: xous::CID,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ use utralib::*;
|
|||
use xous::{CID, Message, msg_blocking_scalar_unpack, msg_scalar_unpack, send_message, sender::Sender};
|
||||
use xous_api_susres::*;
|
||||
use xous_ipc::Buffer;
|
||||
use bao1x_api::divide_by_fd;
|
||||
use bao1x_hal::clocks::{fd_from_frequency,ClockOp};
|
||||
|
||||
use crate::api::ClockOp;
|
||||
|
||||
static TIMEOUT_TIME: AtomicU32 = AtomicU32::new(5000);
|
||||
|
||||
|
|
@ -376,7 +377,7 @@ fn susres_service() {
|
|||
}),
|
||||
Some(Opcode::Quit) => break,
|
||||
Some(Opcode::PlatformSpecific) => {
|
||||
msg_blocking_scalar_unpack!(msg, op, _arg2, _arg3, _arg4, {
|
||||
msg_blocking_scalar_unpack!(msg, op, arg2, _arg3, _arg4, {
|
||||
let platform_op = FromPrimitive::from_usize(op);
|
||||
match platform_op {
|
||||
Some(ClockOp::GetVco) => {
|
||||
|
|
@ -400,6 +401,21 @@ fn susres_service() {
|
|||
Some(ClockOp::GetPer) => {
|
||||
xous::return_scalar(msg.sender, clk_mgr.perclk as usize).unwrap()
|
||||
}
|
||||
Some(ClockOp::SetFclk) => {
|
||||
const MAX_DEVIATION: f32 = 0.05;
|
||||
let requested_freq = arg2 as u32;
|
||||
let fclk_fd = fd_from_frequency(requested_freq, clk_mgr.clktop);
|
||||
let achievable_freq = divide_by_fd(fclk_fd, clk_mgr.clktop);
|
||||
if (1.0 - (achievable_freq as f32 / requested_freq as f32)).abs() < MAX_DEVIATION {
|
||||
clk_mgr.set_fclk_fd(fclk_fd as u8);
|
||||
clk_mgr.update_clocks();
|
||||
log::info!("Changed fclk to {}", clk_mgr.fclk);
|
||||
xous::return_scalar2(msg.sender, 1, achievable_freq as usize).unwrap();
|
||||
} else {
|
||||
// let user know closest achievable frequency
|
||||
xous::return_scalar2(msg.sender, 0, achievable_freq as usize).unwrap();
|
||||
}
|
||||
}
|
||||
Some(ClockOp::DeepSleep) => {
|
||||
log::info!("entering deep sleep");
|
||||
clk_mgr.deep_sleep();
|
||||
|
|
|
|||
Loading…
Reference in a new issue