24
24
25
25
extern " C"
26
26
{
27
- uint32_t mock_spiffs_phys_addr = 0 ;
28
- uint32_t mock_spiffs_phys_size = 0 ;
29
- uint32_t mock_spiffs_phys_page = 0 ;
30
- uint32_t mock_spiffs_phys_block = 0 ;
31
- uint8_t * mock_spiffs_phys_data = nullptr ;
27
+ static uint32_t s_phys_addr = 0 ;
28
+ uint32_t s_phys_size = 0 ;
29
+ uint32_t s_phys_page = 0 ;
30
+ uint32_t s_phys_block = 0 ;
31
+ uint8_t * s_phys_data = nullptr ;
32
32
}
33
33
34
34
FS SPIFFS (nullptr );
35
35
36
-
37
-
38
36
SpiffsMock::SpiffsMock (size_t fs_size, size_t fs_block, size_t fs_page)
39
37
{
40
38
m_fs.resize (fs_size, 0xff );
41
- mock_spiffs_phys_addr = 0 ;
42
- mock_spiffs_phys_size = fs_size;
43
- mock_spiffs_phys_page = fs_page;
44
- mock_spiffs_phys_block = fs_block;
45
- mock_spiffs_phys_data = m_fs.data ();
46
- SPIFFS = FS (FSImplPtr (new SPIFFSImpl (0 , fs_size, fs_page, fs_block, 5 )));
39
+ s_phys_addr = 0 ;
40
+ s_phys_size = static_cast <uint32_t >(fs_size);
41
+ s_phys_page = static_cast <uint32_t >(fs_page);
42
+ s_phys_block = static_cast <uint32_t >(fs_block);
43
+ s_phys_data = m_fs.data ();
44
+ reset ();
45
+ }
46
+
47
+ void SpiffsMock::reset ()
48
+ {
49
+ SPIFFS = FS (FSImplPtr (new SPIFFSImpl (0 , s_phys_size, s_phys_page, s_phys_block, 5 )));
47
50
}
48
51
49
52
SpiffsMock::~SpiffsMock ()
50
53
{
51
- mock_spiffs_phys_addr = 0 ;
52
- mock_spiffs_phys_size = 0 ;
53
- mock_spiffs_phys_page = 0 ;
54
- mock_spiffs_phys_block = 0 ;
55
- mock_spiffs_phys_data = nullptr ;
54
+ s_phys_addr = 0 ;
55
+ s_phys_size = 0 ;
56
+ s_phys_page = 0 ;
57
+ s_phys_block = 0 ;
58
+ s_phys_data = nullptr ;
56
59
SPIFFS = FS (FSImplPtr (nullptr ));
57
60
}
58
61
59
- /*
60
- spi_flash_read function requires flash address to be aligned on word boundary.
61
- We take care of this by reading first and last words separately and memcpy
62
- relevant bytes into result buffer.
63
-
64
- alignment: 012301230123012301230123
65
- bytes requested: -------***********------
66
- read directly: --------xxxxxxxx--------
67
- read pre: ----aaaa----------------
68
- read post: ----------------bbbb----
69
- alignedBegin: ^
70
- alignedEnd: ^
71
- */
72
-
73
62
int32_t spiffs_hal_read (uint32_t addr, uint32_t size, uint8_t *dst) {
74
- memcpy (dst, mock_spiffs_phys_data + addr, size);
63
+ memcpy (dst, s_phys_data + addr, size);
75
64
return SPIFFS_OK;
76
65
}
77
66
78
- /*
79
- Like spi_flash_read, spi_flash_write has a requirement for flash address to be
80
- aligned. However it also requires RAM address to be aligned as it reads data
81
- in 32-bit words. Flash address (mis-)alignment is handled much the same way
82
- as for reads, but for RAM alignment we have to copy data into a temporary
83
- buffer. The size of this buffer is a tradeoff between number of writes required
84
- and amount of stack required. This is chosen to be 512 bytes here, but might
85
- be adjusted in the future if there are good reasons to do so.
86
- */
87
-
88
67
int32_t spiffs_hal_write (uint32_t addr, uint32_t size, uint8_t *src) {
89
- memcpy (mock_spiffs_phys_data + addr, src, size);
68
+ memcpy (s_phys_data + addr, src, size);
90
69
return SPIFFS_OK;
91
70
}
92
71
@@ -98,7 +77,7 @@ int32_t spiffs_hal_erase(uint32_t addr, uint32_t size) {
98
77
const uint32_t sector = addr / FLASH_SECTOR_SIZE;
99
78
const uint32_t sectorCount = size / FLASH_SECTOR_SIZE;
100
79
for (uint32_t i = 0 ; i < sectorCount; ++i) {
101
- memset (mock_spiffs_phys_data + (sector + i) * FLASH_SECTOR_SIZE, 0xff , FLASH_SECTOR_SIZE);
80
+ memset (s_phys_data + (sector + i) * FLASH_SECTOR_SIZE, 0xff , FLASH_SECTOR_SIZE);
102
81
}
103
82
return SPIFFS_OK;
104
83
}
0 commit comments