v2.0.0
Functions
hardware_riscv_platform_timer
Hardware APIs

Accessors for standard RISC-V platform timer (mtime/mtimecmp), available on Raspberry Pi microcontrollers with RISC-V processors. More...

## Functions
static void | riscv_timer_set_enabled (bool enabled)
| Enable or disable the RISC-V platform timer. More...
static void | riscv_timer_set_fullspeed (bool fullspeed)
| Configure the RISC-V platform timer to run at full system clock speed. More...
static uint64_t | riscv_timer_get_mtime (void)
| Read the RISC-V platform timer. More...
static void | riscv_timer_set_mtime (uint64_t mtime)
| Update the RISC-V platform timer. More...
static uint64_t | riscv_timer_get_mtimecmp (void)
| Get the current RISC-V platform timer mtimecmp value for this core. More...
static void | riscv_timer_set_mtimecmp (uint64_t mtimecmp)
| Set a new RISC-V platform timer interrupt comparison value (mtimecmp) for this core. More...

## Detailed Description

Accessors for standard RISC-V platform timer (mtime/mtimecmp), available on Raspberry Pi microcontrollers with RISC-V processors.

Note this header can be used by Arm as well as RISC-V processors, as the timer is a memory-mapped peripheral external to the processors. The name refers to this timer being a standard RISC-V peripheral.

## Function Documentation

## ◆ riscv_timer_get_mtime()

static uint64_t riscv_timer_get_mtime | ( | void |  | ) |
| inlinestatic

Read the RISC-V platform timer.

Returns
  Current 64-bit mtime value

## ◆ riscv_timer_get_mtimecmp()

static uint64_t riscv_timer_get_mtimecmp | ( | void |  | ) |
| inlinestatic

Get the current RISC-V platform timer mtimecmp value for this core.

Get the current mtimecmp value for the calling core. This function is interrupt-safe as long as timer interrupts only increase the value of mtimecmp. Otherwise, it must be called with timer interrupts disabled.

Returns
  Current value of mtimecmp

## ◆ riscv_timer_set_enabled()

static void riscv_timer_set_enabled | ( | bool | enabled | ) |
| inlinestatic

Enable or disable the RISC-V platform timer.

This enables and disables the counting of the RISC-V platform timer. It does not enable or disable the interrupts, which are asserted unconditionally when a given core's mtimecmp/mtimecmph registers are greater than the current 64-bit value of the mtime/mtimeh registers.

Parameters

  enabled | Pass true to enable, false to disable

## ◆ riscv_timer_set_fullspeed()

static void riscv_timer_set_fullspeed | ( | bool | fullspeed | ) |
| inlinestatic

Configure the RISC-V platform timer to run at full system clock speed.

Parameters

  fullspeed | Pass true to increment at system clock speed, false to increment at the frequency defined by the system tick generator (the `ticks` block)

## ◆ riscv_timer_set_mtime()

static void riscv_timer_set_mtime | ( | uint64_t | mtime | ) |
| inlinestatic

Update the RISC-V platform timer.

This function should only be called when the timer is disabled via riscv_timer_set_enabled(). Note also that unlike the mtimecmp comparison values, mtime is not core-local, so updates on one core will be visible to the other core.

Parameters

  mtime | New value to set the RISC-V platform timer to

## ◆ riscv_timer_set_mtimecmp()

static void riscv_timer_set_mtimecmp | ( | uint64_t | mtimecmp | ) |
| inlinestatic

Set a new RISC-V platform timer interrupt comparison value (mtimecmp) for this core.

This function updates the mtimecmp value for the current core. The calling core's RISC-V platform timer interrupt is asserted whenever the 64-bit mtime value (stored in 32-bit mtime/mtimeh registers) is greater than or equal to this core's current mtime/mtimecmph value.

Parameters

  mtime | New value to set the RISC-V platform timer to