gr55xx_hal_cortex.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file gr55xx_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 __GR55xx_HAL_CORTEX_H__
53 #define __GR55xx_HAL_CORTEX_H__
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_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 /** @defgroup CORTEX_SysTick_clock_source CORTEX SysTick clock source
153 * @{
154 */
155 #define SYSTICK_CLKSOURCE_REFCLK (0x00000000U) /**< SYSTICK clock source External Reference Clock */
156 #define SYSTICK_CLKSOURCE_HCLK (0x00000004U) /**< SYSTICK clock source HCLK */
157 /** @} */
158
159 #if (__MPU_PRESENT == 1U)
160 /** @defgroup CORTEX_MPU_HFNMI_PRIVDEF_Control MPU HFNMI and PRIVILEGED Access control
161 * @{
162 */
163 #define MPU_HFNMI_PRIVDEF_NONE (0x00000000U) /**< HFNMIENA disable, PRIVDEFENA disable */
164 #define MPU_HARDFAULT_NMI (0x00000002U) /**< HFNMIENA enable, PRIVDEFENA disable */
165 #define MPU_PRIVILEGED_DEFAULT (0x00000004U) /**< HFNMIENA disable, PRIVDEFENA enable */
166 #define MPU_HFNMI_PRIVDEF (0x00000006U) /**< HFNMIENA enable, PRIVDEFENA enable */
167 /** @} */
168
169 /** @defgroup CORTEX_MPU_Region_Enable CORTEX MPU Region Enable
170 * @{
171 */
172 #define MPU_REGION_ENABLE ((uint8_t)0x01U) /**< MPU Region Enable */
173 #define MPU_REGION_DISABLE ((uint8_t)0x00U) /**< MPU Region Disable */
174 /** @} */
175
176 /** @defgroup CORTEX_MPU_Instruction_Access CORTEX MPU Instruction Access
177 * @{
178 */
179 #define MPU_INSTRUCTION_ACCESS_ENABLE ((uint8_t)0x00U) /**< MPU Instruction Access Enable */
180 #define MPU_INSTRUCTION_ACCESS_DISABLE ((uint8_t)0x01U) /**< MPU Instruction Access Disable */
181 /** @} */
182
183 /** @defgroup CORTEX_MPU_Access_Shareable CORTEX MPU Instruction Access Shareable
184 * @{
185 */
186 #define MPU_ACCESS_SHAREABLE ((uint8_t)0x01U) /**< MPU Instruction Access Shareable */
187 #define MPU_ACCESS_NOT_SHAREABLE ((uint8_t)0x00U) /**< MPU Instruction Access Not Shareable */
188 /** @} */
189
190 /** @defgroup CORTEX_MPU_Access_Cacheable CORTEX MPU Instruction Access Cacheable
191 * @{
192 */
193 #define MPU_ACCESS_CACHEABLE ((uint8_t)0x01U) /**< MPU Instruction Access Cacheable */
194 #define MPU_ACCESS_NOT_CACHEABLE ((uint8_t)0x00U) /**< MPU Instruction Access Not Cacheable */
195 /** @} */
196
197 /** @defgroup CORTEX_MPU_Access_Bufferable CORTEX MPU Instruction Access Bufferable
198 * @{
199 */
200 #define MPU_ACCESS_BUFFERABLE ((uint8_t)0x01U) /**< MPU Instruction Access Bufferable */
201 #define MPU_ACCESS_NOT_BUFFERABLE ((uint8_t)0x00U) /**< MPU Instruction Access Not Bufferable */
202 /** @} */
203
204 /** @defgroup CORTEX_MPU_TEX_Levels MPU TEX Levels
205 * @{
206 */
207 #define MPU_TEX_LEVEL0 ((uint8_t)0x00U) /**< MPU TEX Level 0 */
208 #define MPU_TEX_LEVEL1 ((uint8_t)0x01U) /**< MPU TEX Level 1 */
209 #define MPU_TEX_LEVEL2 ((uint8_t)0x02U) /**< MPU TEX Level 2 */
210 /** @} */
211
212 /** @defgroup CORTEX_MPU_Region_Size CORTEX MPU Region Size
213 * @{
214 */
215 #define MPU_REGION_SIZE_32B ((uint8_t)0x04U) /**< MPU Region Size 32B */
216 #define MPU_REGION_SIZE_64B ((uint8_t)0x05U) /**< MPU Region Size 64B */
217 #define MPU_REGION_SIZE_128B ((uint8_t)0x06U) /**< MPU Region Size 128B */
218 #define MPU_REGION_SIZE_256B ((uint8_t)0x07U) /**< MPU Region Size 256B */
219 #define MPU_REGION_SIZE_512B ((uint8_t)0x08U) /**< MPU Region Size 512B */
220 #define MPU_REGION_SIZE_1KB ((uint8_t)0x09U) /**< MPU Region Size 1KB */
221 #define MPU_REGION_SIZE_2KB ((uint8_t)0x0AU) /**< MPU Region Size 2KB */
222 #define MPU_REGION_SIZE_4KB ((uint8_t)0x0BU) /**< MPU Region Size 4KB */
223 #define MPU_REGION_SIZE_8KB ((uint8_t)0x0CU) /**< MPU Region Size 8KB */
224 #define MPU_REGION_SIZE_16KB ((uint8_t)0x0DU) /**< MPU Region Size 16KB */
225 #define MPU_REGION_SIZE_32KB ((uint8_t)0x0EU) /**< MPU Region Size 32KB */
226 #define MPU_REGION_SIZE_64KB ((uint8_t)0x0FU) /**< MPU Region Size 64KB */
227 #define MPU_REGION_SIZE_128KB ((uint8_t)0x10U) /**< MPU Region Size 128KB */
228 #define MPU_REGION_SIZE_256KB ((uint8_t)0x11U) /**< MPU Region Size 256KB */
229 #define MPU_REGION_SIZE_512KB ((uint8_t)0x12U) /**< MPU Region Size 512KB */
230 #define MPU_REGION_SIZE_1MB ((uint8_t)0x13U) /**< MPU Region Size 1MB */
231 #define MPU_REGION_SIZE_2MB ((uint8_t)0x14U) /**< MPU Region Size 2MB */
232 #define MPU_REGION_SIZE_4MB ((uint8_t)0x15U) /**< MPU Region Size 4MB */
233 #define MPU_REGION_SIZE_8MB ((uint8_t)0x16U) /**< MPU Region Size 8MB */
234 #define MPU_REGION_SIZE_16MB ((uint8_t)0x17U) /**< MPU Region Size 16MB */
235 #define MPU_REGION_SIZE_32MB ((uint8_t)0x18U) /**< MPU Region Size 32MB */
236 #define MPU_REGION_SIZE_64MB ((uint8_t)0x19U) /**< MPU Region Size 64MB */
237 #define MPU_REGION_SIZE_128MB ((uint8_t)0x1AU) /**< MPU Region Size 128MB */
238 #define MPU_REGION_SIZE_256MB ((uint8_t)0x1BU) /**< MPU Region Size 256MB */
239 #define MPU_REGION_SIZE_512MB ((uint8_t)0x1CU) /**< MPU Region Size 512MB */
240 #define MPU_REGION_SIZE_1GB ((uint8_t)0x1DU) /**< MPU Region Size 1GB */
241 #define MPU_REGION_SIZE_2GB ((uint8_t)0x1EU) /**< MPU Region Size 2GB */
242 #define MPU_REGION_SIZE_4GB ((uint8_t)0x1FU) /**< MPU Region Size 4GB */
243 /** @} */
244
245 /** @defgroup CORTEX_MPU_Region_Permission_Attributes CORTEX MPU Region Permission Attributes
246 * @{
247 */
248 #define MPU_REGION_NO_ACCESS ((uint8_t)0x00U) /**< All accesses generate a permission fault */
249 #define MPU_REGION_PRIV_RW ((uint8_t)0x01U) /**< Access from privileged software only */
250 #define MPU_REGION_PRIV_RW_URO ((uint8_t)0x02U) /**< Writes by unprivileged software generate a permission fault */
251 #define MPU_REGION_FULL_ACCESS ((uint8_t)0x03U) /**< Full access */
252 #define MPU_REGION_PRIV_RO ((uint8_t)0x05U) /**< Reads by privileged software only */
253 #define MPU_REGION_PRIV_RO_URO ((uint8_t)0x06U) /**< Read only, by privileged or unprivileged software */
254 /** @} */
255
256 /** @defgroup CORTEX_MPU_Region_Number CORTEX MPU Region Number
257 * @{
258 */
259 #define MPU_REGION_NUMBER0 ((uint8_t)0x00U) /**< MPU Region Number 0 */
260 #define MPU_REGION_NUMBER1 ((uint8_t)0x01U) /**< MPU Region Number 1 */
261 #define MPU_REGION_NUMBER2 ((uint8_t)0x02U) /**< MPU Region Number 2 */
262 #define MPU_REGION_NUMBER3 ((uint8_t)0x03U) /**< MPU Region Number 3 */
263 #define MPU_REGION_NUMBER4 ((uint8_t)0x04U) /**< MPU Region Number 4 */
264 #define MPU_REGION_NUMBER5 ((uint8_t)0x05U) /**< MPU Region Number 5 */
265 #define MPU_REGION_NUMBER6 ((uint8_t)0x06U) /**< MPU Region Number 6 */
266 #define MPU_REGION_NUMBER7 ((uint8_t)0x07U) /**< MPU Region Number 7 */
267 /** @} */
268 #endif /* __MPU_PRESENT */
269
270 /** @} */
271
272 /* Exported Macros -----------------------------------------------------------*/
273 /* Private types -------------------------------------------------------------*/
274 /* Private variables ---------------------------------------------------------*/
275 /* Private constants ---------------------------------------------------------*/
276
277 /* Private macros ------------------------------------------------------------*/
278 /** @defgroup CORTEX_Private_Macros CORTEX Private Macros
279 * @{
280 */
281
282 /**
283 * @brief Check if NVIC priority group is valid.
284 * @param __GROUP__ NVIC priority group.
285 * @retval SET (__GROUP__ is valid) or RESET (__GROUP__ is invalid)
286 */
287 #define IS_NVIC_PRIORITY_GROUP(__GROUP__) (((__GROUP__) == NVIC_PRIORITYGROUP_0) || \
288 ((__GROUP__) == NVIC_PRIORITYGROUP_1) || \
289 ((__GROUP__) == NVIC_PRIORITYGROUP_2) || \
290 ((__GROUP__) == NVIC_PRIORITYGROUP_3) || \
291 ((__GROUP__) == NVIC_PRIORITYGROUP_4) || \
292 ((__GROUP__) == NVIC_PRIORITYGROUP_5) || \
293 ((__GROUP__) == NVIC_PRIORITYGROUP_6) || \
294 ((__GROUP__) == NVIC_PRIORITYGROUP_7))
295
296 /**
297 * @brief Check if NVIC priority group is valid.
298 * @param __PRIORITY__ NVIC priority group.
299 * @retval SET (__PRIORITY__ is valid) or RESET (__PRIORITY__ is invalid)
300 */
301 #define IS_NVIC_PREEMPTION_PRIORITY(__PRIORITY__) ((__PRIORITY__) < 0x80U)
302
303 /**
304 * @brief Check if NVIC sub priority is valid.
305 * @param __PRIORITY__ NVIC sub priority.
306 * @retval SET (__PRIORITY__ is valid) or RESET (__PRIORITY__ is invalid)
307 */
308 #define IS_NVIC_SUB_PRIORITY(__PRIORITY__) ((__PRIORITY__) <= 0xFFU)
309
310 /**
311 * @brief Check if NVIC deivce IRQ is valid.
312 * @param __IRQ__ NVIC device IRQ.
313 * @retval SET (__IRQ__ is valid) or RESET (__IRQ__ is invalid)
314 */
315 #define IS_NVIC_DEVICE_IRQ(__IRQ__) ((__IRQ__) >= 0x00)
316
317 /**
318 * @brief Check if SYSTICK clock source is valid.
319 * @param __SOURCE__ SYSTICK clock source.
320 * @retval SET (__SOURCE__ is valid) or RESET (__SOURCE__ is invalid)
321 */
322 #define IS_SYSTICK_CLK_SOURCE(__SOURCE__) (((__SOURCE__) == SYSTICK_CLKSOURCE_HCLK) || \
323 ((__SOURCE__) == SYSTICK_CLKSOURCE_REFCLK))
324
325 #if (__MPU_PRESENT == 1U)
326
327 /**
328 * @brief Check if MPU enable state is valid.
329 * @param __STATE__ Enable state.
330 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is not invalid)
331 */
332 #define IS_MPU_REGION_ENABLE(__STATE__) (((__STATE__) == MPU_REGION_ENABLE) || \
333 ((__STATE__) == MPU_REGION_DISABLE))
334
335 /**
336 * @brief Check if MPU instruction access state is valid.
337 * @param __STATE__ MPU instruction access state.
338 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is not invalid)
339 */
340 #define IS_MPU_INSTRUCTION_ACCESS(__STATE__) (((__STATE__) == MPU_INSTRUCTION_ACCESS_ENABLE) || \
341 ((__STATE__) == MPU_INSTRUCTION_ACCESS_DISABLE))
342
343 /**
344 * @brief Check if MPU access shareable state is valid.
345 * @param __STATE__ MPU access shareable state.
346 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is not invalid)
347 */
348 #define IS_MPU_ACCESS_SHAREABLE(__STATE__) (((__STATE__) == MPU_ACCESS_SHAREABLE) || \
349 ((__STATE__) == MPU_ACCESS_NOT_SHAREABLE))
350
351 /**
352 * @brief Check if MPU access cacheable state is valid.
353 * @param __STATE__ MPU access cacheable state.
354 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is not invalid)
355 */
356 #define IS_MPU_ACCESS_CACHEABLE(__STATE__) (((__STATE__) == MPU_ACCESS_CACHEABLE) || \
357 ((__STATE__) == MPU_ACCESS_NOT_CACHEABLE))
358
359 /**
360 * @brief Check if MPU access bufferable state is valid.
361 * @param __STATE__ MPU access bufferable state.
362 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is not invalid)
363 */
364 #define IS_MPU_ACCESS_BUFFERABLE(__STATE__) (((__STATE__) == MPU_ACCESS_BUFFERABLE) || \
365 ((__STATE__) == MPU_ACCESS_NOT_BUFFERABLE))
366
367 /**
368 * @brief Check if MPU Tex level is valid.
369 * @param __TYPE__ MPU Tex level.
370 * @retval SET (__TYPE__ is valid) or RESET (__TYPE__ is invalid)
371 */
372 #define IS_MPU_TEX_LEVEL(__TYPE__) (((__TYPE__) == MPU_TEX_LEVEL0) || \
373 ((__TYPE__) == MPU_TEX_LEVEL1) || \
374 ((__TYPE__) == MPU_TEX_LEVEL2))
375
376 /**
377 * @brief Check if MPU region permission attribute type is valid.
378 * @param __TYPE__ MPU region permission attribute type.
379 * @retval SET (__TYPE__ is valid) or RESET (__TYPE__ is invalid)
380 */
381 #define IS_MPU_REGION_PERMISSION_ATTRIBUTE(__TYPE__) (((__TYPE__) == MPU_REGION_NO_ACCESS) || \
382 ((__TYPE__) == MPU_REGION_PRIV_RW) || \
383 ((__TYPE__) == MPU_REGION_PRIV_RW_URO) || \
384 ((__TYPE__) == MPU_REGION_FULL_ACCESS) || \
385 ((__TYPE__) == MPU_REGION_PRIV_RO) || \
386 ((__TYPE__) == MPU_REGION_PRIV_RO_URO))
387
388 /**
389 * @brief Check if MPU region number is valid.
390 * @param __NUMBER__ MPU region number.
391 * @retval SET (__NUMBER__ is valid) or RESET (__NUMBER__ is invalid)
392 */
393 #define IS_MPU_REGION_NUMBER(__NUMBER__) (((__NUMBER__) == MPU_REGION_NUMBER0) || \
394 ((__NUMBER__) == MPU_REGION_NUMBER1) || \
395 ((__NUMBER__) == MPU_REGION_NUMBER2) || \
396 ((__NUMBER__) == MPU_REGION_NUMBER3) || \
397 ((__NUMBER__) == MPU_REGION_NUMBER4) || \
398 ((__NUMBER__) == MPU_REGION_NUMBER5) || \
399 ((__NUMBER__) == MPU_REGION_NUMBER6) || \
400 ((__NUMBER__) == MPU_REGION_NUMBER7))
401
402 /**
403 * @brief Check if MPU region size is valid.
404 * @param __SIZE__ MPU region size.
405 * @retval SET (__SIZE__ is valid) or RESET (__SIZE__ is invalid)
406 */
407 #define IS_MPU_REGION_SIZE(__SIZE__) (((__SIZE__) == MPU_REGION_SIZE_32B) || \
408 ((__SIZE__) == MPU_REGION_SIZE_64B) || \
409 ((__SIZE__) == MPU_REGION_SIZE_128B) || \
410 ((__SIZE__) == MPU_REGION_SIZE_256B) || \
411 ((__SIZE__) == MPU_REGION_SIZE_512B) || \
412 ((__SIZE__) == MPU_REGION_SIZE_1KB) || \
413 ((__SIZE__) == MPU_REGION_SIZE_2KB) || \
414 ((__SIZE__) == MPU_REGION_SIZE_4KB) || \
415 ((__SIZE__) == MPU_REGION_SIZE_8KB) || \
416 ((__SIZE__) == MPU_REGION_SIZE_16KB) || \
417 ((__SIZE__) == MPU_REGION_SIZE_32KB) || \
418 ((__SIZE__) == MPU_REGION_SIZE_64KB) || \
419 ((__SIZE__) == MPU_REGION_SIZE_128KB) || \
420 ((__SIZE__) == MPU_REGION_SIZE_256KB) || \
421 ((__SIZE__) == MPU_REGION_SIZE_512KB) || \
422 ((__SIZE__) == MPU_REGION_SIZE_1MB) || \
423 ((__SIZE__) == MPU_REGION_SIZE_2MB) || \
424 ((__SIZE__) == MPU_REGION_SIZE_4MB) || \
425 ((__SIZE__) == MPU_REGION_SIZE_8MB) || \
426 ((__SIZE__) == MPU_REGION_SIZE_16MB) || \
427 ((__SIZE__) == MPU_REGION_SIZE_32MB) || \
428 ((__SIZE__) == MPU_REGION_SIZE_64MB) || \
429 ((__SIZE__) == MPU_REGION_SIZE_128MB) || \
430 ((__SIZE__) == MPU_REGION_SIZE_256MB) || \
431 ((__SIZE__) == MPU_REGION_SIZE_512MB) || \
432 ((__SIZE__) == MPU_REGION_SIZE_1GB) || \
433 ((__SIZE__) == MPU_REGION_SIZE_2GB) || \
434 ((__SIZE__) == MPU_REGION_SIZE_4GB))
435
436
437 /**
438 * @brief Check if MPU sub region is valid.
439 * @param __SUBREGION__ MPU sub region.
440 * @retval SET (__SUBREGION__ is valid) or RESET (__SUBREGION__ is invalid)
441 */
442 #define IS_MPU_SUB_REGION_DISABLE(__SUBREGION__) ((__SUBREGION__) < (uint16_t)0x00FFU)
443 #endif /* __MPU_PRESENT */
444
445 /** @} */
446
447 /** @} */
448
449 /* Exported functions --------------------------------------------------------*/
450 /** @addtogroup HAL_CORTEX_DRIVER_FUNCTIONS Functions
451 * @{
452 */
453
454 /** @addtogroup CORTEX_Exported_Functions_Group1 Initialization and de-initialization functions
455 * @brief Initialization and Configuration functions.
456 *
457 @verbatim
458 ==============================================================================
459 ##### Initialization and de-initialization functions #####
460 ==============================================================================
461 [..]
462 This section provides the CORTEX HAL driver functions allowing to configure Interrupts
463 Systick functionalities
464
465 @endverbatim
466 * @{
467 */
468
469 /**
470 ****************************************************************************************
471 * @brief Set the priority grouping field (pre-emption priority and subpriority)
472 * using the required unlock sequence.
473 *
474 * @note When the NVIC_PriorityGroup_0 is selected, IRQ pre-emption is no more possible.
475 * The pending IRQ priority will be managed only by the subpriority.
476 *
477 * @param[in] priority_group: The priority grouping bits length.
478 * This parameter can be one of the following values:
479 * @arg @ref NVIC_PRIORITYGROUP_0 0 bit for pre-emption priority,
480 * 8 bits for subpriority
481 * @arg @ref NVIC_PRIORITYGROUP_1 1 bit for pre-emption priority,
482 * 7 bits for subpriority
483 * @arg @ref NVIC_PRIORITYGROUP_2 2 bits for pre-emption priority,
484 * 6 bits for subpriority
485 * @arg @ref NVIC_PRIORITYGROUP_3 3 bits for pre-emption priority,
486 * 5 bits for subpriority
487 * @arg @ref NVIC_PRIORITYGROUP_4 4 bits for pre-emption priority,
488 * 4 bits for subpriority
489 * @arg @ref NVIC_PRIORITYGROUP_5 5 bits for pre-emption priority,
490 * 3 bits for subpriority
491 * @arg @ref NVIC_PRIORITYGROUP_6 6 bits for pre-emption priority,
492 * 2 bits for subpriority
493 * @arg @ref NVIC_PRIORITYGROUP_7 7 bits for pre-emption priority,
494 * 1 bit for subpriority
495 ****************************************************************************************
496 */
497 void hal_nvic_set_priority_grouping(uint32_t priority_group);
498
499 /**
500 ****************************************************************************************
501 * @brief Set the priority of an interrupt.
502 *
503 * @param[in] IRQn: External interrupt number.
504 * This parameter can be an enumerator of IRQn_Type enumeration
505 * (For the complete GR55xx Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr55xxxx.h))
506 * @param[in] preempt_priority: The pre-emption priority for the IRQn channel.
507 * This parameter can be a value between 0 and 127 as described in the table CORTEX_NVIC_Priority_Table.
508 * A lower priority value indicates a higher priority
509 * @param[in] sub_priority: The subpriority level for the IRQ channel.
510 * This parameter can be a value between 0 and 255 as described in the table CORTEX_NVIC_Priority_Table.
511 * A lower priority value indicates a higher priority.
512 ****************************************************************************************
513 */
514 void hal_nvic_set_priority(IRQn_Type IRQn, uint32_t preempt_priority, uint32_t sub_priority);
515
516 /**
517 ****************************************************************************************
518 * @brief Enable a device specific interrupt in the NVIC interrupt controller.
519 *
520 * @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
521 * function should be called before.
522 *
523 * @param[in] IRQn: External interrupt number.
524 * This parameter can be an enumerator of IRQn_Type enumeration
525 * (For the complete GR55xx Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr55xxxx.h))
526 ****************************************************************************************
527 */
528 void hal_nvic_enable_irq(IRQn_Type IRQn);
529
530 /**
531 ****************************************************************************************
532 * @brief Disable a device specific interrupt in the NVIC interrupt controller.
533 *
534 * @param[in] IRQn: External interrupt number.
535 * This parameter can be an enumerator of IRQn_Type enumeration
536 * (For the complete GR55xx Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr55xxxx.h))
537 ****************************************************************************************
538 */
539 void hal_nvic_disable_irq(IRQn_Type IRQn);
540
541 /**
542 ****************************************************************************************
543 * @brief Initiate a system reset request to reset the MCU.
544 ****************************************************************************************
545 */
546 void hal_nvic_system_reset(void);
547
548
549 /**
550 ****************************************************************************************
551 * @brief Initialize the System Timer and its interrupt, and start the System Tick Timer.
552 * Counter is in free running mode to generate periodic interrupts.
553 *
554 * @param[in] ticks_number: Specifies the number of ticks between two interrupts.
555 *
556 * @retval status
557 * - 0 Function succeeded.
558 * - 1 Function failed.
559 ****************************************************************************************
560 */
561 uint32_t hal_systick_config(uint32_t ticks_number);
562
563 /** @} */
564
565 /** @addtogroup CORTEX_Exported_Functions_Group2 Peripheral Control functions
566 * @brief Cortex control functions.
567 *
568 @verbatim
569 ==============================================================================
570 ##### Peripheral Control functions #####
571 ==============================================================================
572 [..]
573 This subsection provides a set of functions allowing to control the CORTEX
574 (NVIC, SYSTICK, MPU) functionalities.
575
576
577 @endverbatim
578 * @{
579 */
580
581 #if (__MPU_PRESENT == 1U)
582 /**
583 ****************************************************************************************
584 * @brief Initialize and configures the Region and the memory to be protected.
585 *
586 * @param[in] p_mpu_init: Pointer to a mpu_region_init_t structure that contains
587 * the initialization and configuration information.
588 ****************************************************************************************
589 */
590 void hal_mpu_config_region(mpu_region_init_t *p_mpu_init);
591 #endif /* __MPU_PRESENT */
592
593 /**
594 ****************************************************************************************
595 * @brief Get the priority grouping field from the NVIC Interrupt Controller.
596 *
597 * @return Priority grouping field (SCB->AIRCR [10:8] PRIGROUP field)
598 ****************************************************************************************
599 */
600 uint32_t hal_nvic_get_priority_grouping(void);
601
602 /**
603 ****************************************************************************************
604 * @brief Get the priority of an interrupt.
605 *
606 * @param[in] IRQn: External interrupt number.
607 * This parameter can be an enumerator of IRQn_Type enumeration.
608 * (For the complete GR55xx Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr55xxxx.h))
609 * @param[in] priority_group: The priority grouping bits length.
610 * This parameter can be one of the following values:
611 * @arg @ref NVIC_PRIORITYGROUP_0 0 bit for pre-emption priority,
612 * 8 bits for subpriority
613 * @arg @ref NVIC_PRIORITYGROUP_1 1 bit for pre-emption priority,
614 * 7 bits for subpriority
615 * @arg @ref NVIC_PRIORITYGROUP_2 2 bits for pre-emption priority,
616 * 6 bits for subpriority
617 * @arg @ref NVIC_PRIORITYGROUP_3 3 bits for pre-emption priority,
618 * 5 bits for subpriority
619 * @arg @ref NVIC_PRIORITYGROUP_4 4 bits for pre-emption priority,
620 * 4 bits for subpriority
621 * @arg @ref NVIC_PRIORITYGROUP_5 5 bits for pre-emption priority,
622 * 3 bits for subpriority
623 * @arg @ref NVIC_PRIORITYGROUP_6 6 bits for pre-emption priority,
624 * 2 bits for subpriority
625 * @arg @ref NVIC_PRIORITYGROUP_7 7 bits for pre-emption priority,
626 * 1 bit for subpriority
627 * @param[in] p_preempt_priority: Pointer on the Preemptive priority value (starting from 0).
628 * @param[in] p_sub_priority: Pointer on the Subpriority value (starting from 0).
629 ****************************************************************************************
630 */
631 void hal_nvic_get_priority(IRQn_Type IRQn, uint32_t priority_group, uint32_t *p_preempt_priority, uint32_t *p_sub_priority);
632
633 /**
634 ****************************************************************************************
635 * @brief Set Pending bit of an external interrupt.
636 *
637 * @param[in] IRQn: External interrupt number.
638 * This parameter can be an enumerator of IRQn_Type enumeration
639 * (For the complete GR55xx Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr55xxxx.h))
640 ****************************************************************************************
641 */
642 void hal_nvic_set_pending_irq(IRQn_Type IRQn);
643
644 /**
645 ****************************************************************************************
646 * @brief Get Pending Interrupt (reads the pending register in the NVIC
647 * and returns the pending bit for the specified interrupt).
648 *
649 * @param[in] IRQn: External interrupt number.
650 * This parameter can be an enumerator of IRQn_Type enumeration
651 * (For the complete GR55xx Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr55xxxx.h))
652 *
653 * @return status
654 * - 0 Interrupt status is not pending.
655 * - 1 Interrupt status is pending.
656 ****************************************************************************************
657 */
658 uint32_t hal_nvic_get_pending_irq(IRQn_Type IRQn);
659
660 /**
661 ****************************************************************************************
662 * @brief Clear the pending bit of an external interrupt.
663 *
664 * @param[in] IRQn: External interrupt number.
665 * This parameter can be an enumerator of IRQn_Type enumeration
666 * (For the complete GR55xx Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr55xxxx.h))
667 ****************************************************************************************
668 */
669 void hal_nvic_clear_pending_irq(IRQn_Type IRQn);
670
671 /**
672 ****************************************************************************************
673 * @brief Get active interrupt (reads the active register in NVIC and returns the active bit).
674 *
675 * @param[in] IRQn: External interrupt number.
676 * This parameter can be an enumerator of IRQn_Type enumeration
677 * (For the complete GR55xx Devices IRQ Channels list, please refer to the appropriate CMSIS device file (gr55xxxx.h))
678 *
679 * @return status
680 * - 0 Interrupt status is not pending.
681 * - 1 Interrupt status is pending.
682 ****************************************************************************************
683 */
684 uint32_t hal_nvic_get_active(IRQn_Type IRQn);
685
686 /**
687 ****************************************************************************************
688 * @brief Configure the SysTick clock source.
689 *
690 * @param[in] clk_source: specifies the SysTick clock source.
691 * This parameter can be one of the following values:
692 * @arg @ref SYSTICK_CLKSOURCE_REFCLK External Reference Clock as SysTick clock source.
693 * @arg @ref SYSTICK_CLKSOURCE_HCLK AHB clock selected as SysTick clock source.
694 ****************************************************************************************
695 */
696 void hal_systick_clk_source_config(uint32_t clk_source);
697
698 /** @} */
699
700 /** @addtogroup CORTEX_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
701 * @brief IRQ Handler and Callbacks functions.
702 * @{
703 */
704
705 /**
706 ****************************************************************************************
707 * @brief This function handles SYSTICK interrupt request.
708 ****************************************************************************************
709 */
710 void hal_systick_irq_handler(void);
711
712 /**
713 ****************************************************************************************
714 * @brief SYSTICK callback.
715 *
716 * @note This function should not be modified. When the callback is needed,
717 * the hal_systick_callback can be implemented in the user file.
718 ****************************************************************************************
719 */
720 void hal_systick_callback(void);
721
722 /** @} */
723
724 /* Private functions ---------------------------------------------------------*/
725 /** @defgroup CORTEX_Private_Functions CORTEX Private Functions
726 * @brief CORTEX private functions
727 * @{
728 */
729
730 #if (__MPU_PRESENT == 1U)
731
732 /**
733 ****************************************************************************************
734 * @brief Disables the MPU and clears the HFNMIENA bit (ARM recommendation)
735 ****************************************************************************************
736 */
737 void hal_mpu_disable(void);
738
739 /**
740 ****************************************************************************************
741 * @brief Enable the MPU
742 *
743 * @param[in] mpu_control: Specifies the control mode of the MPU during hard fault,
744 * NMI, FAULTMASK and privileged access to the default memory.
745 * This parameter can be one of the following values:
746 * @arg @ref MPU_HFNMI_PRIVDEF_NONE
747 * @arg @ref MPU_HARDFAULT_NMI
748 * @arg @ref MPU_PRIVILEGED_DEFAULT
749 * @arg @ref MPU_HFNMI_PRIVDEF
750 ****************************************************************************************
751 */
752 void hal_mpu_enable(uint32_t mpu_control);
753
754 #endif /* __MPU_PRESENT */
755
756 /** @} */
757
758 /** @} */
759
760 #ifdef __cplusplus
761 }
762 #endif
763
764 #endif /* __GR55xx_HAL_CORTEX_H__ */
765
766 /** @} */
767
768 /** @} */
769
770 /** @} */
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_systick_clk_source_config
void hal_systick_clk_source_config(uint32_t clk_source)
Configure the SysTick clock source.
hal_nvic_set_pending_irq
void hal_nvic_set_pending_irq(IRQn_Type IRQn)
Set Pending bit of an external interrupt.
hal_systick_callback
void hal_systick_callback(void)
SYSTICK callback.
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_systick_irq_handler
void hal_systick_irq_handler(void)
This function handles SYSTICK interrupt request.
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.
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...
gr55xx_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.