• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 HPMicro
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "riscv_hal.h"
17 #include "los_debug.h"
18 #include "soc.h"
19 #include "los_reg.h"
20 #include "los_arch_interrupt.h"
21 #include "hpm_soc.h"
22 #include "hpm_interrupt.h"
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif
28 
HalIrqDisable(UINT32 vector)29 VOID HalIrqDisable(UINT32 vector)
30 {
31     if (vector <= RISCV_SYS_MAX_IRQ) {
32         CLEAR_CSR(mie, 1 << vector);
33     } else {
34         intc_m_disable_irq(LITEOS2HPM_IRQ(vector));
35     }
36 }
37 
HalIrqEnable(UINT32 vector)38 VOID HalIrqEnable(UINT32 vector)
39 {
40     if (vector <= RISCV_SYS_MAX_IRQ) {
41         SET_CSR(mie, 1 << vector);
42     } else {
43         intc_m_enable_irq(LITEOS2HPM_IRQ(vector));
44     }
45 }
46 
HalSetLocalInterPri(UINT32 interPriNum,UINT16 prior)47 VOID HalSetLocalInterPri(UINT32 interPriNum, UINT16 prior)
48 {
49     intc_set_irq_priority(LITEOS2HPM_IRQ(interPriNum), prior);
50 }
51 
HalBackTraceFpCheck(UINT32 value)52 BOOL HalBackTraceFpCheck(UINT32 value)
53 {
54     if (value >= (UINT32)(UINTPTR)(&__bss_end)) {
55         return TRUE;
56     }
57 
58     if ((value >= (UINT32)(UINTPTR)(&__start_and_irq_stack_top)) && (value < (UINT32)(UINTPTR)(&__except_stack_top))) {
59         return TRUE;
60     }
61 
62     return FALSE;
63 }
64 
65 extern UINT32 g_hwiFormCnt[];
OsMachineExternalInterrupt(VOID * arg)66 STATIC VOID OsMachineExternalInterrupt(VOID *arg)
67 {
68     UINT32 irqNum = intc_m_claim_irq();
69     UINT32 liteosIrqNum = HPM2LITEOS_IRQ(irqNum);
70 
71     if ((irqNum >= OS_RISCV_CUSTOM_IRQ_VECTOR_CNT) || (irqNum == 0)) {
72         HalHwiDefaultHandler((VOID *)irqNum);
73     }
74 
75     g_hwiForm[liteosIrqNum].pfnHook(g_hwiForm[liteosIrqNum].uwParam);
76     ++g_hwiFormCnt[liteosIrqNum];
77 
78     intc_m_complete_irq(irqNum);
79 }
80 
HalPlicInit(VOID)81 VOID HalPlicInit(VOID)
82 {
83     UINT32 ret;
84     ret = LOS_HwiCreate(RISCV_MACH_EXT_IRQ, 0x1, 0, OsMachineExternalInterrupt, 0);
85     if (ret != LOS_OK) {
86         PRINT_ERR("Create machine external failed! ret : 0x%x\n", ret);
87     }
88 
89     HalIrqEnable(RISCV_MACH_EXT_IRQ);
90 }
91 
92 HwiControllerOps g_archHwiOps = {
93     .disableIrq = (UINT32 (*)(HWI_HANDLE_T ))HalIrqDisable,
94     .enableIrq = (UINT32 (*)(HWI_HANDLE_T ))HalIrqEnable,
95     .setIrqPriority = (UINT32 (*)(HWI_HANDLE_T , UINT8 ))HalSetLocalInterPri,
96 };
97 
98 
99 #ifdef __cplusplus
100 #if __cplusplus
101 }
102 #endif
103 #endif
104