1/*
2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
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 "plic.h"
20
21#ifdef __cplusplus
22#if __cplusplus
23extern "C" {
24#endif
25#endif
26
27VOID HalIrqDisable(UINT32 vector)
28{
29    if (vector <= RISCV_SYS_MAX_IRQ) {
30        CLEAR_CSR(mie, 1 << vector);
31    } else {
32        PlicIrqDisable(vector);
33    }
34}
35
36VOID HalIrqEnable(UINT32 vector)
37{
38    if (vector <= RISCV_SYS_MAX_IRQ) {
39        SET_CSR(mie, 1 << vector);
40    } else {
41        PlicIrqEnable(vector);
42    }
43}
44
45VOID HalSetLocalInterPri(UINT32 interPriNum, UINT16 prior)
46{
47    PlicIrqSetPrio(interPriNum, prior);
48}
49
50BOOL HalBackTraceFpCheck(UINT32 value)
51{
52    if (value >= (UINT32)(UINTPTR)(&__bss_end)) {
53        return TRUE;
54    }
55
56    if ((value >= (UINT32)(UINTPTR)(&__start_and_irq_stack_top)) && (value < (UINT32)(UINTPTR)(&__except_stack_top))) {
57        return TRUE;
58    }
59
60    return FALSE;
61}
62
63VOID HalPlicInit(VOID)
64{
65    PlicIrqInit();
66
67    HalIrqEnable(RISCV_MACH_EXT_IRQ);
68}
69
70#ifdef __cplusplus
71#if __cplusplus
72}
73#endif
74#endif
75