1 /***************************************************************************//**
2 * \file cy_crypto_core_hw.h
3 * \version 2.40
4 *
5 * \brief
6 * This file provides the headers to the API for the utils
7 * in the Crypto driver.
8 *
9 ********************************************************************************
10 * Copyright 2016-2020 Cypress Semiconductor Corporation
11 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *******************************************************************************/
25
26
27 #if !defined (CY_CRYPTO_CORE_VU_H)
28 #define CY_CRYPTO_CORE_VU_H
29
30 #include "cy_device.h"
31
32 #if defined (CY_IP_MXCRYPTO)
33
34 #include "cy_crypto_common.h"
35
36 #if defined(__cplusplus)
37 extern "C" {
38 #endif
39
40 #if (CPUSS_CRYPTO_VU == 1)
41
42 #include "cy_crypto_core_hw.h"
43 #include "cy_crypto_core_hw_vu.h"
44 #include <string.h>
45
46 /**
47 * \addtogroup group_crypto_lld_vu_functions
48 * \{
49 */
50
51 /*******************************************************************************
52 * Function Name: Cy_Crypto_Core_Cleanup
53 ****************************************************************************//**
54 *
55 * Cleans up the Crypto block.
56 *
57 * \param base
58 * The pointer to the CRYPTO instance.
59 *
60 * \return
61 * \ref cy_en_crypto_status_t
62 *
63 *******************************************************************************/
64 cy_en_crypto_status_t Cy_Crypto_Core_Cleanup(CRYPTO_Type *base);
65
66 /*******************************************************************************
67 * Function Name: Cy_Crypto_Core_Vu_SetMemValue
68 ****************************************************************************//**
69 *
70 * Sets the value in the Crypto memory allocated by the destination VU register.
71 *
72 * \param base
73 * The pointer to the CRYPTO instance.
74 *
75 * \param dstReg
76 * The destination vector unit register.
77 *
78 * \param src
79 * The pointer to the source value.
80 *
81 * \param size
82 * The size of the operated value.
83 *
84 *******************************************************************************/
85 void Cy_Crypto_Core_Vu_SetMemValue(CRYPTO_Type *base, uint32_t dstReg, uint8_t const *src, uint32_t size);
86
87 /*******************************************************************************
88 * Function Name: Cy_Crypto_Core_Vu_GetMemValue
89 ****************************************************************************//**
90 *
91 * Gets the value located in the crypto memory and pointed by source VU register.
92 *
93 * \param base
94 * The pointer to the CRYPTO instance.
95 *
96 * \param dst
97 * The pointer to the destination value.
98 *
99 * \param srcReg
100 * The source vector unit register.
101 *
102 * \param size
103 * The size of the operated value.
104 *
105 *******************************************************************************/
106 void Cy_Crypto_Core_Vu_GetMemValue(CRYPTO_Type *base, uint8_t *dst, uint32_t srcReg, uint32_t size);
107
108 /*******************************************************************************
109 * Function Name: Cy_Crypto_Core_Vu_IsRegZero
110 ****************************************************************************//**
111 *
112 * Returns TRUE if srcReg contains 0. FALSE - otherwise.
113 *
114 * \param base
115 * The pointer to the CRYPTO instance.
116 *
117 * \param srcReg
118 * The source vector unit register.
119 *
120 * \return
121 * The result of the comparison.
122 *
123 *******************************************************************************/
124 bool Cy_Crypto_Core_Vu_IsRegZero(CRYPTO_Type *base, uint32_t srcReg);
125
126 /*******************************************************************************
127 * Function Name: Cy_Crypto_Core_Vu_IsRegEqual
128 ****************************************************************************//**
129 *
130 * Returns TRUE if srcReg0 contains the same value as srcReg1. FALSE - otherwise.
131 *
132 * \param base
133 * The pointer to the CRYPTO instance.
134 *
135 * \param srcReg0
136 * The source 0 vector unit register.
137 *
138 * \param srcReg1
139 * The source 1 vector unit register.
140 *
141 * \return
142 * The result of the comparison.
143 *
144 *******************************************************************************/
145 bool Cy_Crypto_Core_Vu_IsRegEqual(CRYPTO_Type *base, uint32_t srcReg0, uint32_t srcReg1);
146
147 /*******************************************************************************
148 * Function Name: Cy_Crypto_Core_Vu_IsRegEqual
149 ****************************************************************************//**
150 *
151 * Returns TRUE if srcReg0 contains the value less than value of srcReg1.
152 * FALSE - otherwise.
153 *
154 * \param base
155 * The pointer to the CRYPTO instance.
156 *
157 * \param srcReg0
158 * The source 0 vector unit register.
159 *
160 * \param srcReg1
161 * The source 1 vector unit register.
162 *
163 * \return
164 * The result of the comparison.
165 *
166 *******************************************************************************/
167 bool Cy_Crypto_Core_Vu_IsRegLess(CRYPTO_Type *base, uint32_t srcReg0, uint32_t srcReg1);
168
169 /*******************************************************************************
170 * Function Name: Cy_Crypto_Core_Vu_RegRead
171 ****************************************************************************//**
172 *
173 * Returns the data pointed in a given register.
174 *
175 * \param base
176 * The pointer to the CRYPTO instance.
177 *
178 * \param srcReg
179 * The source vector unit register.
180 *
181 *******************************************************************************/
Cy_Crypto_Core_Vu_RegRead(CRYPTO_Type * base,uint32_t srcReg)182 __STATIC_INLINE uint32_t Cy_Crypto_Core_Vu_RegRead(CRYPTO_Type *base, uint32_t srcReg)
183 {
184 return ((uint32_t)_FLD2VAL(CRYPTO_RF_DATA_DATA32, REG_CRYPTO_VU_RF_DATA(base, srcReg)));
185 }
186
187 /*******************************************************************************
188 * Function Name: Cy_Crypto_Core_Vu_RegSizeRead
189 ****************************************************************************//**
190 *
191 * Returns size of the data pointed in given register,
192 * it is lower 12Bit of the 32Bit word
193 *
194 * \param base
195 * The pointer to the CRYPTO instance.
196 *
197 * \param srcReg
198 * The source vector unit register.
199 *
200 *******************************************************************************/
Cy_Crypto_Core_Vu_RegSizeRead(CRYPTO_Type * base,uint32_t srcReg)201 __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegSizeRead(CRYPTO_Type *base, uint32_t srcReg)
202 {
203 return ((uint16_t)(_FLD2VAL(CRYPTO_RF_DATA_DATA32, REG_CRYPTO_VU_RF_DATA(base, srcReg)) & CY_CRYPTO_VU_SIZE_FLD_MASK));
204 }
205
206 /*******************************************************************************
207 * Function Name: Cy_Crypto_Core_Vu_RegBitSizeRead
208 ****************************************************************************//**
209 *
210 * Returns size of the data pointed in given register, in Bits.
211 * It is lower 12Bit of the 32Bit word
212 *
213 * \param base
214 * The pointer to the CRYPTO instance.
215 *
216 * \param srcReg
217 * The source vector unit register.
218 *
219 *******************************************************************************/
Cy_Crypto_Core_Vu_RegBitSizeRead(CRYPTO_Type * base,uint32_t srcReg)220 __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegBitSizeRead(CRYPTO_Type *base, uint32_t srcReg)
221 {
222 return ((uint16_t)(_FLD2VAL(CRYPTO_RF_DATA_DATA32, REG_CRYPTO_VU_RF_DATA(base, srcReg)) & CY_CRYPTO_VU_SIZE_FLD_MASK) + 1u);
223 }
224
225 /*******************************************************************************
226 * Function Name: Cy_Crypto_Core_Vu_RegByteSizeRead
227 ****************************************************************************//**
228 *
229 * Returns size of the data pointed in given register, in Bytes.
230 * It is lower 12Bit of the 32Bit word
231 *
232 * \param base
233 * The pointer to the CRYPTO instance.
234 *
235 * \param srcReg
236 * The source vector unit register.
237 *
238 *******************************************************************************/
Cy_Crypto_Core_Vu_RegByteSizeRead(CRYPTO_Type * base,uint32_t srcReg)239 __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegByteSizeRead(CRYPTO_Type *base, uint32_t srcReg)
240 {
241 return ((uint16_t)((_FLD2VAL(CRYPTO_RF_DATA_DATA32, REG_CRYPTO_VU_RF_DATA(base, srcReg)) & CY_CRYPTO_VU_SIZE_FLD_MASK) + 1u) >> 3u);
242 }
243
244 /*******************************************************************************
245 * Function Name: Cy_Crypto_Core_Vu_RegWordSizeRead
246 ****************************************************************************//**
247 *
248 * Returns size of the data pointed in given register, in words (uint32_t).
249 * It is lower 12Bit of the 32Bit word
250 *
251 * \param base
252 * The pointer to the CRYPTO instance.
253 *
254 * \param srcReg
255 * The source vector unit register.
256 *
257 *******************************************************************************/
Cy_Crypto_Core_Vu_RegWordSizeRead(CRYPTO_Type * base,uint32_t srcReg)258 __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegWordSizeRead(CRYPTO_Type *base, uint32_t srcReg)
259 {
260 return ((uint16_t)((_FLD2VAL(CRYPTO_RF_DATA_DATA32, REG_CRYPTO_VU_RF_DATA(base, srcReg)) & CY_CRYPTO_VU_SIZE_FLD_MASK) + 1u) >> 5u);
261 }
262
263 /*******************************************************************************
264 * Function Name: Cy_Crypto_Core_Vu_RegDataPtrRead
265 ****************************************************************************//**
266 *
267 * Returns the data pointer, in 14-bit format of the data pointed in given register,
268 * it is upper 16Bit of the 32Bir word. Pointer is in words (uint32_t).
269 *
270 * \param base
271 * The pointer to the CRYPTO instance.
272 *
273 * \param srcReg
274 * The source vector unit register.
275 *
276 *******************************************************************************/
Cy_Crypto_Core_Vu_RegDataPtrRead(CRYPTO_Type * base,uint32_t srcReg)277 __STATIC_INLINE uint16_t Cy_Crypto_Core_Vu_RegDataPtrRead(CRYPTO_Type *base, uint32_t srcReg)
278 {
279 return (uint16_t)((_FLD2VAL(CRYPTO_RF_DATA_DATA32, REG_CRYPTO_VU_RF_DATA(base, srcReg)) >> CY_CRYPTO_VU_DATA_FLD_POS)
280 & CY_CRYPTO_VU_DATA_FLD_MASK);
281 }
282
283 /*******************************************************************************
284 * Function Name: Cy_Crypto_Core_Vu_RegMemPointer
285 ****************************************************************************//**
286 *
287 * Returns the memory address of the data pointed in given register.
288 *
289 * \param base
290 * The pointer to the CRYPTO instance.
291 *
292 * \param srcReg
293 * The source vector unit register.
294 *
295 *******************************************************************************/
Cy_Crypto_Core_Vu_RegMemPointer(CRYPTO_Type * base,uint32_t srcReg)296 __STATIC_INLINE uint32_t * Cy_Crypto_Core_Vu_RegMemPointer(CRYPTO_Type *base, uint32_t srcReg)
297 {
298 return (uint32_t *)((uint32_t)REG_CRYPTO_VU_CTL1(base) + (4u * (uint32_t)Cy_Crypto_Core_Vu_RegDataPtrRead(base, srcReg)));
299 }
300
301 /*******************************************************************************
302 * Function Name: Cy_Crypto_Core_Vu_StatusRead
303 ****************************************************************************//**
304 *
305 * Returns the value of the VU status register.
306 *
307 * \param base
308 * The pointer to the CRYPTO instance.
309 *
310 *******************************************************************************/
Cy_Crypto_Core_Vu_StatusRead(CRYPTO_Type * base)311 __STATIC_INLINE uint32_t Cy_Crypto_Core_Vu_StatusRead(CRYPTO_Type *base)
312 {
313 Cy_Crypto_Core_Vu_WaitForComplete(base);
314
315 return((uint32_t)REG_CRYPTO_VU_STATUS(base));
316 }
317
318 /*******************************************************************************
319 * Function Name: Cy_Crypto_Core_VU_RegInvertEndianness
320 ****************************************************************************//**
321 *
322 * Reverts the memory data block pointed in given register.
323 *
324 * \param base
325 * The pointer to the CRYPTO instance.
326 *
327 * \param srcReg
328 * The source vector unit register.
329 *
330 *******************************************************************************/
331 void Cy_Crypto_Core_VU_RegInvertEndianness(CRYPTO_Type *base, uint32_t srcReg);
332
333 /** \} group_crypto_lld_vu_functions */
334
335 #endif /* #if (CPUSS_CRYPTO_VU == 1) */
336
337 #if defined(__cplusplus)
338 }
339 #endif
340
341 #endif /* CY_IP_MXCRYPTO */
342
343 #endif /* #if !defined (CY_CRYPTO_CORE_VU_H) */
344
345 /* [] END OF FILE */
346