Merge pull request #11270 from haslinghuis/rename_attr
[betaflight.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Inc / stm32h7xx_hal_otfdec.h
blobebd4ea744f3b6e2c88d8a5becc8d22999c3374a4
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_hal_otfdec.h
4 * @author MCD Application Team
5 * @brief Header file of OTFDEC HAL module.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
10 * All rights reserved.</center></h2>
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
17 ******************************************************************************
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32H7xx_HAL_OTFDEC_H
22 #define STM32H7xx_HAL_OTFDEC_H
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32h7xx_hal_def.h"
31 /** @addtogroup STM32H7xx_HAL_Driver
32 * @{
35 #if defined(OTFDEC1)
37 /** @addtogroup OTFDEC
38 * @{
41 /* Exported types ------------------------------------------------------------*/
43 /** @defgroup OTFDEC_Exported_Types OTFDEC Exported Types
44 * @{
47 /** @defgroup OTFDEC_Exported_Types_Group1 OTFDEC region configuration definitions
48 * @{
51 /**
52 * @brief OTFDEC region configuration structure definition
54 typedef struct
56 uint32_t Nonce[2]; /*!< OTFDEC region nonce */
58 uint32_t StartAddress; /*!< OTFDEC region start address */
60 uint32_t EndAddress; /*!< OTFDEC region end address */
62 uint16_t Version; /*!< OTFDEC region firmware version */
64 }OTFDEC_RegionConfigTypeDef;
66 /**
67 * @}
70 /** @defgroup OTFDEC_Exported_Types_Group2 OTFDEC Peripheral handle definitions
71 * @{
74 /**
75 * @brief OTFDEC states structure definition
77 typedef enum
79 HAL_OTFDEC_STATE_RESET = 0x00U, /*!< OTFDEC not yet initialized or disabled */
80 HAL_OTFDEC_STATE_READY = 0x01U, /*!< OTFDEC initialized and ready for use */
81 HAL_OTFDEC_STATE_BUSY = 0x02U, /*!< OTFDEC internal processing is ongoing */
82 }HAL_OTFDEC_StateTypeDef;
84 /**
85 * @brief OTFDEC handle structure definition
87 #if (USE_HAL_OTFDEC_REGISTER_CALLBACKS == 1)
88 typedef struct __OTFDEC_HandleTypeDef
89 #else
90 typedef struct
91 #endif /* USE_HAL_OTFDEC_REGISTER_CALLBACKS */
93 OTFDEC_TypeDef *Instance; /*!< OTFDEC registers base address */
95 HAL_OTFDEC_StateTypeDef State; /*!< OTFDEC state */
97 HAL_LockTypeDef Lock; /*!< OTFDEC locking object */
99 __IO uint32_t ErrorCode; /*!< OTFDEC error code */
101 #if (USE_HAL_OTFDEC_REGISTER_CALLBACKS == 1)
102 void (* ErrorCallback)(struct __OTFDEC_HandleTypeDef *hotfdec); /*!< OTFDEC error callback */
104 void (* MspInitCallback)(struct __OTFDEC_HandleTypeDef *hotfdec); /*!< OTFDEC Msp Init callback */
106 void (* MspDeInitCallback)(struct __OTFDEC_HandleTypeDef *hotfdec); /*!< OTFDEC Msp DeInit callback */
107 #endif /* USE_HAL_OTFDEC_REGISTER_CALLBACKS */
109 }OTFDEC_HandleTypeDef;
111 #if (USE_HAL_OTFDEC_REGISTER_CALLBACKS == 1)
113 * @brief HAL OTFDEC Callback ID enumeration definition
115 typedef enum
117 HAL_OTFDEC_ERROR_CB_ID = 0x00U, /*!< OTFDEC error callback ID */
118 HAL_OTFDEC_MSPINIT_CB_ID = 0x01U, /*!< OTFDEC Msp DeInit callback ID */
119 HAL_OTFDEC_MSPDEINIT_CB_ID = 0x02U /*!< OTFDEC Msp DeInit callback ID */
120 } HAL_OTFDEC_CallbackIDTypeDef;
123 * @brief HAL OTFDEC Callback pointer definition
125 typedef void (*pOTFDEC_CallbackTypeDef)(OTFDEC_HandleTypeDef *hotfdec); /*!< pointer to a OTFDEC callback function */
127 #endif /* USE_HAL_OTFDEC_REGISTER_CALLBACKS */
130 * @}
134 * @}
137 /* Exported constants --------------------------------------------------------*/
138 /** @defgroup OTFDEC_Exported_Constants OTFDEC Exported Constants
139 * @{
142 /** @defgroup OTFDEC_Interrupts OTFDEC Interrupts
143 * @{
145 #define OTFDEC_SEC_ERROR_INT (OTFDEC_IER_SEIE ) /*!< OTFDEC security error interrupt */
146 #define OTFDEC_EXE_ERROR_INT ( OTFDEC_IER_XONEIE ) /*!< OTFDEC execution error interrupt */
147 #define OTFDEC_KEY_ERROR_INT ( OTFDEC_IER_KEIE) /*!< OTFDEC key error interrupt */
148 #define OTFDEC_SEC_EXE_ERROR_INT (OTFDEC_IER_SEIE|OTFDEC_IER_XONEIE ) /*!< OTFDEC security and execution errors interrupts */
149 #define OTFDEC_SEC_KEY_ERROR_INT (OTFDEC_IER_SEIE| OTFDEC_IER_KEIE) /*!< OTFDEC security and key errors interrupts */
150 #define OTFDEC_EXE_KEY_ERROR_INT ( OTFDEC_IER_XONEIE|OTFDEC_IER_KEIE) /*!< OTFDEC execution and key errors interrupts */
151 #define OTFDEC_ALL_INT (OTFDEC_IER_SEIE|OTFDEC_IER_XONEIE|OTFDEC_IER_KEIE) /*!< OTFDEC all interrupts */
153 * @}
156 /** @defgroup OTFDEC_Region_Enable OTFDEC Region Enable
157 * @{
159 #define OTFDEC_REG_CONFIGR_REG_DISABLE 0x00000000U /*!< OTFDEC region encryption or on-the-fly decryption disable */
160 #define OTFDEC_REG_CONFIGR_REG_ENABLE OTFDEC_REG_CONFIGR_REG_EN /*!< OTFDEC region encryption or on-the-fly decryption enable */
162 * @}
165 /** @defgroup OTFDEC_Region_Configuration_Lock OTFDEC Region Configuration Lock
166 * @{
168 #define OTFDEC_REG_CONFIGR_LOCK_DISABLE 0x00000000U /*!< OTFDEC region configuration lock disable */
169 #define OTFDEC_REG_CONFIGR_LOCK_ENABLE OTFDEC_REG_CONFIGR_CONFIGLOCK /*!< OTFDEC region configuration lock enable */
171 * @}
174 /** @defgroup OTFDEC_Region_Operating_Mode OTFDEC Region Operating Mode
175 * @{
177 #define OTFDEC_REG_MODE_INSTRUCTION_ACCESSES_ONLY 0x00000000U /*!< Only instruction accesses are decrypted */
178 #define OTFDEC_REG_MODE_DATA_ACCESSES_ONLY OTFDEC_REG_CONFIGR_MODE_0 /*!< Only data accesses are decrypted */
179 #define OTFDEC_REG_MODE_INSTRUCTION_OR_DATA_ACCESSES OTFDEC_REG_CONFIGR_MODE_1 /*!< All read accesses are decrypted */
180 #define OTFDEC_REG_MODE_INSTRUCTION_ACCESSES_ONLY_WITH_CIPHER OTFDEC_REG_CONFIGR_MODE /*!< Only instruction accesses are decrypted with proprietary cipher activated */
182 * @}
185 /** @defgroup OTFDEC_Error_Definition OTFDEC Error Definition
186 * @{
188 #define HAL_OTFDEC_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
189 #define HAL_OTFDEC_SECURITY_ERROR ((uint32_t)0x00000001U) /*!< Security error */
190 #define HAL_OTFDEC_EXECUTE_ERROR ((uint32_t)0x00000002U) /*!< Execute-only Execute-Never error */
191 #define HAL_OTFDEC_KEY_ERROR ((uint32_t)0x00000004U) /*!< Key error */
192 #if (USE_HAL_OTFDEC_REGISTER_CALLBACKS == 1)
193 #define HAL_OTFDEC_ERROR_INVALID_CALLBACK ((uint32_t)0x00000008U) /*!< Invalid Callback error */
194 #endif /* USE_HAL_OTFDEC_REGISTER_CALLBACKS */
196 * @}
199 /** @defgroup OTFDEC_Regions_Index OTFDEC Regions Index
200 * @{
202 #define OTFDEC_REGION1 ((uint32_t)0x00000000U) /*!< OTFDEC region 1 */
203 #define OTFDEC_REGION2 ((uint32_t)0x00000001U) /*!< OTFDEC region 2 */
204 #define OTFDEC_REGION3 ((uint32_t)0x00000002U) /*!< OTFDEC region 3 */
205 #define OTFDEC_REGION4 ((uint32_t)0x00000003U) /*!< OTFDEC region 4 */
207 * @}
211 * @}
214 /* Exported macro ------------------------------------------------------------*/
215 /** @defgroup OTFDEC_Exported_Macros OTFDEC Exported Macros
216 * @{
219 /** @brief Reset OTFDEC handle state.
220 * @param __HANDLE__ pointer to an OTFDEC_HandleTypeDef structure that contains
221 * the configuration information for OTFDEC module
222 * @retval None
224 #if (USE_HAL_OTFDEC_REGISTER_CALLBACKS == 1)
225 #define __HAL_OTFDEC_RESET_HANDLE_STATE(__HANDLE__) \
226 do{ \
227 (__HANDLE__)->State = HAL_OTFDEC_STATE_RESET; \
228 (__HANDLE__)->MspInitCallback = NULL; \
229 (__HANDLE__)->MspDeInitCallback = NULL; \
230 } while(0)
231 #else
232 #define __HAL_OTFDEC_RESET_HANDLE_STATE(__HANDLE__) \
233 ((__HANDLE__)->State = HAL_OTFDEC_STATE_RESET)
234 #endif /* USE_HAL_OTFDEC_REGISTER_CALLBACKS */
237 * @brief Enable OTFDEC peripheral interrupts combination
238 * @param __HANDLE__ pointer to an OTFDEC_HandleTypeDef structure that contains
239 * the configuration information for OTFDEC module
240 * @param __INTERRUPT__ mask on enabled interrupts
241 * This parameter can be one of the following values:
242 * @arg @ref OTFDEC_SEC_ERROR_INT OTFDEC security error interrupt
243 * @arg @ref OTFDEC_EXE_ERROR_INT OTFDEC execution error interrupt
244 * @arg @ref OTFDEC_KEY_ERROR_INT OTFDEC key error interrupt
245 * @arg @ref OTFDEC_SEC_EXE_ERROR_INT OTFDEC security and execution errors interrupts
246 * @arg @ref OTFDEC_SEC_KEY_ERROR_INT OTFDEC security and key errors interrupts
247 * @arg @ref OTFDEC_EXE_KEY_ERROR_INT OTFDEC execution and key errors interrupts
248 * @arg @ref OTFDEC_ALL_INT OTFDEC all interrupts
249 * @retval None
251 #define __HAL_OTFDEC_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT(((__HANDLE__)->Instance->IER), (__INTERRUPT__))
254 * @brief Disable OTFDEC peripheral interrupts combination
255 * @param __HANDLE__ pointer to an OTFDEC_HandleTypeDef structure that contains
256 * the configuration information for OTFDEC module
257 * @param __INTERRUPT__ mask on disabled interrupts
258 * This parameter can be one of the following values:
259 * @arg @ref OTFDEC_SEC_ERROR_INT OTFDEC security error interrupt
260 * @arg @ref OTFDEC_EXE_ERROR_INT OTFDEC execution error interrupt
261 * @arg @ref OTFDEC_KEY_ERROR_INT OTFDEC key error interrupt
262 * @arg @ref OTFDEC_SEC_EXE_ERROR_INT OTFDEC security and execution errors interrupts
263 * @arg @ref OTFDEC_SEC_KEY_ERROR_INT OTFDEC security and key errors interrupts
264 * @arg @ref OTFDEC_EXE_KEY_ERROR_INT OTFDEC execution and key errors interrupts
265 * @arg @ref OTFDEC_ALL_INT OTFDEC all interrupts
266 * @retval None
268 #define __HAL_OTFDEC_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT(((__HANDLE__)->Instance->IER), (__INTERRUPT__))
270 /** @brief Check whether the specified combination of OTFDEC interrupt flags is set or not.
271 * @param __HANDLE__ pointer to an OTFDEC_HandleTypeDef structure that contains
272 * the configuration information for OTFDEC module
273 * @param __FLAG__ mask on combination of interrupts flags
274 * This parameter can be one of the following values:
275 * @arg @ref OTFDEC_SEC_ERROR_INT OTFDEC security error interrupt flag
276 * @arg @ref OTFDEC_EXE_ERROR_INT OTFDEC execution error interrupt flag
277 * @arg @ref OTFDEC_KEY_ERROR_INT OTFDEC key error interrupt flag
278 * @arg @ref OTFDEC_SEC_EXE_ERROR_INT OTFDEC security and execution errors interrupts flags
279 * @arg @ref OTFDEC_SEC_KEY_ERROR_INT OTFDEC security and key errors interrupts flags
280 * @arg @ref OTFDEC_EXE_KEY_ERROR_INT OTFDEC execution and key errors interrupts flag
281 * @arg @ref OTFDEC_ALL_INT OTFDEC all interrupts flags
282 * @retval The state of __FLAG__ (TRUE or FALSE).
284 #define __HAL_OTFDEC_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
286 /** @brief Clear the specified combination of OTFDEC interrupt flags.
287 * @param __HANDLE__ pointer to an OTFDEC_HandleTypeDef structure that contains
288 * the configuration information for OTFDEC module
289 * @param __FLAG__ mask on combination of interrupts flags
290 * This parameter can be one of the following values:
291 * @arg @ref OTFDEC_SEC_ERROR_INT OTFDEC security error interrupt flag
292 * @arg @ref OTFDEC_EXE_ERROR_INT OTFDEC execution error interrupt flag
293 * @arg @ref OTFDEC_KEY_ERROR_INT OTFDEC key error interrupt flag
294 * @arg @ref OTFDEC_SEC_EXE_ERROR_INT OTFDEC security and execution errors interrupts flags
295 * @arg @ref OTFDEC_SEC_KEY_ERROR_INT OTFDEC security and key errors interrupts flags
296 * @arg @ref OTFDEC_EXE_KEY_ERROR_INT OTFDEC execution and key errors interrupts flag
297 * @arg @ref OTFDEC_ALL_INT OTFDEC all interrupts flags
298 * @retval None
300 #define __HAL_OTFDEC_CLEAR_FLAG(__HANDLE__, __FLAG__) SET_BIT((__HANDLE__)->Instance->ICR, (__FLAG__))
303 * @}
306 /* Exported functions --------------------------------------------------------*/
307 /** @defgroup OTFDEC_Exported_Functions OTFDEC Exported Functions
308 * @{
311 /** @addtogroup OTFDEC_Exported_Functions_Group1 Initialization and de-initialization functions
312 * @{
314 HAL_StatusTypeDef HAL_OTFDEC_Init(OTFDEC_HandleTypeDef *hotfdec);
315 HAL_StatusTypeDef HAL_OTFDEC_DeInit(OTFDEC_HandleTypeDef *hotfdec);
316 void HAL_OTFDEC_MspInit(OTFDEC_HandleTypeDef *hotfdec);
317 void HAL_OTFDEC_MspDeInit(OTFDEC_HandleTypeDef *hotfdec);
319 #if (USE_HAL_OTFDEC_REGISTER_CALLBACKS == 1)
320 /* Callbacks Register/UnRegister functions ***********************************/
321 HAL_StatusTypeDef HAL_OTFDEC_RegisterCallback(OTFDEC_HandleTypeDef *hotfdec, HAL_OTFDEC_CallbackIDTypeDef CallbackID,
322 pOTFDEC_CallbackTypeDef pCallback);
323 HAL_StatusTypeDef HAL_OTFDEC_UnRegisterCallback(OTFDEC_HandleTypeDef *hotfdec, HAL_OTFDEC_CallbackIDTypeDef CallbackID);
324 #endif /* USE_HAL_OTFDEC_REGISTER_CALLBACKS */
326 * @}
330 /** @addtogroup OTFDEC_Exported_Functions_Group2 OTFDEC IRQ handler management
331 * @{
333 void HAL_OTFDEC_IRQHandler(OTFDEC_HandleTypeDef *hotfdec);
334 void HAL_OTFDEC_ErrorCallback(OTFDEC_HandleTypeDef *hotfdec);
336 * @}
339 /** @addtogroup OTFDEC_Exported_Functions_Group3 Peripheral Control functions
340 * @{
342 HAL_StatusTypeDef HAL_OTFDEC_RegionKeyLock(OTFDEC_HandleTypeDef *hotfdec, uint32_t RegionIndex);
343 HAL_StatusTypeDef HAL_OTFDEC_RegionSetKey(OTFDEC_HandleTypeDef *hotfdec, uint32_t RegionIndex, uint32_t *pKey);
344 HAL_StatusTypeDef HAL_OTFDEC_RegionSetMode(OTFDEC_HandleTypeDef *hotfdec, uint32_t RegionIndex, uint32_t mode);
345 HAL_StatusTypeDef HAL_OTFDEC_RegionConfig(OTFDEC_HandleTypeDef *hotfdec, uint32_t RegionIndex, OTFDEC_RegionConfigTypeDef *Config, uint32_t lock);
346 uint32_t HAL_OTFDEC_KeyCRCComputation(uint32_t *pKey);
347 HAL_StatusTypeDef HAL_OTFDEC_RegionEnable(OTFDEC_HandleTypeDef *hotfdec, uint32_t RegionIndex);
348 HAL_StatusTypeDef HAL_OTFDEC_RegionDisable(OTFDEC_HandleTypeDef *hotfdec, uint32_t RegionIndex);
350 * @}
353 /** @addtogroup @addtogroup OTFDEC_Exported_Functions_Group4 Peripheral State and Status functions
354 * @{
356 HAL_OTFDEC_StateTypeDef HAL_OTFDEC_GetState(OTFDEC_HandleTypeDef *hotfdec);
357 uint32_t HAL_OTFDEC_RegionGetKeyCRC(OTFDEC_HandleTypeDef *hotfdec, uint32_t RegionIndex);
358 HAL_StatusTypeDef HAL_OTFDEC_RegionGetConfig(OTFDEC_HandleTypeDef *hotfdec, uint32_t RegionIndex, OTFDEC_RegionConfigTypeDef *Config);
360 * @}
364 * @}
367 /* Private types -------------------------------------------------------------*/
368 /** @defgroup OTFDEC_Private_Types OTFDEC Private Types
369 * @{
373 * @}
376 /* Private variables ---------------------------------------------------------*/
377 /** @defgroup OTFDEC_Private_Variables OTFDEC Private Variables
378 * @{
382 * @}
385 /* Private constants ---------------------------------------------------------*/
386 /** @defgroup OTFDEC_Private_Constants OTFDEC Private Constants
387 * @{
390 * @}
393 /* Private macros ------------------------------------------------------------*/
394 /** @defgroup OTFDEC_Private_Macros OTFDEC Private Macros
395 * @{
399 * @brief Verify the OTFDEC peripheral interrupts parameter.
400 * @param __INT__ OTFDEC peripheral set of interrupts parameter
401 * @retval SET (__INT__ is valid) or RESET (__INT__ is invalid)
403 #define IS_OTFDEC_INTERRUPTS(__INT__) (((__INT__) == OTFDEC_SEC_ERROR_INT) || \
404 ((__INT__) == OTFDEC_EXE_ERROR_INT) || \
405 ((__INT__) == OTFDEC_KEY_ERROR_INT) || \
406 ((__INT__) == OTFDEC_SEC_EXE_ERROR_INT) || \
407 ((__INT__) == OTFDEC_SEC_KEY_ERROR_INT) || \
408 ((__INT__) == OTFDEC_EXE_KEY_ERROR_INT) || \
409 ((__INT__) == OTFDEC_ALL_INT) )
412 * @brief Verify the OTFDEC region configuration lock parameter.
413 * @param __LOCK__ OTFDEC region lock parameter.
414 * @retval SET (__LOCK__ is valid) or RESET (__LOCK__ is invalid)
416 #define IS_OTFDEC_REGION_CONFIG_LOCK(__LOCK__) (((__LOCK__) == OTFDEC_REG_CONFIGR_LOCK_DISABLE) || \
417 ((__LOCK__) == OTFDEC_REG_CONFIGR_LOCK_ENABLE) )
420 * @brief Verify the OTFDEC region operating mode.
421 * @param __MODE__ OTFDEC region operating mode parameter.
422 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
424 #define IS_OTFDEC_REGION_OPERATING_MODE(__MODE__) (((__MODE__) == OTFDEC_REG_MODE_INSTRUCTION_ACCESSES_ONLY) || \
425 ((__MODE__) == OTFDEC_REG_MODE_DATA_ACCESSES_ONLY) || \
426 ((__MODE__) == OTFDEC_REG_MODE_INSTRUCTION_OR_DATA_ACCESSES) || \
427 ((__MODE__) == OTFDEC_REG_MODE_INSTRUCTION_ACCESSES_ONLY_WITH_CIPHER))
430 * @brief Verify the OTFDEC region index.
431 * @param __INDEX__ OTFDEC region index
432 * @retval SET (__INDEX__ is valid) or RESET (__INDEX__ is invalid)
434 #define IS_OTFDEC_REGIONINDEX(__INDEX__) (((__INDEX__) == OTFDEC_REGION1) || \
435 ((__INDEX__) == OTFDEC_REGION2) || \
436 ((__INDEX__) == OTFDEC_REGION3) || \
437 ((__INDEX__) == OTFDEC_REGION4) )
440 * @brief Verify the OTFDEC configuration attributes.
441 * @param __ATTRIBUTE__ OTFDEC region index
442 * @retval SET (__ATTRIBUTE__ is valid) or RESET (__ATTRIBUTE__ is invalid)
444 #define IS_OTFDEC_ATTRIBUTE(__ATTRIBUTE__) (((__ATTRIBUTE__) == OTFDEC_ATTRIBUTE_PRIV) || \
445 ((__ATTRIBUTE__) == OTFDEC_ATTRIBUTE_NPRIV) )
448 * @}
451 /* Private functions ---------------------------------------------------------*/
452 /** @defgroup OTFDEC_Private_Functions OTFDEC Private Functions
453 * @{
457 * @}
461 * @}
464 #endif /* OTFDEC1 */
467 * @}
470 #ifdef __cplusplus
472 #endif
474 #endif /* STM32H7xx_HAL_OTFDEC_H */
476 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/