MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / fal_flash_init

Function fal_flash_init

components/fal/src/fal_flash.c:36–81  ·  view source on GitHub ↗

* Initialize all flash device on FAL flash table * * @return result */

Source from the content-addressed store, hash-verified

34 * @return result
35 */
36int fal_flash_init(void)
37{
38 rt_size_t i, j, offset;
39
40 if (init_ok)
41 {
42 return 0;
43 }
44
45 for (i = 0; i < device_table_len; i++)
46 {
47 RT_ASSERT(device_table[i]->ops.read);
48 RT_ASSERT(device_table[i]->ops.write);
49 RT_ASSERT(device_table[i]->ops.erase);
50 /* init flash device on flash table */
51 if (device_table[i]->ops.init)
52 {
53 device_table[i]->ops.init();
54 }
55 LOG_D("Flash device | %*.*s | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.",
56 FAL_DEV_NAME_MAX, FAL_DEV_NAME_MAX, device_table[i]->name, device_table[i]->addr, device_table[i]->len,
57 device_table[i]->blk_size);
58 offset = 0;
59 for (j = 0; j < FAL_DEV_BLK_MAX; j ++)
60 {
61 const struct flash_blk *blk = &device_table[i]->blocks[j];
62 rt_size_t blk_len = blk->count * blk->size;
63 if (blk->count == 0 || blk->size == 0)
64 break;
65
66 if(offset > device_table[i]->len)
67 {
68 LOG_I("Flash device %*.*s: add block failed, offset %d > len %d.",
69 FAL_DEV_NAME_MAX, FAL_DEV_NAME_MAX, device_table[i]->name, device_table[i]->addr, offset, device_table[i]->len);
70 break;
71 }
72
73 LOG_D(" blk%2d | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.",
74 j, device_table[i]->addr + offset, blk_len, blk->size);
75 offset += blk_len;
76 }
77 }
78
79 init_ok = 1;
80 return 0;
81}
82
83/**
84 * find flash device by name

Callers 1

fal_initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected