los_interrupt.h 7.7 KB
Newer Older
C
Caoruihong 已提交
1
/*
M
mamingshuai 已提交
2 3
 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
C
Caoruihong 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 *    conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 *    of conditions and the following disclaimer in the documentation and/or other materials
 *    provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
 *    to endorse or promote products derived from this software without specific prior written
 *    permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _LOS_INTERRUPT_H
#define _LOS_INTERRUPT_H
#include "los_config.h"
#include "los_compiler.h"

#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */

typedef UINT32 HWI_HANDLE_T;

typedef UINT16 HWI_PRIOR_T;

typedef UINT16 HWI_MODE_T;

typedef UINT32 HWI_ARG_T;

L
LiteOS2021 已提交
51
#if (LOSCFG_PLATFORM_HWI_WITH_ARG == 1)
C
Caoruihong 已提交
52 53 54 55
typedef VOID (*HWI_PROC_FUNC)(VOID *parm);
#else
typedef VOID (*HWI_PROC_FUNC)(void);
#endif
M
mamingshuai 已提交
56

57 58 59 60 61 62 63 64 65 66 67
typedef struct {
    UINT32 (*triggerIrq)(HWI_HANDLE_T hwiNum);
    UINT32 (*clearIrq)(HWI_HANDLE_T hwiNum);
    UINT32 (*enableIrq)(HWI_HANDLE_T hwiNum);
    UINT32 (*disableIrq)(HWI_HANDLE_T hwiNum);
    UINT32 (*setIrqPriority)(HWI_HANDLE_T hwiNum, UINT8 priority);
    UINT32 (*getCurIrqNum)(VOID);
} HwiControllerOps;

extern HwiControllerOps g_archHwiOps;

星e雨's avatar
星e雨 已提交
68 69 70 71 72
/* stack protector */
extern UINT32 __stack_chk_guard;

extern VOID __stack_chk_fail(VOID);

L
LiteOS2021 已提交
73 74
UINT32 ArchIsIntActive(VOID);
#define OS_INT_ACTIVE    (ArchIsIntActive())
C
Caoruihong 已提交
75
#define OS_INT_INACTIVE  (!(OS_INT_ACTIVE))
L
LiteOS2021 已提交
76 77
#define LOS_HwiCreate ArchHwiCreate
#define LOS_HwiDelete ArchHwiDelete
78 79 80 81 82
#define LOS_HwiTrigger ArchIntTrigger
#define LOS_HwiEnable ArchIntEnable
#define LOS_HwiDisable ArchIntDisable
#define LOS_HwiClear ArchIntClear
#define LOS_HwiSetPriority ArchIntSetPriority
C
Caoruihong 已提交
83

L
LiteOS2021 已提交
84 85
UINT32 ArchIntLock(VOID);
#define LOS_IntLock ArchIntLock
J
JerryH1011 已提交
86

L
LiteOS2021 已提交
87 88
VOID ArchIntRestore(UINT32 intSave);
#define LOS_IntRestore ArchIntRestore
J
JerryH1011 已提交
89

L
LiteOS2021 已提交
90 91
UINT32 ArchIntUnLock(VOID);
#define LOS_IntUnLock ArchIntUnLock
J
JerryH1011 已提交
92

93 94
#define LOS_HwiOpsGet ArchIntOpsGet

95 96
/**
 * @ingroup  los_interrupt
C
Caoruihong 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
 * @brief Delete hardware interrupt.
 *
 * @par Description:
 * This API is used to delete hardware interrupt.
 *
 * @attention
 * <ul>
 * <li>The hardware interrupt module is usable only when the configuration item for hardware interrupt tailoring is enabled.</li>
 * <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range applicable for a Cortex-A7 platform is [32,95].</li>
 * <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
 * <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
 * </ul>
 *
 * @param  hwiNum   [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable for a Cortex-A7 platform is [32,95].
 *
 * @retval #OS_ERRNO_HWI_NUM_INVALID              0x02000900: Invalid interrupt number.
 * @retval #LOS_OK                                0         : The interrupt is successfully delete.
 * @par Dependency:
115
 * <ul><li>los_interrupt.h: the header file that contains the API declaration.</li></ul>
C
Caoruihong 已提交
116 117
 * @see None.
 */
L
LiteOS2021 已提交
118
UINT32 ArchHwiDelete(HWI_HANDLE_T hwiNum);
C
Caoruihong 已提交
119

120 121
/**
 * @ingroup  los_interrupt
C
Caoruihong 已提交
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
 * @brief Create a hardware interrupt.
 *
 * @par Description:
 * This API is used to configure a hardware interrupt and register a hardware interrupt handling function.
 *
 * @attention
 * <ul>
 * <li>The hardware interrupt module is usable only when the configuration item for hardware interrupt tailoring is enabled.</li>
 * <li>Hardware interrupt number value range: [OS_USER_HWI_MIN,OS_USER_HWI_MAX]. The value range applicable for a Cortex-A7 platform is [32,95].</li>
 * <li>OS_HWI_MAX_NUM specifies the maximum number of interrupts that can be created.</li>
 * <li>Before executing an interrupt on a platform, refer to the chip manual of the platform.</li>
 * </ul>
 *
 * @param  hwiNum   [IN] Type#HWI_HANDLE_T: hardware interrupt number. The value range applicable for a Cortex-A7 platform is [32,95].
 * @param  hwiPrio  [IN] Type#HWI_PRIOR_T: hardware interrupt priority. Ignore this parameter temporarily.
 * @param  mode     [IN] Type#HWI_MODE_T: hardware interrupt mode. Ignore this parameter temporarily.
 * @param  handler  [IN] Type#HWI_PROC_FUNC: interrupt handler used when a hardware interrupt is triggered.
 * @param  arg      [IN] Type#HWI_ARG_T: input parameter of the interrupt handler used when a hardware interrupt is triggered.
 *
 * @retval #OS_ERRNO_HWI_PROC_FUNC_NULL               0x02000901: Null hardware interrupt handling function.
 * @retval #OS_ERRNO_HWI_NUM_INVALID                  0x02000900: Invalid interrupt number.
 * @retval #OS_ERRNO_HWI_NO_MEMORY                    0x02000903: Insufficient memory for hardware interrupt creation.
 * @retval #OS_ERRNO_HWI_ALREADY_CREATED              0x02000904: The interrupt handler being created has already been created.
 * @retval #LOS_OK                                    0         : The interrupt is successfully created.
 * @par Dependency:
147
 * <ul><li>los_interrupt.h: the header file that contains the API declaration.</li></ul>
C
Caoruihong 已提交
148 149
 * @see None.
 */
L
LiteOS2021 已提交
150 151 152 153 154
UINT32 ArchHwiCreate(HWI_HANDLE_T hwiNum,
                     HWI_PRIOR_T hwiPrio,
                     HWI_MODE_T mode,
                     HWI_PROC_FUNC handler,
                     HWI_ARG_T arg);
C
Caoruihong 已提交
155

156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
STATIC INLINE UINT32 ArchIntTrigger(HWI_HANDLE_T hwiNum)
{
    if (g_archHwiOps.triggerIrq == NULL) {
        return LOS_NOK;
    }
    return g_archHwiOps.triggerIrq(hwiNum);
}

STATIC INLINE UINT32 ArchIntEnable(HWI_HANDLE_T hwiNum)
{
    if (g_archHwiOps.enableIrq == NULL) {
        return LOS_NOK;
    }
    return g_archHwiOps.enableIrq(hwiNum);
}

STATIC INLINE UINT32 ArchIntDisable(HWI_HANDLE_T hwiNum)
{
    if (g_archHwiOps.disableIrq == NULL) {
        return LOS_NOK;
    }
    return g_archHwiOps.disableIrq(hwiNum);
}

STATIC INLINE UINT32 ArchIntClear(HWI_HANDLE_T hwiNum)
{
    if (g_archHwiOps.clearIrq == NULL) {
        return LOS_NOK;
    }
    return g_archHwiOps.clearIrq(hwiNum);
}

STATIC INLINE UINT32 ArchIntSetPriority(HWI_HANDLE_T hwiNum, HWI_PRIOR_T priority)
{
    if (g_archHwiOps.setIrqPriority == NULL) {
        return LOS_NOK;
    }
    return g_archHwiOps.setIrqPriority(hwiNum, priority);
}

STATIC INLINE HwiControllerOps *ArchIntOpsGet(VOID)
{
    return &g_archHwiOps;
}

C
Caoruihong 已提交
201 202 203 204 205 206 207
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */

#endif /* _LOS_INTERRUPT_H */