1 /**
2   ******************************************************************************
3   * @file    stm32h5xx_hal_icache.h
4   * @author  MCD Application Team
5   * @brief   Header file of ICACHE HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2023 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software component is licensed by ST under BSD 3-Clause license,
13   * the "License"; You may not use this file except in compliance with the
14   * License. You may obtain a copy of the License at:
15   *                        opensource.org/licenses/BSD-3-Clause
16   *
17   ******************************************************************************
18   */
19 
20 /* Define to prevent recursive inclusion ------------------------------------*/
21 #ifndef STM32H5xx_HAL_ICACHE_H
22 #define STM32H5xx_HAL_ICACHE_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* Includes -----------------------------------------------------------------*/
29 #include "stm32h5xx_hal_def.h"
30 
31 /** @addtogroup STM32H5xx_HAL_Driver
32   * @{
33   */
34 
35 /** @addtogroup ICACHE
36   * @{
37   */
38 
39 /* Exported types -----------------------------------------------------------*/
40 #if defined(ICACHE_CRRx_REN)
41 /** @defgroup ICACHE_Exported_Types ICACHE Exported Types
42   * @{
43   */
44 
45 /**
46   * @brief  HAL ICACHE region configuration structure definition
47   */
48 typedef struct
49 {
50   uint32_t BaseAddress;              /*!< Configures the Base address of Region i to be remapped */
51 
52   uint32_t RemapAddress;             /*!< Configures the Remap address of Region i to be remapped */
53 
54   uint32_t Size;                     /*!< Configures the Region size.
55                                           This parameter can be a value of @ref ICACHE_Region_Size */
56 
57   uint32_t TrafficRoute;             /*!< Selects the traffic route.
58                                           This parameter can be a value of @ref ICACHE_Traffic_Route */
59 
60   uint32_t OutputBurstType;          /*!< Selects the output burst type.
61                                           This parameter can be a value of @ref ICACHE_Output_Burst_Type */
62 } ICACHE_RegionConfigTypeDef;
63 /**
64   * @}
65   */
66 #endif /*  ICACHE_CRRx_REN */
67 
68 /* Exported constants -------------------------------------------------------*/
69 /** @defgroup ICACHE_Exported_Constants ICACHE Exported Constants
70   * @{
71   */
72 
73 /** @defgroup ICACHE_WaysSelection Ways selection
74   * @{
75   */
76 #define ICACHE_1WAY                    0U                /*!< 1-way cache (direct mapped cache) */
77 #define ICACHE_2WAYS                   ICACHE_CR_WAYSEL  /*!< 2-ways set associative cache (default) */
78 /**
79   * @}
80   */
81 
82 /** @defgroup ICACHE_Monitor_Type Monitor type
83   * @{
84   */
85 #define ICACHE_MONITOR_HIT_MISS        (ICACHE_CR_HITMEN | ICACHE_CR_MISSMEN) /*!< Hit & Miss monitoring */
86 #define ICACHE_MONITOR_HIT             ICACHE_CR_HITMEN                       /*!< Hit monitoring */
87 #define ICACHE_MONITOR_MISS            ICACHE_CR_MISSMEN                      /*!< Miss monitoring */
88 /**
89   * @}
90   */
91 
92 #if defined(ICACHE_CRRx_REN)
93 /** @defgroup ICACHE_Region Remapped Region number
94   * @{
95   */
96 #define ICACHE_REGION_0                0U  /*!< Region 0 */
97 #define ICACHE_REGION_1                1U  /*!< Region 1 */
98 #define ICACHE_REGION_2                2U  /*!< Region 2 */
99 #define ICACHE_REGION_3                3U  /*!< Region 3 */
100 /**
101   * @}
102   */
103 
104 /** @defgroup ICACHE_Region_Size Remapped Region size
105   * @{
106   */
107 #define ICACHE_REGIONSIZE_2MB          1U  /*!< Region size 2MB */
108 #define ICACHE_REGIONSIZE_4MB          2U  /*!< Region size 4MB */
109 #define ICACHE_REGIONSIZE_8MB          3U  /*!< Region size 8MB */
110 #define ICACHE_REGIONSIZE_16MB         4U  /*!< Region size 16MB */
111 #define ICACHE_REGIONSIZE_32MB         5U  /*!< Region size 32MB */
112 #define ICACHE_REGIONSIZE_64MB         6U  /*!< Region size 64MB */
113 #define ICACHE_REGIONSIZE_128MB        7U  /*!< Region size 128MB */
114 /**
115   * @}
116   */
117 
118 /** @defgroup ICACHE_Traffic_Route Remapped Traffic route
119   * @{
120   */
121 #define ICACHE_MASTER1_PORT            0U                  /*!< Master1 port */
122 #define ICACHE_MASTER2_PORT            ICACHE_CRRx_MSTSEL  /*!< Master2 port */
123 /**
124   * @}
125   */
126 
127 /** @defgroup ICACHE_Output_Burst_Type Remapped Output burst type
128   * @{
129   */
130 #define ICACHE_OUTPUT_BURST_WRAP       0U                  /*!< WRAP */
131 #define ICACHE_OUTPUT_BURST_INCR       ICACHE_CRRx_HBURST  /*!< INCR */
132 /**
133   * @}
134   */
135 #endif /*  ICACHE_CRRx_REN */
136 
137 /** @defgroup ICACHE_Interrupts Interrupts
138   * @{
139   */
140 #define ICACHE_IT_BUSYEND              ICACHE_IER_BSYENDIE /*!< Busy end interrupt */
141 #define ICACHE_IT_ERROR                ICACHE_IER_ERRIE    /*!< Cache error interrupt */
142 /**
143   * @}
144   */
145 
146 /** @defgroup ICACHE_Flags Flags
147   * @{
148   */
149 #define ICACHE_FLAG_BUSY               ICACHE_SR_BUSYF     /*!< Busy flag */
150 #define ICACHE_FLAG_BUSYEND            ICACHE_SR_BSYENDF   /*!< Busy end flag */
151 #define ICACHE_FLAG_ERROR              ICACHE_SR_ERRF      /*!< Cache error flag */
152 /**
153   * @}
154   */
155 
156 /**
157   * @}
158   */
159 
160 /* Exported macros ----------------------------------------------------------*/
161 /** @defgroup ICACHE_Exported_Macros ICACHE Exported Macros
162   * @{
163   */
164 
165 /** @defgroup ICACHE_Flags_Interrupts_Management Flags and Interrupts Management
166   * @brief macros to manage the specified ICACHE flags and interrupts.
167   * @{
168   */
169 
170 /** @brief  Enable ICACHE interrupts.
171   * @param  __INTERRUPT__ specifies the ICACHE interrupt sources to be enabled.
172   *         This parameter can be any combination of the following values:
173   *            @arg @ref ICACHE_IT_BUSYEND  Busy end interrupt
174   *            @arg @ref ICACHE_IT_ERROR  Cache error interrupt
175   */
176 #define __HAL_ICACHE_ENABLE_IT(__INTERRUPT__) SET_BIT(ICACHE->IER, (__INTERRUPT__))
177 
178 /** @brief  Disable ICACHE interrupts.
179   * @param  __INTERRUPT__ specifies the ICACHE interrupt sources to be disabled.
180   *         This parameter can be any combination of the following values:
181   *            @arg @ref ICACHE_IT_BUSYEND  Busy end interrupt
182   *            @arg @ref ICACHE_IT_ERROR  Cache error interrupt
183   */
184 #define __HAL_ICACHE_DISABLE_IT(__INTERRUPT__) CLEAR_BIT(ICACHE->IER, (__INTERRUPT__))
185 
186 /** @brief  Check whether the specified ICACHE interrupt source is enabled or not.
187   * @param  __INTERRUPT__ specifies the ICACHE interrupt source to check.
188   *         This parameter can be any combination of the following values:
189   *            @arg @ref ICACHE_IT_BUSYEND  Busy end interrupt
190   *            @arg @ref ICACHE_IT_ERROR  Cache error interrupt
191   * @retval The state of __INTERRUPT__ (0 or 1).
192   */
193 #define __HAL_ICACHE_GET_IT_SOURCE(__INTERRUPT__)  \
194   ((READ_BIT(ICACHE->IER, (__INTERRUPT__)) == (__INTERRUPT__)) ? 1U : 0U)
195 
196 /** @brief  Check whether the selected ICACHE flag is set or not.
197   * @param  __FLAG__ specifies the flag to check.
198   *         This parameter can be one of the following values:
199   *            @arg @ref ICACHE_FLAG_BUSY  Busy flag
200   *            @arg @ref ICACHE_FLAG_BUSYEND  Busy end flag
201   *            @arg @ref ICACHE_FLAG_ERROR  Cache error flag
202   * @retval The state of __FLAG__ (0 or 1).
203   */
204 #define __HAL_ICACHE_GET_FLAG(__FLAG__) ((READ_BIT(ICACHE->SR, (__FLAG__)) != 0U) ? 1U : 0U)
205 
206 /** @brief  Clear the selected ICACHE flags.
207   * @param  __FLAG__ specifies the ICACHE flags to clear.
208   *         This parameter can be any combination of the following values:
209   *            @arg @ref ICACHE_FLAG_BUSYEND  Busy end flag
210   *            @arg @ref ICACHE_FLAG_ERROR  Cache error flag
211   */
212 #define __HAL_ICACHE_CLEAR_FLAG(__FLAG__) WRITE_REG(ICACHE->FCR, (__FLAG__))
213 
214 /**
215   * @}
216   */
217 
218 /**
219   * @}
220   */
221 
222 /* Exported functions -------------------------------------------------------*/
223 /** @addtogroup ICACHE_Exported_Functions
224   * @{
225   */
226 
227 /** @addtogroup ICACHE_Exported_Functions_Group1
228   * @brief    Initialization and control functions
229   * @{
230   */
231 /* Peripheral Control functions **********************************************/
232 HAL_StatusTypeDef HAL_ICACHE_Enable(void);
233 HAL_StatusTypeDef HAL_ICACHE_Disable(void);
234 uint32_t HAL_ICACHE_IsEnabled(void);
235 HAL_StatusTypeDef HAL_ICACHE_ConfigAssociativityMode(uint32_t AssociativityMode);
236 HAL_StatusTypeDef HAL_ICACHE_DeInit(void);
237 
238 /******* Invalidate in blocking mode (Polling) */
239 HAL_StatusTypeDef HAL_ICACHE_Invalidate(void);
240 /******* Invalidate in non-blocking mode (Interrupt) */
241 HAL_StatusTypeDef HAL_ICACHE_Invalidate_IT(void);
242 /******* Wait for Invalidate complete in blocking mode (Polling) */
243 HAL_StatusTypeDef HAL_ICACHE_WaitForInvalidateComplete(void);
244 
245 /******* Performance instruction cache monitoring functions */
246 HAL_StatusTypeDef HAL_ICACHE_Monitor_Start(uint32_t MonitorType);
247 HAL_StatusTypeDef HAL_ICACHE_Monitor_Stop(uint32_t MonitorType);
248 HAL_StatusTypeDef HAL_ICACHE_Monitor_Reset(uint32_t MonitorType);
249 uint32_t HAL_ICACHE_Monitor_GetHitValue(void);
250 uint32_t HAL_ICACHE_Monitor_GetMissValue(void);
251 
252 /**
253   * @}
254   */
255 
256 /** @addtogroup ICACHE_Exported_Functions_Group2
257   * @brief    IRQ and callback functions
258   * @{
259   */
260 /******* IRQHandler and Callbacks used in non-blocking mode (Interrupt) */
261 void HAL_ICACHE_IRQHandler(void);
262 void HAL_ICACHE_InvalidateCompleteCallback(void);
263 void HAL_ICACHE_ErrorCallback(void);
264 
265 /**
266   * @}
267   */
268 
269 #if defined(ICACHE_CRRx_REN)
270 /** @addtogroup ICACHE_Exported_Functions_Group3
271   * @brief    Memory remapped regions functions
272   * @{
273   */
274 /******* Memory remapped regions functions */
275 HAL_StatusTypeDef HAL_ICACHE_EnableRemapRegion(uint32_t Region, const ICACHE_RegionConfigTypeDef *const pRegionConfig);
276 HAL_StatusTypeDef HAL_ICACHE_DisableRemapRegion(uint32_t Region);
277 
278 /**
279   * @}
280   */
281 #endif /*  ICACHE_CRRx_REN */
282 
283 /**
284   * @}
285   */
286 
287 /**
288   * @}
289   */
290 
291 /**
292   * @}
293   */
294 
295 #ifdef __cplusplus
296 }
297 #endif
298 
299 #endif /* STM32H5xx_HAL_ICACHE_H */
300