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