1  /*
2  * Copyright (C) 2017-2024 Alibaba Group Holding Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 /******************************************************************************
20  * @file     drv/sasc.h
21  * @brief    Header File for SASC driver
22  * @version  V1.0
23  * @date     02. June 2020
24  * @model    sasc
25  ******************************************************************************/
26 #ifndef _DRV_SASC_H_
27 #define _DRV_SASC_H_
28 
29 
30 #include <stdint.h>
31 #include <drv/common.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 typedef enum {
37     SASC_RW = 0,
38     SASC_RO = 1,
39     SASC_WO = 2,
40     SASC_AP_DENY = 3
41 } csi_sasc_ap_t;
42 
43 typedef enum {
44     SASC_DI = 0,
45     SASC_DO = 1,
46     SASC_IO = 2,
47     SASC_DI_DENY = 3
48 } csi_sasc_di_t;
49 
50 typedef enum {
51     SASC_RAM_4B = 5,
52     SASC_RAM_8B = 6,
53     SASC_RAM_16B = 7,
54     SASC_RAM_32B = 8,
55     SASC_RAM_64B = 9,
56     SASC_RAM_128B = 10,
57     SASC_RAM_256B = 11,
58     SASC_RAM_512B = 12,
59     SASC_RAM_1KB = 13,
60     SASC_RAM_2KB = 14,
61     SASC_RAM_4KB = 15,
62     SASC_RAM_8KB = 16,
63     SASC_RAM_16KB = 17,
64     SASC_RAM_32KB = 18,
65     SASC_RAM_64KB = 19,
66     SASC_RAM_128KB = 20,
67 } csi_sasc_ram_size_t;
68 
69 typedef enum {
70     SASC_FLASH_1S = 0,
71     SASC_FLASH_2S,
72     SASC_FLASH_4S,
73     SASC_FLASH_8S,
74     SASC_FLASH_16S,
75     SASC_FLASH_32S,
76     SASC_FLASH_64S,
77     SASC_FLASH_128S,
78     SASC_FLASH_256S,
79     SASC_FLASH_512S,
80     SASC_FLASH_1024S,
81     SASC_FLASH_2048S
82 } csi_sasc_flash_size_t;
83 
84 typedef struct {
85     csi_sasc_ap_t   super_ap;
86     csi_sasc_ap_t   user_ap;
87     csi_sasc_di_t   super_di;
88     csi_sasc_di_t   user_di;
89     bool            is_secure;
90 } csi_sasc_attr_t;
91 
92 /**
93   \brief       Config the sasc ram region attribute.
94   \param[in]   region_id  Config region index
95   \param[in]   base_addr  Config region base address.
96   \param[in]   size  config region size.
97   \param[in]   attr  Region attr.
98   \return      Error code
99 */
100 csi_error_t csi_sasc_ram_config(uint8_t region_id, uint32_t base_addr, csi_sasc_ram_size_t size, csi_sasc_attr_t attr);
101 
102 /**
103   \brief       Config the sasc flash region attribute.
104   \param[in]   region_id  Config region index
105   \param[in]   base_addr  Config region base address.
106   \param[in]   size  Config region size.
107   \param[in]   attr  Region attr.
108   \return      Error code
109 */
110 csi_error_t csi_sasc_flash_config(uint8_t region_id, uint32_t base_addr, csi_sasc_flash_size_t size, csi_sasc_attr_t attr);
111 
112 /**
113   \brief       Enable sasc ram config.
114   \param[in]   region_id  Region index
115   \return      error code
116 */
117 csi_error_t csi_sasc_ram_enable(uint8_t region_id);
118 
119 /**
120   \brief       Enable sasc flash config
121   \param[in]   region_id  Config region index
122   \return      error code
123 */
124 csi_error_t csi_sasc_flash_enable(uint8_t region_id);
125 
126 /**
127   \brief       Disable sasc ram config.
128   \param[in]   region_id  Region index
129   \return      error code
130 */
131 csi_error_t csi_sasc_ram_disable(uint8_t region_id);
132 
133 /**
134   \brief       Disable sasc flash config
135   \param[in]   region_id  Region index
136   \return      error code
137 */
138 csi_error_t csi_sasc_flash_disable(uint8_t region_id);
139 
140 #ifdef __cplusplus
141 }
142 #endif
143 
144 #endif /* _DRV_SASC_H_ */
145