xref: /btstack/port/stm32-l451-miromico-sx1280/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_ll_pka.c (revision 2fd737d36a1de5d778cacc671d4b4d8c4f3fed82)
1 /**
2   ******************************************************************************
3   * @file    stm32l4xx_ll_pka.c
4   * @author  MCD Application Team
5   * @brief   PKA LL module driver.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
10   * All rights reserved.</center></h2>
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 #if defined(USE_FULL_LL_DRIVER)
20 
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32l4xx_ll_pka.h"
23 #include "stm32l4xx_ll_bus.h"
24 
25 #ifdef  USE_FULL_ASSERT
26 #include "stm32_assert.h"
27 #else
28 #define assert_param(expr) ((void)0U)
29 #endif
30 
31 /** @addtogroup STM32L4xx_LL_Driver
32   * @{
33   */
34 
35 #if defined(PKA)
36 
37 /** @addtogroup PKA_LL
38   * @{
39   */
40 
41 /* Private types -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43 /* Private constants ---------------------------------------------------------*/
44 /* Private macros ------------------------------------------------------------*/
45 /** @defgroup PKA_LL_Private_Macros PKA Private Constants
46   * @{
47   */
48 #define IS_LL_PKA_MODE(__VALUE__)     (((__VALUE__) == LL_PKA_MODE_MONTGOMERY_PARAM_MOD_EXP) ||\
49                                       ((__VALUE__) == LL_PKA_MODE_MONTGOMERY_PARAM)          ||\
50                                       ((__VALUE__) == LL_PKA_MODE_MODULAR_EXP)               ||\
51                                       ((__VALUE__) == LL_PKA_MODE_MONTGOMERY_PARAM_ECC)      ||\
52                                       ((__VALUE__) == LL_PKA_MODE_ECC_KP_PRIMITIVE)          ||\
53                                       ((__VALUE__) == LL_PKA_MODE_ECDSA_SIGNATURE)           ||\
54                                       ((__VALUE__) == LL_PKA_MODE_ECDSA_VERIFICATION)        ||\
55                                       ((__VALUE__) == LL_PKA_MODE_POINT_CHECK)               ||\
56                                       ((__VALUE__) == LL_PKA_MODE_RSA_CRT_EXP)               ||\
57                                       ((__VALUE__) == LL_PKA_MODE_MODULAR_INV)               ||\
58                                       ((__VALUE__) == LL_PKA_MODE_ARITHMETIC_ADD)            ||\
59                                       ((__VALUE__) == LL_PKA_MODE_ARITHMETIC_SUB)            ||\
60                                       ((__VALUE__) == LL_PKA_MODE_ARITHMETIC_MUL)            ||\
61                                       ((__VALUE__) == LL_PKA_MODE_COMPARISON)                ||\
62                                       ((__VALUE__) == LL_PKA_MODE_MODULAR_REDUC)             ||\
63                                       ((__VALUE__) == LL_PKA_MODE_MODULAR_ADD)               ||\
64                                       ((__VALUE__) == LL_PKA_MODE_MODULAR_SUB)               ||\
65                                       ((__VALUE__) == LL_PKA_MODE_MONTGOMERY_MUL))
66 /**
67   * @}
68   */
69 
70 /* Private function prototypes -----------------------------------------------*/
71 
72 /* Exported functions --------------------------------------------------------*/
73 /** @addtogroup PKA_LL_Exported_Functions
74   * @{
75   */
76 
77 /** @addtogroup PKA_LL_EF_Init
78   * @{
79   */
80 
81 /**
82   * @brief  De-initialize PKA registers (Registers restored to their default values).
83   * @param  PKAx PKA Instance.
84   * @retval ErrorStatus
85   *          - SUCCESS: PKA registers are de-initialized
86   *          - ERROR: PKA registers are not de-initialized
87   */
LL_PKA_DeInit(PKA_TypeDef * PKAx)88 ErrorStatus LL_PKA_DeInit(PKA_TypeDef *PKAx)
89 {
90   ErrorStatus status = SUCCESS;
91 
92   /* Check the parameters */
93   assert_param(IS_PKA_ALL_INSTANCE(PKAx));
94 
95   if (PKAx == PKA)
96   {
97     /* Force PKA reset */
98     LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_PKA);
99 
100     /* Release PKA reset */
101     LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_PKA);
102   }
103   else
104   {
105     status = ERROR;
106   }
107 
108   return (status);
109 }
110 
111 /**
112   * @brief  Initialize PKA registers according to the specified parameters in PKA_InitStruct.
113   * @param  PKAx PKA Instance.
114   * @param  PKA_InitStruct pointer to a @ref LL_PKA_InitTypeDef structure
115   *         that contains the configuration information for the specified PKA peripheral.
116   * @retval ErrorStatus
117   *          - SUCCESS: PKA registers are initialized according to PKA_InitStruct content
118   *          - ERROR:   Not applicable
119   */
LL_PKA_Init(PKA_TypeDef * PKAx,LL_PKA_InitTypeDef * PKA_InitStruct)120 ErrorStatus LL_PKA_Init(PKA_TypeDef *PKAx, LL_PKA_InitTypeDef *PKA_InitStruct)
121 {
122   assert_param(IS_PKA_ALL_INSTANCE(PKAx));
123   assert_param(IS_LL_PKA_MODE(PKA_InitStruct->Mode));
124 
125   LL_PKA_Config(PKAx, PKA_InitStruct->Mode);
126 
127   return (SUCCESS);
128 }
129 
130 /**
131   * @brief Set each @ref LL_PKA_InitTypeDef field to default value.
132   * @param PKA_InitStruct pointer to a @ref LL_PKA_InitTypeDef structure
133   *                       whose fields will be set to default values.
134   * @retval None
135   */
136 
LL_PKA_StructInit(LL_PKA_InitTypeDef * PKA_InitStruct)137 void LL_PKA_StructInit(LL_PKA_InitTypeDef *PKA_InitStruct)
138 {
139   /* Reset PKA init structure parameters values */
140   PKA_InitStruct->Mode       = LL_PKA_MODE_MONTGOMERY_PARAM_MOD_EXP;
141 }
142 
143 /**
144   * @}
145   */
146 
147 /**
148   * @}
149   */
150 
151 /**
152   * @}
153   */
154 
155 #endif /* defined (PKA) */
156 
157 /**
158   * @}
159   */
160 
161 #endif /* USE_FULL_LL_DRIVER */
162 
163 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
164 
165