Skip to content

Commit 7654a70

Browse files
committed
board: iotdk: code clean up, optimization and bug fixes
* code cleanup * code style * comments * unused codes * optimizations * flash driver * bug fixes * flash driver Signed-off-by: Watson Zeng <[email protected]>
1 parent 31e4196 commit 7654a70

File tree

11 files changed

+153
-161
lines changed

11 files changed

+153
-161
lines changed

board/iotdk/configs/10/iotdk_hardware.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#define BOARD_DFSS_AHB_CLK (BOARD_DFSS_CORE_CLK) /* iotdk top-level AHB peripherals clock as DFSS */
4242
#define BOARD_DFSS_APB_CLK (BOARD_DFSS_CORE_CLK) /* iotdk top-level APB peripherals clock as DFSS */
4343
#define BOARD_APB_CLK (BOARD_DFSS_APB_CLK) /* iotdk top-level APB peripherals clock */
44-
#define BOARD_SPI_CLK (100000000U) /* iotdk SPI clock*/
44+
#define BOARD_SPI_CLK (BOARD_DFSS_AHB_CLK) /* iotdk SPI clock*/
4545

4646
/* CPU clock frequency definition */
4747
#ifdef BOARD_DFSS_CORE_CLK

board/iotdk/drivers/flash_obj/flash_obj.c

Lines changed: 40 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,26 @@
4040

4141
#define DW_FLASH_CHECK_EXP(EXPR, ERROR_CODE) CHECK_EXP(EXPR, ercd, ERROR_CODE, error_exit)
4242

43-
void iotdk_flash_obj_all_install(void);
44-
4543
#if (USE_IOTDK_EFLASH)
4644
static DEV_FLASH iotdk_eflash_obj;
47-
EFLASH_DEFINE(eflash, EFLASH_CRTL_BASE);
45+
EFLASH_DEFINE(eflash, EFLASH_CTRL_BASE);
4846

49-
static int32_t iotdk_eflash_open()
47+
static int32_t iotdk_eflash_open(void)
5048
{
5149
int32_t ercd = E_OK;
5250
DEV_FLASH_PTR obj_ptr = &iotdk_eflash_obj;
5351
DEV_FLASH_INFO_PTR info_ptr = &(obj_ptr->flash_info);
52+
5453
DW_FLASH_CHECK_EXP(info_ptr->open_cnt == 0, E_OPNED);
54+
5555
info_ptr->open_cnt++;
56-
smic_eflash_open(eflash);
56+
ercd = smic_eflash_open(eflash);
5757

5858
error_exit:
5959
return ercd;
6060
}
6161

62-
static int32_t iotdk_eflash_close()
62+
static int32_t iotdk_eflash_close(void)
6363
{
6464
int32_t ercd = E_OK;
6565
DEV_FLASH_PTR obj_ptr = &iotdk_eflash_obj;
@@ -68,13 +68,12 @@ static int32_t iotdk_eflash_close()
6868
DW_FLASH_CHECK_EXP(info_ptr->open_cnt != 0, E_OK);
6969

7070
info_ptr->open_cnt--;
71-
smic_eflash_close(eflash);
71+
ercd = smic_eflash_close(eflash);
7272

7373
error_exit:
7474
return ercd;
7575
}
7676

77-
7877
static int32_t iotdk_eflash_control(uint32_t cmd, void *param)
7978
{
8079
int32_t ercd = E_OK;
@@ -90,19 +89,18 @@ static int32_t iotdk_eflash_control(uint32_t cmd, void *param)
9089
break;
9190

9291
case FLASH_CMD_PAGE_ERASE:
93-
smic_eflash_control(eflash, SMIC_EFLASH_PAGE_ERASE, param);
92+
ercd = smic_eflash_control(eflash, SMIC_EFLASH_PAGE_ERASE, param);
9493
break;
9594

9695
case FLASH_CMD_CHIP_ERASE:
97-
smic_eflash_control(eflash, SMIC_EFLASH_MACRO_ERASE, param);
96+
ercd = smic_eflash_control(eflash, SMIC_EFLASH_MACRO_ERASE, param);
9897
break;
9998

10099
default:
100+
ercd = E_NOSPT;
101101
break;
102102
}
103103

104-
105-
106104
error_exit:
107105
return ercd;
108106
}
@@ -120,9 +118,7 @@ static int32_t iotdk_eflash_read(uint32_t addr, void *dst, uint32_t len)
120118
len = info_ptr->begin_addr + info_ptr->total_size - len;
121119
}
122120

123-
smic_eflash_read(eflash, addr, len, dst);
124-
125-
return len;
121+
ercd = smic_eflash_read(eflash, addr, len, dst);
126122

127123
error_exit:
128124
return ercd;
@@ -141,9 +137,7 @@ static int32_t iotdk_eflash_write(uint32_t addr, void *src, uint32_t len)
141137
len = info_ptr->begin_addr + info_ptr->total_size - len;
142138
}
143139

144-
smic_eflash_write(eflash, addr, len, src);
145-
146-
return len;
140+
ercd = smic_eflash_write(eflash, addr, len, src);
147141

148142
error_exit:
149143
return ercd;
@@ -162,9 +156,7 @@ static int32_t iotdk_eflash_write_nocheck(uint32_t addr, void *src, uint32_t len
162156
len = info_ptr->begin_addr + info_ptr->total_size - len;
163157
}
164158

165-
smic_eflash_write_nocheck(eflash, addr, len, src);
166-
167-
return len;
159+
ercd = smic_eflash_write_nocheck(eflash, addr, len, src);
168160

169161
error_exit:
170162
return ercd;
@@ -183,13 +175,12 @@ static int32_t iotdk_eflash_erase(uint32_t addr, uint32_t len)
183175
len = info_ptr->begin_addr + info_ptr->total_size - len;
184176
}
185177

186-
smic_eflash_erase(eflash, addr, len);
187-
188-
return len;
178+
ercd = smic_eflash_erase(eflash, addr, len);
189179

190180
error_exit:
191181
return ercd;
192182
}
183+
193184
static void iotdk_eflash_install(void)
194185
{
195186
DEV_FLASH_PTR obj_ptr = &iotdk_eflash_obj;
@@ -214,30 +205,33 @@ static void iotdk_eflash_install(void)
214205

215206
#if (USE_IOTDK_BOOT_SPI_FLASH)
216207
static DEV_FLASH iotdk_bootspi_obj;
217-
BOOTSPI_DEFINE(bootspi, BOOTSPI_CRTL_BASE);
208+
BOOTSPI_DEFINE(bootspi, BOOTSPI_CTRL_BASE);
218209

219-
static int32_t iotdk_bootspi_open()
210+
static int32_t iotdk_bootspi_open(void)
220211
{
221212
int32_t ercd = E_OK;
222213
DEV_FLASH_PTR obj_ptr = &iotdk_bootspi_obj;
223214
DEV_FLASH_INFO_PTR info_ptr = &(obj_ptr->flash_info);
215+
224216
DW_FLASH_CHECK_EXP(info_ptr->open_cnt == 0, E_OPNED);
217+
225218
info_ptr->open_cnt++;
226-
smic_bootspi_open(bootspi);
219+
ercd = smic_bootspi_open(bootspi);
227220

228221
error_exit:
229222
return ercd;
230223
}
231224

232-
static int32_t iotdk_bootspi_close()
225+
static int32_t iotdk_bootspi_close(void)
233226
{
234227
int32_t ercd = E_OK;
235228
DEV_FLASH_PTR obj_ptr = &iotdk_bootspi_obj;
236229
DEV_FLASH_INFO_PTR info_ptr = &(obj_ptr->flash_info);
230+
237231
DW_FLASH_CHECK_EXP(info_ptr->open_cnt != 0, E_OK);
238232

239233
info_ptr->open_cnt--;
240-
smic_bootspi_close(bootspi);
234+
ercd = smic_bootspi_close(bootspi);
241235

242236
error_exit:
243237
return ercd;
@@ -258,19 +252,18 @@ static int32_t iotdk_bootspi_control(uint32_t cmd, void *param)
258252
break;
259253

260254
case FLASH_CMD_PAGE_ERASE:
261-
smic_bootspi_control(bootspi, SMIC_BOOTSPI_SEC_ERASE, param);
255+
ercd = smic_bootspi_control(bootspi, SMIC_BOOTSPI_SEC_ERASE, param);
262256
break;
263257

264258
case FLASH_CMD_CHIP_ERASE:
265-
smic_bootspi_control(bootspi, SMIC_BOOTSPI_CHIP_ERASE, param);
259+
ercd = smic_bootspi_control(bootspi, SMIC_BOOTSPI_CHIP_ERASE, param);
266260
break;
267261

268262
default:
263+
ercd = E_NOSPT;
269264
break;
270265
}
271266

272-
273-
274267
error_exit:
275268
return ercd;
276269
}
@@ -288,9 +281,8 @@ static int32_t iotdk_bootspi_read(uint32_t addr, void *dst, uint32_t len)
288281
len = info_ptr->begin_addr + info_ptr->total_size - len;
289282
}
290283
addr -= info_ptr->begin_addr;
291-
smic_bootspi_read(bootspi, addr, len, dst);
292284

293-
return len;
285+
ercd = smic_bootspi_read(bootspi, addr, len, dst);
294286

295287
error_exit:
296288
return ercd;
@@ -309,9 +301,7 @@ static int32_t iotdk_bootspi_write(uint32_t addr, void *src, uint32_t len)
309301
len = info_ptr->begin_addr + info_ptr->total_size - len;
310302
}
311303
addr -= info_ptr->begin_addr;
312-
smic_bootspi_write(bootspi, addr, len, src);
313-
314-
return len;
304+
ercd = smic_bootspi_write(bootspi, addr, len, src);
315305

316306
error_exit:
317307
return ercd;
@@ -330,9 +320,7 @@ static int32_t iotdk_bootspi_write_nocheck(uint32_t addr, void *src, uint32_t le
330320
len = info_ptr->begin_addr + info_ptr->total_size - len;
331321
}
332322
addr -= info_ptr->begin_addr;
333-
smic_bootspi_write_nocheck(bootspi, addr, len, src);
334-
335-
return len;
323+
ercd = smic_bootspi_write_nocheck(bootspi, addr, len, src);
336324

337325
error_exit:
338326
return ercd;
@@ -351,13 +339,12 @@ static int32_t iotdk_bootspi_erase(uint32_t addr, uint32_t len)
351339
len = info_ptr->begin_addr + info_ptr->total_size - len;
352340
}
353341
addr -= info_ptr->begin_addr;
354-
smic_bootspi_erase(bootspi, addr, len);
355-
356-
return len;
342+
ercd = smic_bootspi_erase(bootspi, addr, len);
357343

358344
error_exit:
359345
return ercd;
360346
}
347+
361348
static void iotdk_bootspi_install(void)
362349
{
363350
DEV_FLASH_PTR obj_ptr = &iotdk_bootspi_obj;
@@ -380,7 +367,16 @@ static void iotdk_bootspi_install(void)
380367
}
381368
#endif
382369

370+
static void iotdk_flash_obj_all_install(void)
371+
{
372+
#if (USE_IOTDK_EFLASH)
373+
iotdk_eflash_install();
374+
#endif
383375

376+
#if (USE_IOTDK_BOOT_SPI_FLASH)
377+
iotdk_bootspi_install();
378+
#endif
379+
}
384380

385381
DEV_FLASH_PTR flash_get_dev(int32_t flash_id)
386382
{
@@ -409,15 +405,3 @@ DEV_FLASH_PTR flash_get_dev(int32_t flash_id)
409405
}
410406
return NULL;
411407
}
412-
413-
414-
void iotdk_flash_obj_all_install(void)
415-
{
416-
#if (USE_IOTDK_EFLASH)
417-
iotdk_eflash_install();
418-
#endif
419-
420-
#if (USE_IOTDK_BOOT_SPI_FLASH)
421-
iotdk_bootspi_install();
422-
#endif
423-
}

board/iotdk/drivers/sdcard/sdcard_sdio.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ static FS_SDCARD_SDIO_CTRL sdcard_sdio0 = {
5858
.drv_status = STA_NOINIT
5959
};
6060

61-
6261
static int32_t sdcard_sdio_0_diskio_initialize(void)
6362
{
6463
sdcard_sdio0.host = (void *)sdio_get_dev(SDCARD_SDIO_ID);

board/iotdk/drivers/smic/smic_adc/smic_adc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,4 @@ int32_t smic_adc_int_isr(SMIC_ADC_DEF_PTR obj, void *ptr)
215215

216216
error_exit:
217217
return ercd;
218-
}
218+
}

board/iotdk/drivers/smic/smic_adc/smic_adc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@ extern int32_t smic_adc_int_isr(SMIC_ADC_DEF_PTR obj, void *ptr);
113113
}
114114
#endif
115115

116-
#endif /* _SMIC_ADC_H_ */
116+
#endif /* _SMIC_ADC_H_ */

0 commit comments

Comments
 (0)