1 /***************************************************************************//**
2 * \file cyhal_crypto_common.h
3 *
4 * Description:
5 * This file provides common defines, addresses, and functions required by drivers
6 * using the Crypto block.
7 *
8 ********************************************************************************
9 * \copyright
10 * Copyright 2018-2022 Cypress Semiconductor Corporation (an Infineon company) or
11 * an affiliate of Cypress Semiconductor Corporation
12 *
13 * SPDX-License-Identifier: Apache-2.0
14 *
15 * Licensed under the Apache License, Version 2.0 (the "License");
16 * you may not use this file except in compliance with the License.
17 * You may obtain a copy of the License at
18 *
19 *     http://www.apache.org/licenses/LICENSE-2.0
20 *
21 * Unless required by applicable law or agreed to in writing, software
22 * distributed under the License is distributed on an "AS IS" BASIS,
23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 * See the License for the specific language governing permissions and
25 * limitations under the License.
26 *******************************************************************************/
27 
28 #pragma once
29 
30 #include "cy_device.h"
31 #include "cy_pdl.h"
32 #include "cy_result.h"
33 #include "cyhal_hw_types.h"
34 
35 #if (_CYHAL_DRIVER_AVAILABLE_CRYPTO)
36 
37 #if defined(__cplusplus)
38 extern "C" {
39 #endif
40 
41 /* Block count for CRYPTO blocks */
42 #if defined(CY_IP_MXCRYPTO)
43 #define CYHAL_CRYPTO_INST_COUNT      CY_IP_MXCRYPTO_INSTANCES
44 #elif defined(CY_IP_MXCRYPTOLITE)
45 #define CYHAL_CRYPTO_INST_COUNT      CY_IP_MXCRYPTOLITE_INSTANCES
46 #elif defined(CY_IP_M0S8CRYPTO)
47 #define CYHAL_CRYPTO_INST_COUNT      CY_IP_M0S8CRYPTO_INSTANCES
48 #elif defined(CY_IP_M0S8CRYPTOLITE)
49 #define CYHAL_CRYPTO_INST_COUNT      CY_IP_M0S8CRYPTOLITE_INSTANCES
50 #endif
51 
52 typedef enum
53 {
54     /* CRC hardware acceleration */
55     CYHAL_CRYPTO_CRC,
56     /* TRNG hardware acceleration */
57     CYHAL_CRYPTO_TRNG,
58     /* VU hardware acceleration */
59     CYHAL_CRYPTO_VU,
60     /* Common features of the Crypto block  */
61     CYHAL_CRYPTO_COMMON,
62 } cyhal_crypto_feature_t;
63 
64 
65 /* Reserve the Crypto block and enable it.
66  *
67  * @param[out]  base Base address to the Crypto block.
68  * @param[out]  resource Resource inst for the function (eg. CRC, TRNG) in the Crypto block.
69  * @param[in]   feature feature to reserve on the Crypto block (eg. TRNG, CRC, etc.).
70  * @return The status of the reserve request.
71  */
72 cy_rslt_t cyhal_crypto_reserve(CRYPTO_Type** base, cyhal_resource_inst_t *resource, cyhal_crypto_feature_t feature);
73 
74 /* Free the Crypto block and disable it.
75  *
76  * @param[in]  base Base address to the Crypto block.
77  * @param[in]  resource Resource inst for the function in Crypto block.
78  * @param[in]  feature Feature to free on the Crypto block (eg. TRNG, CRC, etc.).
79  */
80 void cyhal_crypto_free(CRYPTO_Type* base, cyhal_resource_inst_t *resource, cyhal_crypto_feature_t feature);
81 
82 #if defined(__cplusplus)
83 }
84 #endif
85 
86 #endif /* _CYHAL_DRIVER_AVAILABLE_CRYPTO */
87