• 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 flash config info header file.
16  *
17  * History:
18  * 2022-11-30, Create file.
19  */
20 
21 #ifndef FLASH_CONFIG_INFO_H
22 #define FLASH_CONFIG_INFO_H
23 
24 #include <stdint.h>
25 
26 #ifdef __cplusplus
27 #if __cplusplus
28 extern "C" {
29 #endif
30 #endif
31 
32 /**
33  * @ingroup  drivers_port_sfc
34  * @{
35  */
36 
37 #define EFLASH_CMD_LEN_MAX             4
38 #define SPI_CMD_SUPPORT                0x1
39 
40 #define FLASH_INFO_TABLE_SIZE g_flash_spi_info_num
41 /**
42  * @if Eng
43  * @brief  SPI instruction execution mode.
44  * @else
45  * @brief  表驱动执行Flash指令的指令格式
46  * @endif
47 */
48 typedef enum {
49     FLASH_CMD_TYPE_CMD,                      /*!<@if Eng Command for setting the flash attribute
50                                                  @else   设置flash属性类型的指令         @endif */
51     FLASH_CMD_TYPE_PROCESSING,               /*!<@if Eng Read the flash information and compares a certain bit.
52                                                  @else   读取Flash信息并比对某一位的值         @endif */
53     FLASH_CMD_TYPE_END,                      /*!<@if Eng Command end flag
54                                                  @else   指令结束标志         @endif */
55     FLASH_CMD_BUFF = 0xFF
56 } flash_cmd_type_t;
57 
58 /**
59  * @if Eng
60  * @brief  Parameters related to SPI read, write and erase operation.
61  * @else
62  * @brief  SPI读写擦操作相关参数
63  * @endif
64 */
65 typedef struct spi_opreation {
66     uint32_t cmd_support : 3;                /*!<@if Eng SPI command support
67                                                  @else   是否支持该索引对应的指令 @endif */
68     uint32_t cmd : 8;                        /*!<@if Eng SPI command
69                                                  @else   SPI指令码             @endif */
70     uint32_t iftype : 3;                     /*!<@if Eng SPI interface type
71                                                          value:
72                                                             000:Standard SPI
73                                                             001:Dual-Input/Dual-Output SPI(based on read/write)
74                                                             010:Dual-I/O SPI
75                                                             101:Quad-Input/Dual-Output SPI(based on read/write)
76                                                             110:Quad-I/O SPI
77                                                             other: reserved
78                                                  @else   SPI 接口类型
79                                                          合法值:
80                                                             000:标准单线SPI
81                                                             001:双线In/双线Out SPI(根据指令的读写模式调整)
82                                                             010:双线I/O SPI
83                                                             101:四线In/四线Out SPI(根据指令的读写模式调整)
84                                                             110:四线I/O SPI
85                                                             其他:保留 @endif */
86     uint32_t size : 18;                      /*!<@if Eng   erase size for erase and dummy byte for read.
87                                                  @else     擦除指令的大小和读指令的dummy字节数     @endif */
88 } spi_opreation_t;
89 
90 /**
91  * @if Eng
92  * @brief  Command format for enabling the Quad SPI flash
93  * @else
94  * @brief  开启Flash的Quad SPI的指令格式
95  * @endif
96 */
97 typedef struct flash_cmd_execute_t {
98     flash_cmd_type_t cmd_type;               /*!<@if Eng For details, see @ref flash_cmd_type_t
99                                                  @else   参考 @ref flash_cmd_type_t @endif */
100     uint8_t cmd_len;                         /*!<@if Eng CMD mode : Length of the SPI command including 1byte data.
101                                                          PROCESSING mode : The value is fixed to 3.
102                                                  @else   CMD模式包含一字节数据在内的SPI指令长度。
103                                                          PROCESSING模式固定为3 @endif */
104     uint8_t cmd[EFLASH_CMD_LEN_MAX];         /*!<@if Eng SPI command. The format is as follows:
105                                                          CMD: cmd[0] command code.
106                                                               cmd[1] One-byte data.
107                                                          PROCESS: cmd[0] command code.
108                                                                   cmd[1] Expected Compare Bit.
109                                                                   cmd[2] Expected value of this bit.
110                                                  @else   SPI指令,格式如下
111                                                          CMD: cmd[0] 指令码
112                                                               cmd[1] 一字节数据
113                                                          PROCESS: cmd[0] 指令码
114                                                                   cmd[1] 预计比较的位
115                                                                   cmd[2] 该位预计的值 @endif */
116 } flash_cmd_execute_t;
117 
118 /**
119  * @if Eng
120  * @brief  Flash basic information struct
121  * @else
122  * @brief  Flash基本信息结构
123  * @endif
124 */
125 typedef struct flash_spi_info {
126     uint32_t chip_id;                        /*!<@if Eng Flash manufacture id.
127                                                  @else   Flash 制造id @endif */
128     uint32_t chip_size;                      /*!<@if Eng Actual size of flash
129                                                  @else   Flash实际大小 @endif */
130     uint32_t erase_cmd_num;                  /*!<@if Eng Number of erase commands
131                                                  @else   擦除指令的个数@endif */
132     spi_opreation_t *read_cmds;              /*!<@if Eng Read command form. index:@ref sfc_read_if_t.
133                                                  @else   读指令表单 索引 @ref sfc_read_if_t
134                                                  @endif */
135     spi_opreation_t *write_cmds;             /*!<@if Eng Write command form. index:@ref sfc_write_if_t.
136                                                  @else   写指令表单 索引 @ref sfc_write_if_t
137                                                  @endif */
138     spi_opreation_t *erase_cmds;             /*!<@if Eng Erase command form. Indexes are sorted by erase size in desc.
139                                                  @else   写指令表单 索引按照擦除大小降序排列
140                                                  @endif */
141     flash_cmd_execute_t *quad_mode;          /*!<@if Eng Enable Quad SPI Mode command Form. @ref flash_cmd_execute_t
142                                                  @else   开启四线模式指令表单 @ref flash_cmd_execute_t @endif */
143 } flash_spi_info_t;
144 
145 flash_spi_info_t *sfc_port_get_flash_spi_infos(void);
146 
147 uint32_t sfc_port_get_flash_num(void);
148 
149 flash_spi_info_t *sfc_port_get_unknown_flash_info(void);
150 
151 /**
152  * @}
153  */
154 
155 #ifdef __cplusplus
156 #if __cplusplus
157 }
158 #endif /* __cplusplus */
159 #endif /* __cplusplus */
160 #endif
161