@@ -37,11 +37,19 @@ const CALIBRATION_PAGE_SIZE = FLASH_PAGE_SIZE;
37
37
// Temporary maintained state pointing to the next available chunk.
38
38
// TODO: Remove once nextAvailableChunk() is updated.
39
39
// Chosen by fair dice roll, guaranteed to be random.
40
- const FS_START_CHUNK = 0x2b ;
40
+ const FS_START_CHUNK = 0x01 ;
41
41
let FS_NEXT_AVAILABLE_CHUNK = FS_START_CHUNK ;
42
42
43
43
function fsIncreaseChunkIndex ( numberOfChunks : number ) : void {
44
44
FS_NEXT_AVAILABLE_CHUNK += numberOfChunks ;
45
+ const unusedMap = new MemoryMap ( ) ;
46
+ // Check if we are over the filesystem area
47
+ if (
48
+ chuckIndexAddress ( unusedMap , FS_NEXT_AVAILABLE_CHUNK ) >=
49
+ getEndAddress ( unusedMap )
50
+ ) {
51
+ throw new Error ( 'There is no more space in the file system.' ) ;
52
+ }
45
53
}
46
54
47
55
function resetFileSystem ( ) : void {
@@ -64,6 +72,7 @@ export function testResetFileSystem(): void {
64
72
* @returns Next available filesystem chunk.
65
73
*/
66
74
function nextAvailableChunk ( intelHexMap : object ) : number {
75
+ // TODO: Check if we have run out of memory.
67
76
return FS_NEXT_AVAILABLE_CHUNK ;
68
77
}
69
78
@@ -128,10 +137,7 @@ function getPersistentPageAddress(intelHexMap: object): number {
128
137
* @param chunkIndex - Index for the chunk to calculate.
129
138
* @returns Address in flash for the chunk.
130
139
*/
131
- function addressFromChunkIndexNew (
132
- intelHexMap : object ,
133
- chunkIndex : number
134
- ) : number {
140
+ function chuckIndexAddress ( intelHexMap : object , chunkIndex : number ) : number {
135
141
// Chunk index starts at 1, so we need to account for that in the calculation
136
142
return getStartAddress ( intelHexMap ) + ( chunkIndex - 1 ) * ChunkSizes . All ;
137
143
}
@@ -245,7 +251,7 @@ function addFileToIntelHex(
245
251
246
252
// Find next available chunk and its flash address
247
253
const chunkIndex = nextAvailableChunk ( intelHexMap ) ;
248
- const startAddress = addressFromChunkIndexNew ( intelHexMap , chunkIndex ) ;
254
+ const startAddress = chuckIndexAddress ( intelHexMap , chunkIndex ) ;
249
255
// Store in an array each file converted to file system chunks
250
256
const fsFile = new FsFile ( filename , data ) ;
251
257
const fileFsBytes = fsFile . getFsBytes ( chunkIndex ) ;
0 commit comments