Mistake on this page?
Report an issue in GitHub or email us
wland_flash.h
1 /* Copyright (c) 2019 Unisoc Communications Inc.
2  * SPDX-License-Identifier: Apache-2.0
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _WLAND_FLASH_H_
18 #define _WLAND_FLASH_H_
19 #include "wland_types.h"
20 #include "rda5981_flash.h"
21 #include "rda_ccfg_api.h"
22 
23 //#define FLASH_READ_CHECK
24 
25 #ifndef min
26 #define min(a, b) ((a)<(b)?(a):(b))
27 #endif /*min*/
28 
29 /** This struct contains all smartconfig mbed flash parameter. */
30 typedef struct
31 {
32  char ssid[36];
33  char key[64];
35 
36 /** This struct contains ap data, include ssid key and channel. */
37 typedef struct
38 {
39  u8 channel;
40  char ssid[35];
41  char key[64];
43 
44 /** This struct contains ap net data. */
45 typedef struct
46 {
47  u32 ip;
48  u32 msk;
49  u32 gw;
50  u32 dhcps;
51  u32 dhcpe;
53 
54 typedef struct
55 {
56  u32 fixip;
57  u32 ip;
58  u32 msk;
59  u32 gw;
60 } wland_dhcp_t;
61 
62 #define RDA5991H_USER_DATA_FLAG_UNINITIALIZED (0xFFFFFFFF & \
63  (~(RDA5991H_USER_DATA_FLAG_MAC | \
64  RDA5991H_USER_DATA_FLAG_STA | \
65  RDA5991H_USER_DATA_FLAG_PMK | \
66  RDA5991H_USER_DATA_FLAG_IP | \
67  RDA5991H_USER_DATA_FLAG_PARTER_DATA_LEN | \
68  RDA5991H_USER_DATA_FLAG_TX_POWER | \
69  RDA5991H_USER_DATA_FLAG_XTAL_CAL | \
70  RDA5991H_USER_DATA_FLAG_TX_POWER_RF | \
71  RDA5991H_USER_DATA_FLAG_TX_POWER_PHY_GN | \
72  RDA5991H_USER_DATA_FLAG_TX_POWER_PHY_B | \
73  RDA5991H_USER_DATA_FLAG_AP | \
74  RDA5991H_USER_DATA_FLAG_APNET | \
75  RDA5991H_USER_DATA_FLAG_DHCP | \
76  RDA5991H_USER_DATA_FLAG_UART | \
77  RDA5991H_USER_DATA_FLAG_RF | \
78  RDA5991H_USER_DATA_FLAG_RF_CHANNELS | \
79  RDA5991H_USER_DATA_FLAG_PHY | \
80  RDA5991H_USER_DATA_FLAG_PHY_CHANNELS | \
81  RDA5991H_USER_DATA_FLAG_TX_POWER_OFFSET)))
82 
83 #define RDA5991H_USER_DATA_IP_LENGTH 8
84 
85 #define RDA5981_FLAG_FLAG "RDA5981"
86 
87 typedef struct
88 {
89  u32 flag;
90  u8 rda5981_flag[8];
91  u8 mac_addr[6];
92  u8 tp_offset;
93  u8 padding1;//alignment
94  wland_sta_data_t sta_data;
95  u8 pmk[32];
96  u8 ip[RDA5991H_USER_DATA_IP_LENGTH];
97  u32 parter_data_len;
98  wland_tx_power_t tx_power;
99  u16 xtal_cal;
100  u8 padding2[2];//alignment
101  u16 tx_power_rf[14];
102  u8 tx_power_phy_gn;
103  u8 tx_power_phy_b;
104  u8 padding3[2];
105  wland_ap_data_t ap_data;
106  wland_ap_net_data_t ap_net_data;
107  wland_dhcp_t dhcp;
108  u32 uart;
109  wland_rf_t rf;
110  wland_rf_channels_t rf_channels;
111  wland_phy_t phy;
112  wland_phy_channels_t phy_channels;
114 
115 #define SECTOR_SIZE 4096
116 #define FLASH_SIZE 0x100000
117 
118 #define RDA5991H_PARTITION_TABLE_END_ADDR 0x18001000 //partition table end addr
119 
120 #define RDA5991H_USER_DATA_ADDR 0x180fb000 //4k(partition table)+500k+500k:
121 #define RDA5991H_3RDPARTER_DATA_ADDR 0x180fc000
122 #define RDA5991H_3RDPARTER_DATA_LEN 0x1000
123 
124 #define FLASH_CTL_REG_BASE 0x17fff000
125 #define FLASH_CTL_TX_CMD_ADDR_REG (FLASH_CTL_REG_BASE + 0x00)
126 #define CMD_64KB_BLOCK_ERASE (0x000000d8UL)
127 #define WRITE_REG32(REG, VAL) ((*(volatile unsigned int*)(REG)) = (unsigned int)(VAL))
128 
129 #define FLASH_ERASE_FUN_ADDR 0x21f1//smartlink_erase_for_mbed
130 #define FLASH_WRITE_FUN_ADDR 0x2241//smartlink_write_for_mbed
131 #define FLASH_READ_FUN_ADDR 0x2243//smartlink_read_for_mbed
132 #define FLASH_ERASE_PARTITION_FUN_ADDR 0x2139//spi_flash_erase_partition
133 #define SPI_FLASH_READ_DATA_FOR_MBED_ADDR 0x2007//spi_flash_read_data_for_mbed
134 #define spi_flash_disable_cache_addr 0x1eb7//spi_flash_disable_cache
135 #define spi_flash_flush_cache_addr 0x1ecd//spi_flash_flush_cache
136 #define spi_flash_cfg_cache_addr 0x1e9f//spi_flash_cfg_cache
137 #define spi_flash_erase_4KB_sector_addr 0x23a3
138 #define spi_wip_reset_addr 0x1d8b
139 #define spi_write_reset_addr 0x1d9f
140 #define wait_busy_down_addr 0x1d81
141 
142 #define FLASH_ERASE_FUN_ADDR_4 0x2221//smartlink_erase_for_mbed
143 #define FLASH_WRITE_FUN_ADDR_4 0x2271//smartlink_write_for_mbed
144 #define FLASH_READ_FUN_ADDR_4 0x2273//smartlink_read_for_mbed
145 #define FLASH_ERASE_PARTITION_FUN_ADDR_4 0x2169//spi_flash_erase_partition
146 #define SPI_FLASH_READ_DATA_FOR_MBED_ADDR_4 0x2037//spi_flash_read_data_for_mbed
147 #define spi_flash_disable_cache_addr_4 0x1ee7//spi_flash_disable_cache
148 #define spi_flash_flush_cache_addr_4 0x1efd//spi_flash_flush_cache
149 #define spi_flash_cfg_cache_addr_4 0x1ecf//spi_flash_cfg_cache
150 #define spi_flash_erase_4KB_sector_addr_4 0x23d3
151 #define spi_wip_reset_addr_4 0x1dbb
152 #define spi_write_reset_addr_4 0x1dcf
153 #define wait_busy_down_addr_4 0x1db1
154 
155 /*
156  * return 0 if find
157  */
158 int rda5981_flash_read_pmk(u8 *pmk);
159 int rda5981_flash_read_sta_data(char *ssid, char *passwd);
160 void rda5981_spi_erase_partition(void *src, u32 counts);
161 
162 //@len must be 4k aligment
163 //int rda5981_write_flash(u32 addr, char *buf, u32 len);
164 //int rda5981_read_flash(u32 addr, char *buf, u32 len);
165 
166 #define VERSION_SZ 24
168 {
169  u32 magic;
170  u8 version[VERSION_SZ];
171 
172  u32 addr;
173  u32 size;
174  u32 crc32;
175  u32 bootaddr;//add for rf_test
176  u32 bootmagic;
177 };
178 
179 #define RDA5981_FIRMWARE_MAGIC 0xEAEA
180 
181 static inline void wait_busy_down_2(void)
182 {
183  ((void(*)(void))wait_busy_down_addr)();
184 }
185 
186 static inline void spi_write_reset_2(void)
187 {
188  ((void(*)(void))spi_write_reset_addr)();
189 }
190 
191 static inline void spi_wip_reset_2(void)
192 {
193  ((void(*)(void))spi_wip_reset_addr)();
194 }
195 
196 static inline void wait_busy_down_4(void)
197 {
198  ((void(*)(void))wait_busy_down_addr_4)();
199 }
200 
201 static inline void spi_write_reset_4(void)
202 {
203  ((void(*)(void))spi_write_reset_addr_4)();
204 }
205 
206 static inline void spi_wip_reset_4(void)
207 {
208  ((void(*)(void))spi_wip_reset_addr_4)();
209 }
210 
211 static void wait_busy_down(void)
212 {
213  if (rda_ccfg_hwver() >= 4) {
214  wait_busy_down_4();
215  } else {
216  wait_busy_down_2();
217  }
218 }
219 
220 static void spi_write_reset(void)
221 {
222  if (rda_ccfg_hwver() >= 4) {
223  spi_write_reset_4();
224  } else {
225  spi_write_reset_2();
226  }
227 }
228 
229 static void spi_wip_reset(void)
230 {
231  if (rda_ccfg_hwver() >= 4) {
232  spi_wip_reset_4();
233  } else {
234  spi_wip_reset_2();
235  }
236 }
237 
238 static inline void spi_flash_enable_cache(void)
239 {
240  unsigned int func = spi_flash_cfg_cache_addr;
241  if (rda_ccfg_hwver() >= 4) {
242  func = spi_flash_cfg_cache_addr_4;
243  }
244  ((void(*)(void))func)();
245 }
246 
247 static inline void spi_flash_disable_cache(void)
248 {
249  unsigned int func = spi_flash_disable_cache_addr;
250  if (rda_ccfg_hwver() >= 4) {
251  func = spi_flash_disable_cache_addr_4;
252  }
253  ((void(*)(void))func)();
254 }
255 
256 static inline void spi_flash_flush_cache(void)
257 {
258  unsigned int func = spi_flash_flush_cache_addr;
259  if (rda_ccfg_hwver() >= 4) {
260  func = spi_flash_flush_cache_addr_4;
261  }
262  ((void(*)(void))func)();
263 }
264 
265 static inline void rda5981_spi_flash_erase_4KB_sector(u32 addr)
266 {
267  unsigned int func = spi_flash_erase_4KB_sector_addr;
268  if (rda_ccfg_hwver() >= 4) {
269  func = spi_flash_erase_4KB_sector_addr_4;
270  }
271  ((void(*)(u32))func)(addr);
272 }
273 
274 static inline void RDA5991H_ERASE_FLASH(void *addr, u32 len)
275 {
276  unsigned int func = FLASH_ERASE_FUN_ADDR;
277  if (rda_ccfg_hwver() >= 4) {
278  func = FLASH_ERASE_FUN_ADDR_4;
279  }
280  ((void(*)(void *, u32))func)(addr, len);
281 }
282 
283 static inline void RDA5991H_WRITE_FLASH(u32 addr, u8 *data, u32 len)
284 {
285  unsigned int func = FLASH_WRITE_FUN_ADDR;
286  if (rda_ccfg_hwver() >= 4) {
287  func = FLASH_WRITE_FUN_ADDR_4;
288  }
289  ((void(*)(u32, u8 *, u32))func)(addr, data, len);
290 }
291 
292 static inline void RDA5991H_READ_FLASH(u32 addr, u8 *buf, u32 len)
293 {
294  unsigned int func = FLASH_READ_FUN_ADDR;
295  if (rda_ccfg_hwver() >= 4) {
296  func = FLASH_READ_FUN_ADDR_4;
297  }
298  ((void(*)(u32, u8 *, u32))func)(addr, buf, len);
299 }
300 
301 static inline void SPI_FLASH_READ_DATA_FOR_MBED(void *addr, void *buf, u32 len)
302 {
303  unsigned int func = SPI_FLASH_READ_DATA_FOR_MBED_ADDR;
304  if (rda_ccfg_hwver() >= 4) {
305  func = SPI_FLASH_READ_DATA_FOR_MBED_ADDR_4;
306  }
307  ((void(*)(void *, void *, u32))func)(buf, addr, len);
308 }
309 
310 #endif /*_WLAND_FLASH_H_*/
311 
This struct contains ap data, include ssid key and channel.
Definition: wland_flash.h:37
This struct contains all smartconfig mbed flash parameter.
Definition: wland_flash.h:30
This struct contains tx power parameter.
Definition: rda5981_flash.h:23
This struct contains ap net data.
Definition: wland_flash.h:45
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.