PebbleOS v4.44.0-150-gc3023ce72
Loading...
Searching...
No Matches
System timer

Clock source and clock event devices the kernel keeps time with. More...

Data Structures

struct  pbl_clocksource_ops
 Clock source operations. More...
 
struct  pbl_clocksource
 Clock source: a free-running counter. More...
 
struct  pbl_clockevent_ops
 Clock event device operations. More...
 
struct  pbl_clockevent
 Clock event device: a one-shot timer interrupt. More...
 

Macros

#define PBL_CLOCKSOURCE_INIT(sym, _name, _init, _ops, _bits)
 Clock source initializer.
 
#define PBL_CLOCKEVENT_INIT(sym, _name, _init, _ops, _min, _max)
 Clock event device initializer.
 

Functions

void pbl_clocksource_set_hz (const struct pbl_clocksource *cs, uint32_t hz)
 Set the rate of a clock source.
 
void pbl_clocksource_set_mhz (const struct pbl_clocksource *cs, uint64_t mhz)
 Set the rate of a clock source, with millihertz resolution.
 
void pbl_clockevent_set_hz (const struct pbl_clockevent *ce, uint32_t hz)
 Set the rate of a clock event device.
 
void pbl_clockevent_handler (const struct pbl_clockevent *ce)
 Report a clock event.
 

Variables

const struct pbl_clocksource *const pbl_system_clocksource
 The system clock source, defined by the SoC's timer driver.
 
const struct pbl_clockevent *const pbl_system_clockevent
 The system clock event device, defined by the SoC's timer driver.
 

Detailed Description

Clock source and clock event devices the kernel keeps time with.

A clock source is a free-running counter: the kernel reads it to know how much time passed, extending it to 64 bits. A clock event device raises an interrupt after a given number of its cycles, once: the kernel programs it for the next tick while threads run, and for the next timeout when the CPU idles. Drivers know nothing about ticks.

The system clock source and clock event device are pbl_system_clocksource and pbl_system_clockevent, defined by the timer drivers of the SoC; one device may provide both. The kernel initializes them when the scheduler starts, or earlier through pbl_device_init(). Both must keep running in every idle state the SoC enters.

static uint32_t prv_read(const struct pbl_clocksource *cs) {
return pbl_readl(FOO_CNT);
}
static void prv_set_next(const struct pbl_clockevent *ce, uint32_t delta) {
pbl_writel(pbl_readl(FOO_CNT) + delta, FOO_CMP);
}
static void prv_isr(void) {
pbl_writel(FOO_EVENT_CMP, FOO_EVENT_CLR);
}
Clock event device: a one-shot timer interrupt.
Definition timer.h:73
Clock source: a free-running counter.
Definition timer.h:52
void pbl_clockevent_handler(const struct pbl_clockevent *ce)
Report a clock event.
static uint32_t pbl_readl(uintptr_t addr)
Read a 32-bit register.
Definition mmio.h:67
static void pbl_writel(uint32_t val, uintptr_t addr)
Write a 32-bit register.
Definition mmio.h:97

Data Structure Documentation

◆ pbl_clocksource

struct pbl_clocksource

Clock source: a free-running counter.

Data Fields
struct pbl_device dev Device.
uint32_t mask Counter mask, 2^bits - 1.
const struct pbl_clocksource_ops * ops Driver operations.

◆ pbl_clockevent

struct pbl_clockevent

Clock event device: a one-shot timer interrupt.

Data Fields
struct pbl_device dev Device.
uint32_t max_delta Longest delay the device can generate, in its cycles.
uint32_t min_delta Shortest delay the device can generate, in its cycles.
const struct pbl_clockevent_ops * ops Driver operations.

Macro Definition Documentation

◆ PBL_CLOCKEVENT_INIT

#define PBL_CLOCKEVENT_INIT (   sym,
  _name,
  _init,
  _ops,
  _min,
  _max 
)
Value:
{ \
.dev = PBL_DEVICE_INIT_CLASS(sym, _name, _init, nullptr, nullptr, &pbl_clockevent_class), \
.ops = (_ops), \
.min_delta = (_min), \
.max_delta = (_max), \
}
#define PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, _deps, _cls)
Initializer for the struct pbl_device of device instance sym, in class _cls.
Definition device.h:123

Clock event device initializer.

Parameters
symSymbol of the device instance, with its state defined by PBL_DEVICE_STATE_DEFINE().
_nameName.
_initInit function, which must set the rate with pbl_clockevent_set_hz().
_opsDriver operations.
_minShortest delay, in cycles.
_maxLongest delay, in cycles.

◆ PBL_CLOCKSOURCE_INIT

#define PBL_CLOCKSOURCE_INIT (   sym,
  _name,
  _init,
  _ops,
  _bits 
)
Value:
{ \
.dev = PBL_DEVICE_INIT_CLASS(sym, _name, _init, nullptr, nullptr, &pbl_clocksource_class), \
.ops = (_ops), \
.mask = (uint32_t)((1ULL << (_bits)) - 1U), \
}

Clock source initializer.

Parameters
symSymbol of the device instance, with its state defined by PBL_DEVICE_STATE_DEFINE().
_nameName.
_initInit function, which must set the rate with pbl_clocksource_set_hz() or pbl_clocksource_set_mhz().
_opsDriver operations.
_bitsCounter width.

Function Documentation

◆ pbl_clockevent_handler()

void pbl_clockevent_handler ( const struct pbl_clockevent *  ce)

Report a clock event.

Called by the driver from its interrupt handler.

Parameters
ceClock event device.

◆ pbl_clockevent_set_hz()

void pbl_clockevent_set_hz ( const struct pbl_clockevent *  ce,
uint32_t  hz 
)

Set the rate of a clock event device.

Called by the driver from its init, and again whenever the rate changes.

Parameters
ceClock event device.
hzRate of the cycles the device counts delays in.

◆ pbl_clocksource_set_hz()

void pbl_clocksource_set_hz ( const struct pbl_clocksource *  cs,
uint32_t  hz 
)

Set the rate of a clock source.

Called by the driver from its init, and again whenever the rate changes, for instance after a low-power oscillator calibration. Time stays continuous across changes.

Parameters
csClock source.
hzCounter rate.

◆ pbl_clocksource_set_mhz()

void pbl_clocksource_set_mhz ( const struct pbl_clocksource *  cs,
uint64_t  mhz 
)

Set the rate of a clock source, with millihertz resolution.

As pbl_clocksource_set_hz(), for counters whose rate is not a whole number of hertz, such as a calibrated RC oscillator.

Parameters
csClock source.
mhzCounter rate, in millihertz.

Variable Documentation

◆ pbl_system_clockevent

const struct pbl_clockevent* const pbl_system_clockevent
extern

The system clock event device, defined by the SoC's timer driver.

◆ pbl_system_clocksource

const struct pbl_clocksource* const pbl_system_clocksource
extern

The system clock source, defined by the SoC's timer driver.