pub struct Clk(/* private fields */);
Expand description
A reference-counted clock.
Rust abstraction for the C struct clk
.
§Invariants
A Clk
instance holds either a pointer to a valid struct clk
created by the C portion of
the kernel or a NULL pointer.
Instances of this type are reference-counted. Calling Clk::get
ensures that the allocation
remains valid for the lifetime of the Clk
.
§Examples
The following example demonstrates how to obtain and configure a clock for a device.
use kernel::c_str;
use kernel::clk::{Clk, Hertz};
use kernel::device::Device;
use kernel::error::Result;
fn configure_clk(dev: &Device) -> Result {
let clk = Clk::get(dev, Some(c_str!("apb_clk")))?;
clk.prepare_enable()?;
let expected_rate = Hertz::from_ghz(1);
if clk.rate() != expected_rate {
clk.set_rate(expected_rate)?;
}
clk.disable_unprepare();
Ok(())
}
Implementations§
Source§impl Clk
impl Clk
Sourcepub fn enable(&self) -> Result
pub fn enable(&self) -> Result
Enable the clock.
Equivalent to the kernel’s clk_enable
API.
Sourcepub fn disable(&self)
pub fn disable(&self)
Disable the clock.
Equivalent to the kernel’s clk_disable
API.
Sourcepub fn prepare(&self) -> Result
pub fn prepare(&self) -> Result
Prepare the clock.
Equivalent to the kernel’s clk_prepare
API.
Sourcepub fn unprepare(&self)
pub fn unprepare(&self)
Unprepare the clock.
Equivalent to the kernel’s clk_unprepare
API.
Sourcepub fn prepare_enable(&self) -> Result
pub fn prepare_enable(&self) -> Result
Prepare and enable the clock.
Equivalent to calling Clk::prepare
followed by Clk::enable
.
Sourcepub fn disable_unprepare(&self)
pub fn disable_unprepare(&self)
Disable and unprepare the clock.
Equivalent to calling Clk::disable
followed by Clk::unprepare
.
Sourcepub fn rate(&self) -> Hertz
pub fn rate(&self) -> Hertz
Get clock’s rate.
Equivalent to the kernel’s clk_get_rate
API.
Sourcepub fn set_rate(&self, rate: Hertz) -> Result
pub fn set_rate(&self, rate: Hertz) -> Result
Set clock’s rate.
Equivalent to the kernel’s clk_set_rate
API.