summaryrefslogtreecommitdiff
path: root/bsp/rockchip/common/rk_hal/lib/hal/inc/hal_nvic.h
blob: d897c8fcfc019230859de154aa9c3c2a219db542 (plain)
1
2
3
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* SPDX-License-Identifier: BSD-3-Clause */
/*
 * Copyright (c) 2020-2021 Rockchip Electronics Co., Ltd.
 */

#include "hal_conf.h"

#ifdef HAL_NVIC_MODULE_ENABLED

/** @addtogroup RK_HAL_Driver
 *  @{
 */

/** @addtogroup NVIC
 *  @{
 */

#ifndef _HAL_NVIC_H_
#define _HAL_NVIC_H_

#include "hal_def.h"

/***************************** MACRO Definition ******************************/
/** @defgroup NVIC_Exported_Definition_Group1 Basic Definition
 *  @{
 */

typedef enum {
    NVIC_PRIORITYGROUP_0 = (0x7U), /*!< 0 bits pre-emption, 8 bits subpriority*/
    NVIC_PRIORITYGROUP_1 = (0x6U), /*!< 1 bits pre-emption, 7 bits subpriority*/
    NVIC_PRIORITYGROUP_2 = (0x5U), /*!< 2 bits pre-emption, 6 bits subpriority*/
    NVIC_PRIORITYGROUP_3 = (0x4U), /*!< 3 bits pre-emption, 5 bits subpriority*/
    NVIC_PRIORITYGROUP_4 = (0x3U), /*!< 4 bits pre-emption, 4 bits subpriority*/
    NVIC_PRIORITYGROUP_5 = (0x2U), /*!< 5 bits pre-emption, 3 bits subpriority*/
} eNVIC_PriorityGroup;

#ifndef NVIC_PRIORITYGROUP_DEFAULT
#define NVIC_PRIORITYGROUP_DEFAULT NVIC_PRIORITYGROUP_5 /**< Can be redefined in soc.h */
#endif

/* preempt priority */
#define NVIC_PERIPH_PRIO_LOWEST (0xFFU)
#ifndef NVIC_PERIPH_PRIO_DEFAULT
#if (__NVIC_PRIO_BITS == 2U)
#define NVIC_PERIPH_PRIO_DEFAULT (0x2U) /**< Can be redefined in soc.h */
#elif (__NVIC_PRIO_BITS == 3U)
#define NVIC_PERIPH_PRIO_DEFAULT (0x4U) /**< Can be redefined in soc.h */
#else
#define NVIC_PERIPH_PRIO_DEFAULT (0xFFU) /**< Can be redefined in soc.h */
#endif
#endif
#define NVIC_PERIPH_PRIO_HIGHEST (0x0U)

/* sub priority */
#define NVIC_PERIPH_SUB_PRIO_LOWEST  (0xFFU)
#define NVIC_PERIPH_SUB_PRIO_DEFAULT (0xFFU)
#define NVIC_PERIPH_SUB_PRIO_HIGHEST (0x0U)

#define IS_NVIC_PREEMPTION_PRIORITY(PRIORITY) ((PRIORITY) < 0x100U)
#define IS_NVIC_SUB_PRIORITY(PRIORITY)        ((PRIORITY) < 0x100U)

/** @brief Type define of NVIC interrupt handler */
typedef void (*NVIC_IRQHandler)(void);

/***************************** Structure Definition **************************/

/** @} */

/***************************** Function Declare ******************************/
/** @defgroup NVIC_Public_Function_Declare Public Function Declare
 *  @{
 */

HAL_Status HAL_NVIC_SetIRQHandler(IRQn_Type IRQn, NVIC_IRQHandler handler);
NVIC_IRQHandler HAL_NVIC_GetIRQHandler(IRQn_Type IRQn);
HAL_Status HAL_NVIC_SetPriorityGrouping(eNVIC_PriorityGroup priorityGroup);
uint32_t HAL_NVIC_GetPriorityGrouping(void);
HAL_Status HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t preemptPriority, uint32_t subPriority);
uint32_t HAL_NVIC_GetPriority(IRQn_Type IRQn);
HAL_Status HAL_NVIC_EnableIRQ(IRQn_Type IRQn);
HAL_Status HAL_NVIC_DisableIRQ(IRQn_Type IRQn);
HAL_Status HAL_NVIC_SetPendingIRQ(IRQn_Type IRQn);
HAL_Check HAL_NVIC_IsPendingIRQ(IRQn_Type IRQn);
HAL_Status HAL_NVIC_ClearPendingIRQ(IRQn_Type IRQn);
HAL_Status HAL_NVIC_ConfigExtIRQ(IRQn_Type IRQn, NVIC_IRQHandler handler,
                                 uint32_t preemptPriority, uint32_t subPriority);
HAL_Status HAL_NVIC_Init(void);

/** @} */

#endif

/** @} */

/** @} */

#endif /* HAL_NVIC_MODULE_ENABLED */