• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
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  * Description: Provides sfc port template \n
16  *
17  * History: \n
18  * 2022-11-30, Create file. \n
19  */
20 #ifndef SFC_PORTING_H
21 #define SFC_PORTING_H
22 
23 #include <stdbool.h>
24 
25 #include "errcode.h"
26 #include "flash_config_info.h"
27 #include "sfc_protect.h"
28 
29 #ifdef __cplusplus
30 #if __cplusplus
31 extern "C" {
32 #endif
33 #endif
34 
35 /**
36  * @defgroup drivers_port_sfc SFC
37  * @ingroup  drivers_port
38  * @{
39  */
40 #define FLASH_CHIP_PROTECT_END      0x400000
41 #define SFC_SAFE_OFFSET             0x10000
42 
43 /**
44  * @if Eng
45  * @brief  Read, write and erase operations.
46  * @else
47  * @brief  Flash的基本信息和操作信息
48  * @endif
49 */
50 typedef struct flash_spi_ctrl {
51     uint32_t        chip_size;                                   /*!<@if Eng Size of the flash mapped to the SFC
52                                                                      @else   Flash映射到SFC的大小      @endif */
53     spi_opreation_t read_opreation;                              /*!<@if Eng Read operation
54                                                                      @else   读操作               @endif */
55     uint32_t        erase_cmd_num;                               /*!<@if Eng Number of erase commands
56                                                                      @else   擦除指令的个数@endif */
57     spi_opreation_t write_opreation;                             /*!<@if Eng Write opreation
58                                                                      @else   写操作               @endif */
59     spi_opreation_t *erase_opreation_array;                       /*!<@if Eng Erase opreations
60                                                                      @else   擦除操作      @endif */
61     flash_cmd_execute_t *quad_mode;                              /*!<@if Eng Quad SPI Enable opreations
62                                                                      @else   Quad SPI 使能操作      @endif */
63 } flash_spi_ctrl_t;
64 
65 /**
66  * @if Eng
67  * @brief  Get SFC bus space start address.
68  * @retval SFC bus space start address.
69  * @else
70  * @brief  获取SFC总线空间首地址。
71  * @retval SFC总线空间首地址。
72  * @endif
73  */
74 uintptr_t sfc_port_get_sfc_start_addr(void);
75 
76 /**
77  * @if Eng
78  * @brief  Get SFC bus space end address.
79  * @retval SFC bus space end address.
80  * @else
81  * @brief  获取SFC总线空间尾地址。
82  * @retval SFC总线空间尾地址。
83  * @endif
84  */
85 uintptr_t sfc_port_get_sfc_end_addr(void);
86 
87 /**
88  * @if Eng
89  * @brief  Get base address for SFC bus registers.
90  * @retval Base address for SFC bus registers.
91  * @else
92  * @brief  获取SFC公共配置相关寄存器基地址。
93  * @retval SFC公共配置相关寄存器基地址。
94  * @endif
95  */
96 uintptr_t sfc_port_get_sfc_global_conf_base_addr(void);
97 
98 /**
99  * @if Eng
100  * @brief  Get base address for SFC bus registers.
101  * @retval Base address for SFC bus registers.
102  * @else
103  * @brief  获取SFC总线模式访问相关寄存器基地址。
104  * @retval SFC总线模式访问相关寄存器基地址。
105  * @endif
106  */
107 uintptr_t sfc_port_get_sfc_bus_regs_base_addr(void);
108 
109 /**
110  * @if Eng
111  * @brief  Get base address for SFC DMA registers.
112  * @retval Base address for SFC DMA registers.
113  * @else
114  * @brief  获取SFC DMA操作相关寄存器基地址。
115  * @retval SFC DMA操作相关寄存器基地址。
116  * @endif
117  */
118 uintptr_t sfc_port_get_sfc_bus_dma_regs_base_addr(void);
119 
120 /**
121  * @if Eng
122  * @brief  Get base address for SFC command registers.
123  * @retval Base address for SFC command registers.
124  * @else
125  * @brief  获取SFC SPI操作寄存器相关基地址。
126  * @retval SFC SPI操作寄存器相关基地址。
127  * @endif
128  */
129 uintptr_t sfc_port_get_sfc_cmd_regs_base_addr(void);
130 
131 /**
132  * @if Eng
133  * @brief  Get base address for SFC command data buffer registers.
134  * @retval Base address for SFC command data buffer registers.
135  * @else
136  * @brief  获取SFC SPI操作数据缓冲区寄存器基地址。
137  * @retval SFC SPI操作数据缓冲区寄存器基地址。
138  * @endif
139  */
140 uintptr_t sfc_port_get_sfc_cmd_databuf_base_addr(void);
141 
142 /**
143  * @if Eng
144  * @brief  Register hal funcs objects into hal_sfc module.
145  * @else
146  * @brief  将hal funcs对象注册到hal_sfc模块中。
147  * @endif
148  */
149 void sfc_port_register_hal_funcs(void);
150 
151 /**
152  * @if Eng
153  * @brief  Unregister hal funcs objects from hal_sfc module.
154  * @else
155  * @brief  从hal_sfc模块注销hal funcs对象。
156  * @endif
157  */
158 void sfc_port_unregister_hal_funcs(void);
159 
160 /**
161  * @if Eng
162  * @brief  Set the single delay time for querying the flash WIP bit.
163  * @param  [in]  delay_us Delay time for querying the flash WIP bit.
164  * @else
165  * @brief  设置查询Flash WIP位的单次延时时间。
166  * @param  [in]  delay_us 查询Flash WIP位的单次延时时间。
167  * @endif
168  */
169 void sfc_port_set_delay_once_time(uint32_t delay_us);
170 
171 /**
172  * @if Eng
173  * @brief  Get the single delay time for querying the flash WIP bit
174  * @retval single delay time for querying the flash WIP bit.The unit is us.
175  * @else
176  * @brief  获取查询Flash WIP位的单次延时时间
177  * @retval 查询Flash WIP位的单次延时时间,单位为us
178  * @endif
179  */
180 uint32_t sfc_port_get_delay_once_time(void);
181 
182 /**
183  * @if Eng
184  * @brief  Set delay times for querying the flash WIP bit
185  * @param  [in]  delay_times Delay times for querying the flash WIP bit
186  * @else
187  * @brief  配置查询Flash WIP位的延时次数
188  * @param  [in]  delay_times 查询Flash WIP位的延时次数
189  * @endif
190  */
191 void sfc_port_set_delay_times(uint32_t delay_times);
192 
193 /**
194  * @if Eng
195  * @brief  Get delay times for querying the flash WIP bit
196  * @retval delay times for querying the flash WIP bit
197  * @else
198  * @brief  获取查询Flash WIP位的延时次数
199  * @retval 查询Flash WIP位的延时次数
200  * @endif
201  */
202 uint32_t sfc_port_get_delay_times(void);
203 
204 /**
205  * @if Eng
206  * @brief  sfc lock initialize.
207  * @else
208  * @brief  SFC锁初始化。
209  * @endif
210  */
211 void sfc_port_lock_init(void);
212 
213 /**
214  * @if Eng
215  * @brief  sfc lock.
216  * @retval lock status.
217  * @else
218  * @brief  SFC上锁。
219  * @retval 锁状态。
220  * @endif
221  */
222 uint32_t sfc_port_lock(void);
223 
224 /**
225  * @if Eng
226  * @brief  sfc unlock.
227  * @param [in] lock_sts lock status.
228  * @else
229  * @brief  SFC解锁。
230  * @param [in] lock_sts 锁状态,传入的为由lock接口返回的值
231  * @endif
232  */
233 void sfc_port_unlock(uint32_t lock_sts);
234 
235 #ifndef BUILD_NOOSAL
236 errcode_t hal_sfc_get_flash_id(uint32_t *flash_id);
237 #endif
238 
239 /**
240  * @}
241  */
242 
243 #ifdef __cplusplus
244 #if __cplusplus
245 }
246 #endif /* __cplusplus */
247 #endif /* __cplusplus */
248 #endif
249