Clocks

API for manipulating clock sources.

The clock interface allows for controlling the rate of various clocks in the system.

Typedefs

typedef void (*metal_clock_rate_change_callback)(void *priv)

Function signature of clock rate change callbacks.

typedef struct _metal_clock_callback_t metal_clock_callback

Type for the linked list of callbacks for clock rate changes.

Functions

__inline__ long metal_clock_get_rate_hz(const struct metal_clock *clk)

Returns the current rate of the given clock.

Return

The current rate of the clock in Hz

Parameters
  • clk: The handle for the clock

__inline__ long metal_clock_set_rate_hz(struct metal_clock *clk, long hz)

Set the current rate of a clock.

Attempts to set the current rate of the given clock to as close as possible to the given rate in Hz. Returns the actual value that’s been selected, which could be anything!

Return

The new rate of the clock in Hz.

Parameters
  • clk: The handle for the clock

  • hz: The desired rate in Hz

Prior to and after the rate change of the clock, this will call the registered pre- and post-rate change callbacks.

__inline__ void metal_clock_register_pre_rate_change_callback(struct metal_clock *clk, metal_clock_callback *cb)

Register a callback that must be called before a rate change.

Parameters
  • clk: The handle for the clock

  • cb: The callback to be registered

__inline__ void metal_clock_register_post_rate_change_callback(struct metal_clock *clk, metal_clock_callback *cb)

Registers a callback that must be called after a rate change.

Parameters
  • clk: The handle for the clock

  • cb: The callback to be registered

struct metal_clock
#include <clock.h>

The handle for a clock.

Clocks are defined as a pointer to a struct metal_clock, the contents of which are implementation defined. Users of the clock interface must call functions which accept a struct metal_clock * as an argument to interract with the clock.

Note that no mechanism for obtaining a pointer to a struct metal_clock has been defined, making it impossible to call any of these functions without invoking implementation-defined behavior.