NMSIS-Core  Version 1.4.0
NMSIS-Core support for Nuclei processor-based devices
PLIC Interrupt

Functions that manage interrupts via the PLIC. More...

Macros

#define PLIC_Init(num_sources, enable, thresh)   PLIC_Context_Init(PLIC_GetHartMContextID(), (num_sources), (enable), (thresh))
 
#define PLIC_Init_S(num_sources, enable, thresh)   PLIC_Context_Init(PLIC_GetHartSContextID(), (num_sources), (enable), (thresh))
 
#define PLIC_ClaimInterrupt()   PLIC_ClaimContextInterrupt(PLIC_GetHartMContextID())
 
#define PLIC_ClaimInterrupt_S()   PLIC_ClaimContextInterrupt(PLIC_GetHartSContextID())
 
#define PLIC_CompleteInterrupt(source)   PLIC_CompleteContextInterrupt(PLIC_GetHartMContextID(), (source))
 
#define PLIC_CompleteInterrupt_S(source)   PLIC_CompleteContextInterrupt(PLIC_GetHartSContextID(), (source))
 
#define PLIC_GetInterruptEnable(source)   PLIC_GetContextInterruptEnable(PLIC_GetHartMContextID(), (source))
 
#define PLIC_GetInterruptEnable_S(source)   PLIC_GetContextInterruptEnable(PLIC_GetHartSContextID(), (source))
 
#define PLIC_EnableInterrupt(source)   PLIC_EnableContextInterrupt(PLIC_GetHartMContextID(), (source))
 
#define PLIC_EnableInterrupt_S(source)   PLIC_EnableContextInterrupt(PLIC_GetHartSContextID(), (source))
 
#define PLIC_DisableInterrupt(source)   PLIC_DisableContextInterrupt(PLIC_GetHartMContextID(), (source))
 
#define PLIC_DisableInterrupt_S(source)   PLIC_DisableContextInterrupt(PLIC_GetHartSContextID(), (source))
 
#define PLIC_SetThreshold(source, thresh)   PLIC_SetContextThreshold(PLIC_GetHartMContextID(), (source), (thresh))
 
#define PLIC_SetThreshold_S(source, thresh)   PLIC_SetContextThreshold(PLIC_GetHartSContextID(), (source), (thresh))
 
#define PLIC_GetThreshold()   PLIC_GetContextThreshold(PLIC_GetHartMContextID())
 
#define PLIC_GetThreshold_S()   PLIC_GetContextThreshold(PLIC_GetHartSContextID())
 

Functions

__STATIC_FORCEINLINE void PLIC_SetContextThreshold (uint32_t ctxid, uint32_t thresh)
 Set priority threshold value of plic for selected context. More...
 
__STATIC_FORCEINLINE uint32_t PLIC_GetContextThreshold (uint32_t ctxid)
 Get priority threshold value of plic for selected context. More...
 
__STATIC_FORCEINLINE void PLIC_EnableContextInterrupt (uint32_t ctxid, uint32_t source)
 Enable interrupt of selected source plic for selected context. More...
 
__STATIC_FORCEINLINE void PLIC_DisableContextInterrupt (uint32_t ctxid, uint32_t source)
 Disable interrupt of selected source plic for selected context. More...
 
__STATIC_FORCEINLINE uint32_t PLIC_GetContextInterruptEnable (uint32_t ctxid, uint32_t source)
 Get interrupt enable status of selected source plic for selected context. More...
 
__STATIC_FORCEINLINE void PLIC_SetInterruptPending (uint32_t source)
 Set interrupt pending of selected source plic. More...
 
__STATIC_FORCEINLINE void PLIC_ClearInterruptPending (uint32_t source)
 Clear interrupt pending of selected source plic. More...
 
__STATIC_FORCEINLINE uint32_t PLIC_GetInterruptPending (uint32_t source)
 Get interrupt pending status of selected source plic. More...
 
__STATIC_FORCEINLINE void PLIC_SetPriority (uint32_t source, uint32_t priority)
 Set interrupt priority for selected source plic. More...
 
__STATIC_FORCEINLINE uint32_t PLIC_GetPriority (uint32_t source)
 Get interrupt priority for selected source plic. More...
 
__STATIC_FORCEINLINE uint32_t PLIC_ClaimContextInterrupt (uint32_t ctxid)
 Claim interrupt for plic for selected context. More...
 
__STATIC_FORCEINLINE void PLIC_CompleteContextInterrupt (uint32_t ctxid, uint32_t source)
 Complete interrupt for plic for selected context. More...
 
__STATIC_FORCEINLINE void PLIC_Context_Init (uint32_t ctxid, uint32_t num_sources, uint32_t enable, uint32_t thresh)
 Perform init for plic for selected context. More...
 
__STATIC_FORCEINLINE void __set_trap_entry (rv_csr_t addr)
 Set Trap entry address. More...
 
__STATIC_FORCEINLINE rv_csr_t __get_trap_entry (void)
 Get trap entry address. More...
 

Detailed Description

Functions that manage interrupts via the PLIC.

Macro Definition Documentation

◆ PLIC_ClaimInterrupt

#define PLIC_ClaimInterrupt ( )    PLIC_ClaimContextInterrupt(PLIC_GetHartMContextID())

Definition at line 368 of file core_feature_plic.h.

◆ PLIC_ClaimInterrupt_S

#define PLIC_ClaimInterrupt_S ( )    PLIC_ClaimContextInterrupt(PLIC_GetHartSContextID())

Definition at line 369 of file core_feature_plic.h.

◆ PLIC_CompleteInterrupt

#define PLIC_CompleteInterrupt (   source)    PLIC_CompleteContextInterrupt(PLIC_GetHartMContextID(), (source))

Definition at line 371 of file core_feature_plic.h.

◆ PLIC_CompleteInterrupt_S

#define PLIC_CompleteInterrupt_S (   source)    PLIC_CompleteContextInterrupt(PLIC_GetHartSContextID(), (source))

Definition at line 372 of file core_feature_plic.h.

◆ PLIC_DisableInterrupt

#define PLIC_DisableInterrupt (   source)    PLIC_DisableContextInterrupt(PLIC_GetHartMContextID(), (source))

Definition at line 380 of file core_feature_plic.h.

◆ PLIC_DisableInterrupt_S

#define PLIC_DisableInterrupt_S (   source)    PLIC_DisableContextInterrupt(PLIC_GetHartSContextID(), (source))

Definition at line 381 of file core_feature_plic.h.

◆ PLIC_EnableInterrupt

#define PLIC_EnableInterrupt (   source)    PLIC_EnableContextInterrupt(PLIC_GetHartMContextID(), (source))

Definition at line 377 of file core_feature_plic.h.

◆ PLIC_EnableInterrupt_S

#define PLIC_EnableInterrupt_S (   source)    PLIC_EnableContextInterrupt(PLIC_GetHartSContextID(), (source))

Definition at line 378 of file core_feature_plic.h.

◆ PLIC_GetInterruptEnable

#define PLIC_GetInterruptEnable (   source)    PLIC_GetContextInterruptEnable(PLIC_GetHartMContextID(), (source))

Definition at line 374 of file core_feature_plic.h.

◆ PLIC_GetInterruptEnable_S

#define PLIC_GetInterruptEnable_S (   source)    PLIC_GetContextInterruptEnable(PLIC_GetHartSContextID(), (source))

Definition at line 375 of file core_feature_plic.h.

◆ PLIC_GetThreshold

#define PLIC_GetThreshold ( )    PLIC_GetContextThreshold(PLIC_GetHartMContextID())

Definition at line 386 of file core_feature_plic.h.

◆ PLIC_GetThreshold_S

#define PLIC_GetThreshold_S ( )    PLIC_GetContextThreshold(PLIC_GetHartSContextID())

Definition at line 387 of file core_feature_plic.h.

◆ PLIC_Init

#define PLIC_Init (   num_sources,
  enable,
  thresh 
)    PLIC_Context_Init(PLIC_GetHartMContextID(), (num_sources), (enable), (thresh))

Definition at line 365 of file core_feature_plic.h.

◆ PLIC_Init_S

#define PLIC_Init_S (   num_sources,
  enable,
  thresh 
)    PLIC_Context_Init(PLIC_GetHartSContextID(), (num_sources), (enable), (thresh))

Definition at line 366 of file core_feature_plic.h.

◆ PLIC_SetThreshold

#define PLIC_SetThreshold (   source,
  thresh 
)    PLIC_SetContextThreshold(PLIC_GetHartMContextID(), (source), (thresh))

Definition at line 383 of file core_feature_plic.h.

◆ PLIC_SetThreshold_S

#define PLIC_SetThreshold_S (   source,
  thresh 
)    PLIC_SetContextThreshold(PLIC_GetHartSContextID(), (source), (thresh))

Definition at line 384 of file core_feature_plic.h.

Function Documentation

◆ __get_trap_entry()

__STATIC_FORCEINLINE rv_csr_t __get_trap_entry ( void  )

Get trap entry address.

This function get trap entry address from 'CSR_MTVEC'.

Returns
trap entry address
Remarks
  • This function use to get trap entry address from 'CSR_MTVEC'.
See also

Definition at line 415 of file core_feature_plic.h.

416 {
417  unsigned long addr = __RV_CSR_READ(CSR_MTVEC);
418  return (addr);
419 }
#define __RV_CSR_READ(csr)
CSR operation Macro for csrr instruction.
#define CSR_MTVEC

References __RV_CSR_READ, and CSR_MTVEC.

◆ __set_trap_entry()

__STATIC_FORCEINLINE void __set_trap_entry ( rv_csr_t  addr)

Set Trap entry address.

This function set trap entry address to 'CSR_MTVEC'.

Parameters
[in]addrtrap entry address
Remarks
  • This function use to set trap entry address to 'CSR_MTVEC'.
See also

Definition at line 399 of file core_feature_plic.h.

400 {
401  addr &= (rv_csr_t)(~0x7);
402  __RV_CSR_WRITE(CSR_MTVEC, addr);
403 }
#define __RV_CSR_WRITE(csr, val)
CSR operation Macro for csrw instruction.
unsigned long rv_csr_t
Type of Control and Status Register(CSR), depends on the XLEN defined in RISC-V.

References __RV_CSR_WRITE, and CSR_MTVEC.

◆ PLIC_ClaimContextInterrupt()

__STATIC_FORCEINLINE uint32_t PLIC_ClaimContextInterrupt ( uint32_t  ctxid)

Claim interrupt for plic for selected context.

This function claim interrupt for plic for selected context.

Parameters
[in]ctxidselected context id
Returns
the ID of the highest priority pending interrupt or zero if there is no pending interrupt
Remarks
A successful claim will also atomically clear the corresponding pending bit on the interrupt source. The PLIC can perform a claim at any time and the claim operation is not affected by the setting of the priority threshold register.
See also

Definition at line 308 of file core_feature_plic.h.

309 {
310  volatile uint32_t *claim_reg = (uint32_t *)PLIC_CLAIM_REGADDR(ctxid);
311 
312  return (*claim_reg);
313 }
#define PLIC_CLAIM_REGADDR(ctxid)

References PLIC_CLAIM_REGADDR.

◆ PLIC_ClearInterruptPending()

__STATIC_FORCEINLINE void PLIC_ClearInterruptPending ( uint32_t  source)

Clear interrupt pending of selected source plic.

This function clear interrupt pending of selected source plic

Parameters
[in]sourceinterrupt source
Remarks
See also

Definition at line 231 of file core_feature_plic.h.

232 {
233  volatile uint32_t *pending_reg = (uint32_t *)PLIC_PENDING_REGADDR(source);
234 
235  uint32_t current = *pending_reg;
236  current = current & (~(1UL << (source & 0x1F)));
237  *pending_reg = current;
238 }
#define PLIC_PENDING_REGADDR(source)

References PLIC_PENDING_REGADDR.

◆ PLIC_CompleteContextInterrupt()

__STATIC_FORCEINLINE void PLIC_CompleteContextInterrupt ( uint32_t  ctxid,
uint32_t  source 
)

Complete interrupt for plic for selected context.

This function complete interrupt for plic for selected context.

Parameters
[in]ctxidselected context id
Returns
the ID of the highest priority pending interrupt or zero if there is no pending interrupt
Remarks
The PLIC signals it has completed executing an interrupt handler by writing the interrupt ID it received from the claim to the claim/complete register. The PLIC does not check whether the completion ID is the same as the last claim ID for that context. If the completion ID does not match an interrupt source that is currently enabled for the context, the completion is silently ignored.
See also

Definition at line 332 of file core_feature_plic.h.

333 {
334  volatile uint32_t *complete_reg = (uint32_t *)PLIC_COMPLETE_REGADDR(ctxid);
335 
336  *complete_reg = source;
337 }
#define PLIC_COMPLETE_REGADDR(ctxid)

References PLIC_COMPLETE_REGADDR.

◆ PLIC_Context_Init()

__STATIC_FORCEINLINE void PLIC_Context_Init ( uint32_t  ctxid,
uint32_t  num_sources,
uint32_t  enable,
uint32_t  thresh 
)

Perform init for plic for selected context.

This function perform initialization steps for plic for selected context.

Parameters
[in]ctxidselected context id
[in]num_sourcesplic interrupt source count number
[in]enableplic interrupt enable or not
[in]threshplic interrupt threshold
Remarks
  • Disable all interrupts
  • Set priority threshold to value specified by thresh

Definition at line 351 of file core_feature_plic.h.

352 {
353  uint32_t i;
354 
355  for (i = 0; i < num_sources; i ++) {
356  if (enable) {
357  PLIC_EnableContextInterrupt(ctxid, i);
358  } else {
360  }
361  }
362  PLIC_SetContextThreshold(ctxid, thresh);
363 }
__STATIC_FORCEINLINE void PLIC_SetContextThreshold(uint32_t ctxid, uint32_t thresh)
Set priority threshold value of plic for selected context.
__STATIC_FORCEINLINE void PLIC_EnableContextInterrupt(uint32_t ctxid, uint32_t source)
Enable interrupt of selected source plic for selected context.
__STATIC_FORCEINLINE void PLIC_DisableContextInterrupt(uint32_t ctxid, uint32_t source)
Disable interrupt of selected source plic for selected context.

References PLIC_DisableContextInterrupt(), PLIC_EnableContextInterrupt(), and PLIC_SetContextThreshold().

◆ PLIC_DisableContextInterrupt()

__STATIC_FORCEINLINE void PLIC_DisableContextInterrupt ( uint32_t  ctxid,
uint32_t  source 
)

Disable interrupt of selected source plic for selected context.

This function disable interrupt of selected source plic for selected context

Parameters
[in]ctxidselected context id
[in]sourceinterrupt source
Remarks
See also

Definition at line 172 of file core_feature_plic.h.

173 {
174  volatile uint32_t *enable_reg = (uint32_t *)PLIC_ENABLE_REGADDR(ctxid, source);
175 
176  uint32_t current = *enable_reg;
177  current = current & (~(1UL << (source & 0x1F)));
178  *enable_reg = current;
179 }
#define PLIC_ENABLE_REGADDR(ctxid, source)

References PLIC_ENABLE_REGADDR.

Referenced by PLIC_Context_Init().

◆ PLIC_EnableContextInterrupt()

__STATIC_FORCEINLINE void PLIC_EnableContextInterrupt ( uint32_t  ctxid,
uint32_t  source 
)

Enable interrupt of selected source plic for selected context.

This function enable interrupt of selected source plic for selected context.

Parameters
[in]ctxidselected context id
[in]sourceinterrupt source
Remarks
See also

Definition at line 153 of file core_feature_plic.h.

154 {
155  volatile uint32_t *enable_reg = (uint32_t *)PLIC_ENABLE_REGADDR(ctxid, source);
156 
157  uint32_t current = *enable_reg;
158  current = current | (1UL << (source & 0x1F));
159  *enable_reg = current;
160 }

References PLIC_ENABLE_REGADDR.

Referenced by PLIC_Context_Init().

◆ PLIC_GetContextInterruptEnable()

__STATIC_FORCEINLINE uint32_t PLIC_GetContextInterruptEnable ( uint32_t  ctxid,
uint32_t  source 
)

Get interrupt enable status of selected source plic for selected context.

This function get interrupt enable of selected source plic for selected context.

Parameters
[in]ctxidselected context id
[in]sourceinterrupt source
Returns
enable status for selected interrupt source for selected context
Remarks
See also

Definition at line 193 of file core_feature_plic.h.

194 {
195  volatile uint32_t *enable_reg = (uint32_t *)PLIC_ENABLE_REGADDR(ctxid, source);
196 
197  uint32_t current = *enable_reg;
198  current = (current >> (source & 0x1F)) & 0x1;
199  return current;
200 }

References PLIC_ENABLE_REGADDR.

◆ PLIC_GetContextThreshold()

__STATIC_FORCEINLINE uint32_t PLIC_GetContextThreshold ( uint32_t  ctxid)

Get priority threshold value of plic for selected context.

This function get priority threshold value of plic for selected context.

Parameters
[in]ctxidselected context id
Returns
priority threshold value for selected context
Remarks
See also

Definition at line 136 of file core_feature_plic.h.

137 {
138  volatile uint32_t *thresh_reg = (uint32_t *)PLIC_THRESHOLD_REGADDR(ctxid);
139 
140  return (*thresh_reg);
141 }
#define PLIC_THRESHOLD_REGADDR(ctxid)

References PLIC_THRESHOLD_REGADDR.

◆ PLIC_GetInterruptPending()

__STATIC_FORCEINLINE uint32_t PLIC_GetInterruptPending ( uint32_t  source)

Get interrupt pending status of selected source plic.

This function get interrupt pending of selected source plic

Parameters
[in]sourceinterrupt source
Returns
interrupt pending status for selected interrupt source
Remarks
See also

Definition at line 251 of file core_feature_plic.h.

252 {
253  volatile uint32_t *pending_reg = (uint32_t *)PLIC_PENDING_REGADDR(source);
254 
255  uint32_t current = *pending_reg;
256  current = (current >> (source & 0x1F)) & 0x1;
257  return current;
258 }

References PLIC_PENDING_REGADDR.

◆ PLIC_GetPriority()

__STATIC_FORCEINLINE uint32_t PLIC_GetPriority ( uint32_t  source)

Get interrupt priority for selected source plic.

This function get interrupt priority for selected source plic.

Parameters
[in]sourceinterrupt source
[in]priorityinterrupt priority
Remarks
See also

Definition at line 287 of file core_feature_plic.h.

288 {
289  volatile uint32_t *priority_reg = (uint32_t *)PLIC_PRIORITY_REGADDR(source);
290 
291  return (*priority_reg);
292 }
#define PLIC_PRIORITY_REGADDR(source)

References PLIC_PRIORITY_REGADDR.

◆ PLIC_SetContextThreshold()

__STATIC_FORCEINLINE void PLIC_SetContextThreshold ( uint32_t  ctxid,
uint32_t  thresh 
)

Set priority threshold value of plic for selected context.

This function set priority threshold value of plic for selected context.

Parameters
[in]ctxidselected context id
[in]threshthreshold value
Remarks
See also

Definition at line 119 of file core_feature_plic.h.

120 {
121  volatile uint32_t *thresh_reg = (uint32_t *)PLIC_THRESHOLD_REGADDR(ctxid);
122 
123  *thresh_reg = thresh;
124 }

References PLIC_THRESHOLD_REGADDR.

Referenced by PLIC_Context_Init().

◆ PLIC_SetInterruptPending()

__STATIC_FORCEINLINE void PLIC_SetInterruptPending ( uint32_t  source)

Set interrupt pending of selected source plic.

This function set interrupt pending of selected source plic.

Parameters
[in]sourceinterrupt source
Remarks
See also

Definition at line 212 of file core_feature_plic.h.

213 {
214  volatile uint32_t *pending_reg = (uint32_t *)PLIC_PENDING_REGADDR(source);
215 
216  uint32_t current = *pending_reg;
217  current = current | (1UL << (source & 0x1F));
218  *pending_reg = current;
219 }

References PLIC_PENDING_REGADDR.

◆ PLIC_SetPriority()

__STATIC_FORCEINLINE void PLIC_SetPriority ( uint32_t  source,
uint32_t  priority 
)

Set interrupt priority for selected source plic.

This function set interrupt priority for selected source plic.

Parameters
[in]sourceinterrupt source
[in]priorityinterrupt priority
Remarks
See also

Definition at line 270 of file core_feature_plic.h.

271 {
272  volatile uint32_t *priority_reg = (uint32_t *)PLIC_PRIORITY_REGADDR(source);
273 
274  *priority_reg = priority;
275 }

References PLIC_PRIORITY_REGADDR.

Referenced by PLIC_Register_IRQ(), and PLIC_Register_IRQ_S().