1 // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /*******************************************************************************
16 * NOTICE
17 * The ll is not public api, don't use in application code.
18 * See readme.md in soc/include/hal/readme.md
19 ******************************************************************************/
20 #pragma once
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #include "soc/hwcrypto_reg.h"
27 #include "soc/dport_reg.h"
28
29 typedef enum {
30 CRYPTO_DMA_AES= 0,
31 CRYPTO_DMA_SHA,
32 } crypto_dma_mode_t;
33
34 /**
35 * @brief Resets the DMA
36 *
37 */
crypto_dma_ll_reset(void)38 static inline void crypto_dma_ll_reset(void)
39 {
40 SET_PERI_REG_MASK(CRYPTO_DMA_CONF0_REG, CONF0_REG_AHBM_RST | CONF0_REG_OUT_RST | CONF0_REG_AHBM_FIFO_RST);
41 CLEAR_PERI_REG_MASK(CRYPTO_DMA_CONF0_REG, CONF0_REG_AHBM_RST | CONF0_REG_OUT_RST | CONF0_REG_AHBM_FIFO_RST);
42 }
43
44 /**
45 * @brief Selects the crypto DMA mode
46 *
47 * @param mode Mode to use, AES or SHA
48 */
crypto_dma_ll_set_mode(crypto_dma_mode_t mode)49 static inline void crypto_dma_ll_set_mode(crypto_dma_mode_t mode)
50 {
51 REG_WRITE(CRYPTO_DMA_AES_SHA_SELECT_REG, mode);
52 }
53
54 /**
55 * @brief Sets up the outlink for a transfer
56 *
57 * @param outlink_addr Address of the outlink buffer
58 */
crypto_dma_ll_outlink_set(uint32_t outlink_addr)59 static inline void crypto_dma_ll_outlink_set(uint32_t outlink_addr)
60 {
61 CLEAR_PERI_REG_MASK(CRYPTO_DMA_OUT_LINK_REG, OUT_LINK_REG_OUTLINK_ADDR);
62 SET_PERI_REG_MASK(CRYPTO_DMA_OUT_LINK_REG, outlink_addr & OUT_LINK_REG_OUTLINK_ADDR);
63 }
64
65 /**
66 * @brief Sets up the inlink for a transfer
67 *
68 * @param inlink_addr Address of the inlink buffer
69 */
crypto_dma_ll_inlink_set(uint32_t inlink_addr)70 static inline void crypto_dma_ll_inlink_set(uint32_t inlink_addr)
71 {
72 CLEAR_PERI_REG_MASK(CRYPTO_DMA_IN_LINK_REG, IN_LINK_REG_INLINK_ADDR);
73 SET_PERI_REG_MASK(CRYPTO_DMA_IN_LINK_REG, inlink_addr & IN_LINK_REG_INLINK_ADDR);
74 }
75
76 /**
77 * @brief Starts the outlink
78 *
79 */
crypto_dma_ll_outlink_start(void)80 static inline void crypto_dma_ll_outlink_start(void)
81 {
82 SET_PERI_REG_MASK(CRYPTO_DMA_OUT_LINK_REG, OUT_LINK_REG_OUTLINK_START);
83 }
84
85 /**
86 * @brief Starts the inlink
87 *
88 */
crypto_dma_ll_inlink_start(void)89 static inline void crypto_dma_ll_inlink_start(void)
90 {
91 SET_PERI_REG_MASK(CRYPTO_DMA_IN_LINK_REG, IN_LINK_REG_INLINK_START);
92 }
93
crypto_dma_ll_inlink_is_eof(void)94 static inline bool crypto_dma_ll_inlink_is_eof(void)
95 {
96 return ((REG_READ(CRYPTO_DMA_INT_RAW_REG) & INT_RAW_IN_SUC_EOF) == INT_RAW_IN_SUC_EOF);
97 }
98
99
100 #ifdef __cplusplus
101 }
102 #endif
103