HPM SDK
HPMicro Software Development Kit
hpm_interrupt.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-2025 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_INTERRUPT_H
9 #define HPM_INTERRUPT_H
10 #include "hpm_common.h"
11 #include "hpm_csr_drv.h"
12 #include "hpm_plic_drv.h"
13 #include "hpm_soc_feature.h"
14 
21 #define M_MODE 0
22 #define S_MODE 1
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* Machine mode API: these APIs are supposed to be called at machine mode */
29 
35 ATTR_ALWAYS_INLINE static inline void enable_global_irq(uint32_t mask)
36 {
37  set_csr(CSR_MSTATUS, mask);
38 }
39 
46 ATTR_ALWAYS_INLINE static inline uint32_t disable_global_irq(uint32_t mask)
47 {
48  return read_clear_csr(CSR_MSTATUS, mask);
49 }
50 
56 ATTR_ALWAYS_INLINE static inline void restore_global_irq(uint32_t mask)
57 {
58  set_csr(CSR_MSTATUS, mask);
59 }
60 
65 ATTR_ALWAYS_INLINE static inline void enable_irq_from_intc(void)
66 {
68 }
69 
74 ATTR_ALWAYS_INLINE static inline void disable_irq_from_intc(void)
75 {
77 }
78 
82 ATTR_ALWAYS_INLINE static inline void enable_mchtmr_irq(void)
83 {
85 }
86 
91 ATTR_ALWAYS_INLINE static inline void disable_mchtmr_irq(void)
92 {
94 }
95 
96 #ifdef CSR_MIDELEG
102 ATTR_ALWAYS_INLINE static inline void delegate_irq(uint32_t mask)
103 {
104  set_csr(CSR_MIDELEG, mask);
105 }
106 
112 ATTR_ALWAYS_INLINE static inline void undelegate_irq(uint32_t mask)
113 {
114  clear_csr(CSR_MIDELEG, mask);
115 }
116 #endif
117 
118 
119 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
120 /* Supervisor mode API: these APIs are supposed to be called at supervisor mode */
121 
127 ATTR_ALWAYS_INLINE static inline void enable_s_global_irq(uint32_t mask)
128 {
129  set_csr(CSR_SSTATUS, mask);
130 }
131 
138 ATTR_ALWAYS_INLINE static inline uint32_t disable_s_global_irq(uint32_t mask)
139 {
140  return read_clear_csr(CSR_SSTATUS, mask);
141 }
142 
148 ATTR_ALWAYS_INLINE static inline void restore_s_global_irq(uint32_t mask)
149 {
150  set_csr(CSR_SSTATUS, mask);
151 }
152 
157 ATTR_ALWAYS_INLINE static inline void disable_s_irq_from_intc(void)
158 {
160 }
161 
166 ATTR_ALWAYS_INLINE static inline void enable_s_irq_from_intc(void)
167 {
169 }
170 
174 ATTR_ALWAYS_INLINE static inline void enable_s_mchtmr_irq(void)
175 {
177 }
178 
183 ATTR_ALWAYS_INLINE static inline void disable_s_mchtmr_irq(void)
184 {
186 }
187 #endif
188 
189 
190 /*
191  * CPU Machine SWI control
192  *
193  * Machine SWI (MSIP) is connected to PLICSW irq 1.
194  */
195 #define PLICSWI 1
196 
201 ATTR_ALWAYS_INLINE static inline void intc_m_init_swi(void)
202 {
203  __plic_enable_irq(HPM_PLICSW_BASE, HPM_PLIC_TARGET_M_MODE, PLICSWI);
204 }
205 
206 
211 ATTR_ALWAYS_INLINE static inline void intc_m_enable_swi(void)
212 {
214 }
215 
216 
221 ATTR_ALWAYS_INLINE static inline void intc_m_disable_swi(void)
222 {
224 }
225 
226 
231 ATTR_ALWAYS_INLINE static inline void intc_m_trigger_swi(void)
232 {
233  __plic_set_irq_pending(HPM_PLICSW_BASE, PLICSWI);
234 }
235 
240 ATTR_ALWAYS_INLINE static inline void intc_m_claim_swi(void)
241 {
242  __plic_claim_irq(HPM_PLICSW_BASE, 0);
243 }
244 
249 ATTR_ALWAYS_INLINE static inline void intc_m_complete_swi(void)
250 {
251  __plic_complete_irq(HPM_PLICSW_BASE, HPM_PLIC_TARGET_M_MODE, PLICSWI);
252 }
253 
254 /*
255  * @brief Enable IRQ for machine mode
256  *
257  * @param[in] irq Interrupt number
258  */
259 #define intc_m_enable_irq(irq) \
260  intc_enable_irq(HPM_PLIC_TARGET_M_MODE, irq)
261 
262 /*
263  * @brief Disable IRQ for machine mode
264  *
265  * @param[in] irq Interrupt number
266  */
267 #define intc_m_disable_irq(irq) \
268  intc_disable_irq(HPM_PLIC_TARGET_M_MODE, irq)
269 
270 #define intc_m_set_threshold(threshold) \
271  intc_set_threshold(HPM_PLIC_TARGET_M_MODE, threshold)
272 
273 #define intc_m_get_threshold() \
274  intc_get_threshold(HPM_PLIC_TARGET_M_MODE)
275 
276 /*
277  * @brief Complete IRQ for machine mode
278  *
279  * @param[in] irq Interrupt number
280  */
281 #define intc_m_complete_irq(irq) \
282  intc_complete_irq(HPM_PLIC_TARGET_M_MODE, irq)
283 
284 /*
285  * @brief Claim IRQ for machine mode
286  *
287  */
288 #define intc_m_claim_irq() intc_claim_irq(HPM_PLIC_TARGET_M_MODE)
289 
290 /*
291  * @brief Enable IRQ for machine mode with priority
292  *
293  * @param[in] irq Interrupt number
294  * @param[in] priority Priority of interrupt
295  */
296 #define intc_m_enable_irq_with_priority(irq, priority) \
297  do { \
298  intc_set_irq_priority(irq, priority); \
299  intc_m_enable_irq(irq); \
300  } while (0)
301 
302 
303 
304 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
305 /* Supervisor mode */
306 
311 ATTR_ALWAYS_INLINE static inline void intc_s_enable_swi(void)
312 {
314 }
315 
316 
321 ATTR_ALWAYS_INLINE static inline void intc_s_disable_swi(void)
322 {
324 }
325 
326 
331 ATTR_ALWAYS_INLINE static inline void intc_s_trigger_swi(void)
332 {
334 }
335 
336 
341 ATTR_ALWAYS_INLINE static inline void intc_s_complete_swi(void)
342 {
344 }
345 
346 /*
347  * @brief Enable IRQ for supervisor mode
348  *
349  * @param[in] irq Interrupt number
350  */
351 #define intc_s_enable_irq(irq) \
352  intc_enable_irq(HPM_PLIC_TARGET_S_MODE, irq)
353 
354 /*
355  * @brief Disable IRQ for supervisor mode
356  *
357  * @param[in] irq Interrupt number
358  */
359 #define intc_s_disable_irq(irq) \
360  intc_disable_irq(HPM_PLIC_TARGET_S_MODE, irq)
361 
362 #define intc_set_s_threshold(threshold) \
363  intc_set_threshold(HPM_PLIC_TARGET_S_MODE, threshold)
364 
365 /*
366  * @brief Complete IRQ for supervisor mode
367  *
368  * @param[in] irq Interrupt number
369  */
370 #define intc_s_complete_irq(irq) \
371  intc_complete_irq(HPM_PLIC_TARGET_S_MODE, irq)
372 
373 /*
374  * @brief Claim IRQ for supervisor mode
375  *
376  */
377 #define intc_s_claim_irq() intc_claim_irq(HPM_PLIC_TARGET_S_MODE)
378 
379 /*
380  * @brief Enable IRQ for supervisor mode with priority
381  *
382  * @param[in] irq Interrupt number
383  * @param[in] priority Priority of interrupt
384  */
385 #define intc_s_enable_irq_with_priority(irq, priority) \
386  do { \
387  intc_set_irq_priority(irq, priority); \
388  intc_s_enable_irq(irq); \
389  } while (0)
390 
391 #endif
392 
393 /*
394  * @brief Enable specific interrupt
395  *
396  * @param[in] target Target to handle specific interrupt
397  * @param[in] irq Interrupt number
398  */
399 ATTR_ALWAYS_INLINE static inline void intc_enable_irq(uint32_t target, uint32_t irq)
400 {
401  __plic_enable_irq(HPM_PLIC_BASE, target, irq);
402 }
403 
410 ATTR_ALWAYS_INLINE static inline void intc_set_irq_priority(uint32_t irq, uint32_t priority)
411 {
412  __plic_set_irq_priority(HPM_PLIC_BASE, irq, priority);
413 }
414 
421 ATTR_ALWAYS_INLINE static inline void intc_disable_irq(uint32_t target, uint32_t irq)
422 {
423  __plic_disable_irq(HPM_PLIC_BASE, target, irq);
424 }
425 
432 ATTR_ALWAYS_INLINE static inline void intc_set_threshold(uint32_t target, uint32_t threshold)
433 {
434  __plic_set_threshold(HPM_PLIC_BASE, target, threshold);
435 }
436 
442 ATTR_ALWAYS_INLINE static inline uint32_t intc_get_threshold(uint32_t target)
443 {
444  return __plic_get_threshold(HPM_PLIC_BASE, target);
445 }
446 
453 ATTR_ALWAYS_INLINE static inline uint32_t intc_claim_irq(uint32_t target)
454 {
455  return __plic_claim_irq(HPM_PLIC_BASE, target);
456 }
457 
465 ATTR_ALWAYS_INLINE static inline void intc_complete_irq(uint32_t target, uint32_t irq)
466 {
467  __plic_complete_irq(HPM_PLIC_BASE, target, irq);
468 }
469 
470 /*
471  * Vectored based irq install and uninstall
472  */
473 /* Machine mode */
474 extern int __vector_table[];
475 extern void default_irq_entry(void);
476 
484 ATTR_ALWAYS_INLINE static inline void install_isr(uint32_t irq, uint32_t isr)
485 {
486  __vector_table[irq] = isr;
487 }
488 
495 ATTR_ALWAYS_INLINE static inline void uninstall_isr(uint32_t irq)
496 {
497  __vector_table[irq] = (int) default_irq_entry;
498 }
499 
500 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
501 /* Supervisor mode */
502 extern int __vector_s_table[];
503 extern void default_s_irq_entry(void);
511 ATTR_ALWAYS_INLINE static inline void install_s_isr(uint32_t irq, uint32_t isr)
512 {
513  __vector_s_table[irq] = isr;
514 }
515 
522 ATTR_ALWAYS_INLINE static inline void uninstall_s_isr(uint32_t irq)
523 {
524  __vector_s_table[irq] = (int) default_s_irq_entry;
525 }
526 #endif
527 
528 
529 /*
530  * Inline nested irq entry/exit macros
531  */
532 /*
533  * @brief Save CSR
534  * @param[in] r Target CSR to be saved
535  */
536 #define SAVE_CSR(r) register long __##r = read_csr(r);
537 
538 /*
539  * @brief Restore macro
540  *
541  * @param[in] r Target CSR to be restored
542  */
543 #define RESTORE_CSR(r) write_csr(r, __##r);
544 
545 #if defined(SUPPORT_PFT_ARCH) && SUPPORT_PFT_ARCH
546 #define SAVE_MXSTATUS() SAVE_CSR(CSR_MXSTATUS)
547 #define RESTORE_MXSTATUS() RESTORE_CSR(CSR_MXSTATUS)
548 #else
549 #define SAVE_MXSTATUS()
550 #define RESTORE_MXSTATUS()
551 #endif
552 
553 #ifdef __riscv_flen
554 #define SAVE_FCSR() register int __fcsr = read_fcsr();
555 #define RESTORE_FCSR() write_fcsr(__fcsr);
556 #else
557 #define SAVE_FCSR()
558 #define RESTORE_FCSR()
559 #endif
560 
561 #ifdef __riscv_dsp
562 #define SAVE_UCODE() SAVE_CSR(CSR_UCODE)
563 #define RESTORE_UCODE() RESTORE_CSR(CSR_UCODE)
564 #else
565 #define SAVE_UCODE()
566 #define RESTORE_UCODE()
567 #endif
568 
569 #ifdef __riscv_flen
570 #if __riscv_flen == 32
571 /* RV32I caller registers + MCAUSE + MEPC + MSTATUS + FCSR + UCODE (DSP) + MCCTL + 20 FPU caller registers */
572 #define CONTEXT_REG_NUM HPM_ALIGN_UP((4 * (22 + 20)), 16)
573 #else /* __riscv_flen = 64 */
574 /* RV32I caller registers + MCAUSE + MEPC + MSTATUS + FCSR + UCODE (DSP) + MCCTL + 20 DFPU caller */
575 #define CONTEXT_REG_NUM HPM_ALIGN_UP((4 * (22 + 20 * 2)), 16)
576 #endif
577 
578 #else
579 /* RV32I caller registers + MCAUSE + MEPC + MSTATUS + FCSR + UCODE (DSP) + MCCTL */
580 #define CONTEXT_REG_NUM HPM_ALIGN_UP((4 * 22), 16)
581 #endif
582 
583 #ifdef __riscv_flen
584 /*
585  * Save FPU caller registers:
586  * NOTE: To simplify the logic, the FPU caller registers are always stored at word offset 22 in the stack
587  */
588 #if __riscv_flen == 32
589 #ifdef __ICCRISCV__
590 #define SAVE_FPU_CONTEXT() { \
591  __asm volatile("\n\
592  c.fswsp ft0, 22*4\n\
593  c.fswsp ft1, 23*4 \n\
594  c.fswsp ft2, 24*4 \n\
595  c.fswsp ft3, 25*4 \n\
596  c.fswsp ft4, 26*4 \n\
597  c.fswsp ft5, 27*4 \n\
598  c.fswsp ft6, 28*4 \n\
599  c.fswsp ft7, 29*4 \n\
600  c.fswsp fa0, 30*4 \n\
601  c.fswsp fa1, 31*4 \n\
602  c.fswsp fa2, 32*4 \n\
603  c.fswsp fa3, 33*4 \n\
604  c.fswsp fa4, 34*4 \n\
605  c.fswsp fa5, 35*4 \n\
606  c.fswsp fa6, 36*4 \n\
607  c.fswsp fa7, 37*4 \n\
608  c.fswsp ft8, 38*4 \n\
609  c.fswsp ft9, 39*4 \n\
610  c.fswsp ft10, 40*4 \n\
611  c.fswsp ft11, 41*4 \n");\
612 }
613 
614 /*
615  * Restore FPU caller registers:
616  * NOTE: To simplify the logic, the FPU caller registers are always stored at word offset 22 in the stack
617  */
618 #define RESTORE_FPU_CONTEXT() { \
619  __asm volatile("\n\
620  c.flwsp ft0, 22*4\n\
621  c.flwsp ft1, 23*4 \n\
622  c.flwsp ft2, 24*4 \n\
623  c.flwsp ft3, 25*4 \n\
624  c.flwsp ft4, 26*4 \n\
625  c.flwsp ft5, 27*4 \n\
626  c.flwsp ft6, 28*4 \n\
627  c.flwsp ft7, 29*4 \n\
628  c.flwsp fa0, 30*4 \n\
629  c.flwsp fa1, 31*4 \n\
630  c.flwsp fa2, 32*4 \n\
631  c.flwsp fa3, 33*4 \n\
632  c.flwsp fa4, 34*4 \n\
633  c.flwsp fa5, 35*4 \n\
634  c.flwsp fa6, 36*4 \n\
635  c.flwsp fa7, 37*4 \n\
636  c.flwsp ft8, 38*4 \n\
637  c.flwsp ft9, 39*4 \n\
638  c.flwsp ft10, 40*4 \n\
639  c.flwsp ft11, 41*4 \n");\
640 }
641 #else /* __ICCRISCV__ not defined */
642 #define SAVE_FPU_CONTEXT() { \
643  __asm volatile("\n\
644  c.fswsp ft0, 22*4(sp)\n\
645  c.fswsp ft1, 23*4(sp) \n\
646  c.fswsp ft2, 24*4(sp) \n\
647  c.fswsp ft3, 25*4(sp) \n\
648  c.fswsp ft4, 26*4(sp) \n\
649  c.fswsp ft5, 27*4(sp) \n\
650  c.fswsp ft6, 28*4(sp) \n\
651  c.fswsp ft7, 29*4(sp) \n\
652  c.fswsp fa0, 30*4(sp) \n\
653  c.fswsp fa1, 31*4(sp) \n\
654  c.fswsp fa2, 32*4(sp) \n\
655  c.fswsp fa3, 33*4(sp) \n\
656  c.fswsp fa4, 34*4(sp) \n\
657  c.fswsp fa5, 35*4(sp) \n\
658  c.fswsp fa6, 36*4(sp) \n\
659  c.fswsp fa7, 37*4(sp) \n\
660  c.fswsp ft8, 38*4(sp) \n\
661  c.fswsp ft9, 39*4(sp) \n\
662  c.fswsp ft10, 40*4(sp) \n\
663  c.fswsp ft11, 41*4(sp) \n");\
664 }
665 
666 /*
667  * Restore FPU caller registers:
668  * NOTE: To simplify the logic, the FPU caller registers are always stored at word offset 22 in the stack
669  */
670 #define RESTORE_FPU_CONTEXT() { \
671  __asm volatile("\n\
672  c.flwsp ft0, 22*4(sp)\n\
673  c.flwsp ft1, 23*4(sp) \n\
674  c.flwsp ft2, 24*4(sp) \n\
675  c.flwsp ft3, 25*4(sp) \n\
676  c.flwsp ft4, 26*4(sp) \n\
677  c.flwsp ft5, 27*4(sp) \n\
678  c.flwsp ft6, 28*4(sp) \n\
679  c.flwsp ft7, 29*4(sp) \n\
680  c.flwsp fa0, 30*4(sp) \n\
681  c.flwsp fa1, 31*4(sp) \n\
682  c.flwsp fa2, 32*4(sp) \n\
683  c.flwsp fa3, 33*4(sp) \n\
684  c.flwsp fa4, 34*4(sp) \n\
685  c.flwsp fa5, 35*4(sp) \n\
686  c.flwsp fa6, 36*4(sp) \n\
687  c.flwsp fa7, 37*4(sp) \n\
688  c.flwsp ft8, 38*4(sp) \n\
689  c.flwsp ft9, 39*4(sp) \n\
690  c.flwsp ft10, 40*4(sp) \n\
691  c.flwsp ft11, 41*4(sp) \n");\
692 }
693 #endif
694 #else /*__riscv_flen == 64*/
695 #ifdef __ICCRISCV__
696 #define SAVE_FPU_CONTEXT() { \
697  __asm volatile("\n\
698  c.fsdsp ft0, 22*4\n\
699  c.fsdsp ft1, 24*4 \n\
700  c.fsdsp ft2, 26*4 \n\
701  c.fsdsp ft3, 28*4 \n\
702  c.fsdsp ft4, 30*4 \n\
703  c.fsdsp ft5, 32*4 \n\
704  c.fsdsp ft6, 34*4 \n\
705  c.fsdsp ft7, 36*4 \n\
706  c.fsdsp fa0, 38*4 \n\
707  c.fsdsp fa1, 40*4 \n\
708  c.fsdsp fa2, 42*4 \n\
709  c.fsdsp fa3, 44*4 \n\
710  c.fsdsp fa4, 46*4 \n\
711  c.fsdsp fa5, 48*4 \n\
712  c.fsdsp fa6, 50*4 \n\
713  c.fsdsp fa7, 52*4 \n\
714  c.fsdsp ft8, 54*4 \n\
715  c.fsdsp ft9, 56*4 \n\
716  c.fsdsp ft10, 58*4 \n\
717  c.fsdsp ft11, 60*4 \n");\
718 }
719 
720 /*
721  * Restore FPU caller registers:
722  * NOTE: To simplify the logic, the FPU caller registers are always stored at word offset 22 in the stack
723  */
724 #define RESTORE_FPU_CONTEXT() { \
725  __asm volatile("\n\
726  c.fldsp ft0, 22*4\n\
727  c.fldsp ft1, 24*4 \n\
728  c.fldsp ft2, 26*4 \n\
729  c.fldsp ft3, 28*4 \n\
730  c.fldsp ft4, 30*4 \n\
731  c.fldsp ft5, 32*4 \n\
732  c.fldsp ft6, 34*4 \n\
733  c.fldsp ft7, 36*4 \n\
734  c.fldsp fa0, 38*4 \n\
735  c.fldsp fa1, 40*4 \n\
736  c.fldsp fa2, 42*4 \n\
737  c.fldsp fa3, 44*4 \n\
738  c.fldsp fa4, 46*4 \n\
739  c.fldsp fa5, 48*4 \n\
740  c.fldsp fa6, 50*4 \n\
741  c.fldsp fa7, 52*4 \n\
742  c.fldsp ft8, 54*4 \n\
743  c.fldsp ft9, 56*4 \n\
744  c.fldsp ft10, 58*4 \n\
745  c.fldsp ft11, 60*4 \n");\
746 }
747 #else /*__riscv_flen == 64*/
748 #define SAVE_FPU_CONTEXT() { \
749  __asm volatile("\n\
750  c.fsdsp ft0, 22*4(sp)\n\
751  c.fsdsp ft1, 24*4(sp) \n\
752  c.fsdsp ft2, 26*4(sp) \n\
753  c.fsdsp ft3, 28*4(sp) \n\
754  c.fsdsp ft4, 30*4(sp) \n\
755  c.fsdsp ft5, 32*4(sp) \n\
756  c.fsdsp ft6, 34*4(sp) \n\
757  c.fsdsp ft7, 36*4(sp) \n\
758  c.fsdsp fa0, 38*4(sp) \n\
759  c.fsdsp fa1, 40*4(sp) \n\
760  c.fsdsp fa2, 42*4(sp) \n\
761  c.fsdsp fa3, 44*4(sp) \n\
762  c.fsdsp fa4, 46*4(sp) \n\
763  c.fsdsp fa5, 48*4(sp) \n\
764  c.fsdsp fa6, 50*4(sp) \n\
765  c.fsdsp fa7, 52*4(sp) \n\
766  c.fsdsp ft8, 54*4(sp) \n\
767  c.fsdsp ft9, 56*4(sp) \n\
768  c.fsdsp ft10, 58*4(sp) \n\
769  c.fsdsp ft11, 60*4(sp) \n");\
770 }
771 
772 /*
773  * Restore FPU caller registers:
774  * NOTE: To simplify the logic, the FPU caller registers are always stored at word offset 22 in the stack
775  */
776 #define RESTORE_FPU_CONTEXT() { \
777  __asm volatile("\n\
778  c.fldsp ft0, 22*4(sp)\n\
779  c.fldsp ft1, 24*4(sp) \n\
780  c.fldsp ft2, 26*4(sp) \n\
781  c.fldsp ft3, 28*4(sp) \n\
782  c.fldsp ft4, 30*4(sp) \n\
783  c.fldsp ft5, 32*4(sp) \n\
784  c.fldsp ft6, 34*4(sp) \n\
785  c.fldsp ft7, 36*4(sp) \n\
786  c.fldsp fa0, 38*4(sp) \n\
787  c.fldsp fa1, 40*4(sp) \n\
788  c.fldsp fa2, 42*4(sp) \n\
789  c.fldsp fa3, 44*4(sp) \n\
790  c.fldsp fa4, 46*4(sp) \n\
791  c.fldsp fa5, 48*4(sp) \n\
792  c.fldsp fa6, 50*4(sp) \n\
793  c.fldsp fa7, 52*4(sp) \n\
794  c.fldsp ft8, 54*4(sp) \n\
795  c.fldsp ft9, 56*4(sp) \n\
796  c.fldsp ft10, 58*4(sp) \n\
797  c.fldsp ft11, 60*4(sp) \n");\
798 }
799 #endif
800 #endif
801 #else
802 #define SAVE_FPU_CONTEXT()
803 #define RESTORE_FPU_CONTEXT()
804 #endif
805 
806 #ifdef __ICCRISCV__
810 #define SAVE_CALLER_CONTEXT() { \
811  __asm volatile("addi sp, sp, %0" : : "i"(-CONTEXT_REG_NUM) :);\
812  __asm volatile("\n\
813  c.swsp ra, 0*4 \n\
814  c.swsp t0, 1*4 \n\
815  c.swsp t1, 2*4 \n\
816  c.swsp t2, 3*4 \n\
817  c.swsp s1, 4*4 \n\
818  c.swsp a0, 5*4 \n\
819  c.swsp a1, 6*4 \n\
820  c.swsp a2, 7*4 \n\
821  c.swsp a3, 8*4 \n\
822  c.swsp a4, 9*4 \n\
823  c.swsp a5, 10*4 \n\
824  c.swsp a6, 11*4 \n\
825  c.swsp a7, 12*4 \n\
826  c.swsp s2, 13*4 \n\
827  c.swsp s3, 14*4 \n\
828  c.swsp s4, 15*4 \n\
829  c.swsp s5, 16*4 \n\
830  c.swsp s6, 17*4 \n\
831  c.swsp t3, 18*4 \n\
832  c.swsp t4, 19*4 \n\
833  c.swsp t5, 20*4 \n\
834  c.swsp t6, 21*4"); \
835  SAVE_FPU_CONTEXT(); \
836 }
837 
841 #define RESTORE_CALLER_CONTEXT() { \
842  __asm volatile("\n\
843  c.lwsp ra, 0*4 \n\
844  c.lwsp t0, 1*4 \n\
845  c.lwsp t1, 2*4 \n\
846  c.lwsp t2, 3*4 \n\
847  c.lwsp s1, 4*4 \n\
848  c.lwsp a0, 5*4 \n\
849  c.lwsp a1, 6*4 \n\
850  c.lwsp a2, 7*4 \n\
851  c.lwsp a3, 8*4 \n\
852  c.lwsp a4, 9*4 \n\
853  c.lwsp a5, 10*4 \n\
854  c.lwsp a6, 11*4 \n\
855  c.lwsp a7, 12*4 \n\
856  c.lwsp s2, 13*4 \n\
857  c.lwsp s3, 14*4 \n\
858  c.lwsp s4, 15*4 \n\
859  c.lwsp s5, 16*4 \n\
860  c.lwsp s6, 17*4 \n\
861  c.lwsp t3, 18*4 \n\
862  c.lwsp t4, 19*4 \n\
863  c.lwsp t5, 20*4 \n\
864  c.lwsp t6, 21*4 \n");\
865  RESTORE_FPU_CONTEXT(); \
866  __asm volatile("addi sp, sp, %0" : : "i"(CONTEXT_REG_NUM) :);\
867 }
868 #else
872 #define SAVE_CALLER_CONTEXT() { \
873  __asm volatile("addi sp, sp, %0" : : "i"(-CONTEXT_REG_NUM) :);\
874  __asm volatile("\n\
875  c.swsp ra, 0*4(sp) \n\
876  c.swsp t0, 1*4(sp) \n\
877  c.swsp t1, 2*4(sp) \n\
878  c.swsp t2, 3*4(sp) \n\
879  c.swsp s1, 4*4(sp) \n\
880  c.swsp a0, 5*4(sp) \n\
881  c.swsp a1, 6*4(sp) \n\
882  c.swsp a2, 7*4(sp) \n\
883  c.swsp a3, 8*4(sp) \n\
884  c.swsp a4, 9*4(sp) \n\
885  c.swsp a5, 10*4(sp) \n\
886  c.swsp a6, 11*4(sp) \n\
887  c.swsp a7, 12*4(sp) \n\
888  c.swsp s2, 13*4(sp) \n\
889  c.swsp s3, 14*4(sp) \n\
890  c.swsp s4, 15*4(sp) \n\
891  c.swsp s5, 16*4(sp) \n\
892  c.swsp s6, 17*4(sp) \n\
893  c.swsp t3, 18*4(sp) \n\
894  c.swsp t4, 19*4(sp) \n\
895  c.swsp t5, 20*4(sp) \n\
896  c.swsp t6, 21*4(sp)"); \
897  SAVE_FPU_CONTEXT(); \
898 }
899 
903 #define RESTORE_CALLER_CONTEXT() { \
904  __asm volatile("\n\
905  c.lwsp ra, 0*4(sp) \n\
906  c.lwsp t0, 1*4(sp) \n\
907  c.lwsp t1, 2*4(sp) \n\
908  c.lwsp t2, 3*4(sp) \n\
909  c.lwsp s1, 4*4(sp) \n\
910  c.lwsp a0, 5*4(sp) \n\
911  c.lwsp a1, 6*4(sp) \n\
912  c.lwsp a2, 7*4(sp) \n\
913  c.lwsp a3, 8*4(sp) \n\
914  c.lwsp a4, 9*4(sp) \n\
915  c.lwsp a5, 10*4(sp) \n\
916  c.lwsp a6, 11*4(sp) \n\
917  c.lwsp a7, 12*4(sp) \n\
918  c.lwsp s2, 13*4(sp) \n\
919  c.lwsp s3, 14*4(sp) \n\
920  c.lwsp s4, 15*4(sp) \n\
921  c.lwsp s5, 16*4(sp) \n\
922  c.lwsp s6, 17*4(sp) \n\
923  c.lwsp t3, 18*4(sp) \n\
924  c.lwsp t4, 19*4(sp) \n\
925  c.lwsp t5, 20*4(sp) \n\
926  c.lwsp t6, 21*4(sp) \n");\
927  RESTORE_FPU_CONTEXT(); \
928  __asm volatile("addi sp, sp, %0" : : "i"(CONTEXT_REG_NUM) :);\
929 }
930 #endif
931 
932 #ifdef __riscv_flen
933 #define SAVE_FPU_STATE() { \
934  __asm volatile("frcsr s1\n"); \
935 }
936 
937 #define RESTORE_FPU_STATE() { \
938  __asm volatile("fscsr s1\n"); \
939 }
940 #else
941 #define SAVE_FPU_STATE()
942 #define RESTORE_FPU_STATE()
943 #endif
944 
945 #ifdef __riscv_dsp
946 /*
947  * @brief Save DSP context
948  */
949 #define SAVE_DSP_CONTEXT() { \
950  __asm volatile("csrrs s4, %0, x0\n" ::"i"(CSR_UCODE):); \
951 }
952 /*
953  * @brief Restore DSP context
954  */
955 #define RESTORE_DSP_CONTEXT() {\
956  __asm volatile("csrw %0, s4\n" ::"i"(CSR_UCODE):); \
957 }
958 
959 #else
960 #define SAVE_DSP_CONTEXT()
961 #define RESTORE_DSP_CONTEXT()
962 #endif
963 
964 #if !defined(DISABLE_IRQ_PREEMPTIVE) || (DISABLE_IRQ_PREEMPTIVE == 0)
965 /*
966  * @brief Save MCCTL context
967  */
968 #define SAVE_MCCTL_CONTEXT() { \
969  __asm volatile("csrrs s5, %0, x0\n" ::"i"(CSR_MCCTLBEGINADDR):); \
970  __asm volatile("csrrs s6, %0, x0\n" ::"i"(CSR_MCCTLDATA):); \
971 }
972 /*
973  * @brief Restore MCCTL context
974  */
975 #define RESTORE_MCCTL_CONTEXT() {\
976  __asm volatile("csrw %0, s6\n" ::"i"(CSR_MCCTLDATA):); \
977  __asm volatile("csrw %0, s5\n" ::"i"(CSR_MCCTLBEGINADDR):); \
978 }
979 
980 /*
981  * @brief Enter Nested IRQ Handling
982  * @note To simplify the logic, Nested IRQ related registers are stored in the stack as below:
983  * MCAUSE - word offset 16 (not used in the vectored mode)
984  * EPC - word offset 17
985  * MSTATUS = word offset 18
986  * MXSTATUS = word offset 19
987  */
988 #define ENTER_NESTED_IRQ_HANDLING_M() { \
989  __asm volatile("\n\
990  csrr s2, mepc \n\
991  csrr s3, mstatus \n");\
992  SAVE_FPU_STATE(); \
993  SAVE_DSP_CONTEXT(); \
994  SAVE_MCCTL_CONTEXT(); \
995  __asm volatile("csrsi mstatus, 8"); \
996 }
997 
998 /*
999  * @brief Complete IRQ Handling
1000  */
1001  #define COMPLETE_IRQ_HANDLING_M(irq_num) { \
1002  __asm volatile("csrci mstatus, 8"); \
1003  __asm volatile("lui a4, 0xe4200"); \
1004  __asm volatile("li a3, %0" : : "i" (irq_num) :); \
1005  __asm volatile("sw a3, 4(a4)"); \
1006 }
1007 #else
1008 /*
1009  * @brief Save MCCTL context
1010  */
1011  #define SAVE_MCCTL_CONTEXT()
1012 /*
1013 * @brief Restore MCCTL context
1014 */
1015 #define RESTORE_MCCTL_CONTEXT()
1016 
1017 /*
1018 * @brief Enter Nested IRQ Handling
1019 * @note To simplify the logic, Nested IRQ related registers are stored in the stack as below:
1020 * MCAUSE - word offset 16 (not used in the vectored mode)
1021 * EPC - word offset 17
1022 * MSTATUS = word offset 18
1023 * MXSTATUS = word offset 19
1024 */
1025 #define ENTER_NESTED_IRQ_HANDLING_M() { \
1026 __asm volatile("\n\
1027  csrr s2, mepc \n\
1028  csrr s3, mstatus \n");\
1029 SAVE_FPU_STATE(); \
1030 SAVE_DSP_CONTEXT(); \
1031 SAVE_MCCTL_CONTEXT(); \
1032 }
1033 
1034 /*
1035  * @brief Complete IRQ Handling
1036  */
1037  #define COMPLETE_IRQ_HANDLING_M(irq_num) { \
1038  __asm volatile("lui a4, 0xe4200"); \
1039  __asm volatile("li a3, %0" : : "i" (irq_num) :); \
1040  __asm volatile("sw a3, 4(a4)"); \
1041 }
1042 #endif
1043 
1044 
1045 /*
1046  * @brief Exit Nested IRQ Handling
1047  * @note To simplify the logic, Nested IRQ related registers are stored in the stack as below:
1048  * MCAUSE - word offset 16 (not used in the vectored mode)
1049  * EPC - word offset 17
1050  * MSTATUS = word offset 18
1051  * MXSTATUS = word offset 19
1052  */
1053 #define EXIT_NESTED_IRQ_HANDLING_M() { \
1054  __asm volatile("\n\
1055  csrw mstatus, s3 \n\
1056  csrw mepc, s2 \n");\
1057  RESTORE_FPU_STATE(); \
1058  RESTORE_DSP_CONTEXT(); \
1059  RESTORE_MCCTL_CONTEXT(); \
1060 }
1061 
1062 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
1063 #if !defined(DISABLE_IRQ_PREEMPTIVE) || (DISABLE_IRQ_PREEMPTIVE == 0)
1064 #define ENTER_NESTED_IRQ_HANDLING_S() {\
1065  __asm volatile("\n\
1066  csrr s2, sepc \n\
1067  csrr s3, sstatus \n");\
1068  SAVE_FPU_STATE(); \
1069  SAVE_DSP_CONTEXT(); \
1070  __asm volatile("csrsi sstatus, 2"); \
1071 }
1072 #define COMPLETE_IRQ_HANDLING_S(irq_num) {\
1073  __asm volatile("csrci sstatus, 2"); \
1074  __asm volatile("lui a4, 0xe4201"); \
1075  __asm volatile("li a3, %0" : : "i" (irq_num) :); \
1076  __asm volatile("sw a3, 4(a4)"); \
1077 }
1078 #else
1079 #define ENTER_NESTED_IRQ_HANDLING_S() {\
1080  __asm volatile("\n\
1081  csrr s2, sepc \n\
1082  csrr s3, sstatus \n");\
1083  SAVE_FPU_STATE(); \
1084  SAVE_DSP_CONTEXT(); \
1085 }
1086 #define COMPLETE_IRQ_HANDLING_S(irq_num) {\
1087  __asm volatile("lui a4, 0xe4201"); \
1088  __asm volatile("li a3, %0" : : "i" (irq_num) :); \
1089  __asm volatile("sw a3, 4(a4)"); \
1090 }
1091 #endif
1092 
1093 #endif
1094 
1095 /*
1096  * @brief Exit Nested IRQ Handling at supervisor mode
1097  * @note To simplify the logic, Nested IRQ related registers are stored in the stack as below:
1098  * SCAUSE - word offset 16 (not used in the vectored mode)
1099  * EPC - word offset 17
1100  * SSTATUS = word offset 18
1101  */
1102 #define EXIT_NESTED_IRQ_HANDLING_S() { \
1103  __asm volatile("\n\
1104  csrw sstatus, s3 \n\
1105  csrw sepc, s2 \n");\
1106  RESTORE_FPU_STATE(); \
1107  RESTORE_DSP_CONTEXT(); \
1108 }
1109 
1110 /* @brief Nested IRQ entry macro : Save CSRs and enable global irq. */
1111 #define NESTED_IRQ_ENTER() \
1112  SAVE_CSR(CSR_MEPC) \
1113  SAVE_CSR(CSR_MSTATUS) \
1114  SAVE_MXSTATUS() \
1115  SAVE_FCSR() \
1116  SAVE_UCODE() \
1117  set_csr(CSR_MSTATUS, CSR_MSTATUS_MIE_MASK);
1118 
1119 /* @brief Nested IRQ exit macro : Restore CSRs */
1120 #define NESTED_IRQ_EXIT() \
1121  RESTORE_CSR(CSR_MSTATUS) \
1122  RESTORE_CSR(CSR_MEPC) \
1123  RESTORE_MXSTATUS() \
1124  RESTORE_FCSR() \
1125  RESTORE_UCODE()
1126 
1127 #ifdef __cplusplus
1128 #define HPM_EXTERN_C extern "C"
1129 #else
1130 #define HPM_EXTERN_C
1131 #endif
1132 
1133 #define ISR_NAME_M(irq_num) default_isr_##irq_num
1134 
1135 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
1136 #define ISR_NAME_S(irq_num) default_isr_s_##irq_num
1137 #endif
1138 
1145 #if !defined(USE_NONVECTOR_MODE) || (USE_NONVECTOR_MODE == 0)
1146 #if defined(CONFIG_FREERTOS) && CONFIG_FREERTOS
1147 #define FREERTOS_VECTOR_ISR_WRAPPER_NAME(irq_num) irq_handler_wrapper_##irq_num
1148 #define SDK_DECLARE_EXT_ISR_M(irq_num, isr) \
1149 void isr(void) __attribute__((section(".isr_vector"))); \
1150 HPM_EXTERN_C void FREERTOS_VECTOR_ISR_WRAPPER_NAME(irq_num)(void) __attribute__((section(".isr_vector"))); \
1151 void FREERTOS_VECTOR_ISR_WRAPPER_NAME(irq_num)(void) \
1152 { \
1153  isr();\
1154 }
1155 
1156 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
1163 #define SDK_DECLARE_EXT_ISR_S(irq_num, isr) \
1164 void isr(void) __attribute__((section(".isr_s_vector")));\
1165 HPM_EXTERN_C void FREERTOS_VECTOR_ISR_WRAPPER_NAME(irq_num)(void) __attribute__((section(".isr_s_vector")));\
1166 void FREERTOS_VECTOR_ISR_WRAPPER_NAME(irq_num)(void) \
1167 { \
1168  isr();\
1169 }
1170 #endif
1171 #else
1172 
1173 #define SDK_DECLARE_EXT_ISR_M(irq_num, isr) \
1174 void isr(void) __attribute__((section(".isr_vector")));\
1175 HPM_EXTERN_C HPM_ATTR_MACHINE_INTERRUPT void ISR_NAME_M(irq_num)(void);\
1176 HPM_ATTR_MACHINE_INTERRUPT void ISR_NAME_M(irq_num)(void) \
1177 { \
1178  SAVE_CALLER_CONTEXT(); \
1179  ENTER_NESTED_IRQ_HANDLING_M();\
1180  __asm volatile("la t1, %0\n\t" : : "i" (isr) : );\
1181  __asm volatile("jalr t1\n");\
1182  COMPLETE_IRQ_HANDLING_M(irq_num);\
1183  EXIT_NESTED_IRQ_HANDLING_M();\
1184  RESTORE_CALLER_CONTEXT();\
1185  __asm volatile("fence io, io");\
1186 }
1187 
1188 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
1195 #define SDK_DECLARE_EXT_ISR_S(irq_num, isr) \
1196 void isr(void) __attribute__((section(".isr_s_vector")));\
1197 HPM_EXTERN_C HPM_ATTR_SUPERVISOR_INTERRUPT void ISR_NAME_S(irq_num)(void);\
1198 HPM_ATTR_SUPERVISOR_INTERRUPT void ISR_NAME_S(irq_num)(void) {\
1199  SAVE_CALLER_CONTEXT(); \
1200  ENTER_NESTED_IRQ_HANDLING_S();\
1201  __asm volatile("la t1, %0\n\t" : : "i" (isr) : );\
1202  __asm volatile("jalr t1\n");\
1203  COMPLETE_IRQ_HANDLING_S(irq_num);\
1204  EXIT_NESTED_IRQ_HANDLING_S();\
1205  RESTORE_CALLER_CONTEXT();\
1206  __asm volatile("fence io, io");\
1207 }
1208 #endif
1209 
1210 #endif
1211 #else
1212 
1213 #define SDK_DECLARE_EXT_ISR_M(irq_num, isr) \
1214 void isr(void) __attribute__((section(".isr_vector")));\
1215 HPM_EXTERN_C void ISR_NAME_M(irq_num)(void) __attribute__((section(".isr_vector")));\
1216 void ISR_NAME_M(irq_num)(void) { \
1217  isr(); \
1218 }
1219 
1220 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
1221 #define SDK_DECLARE_EXT_ISR_S(irq_num, isr) \
1222 void isr(void) __attribute__((section(".isr_vector")));\
1223 HPM_EXTERN_C void ISR_NAME_S(irq_num)(void) __attribute__((section(".isr_vector")));\
1224 void ISR_NAME_S(irq_num)(void) { \
1225  isr(); \
1226 }
1227 #endif
1228 
1229 #endif
1230 
1231 
1237 #define SDK_DECLARE_MCHTMR_ISR(isr) \
1238 void isr(void) __attribute__((section(".isr_vector")));\
1239 HPM_EXTERN_C void mchtmr_isr(void) __attribute__((section(".isr_vector"))); \
1240 void mchtmr_isr(void) {\
1241  isr();\
1242 }
1243 
1249 #define SDK_DECLARE_SWI_ISR(isr)\
1250 void isr(void) __attribute__((section(".isr_vector")));\
1251 HPM_EXTERN_C void swi_isr(void) __attribute__((section(".isr_vector"))); \
1252 void swi_isr(void) {\
1253  isr();\
1254 }
1255 
1256 #if defined SOC_HAS_S_MODE && SOC_HAS_S_MODE
1257 /* Supervisor mode */
1258 
1264 #define SDK_DECLARE_MCHTMR_ISR_S(isr) \
1265 void isr(void) __attribute__((section(".isr_vector")));\
1266 HPM_EXTERN_C void mchtmr_s_isr(void) __attribute__((section(".isr_vector"))); \
1267 void mchtmr_s_isr(void) {\
1268  isr();\
1269 }
1270 
1276 #define SDK_DECLARE_SWI_ISR_S(isr)\
1277 void isr(void) __attribute__((section(".isr_vector")));\
1278 HPM_EXTERN_C void swi_s_isr(void) __attribute__((section(".isr_vector"))); \
1279 void swi_s_isr(void) {\
1280  isr();\
1281 }
1282 
1283 #define CSR_MSTATUS_MPP_S_MODE (0x1)
1284 #define MODE_SWITCH_FROM_M(mstatus, mepc, label, mode) \
1285 do { \
1286  set_csr(CSR_SSTATUS, CSR_SSTATUS_SUM_MASK); \
1287  write_csr(mepc, label); \
1288  clear_csr(mstatus, CSR_MSTATUS_MPP_MASK); \
1289  set_csr(mstatus, CSR_MSTATUS_MPP_SET(mode)); \
1290  __asm volatile("mret"); \
1291 } while(0)
1292 
1293 typedef void (*s_mode_entry)(void);
1294 
1300 static inline void switch_to_s_mode(s_mode_entry entry)
1301 {
1302  MODE_SWITCH_FROM_M(CSR_MSTATUS, CSR_MEPC, entry, CSR_MSTATUS_MPP_S_MODE);
1303 }
1304 #endif
1305 
1306 #ifdef __cplusplus
1307 }
1308 #endif
1309 
1313 #endif /* HPM_INTERRUPT_H */
#define CSR_MIE_MEIE_MASK
Definition: hpm_csr_regs.h:734
#define CSR_MEPC
Definition: hpm_csr_regs.h:31
#define CSR_MSTATUS
Definition: hpm_csr_regs.h:21
#define CSR_MIE_MTIE_MASK
Definition: hpm_csr_regs.h:758
#define CSR_MIE
Definition: hpm_csr_regs.h:23
#define CSR_MIE_MSIE_MASK
Definition: hpm_csr_regs.h:782
#define HPM_PLICSW_BASE
Definition: hpm_soc_ip.h:51
#define HPM_PLIC_BASE
Definition: hpm_soc_ip.h:37
#define CSR_SSTATUS
Definition: hpm_csr_regs.h:21
#define CSR_SIE_SEIE_MASK
Definition: hpm_csr_regs.h:677
#define CSR_SIE_SSIE_MASK
Definition: hpm_csr_regs.h:725
#define CSR_SIP
Definition: hpm_csr_regs.h:30
#define CSR_SIE_STIE_MASK
Definition: hpm_csr_regs.h:701
#define CSR_MIDELEG
Definition: hpm_csr_regs.h:35
#define CSR_SIP_SSIP_MASK
Definition: hpm_csr_regs.h:889
#define CSR_SIE
Definition: hpm_csr_regs.h:24
static ATTR_ALWAYS_INLINE void intc_complete_irq(uint32_t target, uint32_t irq)
Complete IRQ.
Definition: hpm_interrupt.h:465
static ATTR_ALWAYS_INLINE void enable_global_irq(uint32_t mask)
Enable global IRQ with mask.
Definition: hpm_interrupt.h:35
static ATTR_ALWAYS_INLINE void intc_m_disable_swi(void)
Disable software interrupt.
Definition: hpm_interrupt.h:221
static ATTR_ALWAYS_INLINE void disable_irq_from_intc(void)
Disable IRQ from interrupt controller.
Definition: hpm_interrupt.h:74
static ATTR_ALWAYS_INLINE void intc_set_irq_priority(uint32_t irq, uint32_t priority)
Set interrupt priority.
Definition: hpm_interrupt.h:410
static ATTR_ALWAYS_INLINE void intc_disable_irq(uint32_t target, uint32_t irq)
Disable specific interrupt.
Definition: hpm_interrupt.h:421
static ATTR_ALWAYS_INLINE void intc_m_trigger_swi(void)
Trigger software interrupt.
Definition: hpm_interrupt.h:231
static ATTR_ALWAYS_INLINE void install_isr(uint32_t irq, uint32_t isr)
Install ISR for certain IRQ for ram based vector table.
Definition: hpm_interrupt.h:484
void default_irq_entry(void)
static ATTR_ALWAYS_INLINE void enable_irq_from_intc(void)
Enable IRQ from interrupt controller.
Definition: hpm_interrupt.h:65
static ATTR_ALWAYS_INLINE void restore_global_irq(uint32_t mask)
Restore global IRQ with mask.
Definition: hpm_interrupt.h:56
static ATTR_ALWAYS_INLINE void intc_enable_irq(uint32_t target, uint32_t irq)
Definition: hpm_interrupt.h:399
#define PLICSWI
Definition: hpm_interrupt.h:195
static ATTR_ALWAYS_INLINE void disable_mchtmr_irq(void)
Disable machine timer IRQ.
Definition: hpm_interrupt.h:91
static ATTR_ALWAYS_INLINE void intc_m_init_swi(void)
Initialize software interrupt.
Definition: hpm_interrupt.h:201
static ATTR_ALWAYS_INLINE void intc_m_enable_swi(void)
Enable software interrupt.
Definition: hpm_interrupt.h:211
static ATTR_ALWAYS_INLINE void intc_m_complete_swi(void)
Complete software interrupt.
Definition: hpm_interrupt.h:249
static ATTR_ALWAYS_INLINE uint32_t intc_get_threshold(uint32_t target)
Get interrupt threshold.
Definition: hpm_interrupt.h:442
static ATTR_ALWAYS_INLINE void intc_set_threshold(uint32_t target, uint32_t threshold)
Set interrupt threshold.
Definition: hpm_interrupt.h:432
static ATTR_ALWAYS_INLINE void uninstall_isr(uint32_t irq)
Uninstall ISR for certain IRQ for ram based vector table.
Definition: hpm_interrupt.h:495
static ATTR_ALWAYS_INLINE uint32_t intc_claim_irq(uint32_t target)
Claim IRQ.
Definition: hpm_interrupt.h:453
static ATTR_ALWAYS_INLINE void intc_m_claim_swi(void)
Claim software interrupt.
Definition: hpm_interrupt.h:240
static ATTR_ALWAYS_INLINE uint32_t disable_global_irq(uint32_t mask)
Disable global IRQ with mask and return mstatus.
Definition: hpm_interrupt.h:46
static ATTR_ALWAYS_INLINE void enable_mchtmr_irq(void)
Enable machine timer IRQ.
Definition: hpm_interrupt.h:82
#define HPM_PLIC_TARGET_M_MODE
Definition: hpm_plic_drv.h:17
#define set_csr(csr_num, bit)
set bits in csr
Definition: riscv_core.h:58
#define clear_csr(csr_num, bit)
clear bits in csr
Definition: riscv_core.h:30
#define read_clear_csr(csr_num, bit)
read and clear bits in csr
Definition: riscv_core.h:40