Skip to content

Commit 206fae0

Browse files
committed
[fal] using rt-thread raw API instead of std API
1 parent d9c16ef commit 206fae0

File tree

8 files changed

+89
-138
lines changed

8 files changed

+89
-138
lines changed

components/fal/Kconfig

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ menuconfig RT_USING_FAL
55
default n
66

77
if RT_USING_FAL
8-
config FAL_DEBUG_CONFIG
8+
config FAL_USING_DEBUG
99
bool "Enable debug log output"
10-
default y
11-
12-
config FAL_DEBUG
13-
int
14-
default 1 if FAL_DEBUG_CONFIG
15-
default 0
10+
default y if RT_USING_DEBUG
11+
default n
1612

1713
config FAL_PART_HAS_TABLE_CFG
1814
bool "FAL partition table config has defined on 'fal_cfg.h'"

components/fal/inc/fal_def.h

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,13 @@
1515
#include <stdio.h>
1616
#include <rtthread.h>
1717

18-
#define FAL_PRINTF rt_kprintf
19-
#define FAL_MALLOC rt_malloc
20-
#define FAL_CALLOC rt_calloc
21-
#define FAL_REALLOC rt_realloc
22-
#define FAL_FREE rt_free
23-
24-
#ifndef FAL_DEBUG
25-
#define FAL_DEBUG 0
26-
#endif
27-
28-
#if FAL_DEBUG
29-
#ifdef assert
30-
#undef assert
31-
#endif
32-
#define assert(EXPR) \
33-
if (!(EXPR)) \
34-
{ \
35-
FAL_PRINTF("(%s) has assert failed at %s.\n", #EXPR, __FUNCTION__); \
36-
while (1); \
37-
}
38-
39-
/* debug level log */
40-
#ifdef log_d
41-
#undef log_d
42-
#endif
43-
#define log_d(...) FAL_PRINTF("[D/FAL] (%s:%d) ", __FUNCTION__, __LINE__); FAL_PRINTF(__VA_ARGS__);FAL_PRINTF("\n")
44-
18+
#define DBG_TAG "FAL"
19+
#ifdef FAL_USING_DEBUG
20+
#define DBG_LVL DBG_LOG
4521
#else
46-
47-
#ifdef assert
48-
#undef assert
49-
#endif
50-
#define assert(EXPR) ((void)0);
51-
52-
/* debug level log */
53-
#ifdef log_d
54-
#undef log_d
55-
#endif
56-
#define log_d(...)
57-
#endif /* FAL_DEBUG */
58-
59-
/* error level log */
60-
#ifdef log_e
61-
#undef log_e
62-
#endif
63-
#define log_e(...) FAL_PRINTF("\033[31;22m[E/FAL] (%s:%d) ", __FUNCTION__, __LINE__);FAL_PRINTF(__VA_ARGS__);FAL_PRINTF("\033[0m\n")
64-
65-
/* info level log */
66-
#ifdef log_i
67-
#undef log_i
22+
#define DBG_LVL DBG_INFO
6823
#endif
69-
#define log_i(...) FAL_PRINTF("\033[32;22m[I/FAL] "); FAL_PRINTF(__VA_ARGS__);FAL_PRINTF("\033[0m\n")
24+
#include <rtdbg.h>
7025

7126
/* FAL flash and partition device name max length */
7227
#ifndef FAL_DEV_NAME_MAX

components/fal/samples/porting/fal_flash_sfud_port.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ static int init(void)
6262

6363
static int read(long offset, uint8_t *buf, size_t size)
6464
{
65-
assert(sfud_dev);
66-
assert(sfud_dev->init_ok);
65+
RT_ASSERT(sfud_dev);
66+
RT_ASSERT(sfud_dev->init_ok);
6767
sfud_read(sfud_dev, nor_flash0.addr + offset, size, buf);
6868

6969
return size;
7070
}
7171

7272
static int write(long offset, const uint8_t *buf, size_t size)
7373
{
74-
assert(sfud_dev);
75-
assert(sfud_dev->init_ok);
74+
RT_ASSERT(sfud_dev);
75+
RT_ASSERT(sfud_dev->init_ok);
7676
if (sfud_write(sfud_dev, nor_flash0.addr + offset, size, buf) != SFUD_SUCCESS)
7777
{
7878
return -1;
@@ -83,8 +83,8 @@ static int write(long offset, const uint8_t *buf, size_t size)
8383

8484
static int erase(long offset, size_t size)
8585
{
86-
assert(sfud_dev);
87-
assert(sfud_dev->init_ok);
86+
RT_ASSERT(sfud_dev);
87+
RT_ASSERT(sfud_dev->init_ok);
8888
if (sfud_erase(sfud_dev, nor_flash0.addr + offset, size) != SFUD_SUCCESS)
8989
{
9090
return -1;

components/fal/samples/porting/fal_flash_stm32f2_port.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static uint32_t stm32_get_sector(uint32_t address)
9797
* @return sector size
9898
*/
9999
static uint32_t stm32_get_sector_size(uint32_t sector) {
100-
assert(IS_FLASH_SECTOR(sector));
100+
RT_ASSERT(IS_FLASH_SECTOR(sector));
101101

102102
switch (sector) {
103103
case FLASH_Sector_0: return 16 * 1024;

components/fal/src/fal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ int fal_init(void)
4040
if ((result > 0) && (!init_ok))
4141
{
4242
init_ok = 1;
43-
log_i("RT-Thread Flash Abstraction Layer initialize success.");
43+
LOG_I("RT-Thread Flash Abstraction Layer initialize success.");
4444
}
4545
else if(result <= 0)
4646
{
4747
init_ok = 0;
48-
log_e("RT-Thread Flash Abstraction Layer initialize failed.");
48+
LOG_E("RT-Thread Flash Abstraction Layer initialize failed.");
4949
}
5050

5151
return result;

components/fal/src/fal_flash.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ int fal_flash_init(void)
3636

3737
for (i = 0; i < device_table_len; i++)
3838
{
39-
assert(device_table[i]->ops.read);
40-
assert(device_table[i]->ops.write);
41-
assert(device_table[i]->ops.erase);
39+
RT_ASSERT(device_table[i]->ops.read);
40+
RT_ASSERT(device_table[i]->ops.write);
41+
RT_ASSERT(device_table[i]->ops.erase);
4242
/* init flash device on flash table */
4343
if (device_table[i]->ops.init)
4444
{
4545
device_table[i]->ops.init();
4646
}
47-
log_d("Flash device | %*.*s | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.",
47+
LOG_D("Flash device | %*.*s | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.",
4848
FAL_DEV_NAME_MAX, FAL_DEV_NAME_MAX, device_table[i]->name, device_table[i]->addr, device_table[i]->len,
4949
device_table[i]->blk_size);
5050
offset = 0;
@@ -57,12 +57,12 @@ int fal_flash_init(void)
5757

5858
if(offset > device_table[i]->len)
5959
{
60-
log_i("Flash device %*.*s: add block failed, offset %d > len %d.",
60+
LOG_I("Flash device %*.*s: add block failed, offset %d > len %d.",
6161
FAL_DEV_NAME_MAX, FAL_DEV_NAME_MAX, device_table[i]->name, device_table[i]->addr, offset, device_table[i]->len);
6262
break;
6363
}
6464

65-
log_d(" blk%2d | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.",
65+
LOG_D(" blk%2d | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.",
6666
j, device_table[i]->addr + offset, blk_len, blk->size);
6767
offset += blk_len;
6868
}
@@ -82,8 +82,8 @@ int fal_flash_init(void)
8282
*/
8383
const struct fal_flash_dev *fal_flash_device_find(const char *name)
8484
{
85-
assert(init_ok);
86-
assert(name);
85+
RT_ASSERT(init_ok);
86+
RT_ASSERT(name);
8787

8888
size_t i;
8989

0 commit comments

Comments
 (0)