1 /**
2   ******************************************************************************
3   * @file    stm32wbaxx_ll_pka.c
4   * @author  MCD Application Team
5   * @brief   PKA LL module driver.
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 #if defined(USE_FULL_LL_DRIVER)
19 
20 /* Includes ------------------------------------------------------------------*/
21 #include "stm32wbaxx_ll_pka.h"
22 #include "stm32wbaxx_ll_bus.h"
23 
24 #ifdef  USE_FULL_ASSERT
25 #include "stm32_assert.h"
26 #else
27 #define assert_param(expr) ((void)0U)
28 #endif /* USE_FULL_ASSERT */
29 
30 /** @addtogroup STM32WBAxx_LL_Driver
31   * @{
32   */
33 
34 #if defined(PKA)
35 
36 /** @addtogroup PKA_LL
37   * @{
38   */
39 
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /* Private macros ------------------------------------------------------------*/
44 /** @defgroup PKA_LL_Private_Macros PKA Private Constants
45   * @{
46   */
47 #define IS_LL_PKA_MODE(__VALUE__)     (((__VALUE__)==  LL_PKA_MODE_MODULAR_EXP)          ||\
48                                        ((__VALUE__) ==  LL_PKA_MODE_MONTGOMERY_PARAM)     ||\
49                                        ((__VALUE__) ==  LL_PKA_MODE_MODULAR_EXP_FAST)     ||\
50                                        ((__VALUE__) ==  LL_PKA_MODE_MODULAR_EXP_PROTECT)  ||\
51                                        ((__VALUE__) ==  LL_PKA_MODE_ECC_MUL)              ||\
52                                        ((__VALUE__) ==  LL_PKA_MODE_ECC_COMPLETE_ADD)     ||\
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                                        ((__VALUE__) ==  LL_PKA_MODE_DOUBLE_BASE_LADDER)   ||\
67                                        ((__VALUE__) ==  LL_PKA_MODE_ECC_PROJECTIVE_AFF))
68 /**
69   * @}
70   */
71 
72 /* Private function prototypes -----------------------------------------------*/
73 
74 /* Exported functions --------------------------------------------------------*/
75 /** @addtogroup PKA_LL_Exported_Functions
76   * @{
77   */
78 
79 /** @addtogroup PKA_LL_EF_Init
80   * @{
81   */
82 
83 /**
84   * @brief  De-initialize PKA registers (Registers restored to their default values).
85   * @param  PKAx PKA Instance.
86   * @retval ErrorStatus
87   *          - SUCCESS: PKA registers are de-initialized
88   *          - ERROR: PKA registers are not de-initialized
89   */
LL_PKA_DeInit(const PKA_TypeDef * PKAx)90 ErrorStatus LL_PKA_DeInit(const PKA_TypeDef *PKAx)
91 {
92   ErrorStatus status = SUCCESS;
93 
94   /* Check the parameters */
95   assert_param(IS_PKA_ALL_INSTANCE(PKAx));
96 
97   if (PKAx == PKA)
98   {
99     /* Force PKA reset */
100     LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_PKA);
101 
102     /* Release PKA reset */
103     LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_PKA);
104   }
105   else
106   {
107     status = ERROR;
108   }
109 
110   return (status);
111 }
112 
113 /**
114   * @brief  Initialize PKA registers according to the specified parameters in PKA_InitStruct.
115   * @param  PKAx PKA Instance.
116   * @param  PKA_InitStruct pointer to a @ref LL_PKA_InitTypeDef structure
117   *         that contains the configuration information for the specified PKA peripheral.
118   * @retval ErrorStatus
119   *          - SUCCESS: PKA registers are initialized according to PKA_InitStruct content
120   *          - ERROR:   Not applicable
121   */
LL_PKA_Init(PKA_TypeDef * PKAx,LL_PKA_InitTypeDef * PKA_InitStruct)122 ErrorStatus LL_PKA_Init(PKA_TypeDef *PKAx, LL_PKA_InitTypeDef *PKA_InitStruct)
123 {
124   assert_param(IS_PKA_ALL_INSTANCE(PKAx));
125   assert_param(IS_LL_PKA_MODE(PKA_InitStruct->Mode));
126 
127   LL_PKA_Config(PKAx, PKA_InitStruct->Mode);
128 
129   return (SUCCESS);
130 }
131 
132 /**
133   * @brief Set each @ref LL_PKA_InitTypeDef field to default value.
134   * @param PKA_InitStruct pointer to a @ref LL_PKA_InitTypeDef structure
135   *                       whose fields will be set to default values.
136   * @retval None
137   */
138 
LL_PKA_StructInit(LL_PKA_InitTypeDef * PKA_InitStruct)139 void LL_PKA_StructInit(LL_PKA_InitTypeDef *PKA_InitStruct)
140 {
141   /* Reset PKA init structure parameters values */
142   PKA_InitStruct->Mode       = LL_PKA_MODE_MODULAR_EXP;
143 }
144 
145 /**
146   * @}
147   */
148 
149 /**
150   * @}
151   */
152 
153 /**
154   * @}
155   */
156 
157 #endif /* defined (PKA) */
158 
159 /**
160   * @}
161   */
162 
163 #endif /* USE_FULL_LL_DRIVER */
164