-
Notifications
You must be signed in to change notification settings - Fork 0
/
fs.c
65 lines (49 loc) · 1.85 KB
/
fs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "fs.h"
int pico_read(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size)
{
uint32_t fs_start = XIP_BASE + HW_FLASH_STORAGE_BASE;
uint32_t addr = fs_start + (block * c->block_size) + off;
// printf("[FS] READ: %p, %d\n", addr, size);
memcpy(buffer, (unsigned char *)addr, size);
return 0;
}
int pico_prog(const struct lfs_config *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size)
{
uint32_t fs_start = HW_FLASH_STORAGE_BASE;
uint32_t addr = fs_start + (block * c->block_size) + off;
// printf("[FS] WRITE: %p, %d\n", addr, size);
uint32_t ints = save_and_disable_interrupts();
flash_range_program(addr, (const uint8_t *)buffer, size);
restore_interrupts(ints);
return 0;
}
int pico_erase(const struct lfs_config *c, lfs_block_t block)
{
uint32_t fs_start = HW_FLASH_STORAGE_BASE;
uint32_t offset = fs_start + (block * c->block_size);
// printf("[FS] ERASE: %p, %d\n", offset, block);
uint32_t ints = save_and_disable_interrupts();
flash_range_erase(offset, c->block_size);
restore_interrupts(ints);
return 0;
}
int pico_sync(const struct lfs_config *c)
{
return 0;
}
// configuration of the filesystem is provided by this struct
const struct lfs_config PICO_FLASH_CFG = {
// block device operations
.read = &pico_read,
.prog = &pico_prog,
.erase = &pico_erase,
.sync = &pico_sync,
// block device configuration
.read_size = FLASH_PAGE_SIZE, // 256
.prog_size = FLASH_PAGE_SIZE, // 256
.block_size = BLOCK_SIZE_BYTES, // 4096
.block_count = HW_FLASH_STORAGE_BYTES / BLOCK_SIZE_BYTES, // 352
.block_cycles = 16, // ?
.cache_size = FLASH_PAGE_SIZE, // 256
.lookahead_size = FLASH_PAGE_SIZE, // 256
};