]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32L0/stm32l0xx_hal_firewall.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32L0 / stm32l0xx_hal_firewall.h
1 /**
2   ******************************************************************************
3   * @file    stm32l0xx_hal_firewall.h
4   * @author  MCD Application Team
5   * @version V1.2.0
6   * @date    06-February-2015
7   * @brief   Header file of FIREWALL HAL module.
8   ******************************************************************************
9   * @attention
10   *
11   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
12   *
13   * Redistribution and use in source and binary forms, with or without modification,
14   * are permitted provided that the following conditions are met:
15   *   1. Redistributions of source code must retain the above copyright notice,
16   *      this list of conditions and the following disclaimer.
17   *   2. Redistributions in binary form must reproduce the above copyright notice,
18   *      this list of conditions and the following disclaimer in the documentation
19   *      and/or other materials provided with the distribution.
20   *   3. Neither the name of STMicroelectronics nor the names of its contributors
21   *      may be used to endorse or promote products derived from this software
22   *      without 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 ARE
27   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34   *
35   ******************************************************************************  
36   */
37
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32L0xx_HAL_FIREWALL_H
40 #define __STM32L0xx_HAL_FIREWALL_H
41
42 #ifdef __cplusplus
43  extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32l0xx_hal_def.h"
48
49 /** @addtogroup STM32L0xx_HAL_Driver
50   * @{
51   */
52
53 /** @addtogroup FIREWALL  FIREWALL
54   * @{
55   */ 
56
57 /* Exported types ------------------------------------------------------------*/ 
58 /** @defgroup FIREWALL_Exported_Types FIREWALL Exported Types
59   * @{
60   */ 
61
62 /** 
63   * @brief FIREWALL Initialization Structure definition  
64   */ 
65 typedef struct
66 {
67   uint32_t CodeSegmentStartAddress;        /*!< Protected code segment start address. This value is 24-bit long, the 8 LSB bits are
68                                                 reserved and forced to 0 in order to allow a 256-byte granularity. */
69
70   uint32_t CodeSegmentLength;              /*!< Protected code segment length in bytes. This value is 22-bit long, the 8 LSB bits are 
71                                                 reserved and forced to 0 for the length to be a multiple of 256 bytes. */
72
73   uint32_t NonVDataSegmentStartAddress;    /*!< Protected non-volatile data segment start address. This value is 24-bit long, the 8 LSB
74                                                 bits are reserved and forced to 0 in order to allow a 256-byte granularity. */
75
76   uint32_t NonVDataSegmentLength;          /*!< Protected non-volatile data segment length in bytes. This value is 22-bit long, the 8 LSB
77                                                 bits are reserved and forced to 0 for the length to be a multiple of 256 bytes. */
78  
79   uint32_t VDataSegmentStartAddress;       /*!< Protected volatile data segment start address. This value is 17-bit long, the 6 LSB bits
80                                                 are reserved and forced to 0 in order to allow a 64-byte granularity. */
81
82   uint32_t VDataSegmentLength;             /*!< Protected volatile data segment length in bytes. This value is 17-bit long, the 6 LSB
83                                                 bits are reserved and forced to 0 for the length to be a multiple of 64 bytes. */
84   
85   uint32_t VolatileDataExecution;          /*!< Set VDE bit specifying whether or not the volatile data segment can be executed.
86                                                  When VDS = 1 (set by parameter VolatileDataShared), VDE bit has no meaning.
87                                                 This parameter can be a value of @ref FIREWALL_VolatileData_Executable */  
88                                            
89   uint32_t VolatileDataShared;             /*!< Set VDS bit in specifying whether or not the volatile data segment can be shared with a 
90                                                 non-protected application code.
91                                                 This parameter can be a value of @ref FIREWALL_VolatileData_Shared */  
92                                                                                                                                      
93 }FIREWALL_InitTypeDef;
94
95
96 /**
97   * @}
98   */
99
100   
101 /* Exported constants --------------------------------------------------------*/
102 /** @defgroup FIREWALL_Exported_Constants FIREWALL Exported Constants
103   * @{
104   */
105
106 /** @defgroup FIREWALL_VolatileData_Executable   FIREWALL volatile data segment execution status
107   * @{
108   */
109 #define FIREWALL_VOLATILEDATA_NOT_EXECUTABLE                 ((uint32_t)0x0000)
110 #define FIREWALL_VOLATILEDATA_EXECUTABLE                     ((uint32_t)FW_CR_VDE)
111 /**
112   * @}
113   */ 
114
115 /** @defgroup FIREWALL_VolatileData_Shared  FIREWALL volatile data segment share status
116   * @{
117   */ 
118 #define FIREWALL_VOLATILEDATA_NOT_SHARED                ((uint32_t)0x0000)
119 #define FIREWALL_VOLATILEDATA_SHARED                    ((uint32_t)FW_CR_VDS) 
120 /**
121   * @}
122   */ 
123
124 /** @defgroup FIREWALL_Pre_Arm FIREWALL pre arm status
125   * @{
126   */ 
127 #define FIREWALL_PRE_ARM_RESET                 ((uint32_t)0x0000)
128 #define FIREWALL_PRE_ARM_SET                   ((uint32_t)FW_CR_FPA)
129
130 /**
131   * @}
132   */
133
134 /**
135   * @}
136   */
137   
138 /* Private macros --------------------------------------------------------*/
139 /** @defgroup FIREWALL_Private_Macros   FIREWALL Private Macros
140   * @{
141   */
142 #define IS_FIREWALL_CODE_SEGMENT_ADDRESS(ADDRESS)        (((ADDRESS) >= 0x08000000) && ((ADDRESS) <= 0x080FFFFF))                                                   
143 #define IS_FIREWALL_CODE_SEGMENT_LENGTH(ADDRESS, LENGTH) (((ADDRESS) + (LENGTH)) <= 0x080FFFFF) 
144
145 #define IS_FIREWALL_NONVOLATILEDATA_SEGMENT_ADDRESS(ADDRESS)        (((ADDRESS) >= 0x08000000) && ((ADDRESS) <= 0x080FFFFF))                                                   
146 #define IS_FIREWALL_NONVOLATILEDATA_SEGMENT_LENGTH(ADDRESS, LENGTH) (((ADDRESS) + (LENGTH)) <= 0x080FFFFF) 
147
148 #define IS_FIREWALL_VOLATILEDATA_SEGMENT_ADDRESS(ADDRESS)        (((ADDRESS) >= 0x20000000) && ((ADDRESS) <= 0x20017FFF))                                                   
149 #define IS_FIREWALL_VOLATILEDATA_SEGMENT_LENGTH(ADDRESS, LENGTH) (((ADDRESS) + (LENGTH)) <= 0x20017FFF)                                                       
150     
151   
152 #define IS_FIREWALL_VOLATILEDATA_SHARE(SHARE) (((SHARE) == FIREWALL_VOLATILEDATA_NOT_SHARED) || \
153                                                ((SHARE) == FIREWALL_VOLATILEDATA_SHARED))
154                                                
155 #define IS_FIREWALL_VOLATILEDATA_EXECUTE(EXECUTE) (((EXECUTE) == FIREWALL_VOLATILEDATA_NOT_EXECUTABLE) || \
156                                                    ((EXECUTE) == FIREWALL_VOLATILEDATA_EXECUTABLE))                                                                                    
157 /**
158   * @}
159   */  
160
161
162 /* Exported macros -----------------------------------------------------------*/
163 /** @defgroup FIREWALL_Exported_Macros FIREWALL Exported Macros
164   * @{
165   */
166
167 /** @brief  Check whether or not the FIREWALL is enabled
168   * @retval FIREWALL enabling status (TRUE or FALSE).
169   */            
170 #define  __HAL_FIREWALL_IS_ENABLED()  HAL_IS_BIT_CLR(SYSCFG->CFGR2, SYSCFG_CFGR2_FWDISEN)  
171
172
173 /** @brief Enable FIREWALL pre arm. 
174   * @note When FPA bit is set, any code executed outside the protected segment 
175   *       closes the Firewall, otherwise it generates a system reset.
176   * @note This macro provides the same service as HAL_FIREWALL_EnablePreArmFlag() API
177   *       but can be executed inside a code area protected by the Firewall. 
178   * @note This macro can be executed whatever the Firewall state (opened or closed) when
179   *       NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
180   *       0, that is, when the non volatile data segment is defined), the macro can be
181   *       executed only when the Firewall is opened.    
182   */ 
183 #define __HAL_FIREWALL_PREARM_ENABLE()                                         \
184              do {                                                              \
185                   __IO uint32_t tmpreg;                                        \
186                   SET_BIT(FW->CR, FW_CR_FPA) ;                           \
187                   /* Read bit back to ensure it is taken into account by IP */ \
188                   /* (introduce proper delay inside macro execution) */        \
189                   tmpreg = READ_BIT(FW->CR, FW_CR_FPA) ;                 \
190                   UNUSED(tmpreg);                                              \
191                 } while(0)
192
193
194                     
195 /** @brief Disable FIREWALL pre arm. 
196   * @note When FPA bit is set, any code executed outside the protected segment 
197   *       closes the Firewall, otherwise, it generates a system reset.
198   * @note This macro provides the same service as HAL_FIREWALL_DisablePreArmFlag() API
199   *       but can be executed inside a code area protected by the Firewall.
200   * @note This macro can be executed whatever the Firewall state (opened or closed) when
201   *       NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
202   *       0, that is, when the non volatile data segment is defined), the macro can be
203   *       executed only when the Firewall is opened.      
204   */ 
205 #define __HAL_FIREWALL_PREARM_DISABLE()                                        \
206              do {                                                              \
207                   __IO uint32_t tmpreg;                                        \
208                   CLEAR_BIT(FW->CR, FW_CR_FPA) ;                         \
209                   /* Read bit back to ensure it is taken into account by IP */ \
210                   /* (introduce proper delay inside macro execution) */        \
211                   tmpreg = READ_BIT(FW->CR, FW_CR_FPA) ;                 \
212                   UNUSED(tmpreg);                                              \
213                 } while(0)
214
215 /** @brief Enable volatile data sharing in setting VDS bit. 
216   * @note When VDS bit is set, the volatile data segment is shared with non-protected
217   *       application code. It can be accessed whatever the Firewall state (opened or closed). 
218   * @note This macro can be executed inside a code area protected by the Firewall.
219   * @note This macro can be executed whatever the Firewall state (opened or closed) when
220   *       NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
221   *       0, that is, when the non volatile data segment is defined), the macro can be
222   *       executed only when the Firewall is opened.      
223   */ 
224 #define __HAL_FIREWALL_VOLATILEDATA_SHARED_ENABLE()                            \
225              do {                                                              \
226                   __IO uint32_t tmpreg;                                        \
227                   SET_BIT(FW->CR, FW_CR_VDS) ;                           \
228                   /* Read bit back to ensure it is taken into account by IP */ \
229                   /* (introduce proper delay inside macro execution) */        \
230                   tmpreg = READ_BIT(FW->CR, FW_CR_VDS) ;                 \
231                   UNUSED(tmpreg);                                              \
232                 } while(0)
233
234 /** @brief Disable volatile data sharing in resetting VDS bit. 
235   * @note When VDS bit is reset, the volatile data segment is not shared and cannot be 
236   *       hit by a non protected executable code when the Firewall is closed. If it is 
237   *       accessed in such a condition, a system reset is generated by the Firewall.
238   * @note This macro can be executed inside a code area protected by the Firewall. 
239   * @note This macro can be executed whatever the Firewall state (opened or closed) when
240   *       NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
241   *       0, that is, when the non volatile data segment is defined), the macro can be
242   *       executed only when the Firewall is opened.     
243   */ 
244 #define __HAL_FIREWALL_VOLATILEDATA_SHARED_DISABLE()                           \
245              do {                                                              \
246                   __IO uint32_t tmpreg;                                        \
247                   CLEAR_BIT(FW->CR, FW_CR_VDS) ;                         \
248                   /* Read bit back to ensure it is taken into account by IP */ \
249                   /* (introduce proper delay inside macro execution) */        \
250                   tmpreg = READ_BIT(FW->CR, FW_CR_VDS) ;                 \
251                   UNUSED(tmpreg);                                              \
252                 } while(0)
253
254 /** @brief Enable volatile data execution in setting VDE bit.
255   * @note VDE bit is ignored when VDS is set. IF VDS = 1, the Volatile data segment can be 
256   *       executed whatever the VDE bit value.  
257   * @note When VDE bit is set (with VDS = 0), the volatile data segment is executable. When
258   *       the Firewall call is closed, a "call gate" entry procedure is required to open 
259   *       first the Firewall.
260   * @note This macro can be executed inside a code area protected by the Firewall.
261   * @note This macro can be executed whatever the Firewall state (opened or closed) when
262   *       NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
263   *       0, that is, when the non volatile data segment is defined), the macro can be
264   *       executed only when the Firewall is opened.         
265   */ 
266 #define __HAL_FIREWALL_VOLATILEDATA_EXECUTION_ENABLE()                         \
267              do {                                                              \
268                   __IO uint32_t tmpreg;                                        \
269                   SET_BIT(FW->CR, FW_CR_VDE) ;                           \
270                   /* Read bit back to ensure it is taken into account by IP */ \
271                   /* (introduce proper delay inside macro execution) */        \
272                   tmpreg = READ_BIT(FW->CR, FW_CR_VDE) ;                 \
273                   UNUSED(tmpreg);                                              \
274                 } while(0)
275
276 /** @brief Disable volatile data execution in resetting VDE bit.
277   * @note VDE bit is ignored when VDS is set. IF VDS = 1, the Volatile data segment can be 
278   *       executed whatever the VDE bit value.  
279   * @note When VDE bit is reset (with VDS = 0), the volatile data segment cannot  be executed.
280   * @note This macro can be executed inside a code area protected by the Firewall. 
281   * @note This macro can be executed whatever the Firewall state (opened or closed) when
282   *       NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
283   *       0, that is, when the non volatile data segment is defined), the macro can be
284   *       executed only when the Firewall is opened.        
285   */
286 #define __HAL_FIREWALL_VOLATILEDATA_EXECUTION_DISABLE()                           \
287              do {                                                              \
288                   __IO uint32_t tmpreg;                                        \
289                   CLEAR_BIT(FW->CR, FW_CR_VDE) ;                         \
290                   /* Read bit back to ensure it is taken into account by IP */ \
291                   /* (introduce proper delay inside macro execution) */        \
292                   tmpreg = READ_BIT(FW->CR, FW_CR_VDE) ;                 \
293                   UNUSED(tmpreg);                                              \
294                 } while(0)   
295
296
297 /** @brief Check whether or not the volatile data segment is shared.
298   * @note This macro can be executed inside a code area protected by the Firewall.
299   * @note This macro can be executed whatever the Firewall state (opened or closed) when
300   *       NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
301   *       0, that is, when the non volatile data segment is defined), the macro can be
302   *       executed only when the Firewall is opened.      
303   * @retval VDS bit setting status (TRUE or FALSE).
304   */
305 #define __HAL_FIREWALL_GET_VOLATILEDATA_SHARED() ((FW->CR & FW_CR_VDS) == FW_CR_VDS)
306
307 /** @brief Check whether or not the volatile data segment is declared executable.
308   * @note This macro can be executed inside a code area protected by the Firewall.
309   * @note This macro can be executed whatever the Firewall state (opened or closed) when
310   *       NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
311   *       0, that is, when the non volatile data segment is defined), the macro can be
312   *       executed only when the Firewall is opened.      
313   * @retval VDE bit setting status (TRUE or FALSE).
314   */
315 #define __HAL_FIREWALL_GET_VOLATILEDATA_EXECUTION() ((FW->CR & FW_CR_VDE) == FW_CR_VDE)
316
317 /** @brief Check whether or not the Firewall pre arm bit is set.
318   * @note This macro can be executed inside a code area protected by the Firewall.
319   * @note This macro can be executed whatever the Firewall state (opened or closed) when
320   *       NVDSL register is equal to 0. Otherwise (when NVDSL register is different from
321   *       0, that is, when the non volatile data segment is defined), the macro can be
322   *       executed only when the Firewall is opened.      
323   * @retval FPA bit setting status (TRUE or FALSE).
324   */
325 #define __HAL_FIREWALL_GET_PREARM() ((FW->CR & FW_CR_FPA) == FW_CR_FPA)
326
327
328 /**
329   * @}
330   */
331
332 /* Exported functions --------------------------------------------------------*/
333
334 /** @addtogroup FIREWALL_Exported_Functions FIREWALL Exported Functions
335   * @{
336   */
337   
338 /** @addtogroup FIREWALL_Exported_Functions_Group1 Initialization Functions
339   * @brief    Initialization and Configuration Functions  
340   * @{
341   */  
342   
343 /* Initialization functions  ********************************/
344 HAL_StatusTypeDef HAL_FIREWALL_Config(FIREWALL_InitTypeDef * fw_init);
345 void HAL_FIREWALL_GetConfig(FIREWALL_InitTypeDef * fw_config);
346 void HAL_FIREWALL_EnableFirewall(void);
347 void HAL_FIREWALL_EnablePreArmFlag(void);
348 void HAL_FIREWALL_DisablePreArmFlag(void);
349
350 /**
351   * @}
352   */
353   
354 /**
355   * @}
356   */   
357
358 /**
359   * @}
360   */ 
361
362 /**
363   * @}
364   */ 
365   
366 #ifdef __cplusplus
367 }
368 #endif
369
370 #endif /* __STM32L0xx_HAL_FIREWALL_H */
371
372 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/