Sapphire SoC DS Sapphire SoC UG Sapphire HP SoC DS Sapphire HP SoC UG RISC-V Embedded IDE UG Board Support Package
Loading...
Searching...
No Matches
plic.c
Go to the documentation of this file.
1
2// Copyright (C) 2013-2026 Efinix Inc. All rights reserved.
3// Full license header bsp/efinix/EfxSapphireSocRV64/include/LICENSE.MD
5
15
16#include <stdio.h>
17#include <stdint.h>
18#include "plic/plic.h"
19
20
21#define PLIC ((plic_hwreg_t *)SYSTEM_PLIC_CTRL)
27
29{
30 volatile uintptr_t mhartid = csr_read(mhartid);
31 return PLIC->regs_context[mhartid*2].CLAIM;
32}
33
35{
36 volatile uintptr_t mhartid = csr_read(mhartid);
37 PLIC->regs_context[mhartid*2].CLAIM = gateway;
38}
39
41{
42 PLIC->regs_priority.PRIORITY[inst->gateway] = inst->priority;
43}
44
46{
47 return PLIC->regs_priority.PRIORITY[inst->gateway];
48}
49
51{
52 u32 group = inst->gateway / 32;
53 u32 intr_en = 1 << (inst->gateway % 32);
54 u32 current = PLIC->regs_enable[inst->target].ENABLE[group];
55
56 if (inst->enable) {
57 PLIC->regs_enable[inst->target].ENABLE[group] = current | intr_en;
58 } else {
59 PLIC->regs_enable[inst->target].ENABLE[group] = current & ~intr_en;
60 }
61}
62
64{
65 PLIC->regs_context[inst->target].THRESHOLD = inst->threshold;
66}
67
69{
70 return PLIC->regs_context[inst->target].THRESHOLD;
71}
72
74{
75 return PLIC->regs_context[inst->target].CLAIM;
76}
77
79{
80 PLIC->regs_context[inst->target].CLAIM = inst->gateway;
81}
82
84{
85 // 1. Set the threshold for the target context
87 // 2. Set priority for the specific gateway (Source)
89 // 3. Enable this gateway for the specific target
90 plic_set_enable(inst);
91}
92
93
void plic_set_priority(plic_instance_t *inst)
Set priority value to PLIC register.
Definition plic.c:40
u32 plic_get_threshold(plic_instance_t *inst)
Read value from PLIC register.
Definition plic.c:68
void plic_releaseExtIRQ_m(u32 gateway)
Release ID source from external IRQ.
Definition plic.c:34
void plic_applyConfig(plic_instance_t *inst)
Apply stored PLIC configuration to hardware.
Definition plic.c:83
u32 plic_get_priority(plic_instance_t *inst)
Read value from PLIC register.
Definition plic.c:45
void plic_set_threshold(plic_instance_t *inst)
Set threshold value to PLIC register.
Definition plic.c:63
void plic_set_enable(plic_instance_t *inst)
Set enable value to PLIC register.
Definition plic.c:50
u32 plic_claimExtIRQ_m()
Initialize the PLIC instance with a base address. Calculates the internal pointers for the register b...
Definition plic.c:28
#define csr_read(csr)
This function is used to read the value of a CSR.
Definition riscv.h:188
void plic_release(plic_instance_t *inst)
Definition plic.c:78
#define PLIC
Definition plic.c:21
u32 plic_claim(plic_instance_t *inst)
Definition plic.c:73
PLIC driver API definitions.
PLIC instance. Holds the software registers and hardware pointer.
Definition plic.h:112
u32 gateway
Interrupt source ID.
Definition plic.h:114
u32 target
Set Target to handler external interrupt.
Definition plic.h:113
u32 priority
Priority Level: 0=Disable, 1=Low, 3=Highest.
Definition plic.h:115
u32 enable
Interrupt Enable Bit (1=Enable).
Definition plic.h:116
u32 threshold
CPU accepts any priority > 0.
Definition plic.h:117
uint32_t u32
Definition type.h:22