RV32 SoC DS UG
High-Perf RV32 SoC DS UG
RV64 SoC DS UG API and Examples
Embedded IDE UG
Loading...
Searching...
No Matches
UserTimer Driver

Overview

Timer driver API definitions.

This module provides functions to configure and control Timer input/output and interrupt behavior.

Usage & Initialization.

This is an example show how to instantiate TIMER with timer_instance_t.

This implementation depends on PLIC Controller Driver for interrupt configuration.

#include "timer/timer.h"
#include "irq.h"
#define TIMER_0 ((timer_hwreg_t *)SYSTEM_USER_TIMER_0_CTRL)
#define PRESCALER_VALUE 127
#define TIMER_LIMIT_VALUE 4095
// Interrupt handler for user timer 0
// User Timer instance configuration
timer_instance_t timer0 = {
.hwreg = TIMER_0,
.prescaler_value = PRESCALER_VALUE,
.prescaler_enable = 0x1U,
.self_restart = 0x1U,
.timer_limit = TIMER_LIMIT_VALUE,
};
// PLIC instance configuration for user timer 0
plic_instance_t timer0_plic = {
// Configure the interrupt source
.target = BSP_PLIC_CPU_0,
.gateway = SYSTEM_USER_TIMER_0_INTERRUPTS_0,
.priority = 0x1U,
.enable = 0x1U,
.threshold = 0x0U,
};
void isrInit(){
plic_applyConfig(&timer0_plic);
}
#define BSP_PLIC_CPU_0
Primary PLIC CPU 0 External Interrupt base address.
Definition bsp.h:51
void trap_entry(void)
The Main Trap Entry Point (Naked).
Definition mtrap.c:129
void irq_enable(void)
Enable Global Interrupts (MIE bit).
Definition irq.c:56
void irq_setType(cpu_irq_t enable)
Enable specific CPU interrupt sources.
Definition irq.c:76
void irq_setTrapVector(void(*trap_vector)(void))
Set the Machine Trap Vector (mtvec).
Definition irq.c:46
@ IRQ_EXTERNAL
Definition irq.h:122
void plic_applyConfig(plic_instance_t *inst)
Apply stored PLIC configuration to hardware.
Definition plic.c:83
void timer_applyConfig(timer_instance_t *inst)
Apply the software configuration to the hardware.
Definition timer.c:93
RISC-V Core Interrupt Handling and Vector Table.
int irq_m_userTimer0_handler(void)
PLIC instance. Holds the software registers and hardware pointer.
Definition plic.h:137
UserTimer instance. Holds the software registers and hardware pointer.
Definition timer.h:149
User Timer driver API definitions.
See also
Example User Timer Demo - Learn how to use the driver for timer operations

Topics

 API Functions
 Function definitions for Timer driver.
 Data Structures
 Structs used by the driver.
 Register Definitions
 Register bitmasks and offsets.