Struct Clk

Source
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

Source

pub fn get(dev: &Device, name: Option<&CStr>) -> Result<Self>

Gets Clk corresponding to a Device and a connection id.

Equivalent to the kernel’s clk_get API.

Source

pub fn as_raw(&self) -> *mut clk

Obtain the raw [struct clk] pointer.

Source

pub fn enable(&self) -> Result

Enable the clock.

Equivalent to the kernel’s clk_enable API.

Source

pub fn disable(&self)

Disable the clock.

Equivalent to the kernel’s clk_disable API.

Source

pub fn prepare(&self) -> Result

Prepare the clock.

Equivalent to the kernel’s clk_prepare API.

Source

pub fn unprepare(&self)

Unprepare the clock.

Equivalent to the kernel’s clk_unprepare API.

Source

pub fn prepare_enable(&self) -> Result

Prepare and enable the clock.

Equivalent to calling Clk::prepare followed by Clk::enable.

Source

pub fn disable_unprepare(&self)

Disable and unprepare the clock.

Equivalent to calling Clk::disable followed by Clk::unprepare.

Source

pub fn rate(&self) -> Hertz

Get clock’s rate.

Equivalent to the kernel’s clk_get_rate API.

Source

pub fn set_rate(&self, rate: Hertz) -> Result

Set clock’s rate.

Equivalent to the kernel’s clk_set_rate API.

Trait Implementations§

Source§

impl Drop for Clk

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Clk

§

impl RefUnwindSafe for Clk

§

impl !Send for Clk

§

impl !Sync for Clk

§

impl Unpin for Clk

§

impl UnwindSafe for Clk

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, E> Init<T, E> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, E> PinInit<T, E> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.