gr533x_hal_cortex.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr533x_hal_cortex.h
5 * @author BLE Driver Team
6 * @brief Header file of CORTEX HAL module.
7 *
8 ****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 ****************************************************************************************
36 */
37
38 /** @addtogroup PERIPHERAL Peripheral Driver
39 * @{
40 */
41
42 /** @addtogroup HAL_DRIVER HAL Driver
43 * @{
44 */
45
46 /** @defgroup HAL_CORTEX CORTEX
47 * @brief CORTEX HAL module driver.
48 * @{
49 */
50
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR533x_HAL_CORTEX_H__
53 #define __GR533x_HAL_CORTEX_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr533x_hal_def.h"
61
62 /* Exported types ------------------------------------------------------------*/
63
64 /** @addtogroup HAL_CORTEX_STRUCTURES Structures
65 * @{
66 */
67
68 #if (__MPU_PRESENT == 1U)
69
70 /** @defgroup CORTEX_MPU_Region_Configuration MPU Region Configuration
71 * @{
72 */
73
74 /**
75 * @brief MPU Region initialization structure
76 */
77 typedef struct _mpu_region_init_t
78 {
79 uint8_t enable; /**< Specifies the status of the region.
80 This parameter can be a value of @ref CORTEX_MPU_Region_Enable */
81
82 uint8_t number; /**< Specifies the number of the region to protect.
83 This parameter can be a value of @ref CORTEX_MPU_Region_Number */
84
85 uint32_t base_address; /**< Specifies the base address of the region to protect. */
86
87 uint8_t size; /**< Specifies the size of the region to protect.
88 This parameter can be a value of @ref CORTEX_MPU_Region_Size */
89
90 uint8_t subregion_disable; /**< Specifies the number of the subregion protection to disable.
91 This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF */
92
93 uint8_t type_tex_field; /**< Specifies the TEX field level.
94 This parameter can be a value of @ref CORTEX_MPU_TEX_Levels */
95
96 uint8_t access_permission; /**< Specifies the region access permission type.
97 This parameter can be a value of @ref CORTEX_MPU_Region_Permission_Attributes */
98
99 uint8_t disable_exec; /**< Specifies the instruction access status.
100 This parameter can be a value of @ref CORTEX_MPU_Instruction_Access */
101
102 uint8_t is_shareable; /**< Specifies the shareability status of the protected region.
103 This parameter can be a value of @ref CORTEX_MPU_Access_Shareable */
104
105 uint8_t is_cacheable; /**< Specifies the cacheable status of the region protected.
106 This parameter can be a value of @ref CORTEX_MPU_Access_Cacheable */
107
108 uint8_t is_bufferable; /**< Specifies the bufferable status of the protected region.
109 This parameter can be a value of @ref CORTEX_MPU_Access_Bufferable */
110
111 } mpu_region_init_t;
112
113 /** @} */
114
115 #endif /* __MPU_PRESENT */
116
117 /** @} */
118
119
120 /**
121 * @defgroup HAL_CORTEX_MACRO Defines
122 * @{
123 */
124
125 /* Exported constants --------------------------------------------------------*/
126
127 /** @defgroup CORTEX_Exported_Constants CORTEX Exported Constants
128 * @{
129 */
130
131 /** @defgroup CORTEX_Preemption_Priority_Group CORTEX Preemption Priority Group
132 * @{
133 */
134 #define NVIC_PRIORITYGROUP_0 (0x00000007U) /**< 0 bit for pre-emption priority,
135 8 bits for subpriority */
136 #define NVIC_PRIORITYGROUP_1 (0x00000006U) /**< 1 bit for pre-emption priority,
137 7 bits for subpriority */
138 #define NVIC_PRIORITYGROUP_2 (0x00000005U) /**< 2 bits for pre-emption priority,
139 6 bits for subpriority */
140 #define NVIC_PRIORITYGROUP_3 (0x00000004U) /**< 3 bits for pre-emption priority,
141 5 bits for subpriority */
142 #define NVIC_PRIORITYGROUP_4 (0x00000003U) /**< 4 bits for pre-emption priority,
143 4 bits for subpriority */
144 #define NVIC_PRIORITYGROUP_5 (0x00000002U) /**< 5 bits for pre-emption priority,
145 3 bits for subpriority */
146 #define NVIC_PRIORITYGROUP_6 (0x00000001U) /**< 6 bits for pre-emption priority,
147 2 bits for subpriority */
148 #define NVIC_PRIORITYGROUP_7 (0x00000000U) /**< 7 bits for pre-emption priority,
149 1 bit for subpriority */
150 /** @} */
151
152 #if (__MPU_PRESENT == 1U)
153 /** @defgroup CORTEX_MPU_HFNMI_PRIVDEF_Control MPU HFNMI and PRIVILEGED Access control
154 * @{
155 */
156 #define MPU_HFNMI_PRIVDEF_NONE (0x00000000U) /**< HFNMIENA disable, PRIVDEFENA disable */
157 #define MPU_HARDFAULT_NMI (0x00000002U) /**< HFNMIENA enable, PRIVDEFENA disable */
158 #define MPU_PRIVILEGED_DEFAULT (0x00000004U) /**< HFNMIENA disable, PRIVDEFENA enable */
159 #define MPU_HFNMI_PRIVDEF (0x00000006U) /**< HFNMIENA enable, PRIVDEFENA enable */
160 /** @} */
161
162 /** @defgroup CORTEX_MPU_Region_Enable CORTEX MPU Region Enable
163 * @{
164 */
165 #define MPU_REGION_ENABLE ((uint8_t)0x01U) /**< MPU Region Enable */
166 #define MPU_REGION_DISABLE ((uint8_t)0x00U) /**< MPU Region Disable */
167 /** @} */
168
169 /** @defgroup CORTEX_MPU_Instruction_Access CORTEX MPU Instruction Access
170 * @{
171 */
172 #define MPU_INSTRUCTION_ACCESS_ENABLE ((uint8_t)0x00U) /**< MPU Instruction Access Enable */
173 #define MPU_INSTRUCTION_ACCESS_DISABLE ((uint8_t)0x01U) /**< MPU Instruction Access Disable */
174 /** @} */
175
176 /** @defgroup CORTEX_MPU_Access_Shareable CORTEX MPU Instruction Access Shareable
177 * @{
178 */
179 #define MPU_ACCESS_SHAREABLE ((uint8_t)0x01U) /**< MPU Instruction Access Shareable */
180 #define MPU_ACCESS_NOT_SHAREABLE ((uint8_t)0x00U) /**< MPU Instruction Access Not Shareable */
181 /** @} */
182
183 /** @defgroup CORTEX_MPU_Access_Cacheable CORTEX MPU Instruction Access Cacheable
184 * @{
185 */
186 #define MPU_ACCESS_CACHEABLE ((uint8_t)0x01U) /**< MPU Instruction Access Cacheable */
187 #define MPU_ACCESS_NOT_CACHEABLE ((uint8_t)0x00U) /**< MPU Instruction Access Not Cacheable */
188 /** @} */
189
190 /** @defgroup CORTEX_MPU_Access_Bufferable CORTEX MPU Instruction Access Bufferable
191 * @{
192 */
193 #define MPU_ACCESS_BUFFERABLE ((uint8_t)0x01U) /**< MPU Instruction Access Bufferable */
194 #define MPU_ACCESS_NOT_BUFFERABLE ((uint8_t)0x00U) /**< MPU Instruction Access Not Bufferable */
195 /** @} */
196
197 /** @defgroup CORTEX_MPU_TEX_Levels MPU TEX Levels
198 * @{
199 */
200 #define MPU_TEX_LEVEL0 ((uint8_t)0x00U) /**< MPU TEX Level 0 */
201 #define MPU_TEX_LEVEL1 ((uint8_t)0x01U) /**< MPU TEX Level 1 */
202 #define MPU_TEX_LEVEL2 ((uint8_t)0x02U) /**< MPU TEX Level 2 */
203 /** @} */
204
205 /** @defgroup CORTEX_MPU_Region_Size CORTEX MPU Region Size
206 * @{
207 */
208 #define MPU_REGION_SIZE_32B ((uint8_t)0x04U) /**< MPU Region Size 32B */
209 #define MPU_REGION_SIZE_64B ((uint8_t)0x05U) /**< MPU Region Size 64B */
210 #define MPU_REGION_SIZE_128B ((uint8_t)0x06U) /**< MPU Region Size 128B */
211 #define MPU_REGION_SIZE_256B ((uint8_t)0x07U) /**< MPU Region Size 256B */
212 #define MPU_REGION_SIZE_512B ((uint8_t)0x08U) /**< MPU Region Size 512B */
213 #define MPU_REGION_SIZE_1KB ((uint8_t)0x09U) /**< MPU Region Size 1KB */
214 #define MPU_REGION_SIZE_2KB ((uint8_t)0x0AU) /**< MPU Region Size 2KB */
215 #define MPU_REGION_SIZE_4KB ((uint8_t)0x0BU) /**< MPU Region Size 4KB */
216 #define MPU_REGION_SIZE_8KB ((uint8_t)0x0CU) /**< MPU Region Size 8KB */
217 #define MPU_REGION_SIZE_16KB ((uint8_t)0x0DU) /**< MPU Region Size 16KB */
218 #define MPU_REGION_SIZE_32KB ((uint8_t)0x0EU) /**< MPU Region Size 32KB */
219 #define MPU_REGION_SIZE_64KB ((uint8_t)0x0FU) /**< MPU Region Size 64KB */
220 #define MPU_REGION_SIZE_128KB ((uint8_t)0x10U) /**< MPU Region Size 128KB */
221 #define MPU_REGION_SIZE_256KB ((uint8_t)0x11U) /**< MPU Region Size 256KB */
222 #define MPU_REGION_SIZE_512KB ((uint8_t)0x12U) /**< MPU Region Size 512KB */
223 #define MPU_REGION_SIZE_1MB ((uint8_t)0x13U) /**< MPU Region Size 1MB */
224 #define MPU_REGION_SIZE_2MB ((uint8_t)0x14U) /**< MPU Region Size 2MB */
225 #define MPU_REGION_SIZE_4MB ((uint8_t)0x15U) /**< MPU Region Size 4MB */
226 #define MPU_REGION_SIZE_8MB ((uint8_t)0x16U) /**< MPU Region Size 8MB */
227 #define MPU_REGION_SIZE_16MB ((uint8_t)0x17U) /**< MPU Region Size 16MB */
228 #define MPU_REGION_SIZE_32MB ((uint8_t)0x18U) /**< MPU Region Size 32MB */
229 #define MPU_REGION_SIZE_64MB ((uint8_t)0x19U) /**< MPU Region Size 64MB */
230 #define MPU_REGION_SIZE_128MB ((uint8_t)0x1AU) /**< MPU Region Size 128MB */
231 #define MPU_REGION_SIZE_256MB ((uint8_t)0x1BU) /**< MPU Region Size 256MB */
232 #define MPU_REGION_SIZE_512MB ((uint8_t)0x1CU) /**< MPU Region Size 512MB */
233 #define MPU_REGION_SIZE_1GB ((uint8_t)0x1DU) /**< MPU Region Size 1GB */
234 #define MPU_REGION_SIZE_2GB ((uint8_t)0x1EU) /**< MPU Region Size 2GB */
235 #define MPU_REGION_SIZE_4GB ((uint8_t)0x1FU) /**< MPU Region Size 4GB */
236 /** @} */
237
238 /** @defgroup CORTEX_MPU_Region_Permission_Attributes CORTEX MPU Region Permission Attributes
239 * @{
240 */
241 #define MPU_REGION_NO_ACCESS ((uint8_t)0x00U) /**< All accesses generate a permission fault */
242 #define MPU_REGION_PRIV_RW ((uint8_t)0x01U) /**< Access from privileged software only */
243 #define MPU_REGION_PRIV_RW_URO ((uint8_t)0x02U) /**< Writes by unprivileged software generate a permission fault */
244 #define MPU_REGION_FULL_ACCESS ((uint8_t)0x03U) /**< Full access */
245 #define MPU_REGION_PRIV_RO ((uint8_t)0x05U) /**< Reads by privileged software only */
246 #define MPU_REGION_PRIV_RO_URO ((uint8_t)0x06U) /**< Read only, by privileged or unprivileged software */
247 /** @} */
248
249 /** @defgroup CORTEX_MPU_Region_Number CORTEX MPU Region Number
250 * @{
251 */
252 #define MPU_REGION_NUMBER0 ((uint8_t)0x00U) /**< MPU Region Number 0 */
253 #define MPU_REGION_NUMBER1 ((uint8_t)0x01U) /**< MPU Region Number 1 */
254 #define MPU_REGION_NUMBER2 ((uint8_t)0x02U) /**< MPU Region Number 2 */
255 #define MPU_REGION_NUMBER3 ((uint8_t)0x03U) /**< MPU Region Number 3 */
256 #define MPU_REGION_NUMBER4 ((uint8_t)0x04U) /**< MPU Region Number 4 */
257 #define MPU_REGION_NUMBER5 ((uint8_t)0x05U) /**< MPU Region Number 5 */
258 #define MPU_REGION_NUMBER6 ((uint8_t)0x06U) /**< MPU Region Number 6 */
259 #define MPU_REGION_NUMBER7 ((uint8_t)0x07U) /**< MPU Region Number 7 */
260 /** @} */
261 #endif /* __MPU_PRESENT */
262
263 /** @} */
264
265 /* Exported Macros -----------------------------------------------------------*/
266 /* Private types -------------------------------------------------------------*/
267 /* Private variables ---------------------------------------------------------*/
268 /* Private constants ---------------------------------------------------------*/
269
270 /* Private macros ------------------------------------------------------------*/
271 /** @defgroup CORTEX_Private_Macros CORTEX Private Macros
272 * @{
273 */
274
275 /**
276 * @brief Check if NVIC priority group is valid.
277 * @param __GROUP__ NVIC priority group.
278 * @retval SET (__GROUP__ is valid) or RESET (__GROUP__ is invalid)
279 */
280 #define IS_NVIC_PRIORITY_GROUP(__GROUP__) (((__GROUP__) == NVIC_PRIORITYGROUP_0) || \
281 ((__GROUP__) == NVIC_PRIORITYGROUP_1) || \
282 ((__GROUP__) == NVIC_PRIORITYGROUP_2) || \
283 ((__GROUP__) == NVIC_PRIORITYGROUP_3) || \
284 ((__GROUP__) == NVIC_PRIORITYGROUP_4) || \
285 ((__GROUP__) == NVIC_PRIORITYGROUP_5) || \
286 ((__GROUP__) == NVIC_PRIORITYGROUP_6) || \
287 ((__GROUP__) == NVIC_PRIORITYGROUP_7))
288
289 /**
290 * @brief Check if NVIC priority group is valid.
291 * @param __PRIORITY__ NVIC priority group.
292 * @retval SET (__PRIORITY__ is valid) or RESET (__PRIORITY__ is invalid)
293 */
294 #define IS_NVIC_PREEMPTION_PRIORITY(__PRIORITY__) ((__PRIORITY__) < 0x80U)
295
296 /**
297 * @brief Check if NVIC sub priority is valid.
298 * @param __PRIORITY__ NVIC sub priority.
299 * @retval SET (__PRIORITY__ is valid) or RESET (__PRIORITY__ is invalid)
300 */
301 #define IS_NVIC_SUB_PRIORITY(__PRIORITY__) ((__PRIORITY__) <= 0xFFU)
302
303 /**
304 * @brief Check if NVIC deivce IRQ is valid.
305 * @param __IRQ__ NVIC device IRQ.
306 * @retval SET (__IRQ__ is valid) or RESET (__IRQ__ is invalid)
307 */
308 #define IS_NVIC_DEVICE_IRQ(__IRQ__) ((__IRQ__) >= 0x00)
309
310 /**
311 * @brief Check if SYSTICK clock source is valid.
312 * @param __SOURCE__ SYSTICK clock source.
313 * @retval SET (__SOURCE__ is valid) or RESET (__SOURCE__ is invalid)
314 */
315 #define IS_SYSTICK_CLK_SOURCE(__SOURCE__) (((__SOURCE__) == SYSTICK_CLKSOURCE_HCLK) || \
316 ((__SOURCE__) == SYSTICK_CLKSOURCE_REFCLK))
317
318 #if (__MPU_PRESENT == 1U)
319
320 /**
321 * @brief Check if MPU enable state is valid.
322 * @param __STATE__ Enable state.
323 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is not invalid)
324 */
325 #define IS_MPU_REGION_ENABLE(__STATE__) (((__STATE__) == MPU_REGION_ENABLE) || \
326 ((__STATE__) == MPU_REGION_DISABLE))
327
328 /**
329 * @brief Check if MPU instruction access state is valid.
330 * @param __STATE__ MPU instruction access state.
331 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is not invalid)
332 */
333 #define IS_MPU_INSTRUCTION_ACCESS(__STATE__) (((__STATE__) == MPU_INSTRUCTION_ACCESS_ENABLE) || \
334 ((__STATE__) == MPU_INSTRUCTION_ACCESS_DISABLE))
335
336 /**
337 * @brief Check if MPU access shareable state is valid.
338 * @param __STATE__ MPU access shareable state.
339 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is not invalid)
340 */
341 #define IS_MPU_ACCESS_SHAREABLE(__STATE__) (((__STATE__) == MPU_ACCESS_SHAREABLE) || \
342 ((__STATE__) == MPU_ACCESS_NOT_SHAREABLE))
343
344 /**
345 * @brief Check if MPU access cacheable state is valid.
346 * @param __STATE__ MPU access cacheable state.
347 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is not invalid)
348 */
349 #define IS_MPU_ACCESS_CACHEABLE(__STATE__) (((__STATE__) == MPU_ACCESS_CACHEABLE) || \
350 ((__STATE__) == MPU_ACCESS_NOT_CACHEABLE))
351
352 /**
353 * @brief Check if MPU access bufferable state is valid.
354 * @param __STATE__ MPU access bufferable state.
355 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is not invalid)
356 */
357 #define IS_MPU_ACCESS_BUFFERABLE(__STATE__) (((__STATE__) == MPU_ACCESS_BUFFERABLE) || \
358 ((__STATE__) == MPU_ACCESS_NOT_BUFFERABLE))
359
360 /**
361 * @brief Check if MPU Tex level is valid.
362 * @param __TYPE__ MPU Tex level.
363 * @retval SET (__TYPE__ is valid) or RESET (__TYPE__ is invalid)
364 */
365 #define IS_MPU_TEX_LEVEL(__TYPE__) (((__TYPE__) == MPU_TEX_LEVEL0) || \
366 ((__TYPE__) == MPU_TEX_LEVEL1) || \
367 ((__TYPE__) == MPU_TEX_LEVEL2))
368
369 /**
370 * @brief Check if MPU region permission attribute type is valid.
371 * @param __TYPE__ MPU region permission attribute type.
372 * @retval SET (__TYPE__ is valid) or RESET (__TYPE__ is invalid)
373 */
374 #define IS_MPU_REGION_PERMISSION_ATTRIBUTE(__TYPE__) (((__TYPE__) == MPU_REGION_NO_ACCESS) || \
375 ((__TYPE__) == MPU_REGION_PRIV_RW) || \
376 ((__TYPE__) == MPU_REGION_PRIV_RW_URO) || \
377 ((__TYPE__) == MPU_REGION_FULL_ACCESS) || \
378 ((__TYPE__) == MPU_REGION_PRIV_RO) || \
379 ((__TYPE__) == MPU_REGION_PRIV_RO_URO))
380
381 /**
382 * @brief Check if MPU region number is valid.
383 * @param __NUMBER__ MPU region number.
384 * @retval SET (__NUMBER__ is valid) or RESET (__NUMBER__ is invalid)
385 */
386 #define IS_MPU_REGION_NUMBER(__NUMBER__) (((__NUMBER__) == MPU_REGION_NUMBER0) || \
387 ((__NUMBER__) == MPU_REGION_NUMBER1) || \
388 ((__NUMBER__) == MPU_REGION_NUMBER2) || \
389 ((__NUMBER__) == MPU_REGION_NUMBER3) || \
390 ((__NUMBER__) == MPU_REGION_NUMBER4) || \
391 ((__NUMBER__) == MPU_REGION_NUMBER5) || \
392 ((__NUMBER__) == MPU_REGION_NUMBER6) || \
393 ((__NUMBER__) == MPU_REGION_NUMBER7))
394
395 /**
396 * @brief Check if MPU region size is valid.
397 * @param __SIZE__ MPU region size.
398 * @retval SET (__SIZE__ is valid) or RESET (__SIZE__ is invalid)
399 */
400 #define IS_MPU_REGION_SIZE(__SIZE__) (((__SIZE__) == MPU_REGION_SIZE_32B) || \
401 ((__SIZE__) == MPU_REGION_SIZE_64B) || \
402 ((__SIZE__) == MPU_REGION_SIZE_128B) || \
403 ((__SIZE__) == MPU_REGION_SIZE_256B) || \
404 ((__SIZE__) == MPU_REGION_SIZE_512B) || \
405 ((__SIZE__) == MPU_REGION_SIZE_1KB) || \
406 ((__SIZE__) == MPU_REGION_SIZE_2KB) || \
407 ((__SIZE__) == MPU_REGION_SIZE_4KB) || \
408 ((__SIZE__) == MPU_REGION_SIZE_8KB) || \
409 ((__SIZE__) == MPU_REGION_SIZE_16KB) || \
410 ((__SIZE__) == MPU_REGION_SIZE_32KB) || \
411 ((__SIZE__) == MPU_REGION_SIZE_64KB) || \
412 ((__SIZE__) == MPU_REGION_SIZE_128KB) || \
413 ((__SIZE__) == MPU_REGION_SIZE_256KB) || \
414 ((__SIZE__) == MPU_REGION_SIZE_512KB) || \
415 ((__SIZE__) == MPU_REGION_SIZE_1MB) || \
416 ((__SIZE__) == MPU_REGION_SIZE_2MB) || \
417 ((__SIZE__) == MPU_REGION_SIZE_4MB) || \
418 ((__SIZE__) == MPU_REGION_SIZE_8MB) || \
419 ((__SIZE__) == MPU_REGION_SIZE_16MB) || \
420 ((__SIZE__) == MPU_REGION_SIZE_32MB) || \
421 ((__SIZE__) == MPU_REGION_SIZE_64MB) || \
422 ((__SIZE__) == MPU_REGION_SIZE_128MB) || \
423 ((__SIZE__) == MPU_REGION_SIZE_256MB) || \
424 ((__SIZE__) == MPU_REGION_SIZE_512MB) || \
425 ((__SIZE__) == MPU_REGION_SIZE_1GB) || \
426 ((__SIZE__) == MPU_REGION_SIZE_2GB) || \
427 ((__SIZE__) == MPU_REGION_SIZE_4GB))
428
429
430 /**
431 * @brief Check if MPU sub region is valid.
432 * @param __SUBREGION__ MPU sub region.
433 * @retval SET (__SUBREGION__ is valid) or RESET (__SUBREGION__ is invalid)
434 */
435 #define IS_MPU_SUB_REGION_DISABLE(__SUBREGION__) ((__SUBREGION__) < (uint16_t)0x00FFU)
436 #endif /* __MPU_PRESENT */
437
438 /** @} */
439
440 /** @} */
441
442 /* Exported functions --------------------------------------------------------*/
443 /** @addtogroup HAL_CORTEX_DRIVER_FUNCTIONS Functions
444 * @{
445 */
446
447 /** @addtogroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions
448 * @brief Initialization and Configuration functions.
449 *
450 @verbatim
451 ==============================================================================
452 ##### Initialization and de-initialization functions #####
453 ==============================================================================
454 [..]
455 This section provides the CORTEX HAL driver functions allowing to configure Interrupts
456 Systick functionalities
457
458 @endverbatim
459 * @{
460 */
461
462 /**
463 ****************************************************************************************
464 * @brief Set the priority grouping field (pre-emption priority and subpriority)
465 * using the required unlock sequence.
466 *
467 * @note When the NVIC_PriorityGroup_0 is selected, IRQ pre-emption is no more possible.
468 * The pending IRQ priority will be managed only by the subpriority.
469 *
470 * @param[in] priority_group: The priority grouping bits length.
471 * This parameter can be one of the following values:
472 * @arg @ref NVIC_PRIORITYGROUP_0 0 bit for pre-emption priority,
473 * 8 bits for subpriority
474 * @arg @ref NVIC_PRIORITYGROUP_1 1 bit for pre-emption priority,
475 * 7 bits for subpriority
476 * @arg @ref NVIC_PRIORITYGROUP_2 2 bits for pre-emption priority,
477 * 6 bits for subpriority
478 * @arg @ref NVIC_PRIORITYGROUP_3 3 bits for pre-emption priority,
479 * 5 bits for subpriority
480 * @arg @ref NVIC_PRIORITYGROUP_4 4 bits for pre-emption priority,
481 * 4 bits for subpriority
482 * @arg @ref NVIC_PRIORITYGROUP_5 5 bits for pre-emption priority,
483 * 3 bits for subpriority
484 * @arg @ref NVIC_PRIORITYGROUP_6 6 bits for pre-emption priority,
485 * 2 bits for subpriority
486 * @arg @ref NVIC_PRIORITYGROUP_7 7 bits for pre-emption priority,
487 * 1 bit for subpriority
488 ****************************************************************************************
489 */
490 void hal_nvic_set_priority_grouping(uint32_t priority_group);
491
492 /**
493 ****************************************************************************************
494 * @brief Set the priority of an interrupt.
495 *
496 * @param[in] IRQn: External interrupt number.
497 * This parameter can be an enumerator of IRQn_Type enumeration
498 * (For the complete GR533x Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr533xxx.h))
499 * @param[in] preempt_priority: The pre-emption priority for the IRQn channel.
500 * This parameter can be a value between 0 and 127 as described in the table CORTEX_NVIC_Priority_Table.
501 * A lower priority value indicates a higher priority
502 * @param[in] sub_priority: The subpriority level for the IRQ channel.
503 * This parameter can be a value between 0 and 255 as described in the table CORTEX_NVIC_Priority_Table.
504 * A lower priority value indicates a higher priority.
505 ****************************************************************************************
506 */
507 void hal_nvic_set_priority(IRQn_Type IRQn, uint32_t preempt_priority, uint32_t sub_priority);
508
509 /**
510 ****************************************************************************************
511 * @brief Enable a device specific interrupt in the NVIC interrupt controller.
512 *
513 * @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
514 * function should be called before.
515 *
516 * @param[in] IRQn: External interrupt number.
517 * This parameter can be an enumerator of IRQn_Type enumeration
518 * (For the complete GR533x Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr533xxx.h))
519 ****************************************************************************************
520 */
521 void hal_nvic_enable_irq(IRQn_Type IRQn);
522
523 /**
524 ****************************************************************************************
525 * @brief Disable a device specific interrupt in the NVIC interrupt controller.
526 *
527 * @param[in] IRQn: External interrupt number.
528 * This parameter can be an enumerator of IRQn_Type enumeration
529 * (For the complete GR533x Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr533xxx.h))
530 ****************************************************************************************
531 */
532 void hal_nvic_disable_irq(IRQn_Type IRQn);
533
534 /**
535 ****************************************************************************************
536 * @brief Initiate a system reset request to reset the MCU.
537 ****************************************************************************************
538 */
539 void hal_nvic_system_reset(void);
540
541
542 /**
543 ****************************************************************************************
544 * @brief Initialize the System Timer and its interrupt, and start the System Tick Timer.
545 * Counter is in free running mode to generate periodic interrupts.
546 *
547 * @param[in] ticks_number: Specifies the number of ticks between two interrupts.
548 *
549 * @retval status
550 * - 0 Function succeeded.
551 * - 1 Function failed.
552 ****************************************************************************************
553 */
554 uint32_t hal_systick_config(uint32_t ticks_number);
555
556 /** @} */
557
558 /** @addtogroup CORTEX_Exported_Functions_Group2 Peripheral Control functions
559 * @brief Cortex control functions.
560 *
561 @verbatim
562 ==============================================================================
563 ##### Peripheral Control functions #####
564 ==============================================================================
565 [..]
566 This subsection provides a set of functions allowing to control the CORTEX
567 (NVIC, SYSTICK, MPU) functionalities.
568
569
570 @endverbatim
571 * @{
572 */
573
574 #if (__MPU_PRESENT == 1U)
575 /**
576 ****************************************************************************************
577 * @brief Initialize and configures the Region and the memory to be protected.
578 *
579 * @param[in] p_mpu_init: Pointer to a mpu_region_init_t structure that contains
580 * the initialization and configuration information.
581 ****************************************************************************************
582 */
583 void hal_mpu_config_region(mpu_region_init_t *p_mpu_init);
584 #endif /* __MPU_PRESENT */
585
586 /**
587 ****************************************************************************************
588 * @brief Get the priority grouping field from the NVIC Interrupt Controller.
589 *
590 * @return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field)
591 ****************************************************************************************
592 */
593 uint32_t hal_nvic_get_priority_grouping(void);
594
595 /**
596 ****************************************************************************************
597 * @brief Get the priority of an interrupt.
598 *
599 * @param[in] IRQn: External interrupt number.
600 * This parameter can be an enumerator of IRQn_Type enumeration.
601 * (For the complete GR533x Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr533xxx.h))
602 * @param[in] priority_group: The priority grouping bits length.
603 * This parameter can be one of the following values:
604 * @arg @ref NVIC_PRIORITYGROUP_0 0 bit for pre-emption priority,
605 * 8 bits for subpriority
606 * @arg @ref NVIC_PRIORITYGROUP_1 1 bit for pre-emption priority,
607 * 7 bits for subpriority
608 * @arg @ref NVIC_PRIORITYGROUP_2 2 bits for pre-emption priority,
609 * 6 bits for subpriority
610 * @arg @ref NVIC_PRIORITYGROUP_3 3 bits for pre-emption priority,
611 * 5 bits for subpriority
612 * @arg @ref NVIC_PRIORITYGROUP_4 4 bits for pre-emption priority,
613 * 4 bits for subpriority
614 * @arg @ref NVIC_PRIORITYGROUP_5 5 bits for pre-emption priority,
615 * 3 bits for subpriority
616 * @arg @ref NVIC_PRIORITYGROUP_6 6 bits for pre-emption priority,
617 * 2 bits for subpriority
618 * @arg @ref NVIC_PRIORITYGROUP_7 7 bits for pre-emption priority,
619 * 1 bit for subpriority
620 * @param[in] p_preempt_priority: Pointer on the Preemptive priority value (starting from 0).
621 * @param[in] p_sub_priority: Pointer on the Subpriority value (starting from 0).
622 ****************************************************************************************
623 */
624 void hal_nvic_get_priority(IRQn_Type IRQn, uint32_t priority_group, uint32_t *p_preempt_priority, uint32_t *p_sub_priority);
625
626 /**
627 ****************************************************************************************
628 * @brief Set Pending bit of an external interrupt.
629 *
630 * @param[in] IRQn: External interrupt number.
631 * This parameter can be an enumerator of IRQn_Type enumeration
632 * (For the complete GR533x Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr533xxx.h))
633 ****************************************************************************************
634 */
635 void hal_nvic_set_pending_irq(IRQn_Type IRQn);
636
637 /**
638 ****************************************************************************************
639 * @brief Get Pending Interrupt (reads the pending register in the NVIC
640 * and returns the pending bit for the specified interrupt).
641 *
642 * @param[in] IRQn: External interrupt number.
643 * This parameter can be an enumerator of IRQn_Type enumeration
644 * (For the complete GR533x Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr533xxx.h))
645 *
646 * @return status
647 * - 0 Interrupt status is not pending.
648 * - 1 Interrupt status is pending.
649 ****************************************************************************************
650 */
651 uint32_t hal_nvic_get_pending_irq(IRQn_Type IRQn);
652
653 /**
654 ****************************************************************************************
655 * @brief Clear the pending bit of an external interrupt.
656 *
657 * @param[in] IRQn: External interrupt number.
658 * This parameter can be an enumerator of IRQn_Type enumeration
659 * (For the complete GR533x Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr533xxx.h))
660 ****************************************************************************************
661 */
662 void hal_nvic_clear_pending_irq(IRQn_Type IRQn);
663
664 /**
665 ****************************************************************************************
666 * @brief Get active interrupt (reads the active register in NVIC and returns the active bit).
667 *
668 * @param[in] IRQn: External interrupt number.
669 * This parameter can be an enumerator of IRQn_Type enumeration
670 * (For the complete GR533x Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr533xxx.h))
671 *
672 * @return status
673 * - 0 Interrupt status is not pending.
674 * - 1 Interrupt status is pending.
675 ****************************************************************************************
676 */
677 uint32_t hal_nvic_get_active(IRQn_Type IRQn);
678
679 /** @} */
680
681 /* Private functions ---------------------------------------------------------*/
682 /** @defgroup CORTEX_Private_Functions CORTEX Private Functions
683 * @brief CORTEX private functions
684 * @{
685 */
686
687 #if (__MPU_PRESENT == 1U)
688
689 /**
690 ****************************************************************************************
691 * @brief Disables the MPU and clears the HFNMIENA bit (ARM recommendation)
692 ****************************************************************************************
693 */
694 void hal_mpu_disable(void);
695
696 /**
697 ****************************************************************************************
698 * @brief Enable the MPU
699 *
700 * @param[in] mpu_control: Specifies the control mode of the MPU during hard fault,
701 * NMI, FAULTMASK and privileged access to the default memory.
702 * This parameter can be one of the following values:
703 * @arg @ref MPU_HFNMI_PRIVDEF_NONE
704 * @arg @ref MPU_HARDFAULT_NMI
705 * @arg @ref MPU_PRIVILEGED_DEFAULT
706 * @arg @ref MPU_HFNMI_PRIVDEF
707 ****************************************************************************************
708 */
709 void hal_mpu_enable(uint32_t mpu_control);
710
711 #endif /* __MPU_PRESENT */
712
713 /** @} */
714
715 /** @} */
716
717 #ifdef __cplusplus
718 }
719 #endif
720
721 #endif /* __GR533x_HAL_CORTEX_H__ */
722
723 /** @} */
724
725 /** @} */
726
727 /** @} */
hal_nvic_system_reset
void hal_nvic_system_reset(void)
Initiate a system reset request to reset the MCU.
hal_nvic_get_priority
void hal_nvic_get_priority(IRQn_Type IRQn, uint32_t priority_group, uint32_t *p_preempt_priority, uint32_t *p_sub_priority)
Get the priority of an interrupt.
hal_nvic_enable_irq
void hal_nvic_enable_irq(IRQn_Type IRQn)
Enable a device specific interrupt in the NVIC interrupt controller.
hal_nvic_set_pending_irq
void hal_nvic_set_pending_irq(IRQn_Type IRQn)
Set Pending bit of an external interrupt.
hal_nvic_set_priority
void hal_nvic_set_priority(IRQn_Type IRQn, uint32_t preempt_priority, uint32_t sub_priority)
Set the priority of an interrupt.
hal_nvic_get_priority_grouping
uint32_t hal_nvic_get_priority_grouping(void)
Get the priority grouping field from the NVIC Interrupt Controller.
hal_nvic_get_active
uint32_t hal_nvic_get_active(IRQn_Type IRQn)
Get active interrupt (reads the active register in NVIC and returns the active bit).
hal_nvic_clear_pending_irq
void hal_nvic_clear_pending_irq(IRQn_Type IRQn)
Clear the pending bit of an external interrupt.
hal_systick_config
uint32_t hal_systick_config(uint32_t ticks_number)
Initialize the System Timer and its interrupt, and start the System Tick Timer. Counter is in free ru...
hal_nvic_get_pending_irq
uint32_t hal_nvic_get_pending_irq(IRQn_Type IRQn)
Get Pending Interrupt (reads the pending register in the NVIC and returns the pending bit for the spe...
gr533x_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
hal_nvic_set_priority_grouping
void hal_nvic_set_priority_grouping(uint32_t priority_group)
Set the priority grouping field (pre-emption priority and subpriority) using the required unlock sequ...
hal_nvic_disable_irq
void hal_nvic_disable_irq(IRQn_Type IRQn)
Disable a device specific interrupt in the NVIC interrupt controller.