Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define LX_SOURCE_CODE
#define LX_DISABLE_ERROR_CHECKING
#include "lx_api.h"
...
...
_lx_nor_flash_block_reclaim(LX_NOR_FLASH *)
Files
loading...
CodeScopeSTM32 Libraries and Sampleslevelxcommon/src/lx_nor_flash_block_reclaim.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** LevelX Component */ /** */ /** NOR Flash */ /** */... /**************************************************************************/ /**************************************************************************/ #define LX_SOURCE_CODE /* Disable ThreadX error checking. */ #ifndef LX_DISABLE_ERROR_CHECKING #define LX_DISABLE_ERROR_CHECKING #endif /* Include necessary system files. */ #include "lx_api.h" ... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _lx_nor_flash_block_reclaim PORTABLE C */ /* 6.1.7 */ /* AUTHOR */ /* */ /* William E. Lamie, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function reclaims one block from the NOR flash. */ /* */ /* INPUT */ /* */ /* nor_flash NOR flash instance */ /* */ /* OUTPUT */ /* */ /* return status */ /* */ /* CALLS */ /* */ /* _lx_nor_flash_driver_block_erase Driver erase block */ /* _lx_nor_flash_driver_write Driver flash sector write */ /* _lx_nor_flash_driver_read Driver flash sector read */ /* _lx_nor_flash_next_block_to_erase_find */ /* Find next block to erase */ /* _lx_nor_flash_physical_sector_allocate */ /* Allocate new logical sector */ /* _lx_nor_flash_sector_mapping_cache_invalidate */ /* Invalidate cache entry */ /* _lx_nor_flash_system_error Internal system error handler */ /* */ /* CALLED BY */ /* */ /* Internal LevelX */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 William E. Lamie Initial Version 6.0 */ /* 09-30-2020 William E. Lamie Modified comment(s), */ /* resulting in version 6.1 */ /* 06-02-2021 Bhupendra Naphade Modified comment(s), */ /* resulting in version 6.1.7 */ /* */... /**************************************************************************/ UINT _lx_nor_flash_block_reclaim(LX_NOR_FLASH *nor_flash) { ULONG *block_word_ptr; ULONG *list_word_ptr; ULONG list_word; ULONG i; ULONG erase_block; ULONG erase_count; ULONG temp_erase_count; ULONG erase_started_value; ULONG mapped_sectors; ULONG obsolete_sectors; ULONG free_sectors; ULONG logical_sector; ULONG *new_mapping_address; ULONG *new_sector_address; ULONG new_mapping_entry; UINT status; /* Determine the next block to erase. */ _lx_nor_flash_next_block_to_erase_find(nor_flash, &erase_block, &erase_count, &mapped_sectors, &obsolete_sectors); /* Determine if the search pointer is set for this block. */ if (nor_flash -> lx_nor_flash_free_block_search == erase_block) { /* Ensure the search block is not the block we are trying to free. */ nor_flash -> lx_nor_flash_free_block_search = erase_block + 1; /* Check for wrap condition. */ if (nor_flash -> lx_nor_flash_free_block_search >= nor_flash -> lx_nor_flash_total_blocks) nor_flash -> lx_nor_flash_free_block_search = 0; }if (nor_flash -> lx_nor_flash_free_block_search == erase_block) { ... } /* Setup the block word pointer to the first word of the search block. */ block_word_ptr = nor_flash -> lx_nor_flash_base_address + (nor_flash -> lx_nor_flash_words_per_block * erase_block); /* Determine if this block is completely obsolete. */ if (obsolete_sectors == nor_flash -> lx_nor_flash_physical_sectors_per_block) { /* Write the erased started indication. */ erase_started_value = LX_BLOCK_ERASE_STARTED; status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &erase_started_value, 1); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* Erase the entire block. */ status = _lx_nor_flash_driver_block_erase(nor_flash, erase_block, erase_count+1); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* Increment the erase count. */ erase_count++; /* Determine if the new erase count exceeds the maximum. */ if (erase_count > ((ULONG) LX_BLOCK_ERASE_COUNT_MAX)) { /* Yes, erase count is in overflow. Stay at the maximum count. */ erase_count = ((ULONG) LX_BLOCK_ERASE_COUNT_MAX); }if (erase_count > ((ULONG) LX_BLOCK_ERASE_COUNT_MAX)) { ... } /* Determine if we need to update the maximum erase count. */ if (erase_count > nor_flash -> lx_nor_flash_maximum_erase_count) { /* Yes, a new maximum is present. */ nor_flash -> lx_nor_flash_maximum_erase_count = erase_count; }if (erase_count > nor_flash -> lx_nor_flash_maximum_erase_count) { ... } /* Setup the free bit map that corresponds to the free physical sectors in this block. Note that we only need to setup the portion of the free bit map that doesn't have sectors associated with it. *//* ... */ status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr+(nor_flash -> lx_nor_flash_block_free_bit_map_offset + (nor_flash -> lx_nor_flash_block_bit_map_words - 1)), &(nor_flash -> lx_nor_flash_block_bit_map_mask), 1); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* Write the initial erase count for the block with upper bit set. */ temp_erase_count = (erase_count | LX_BLOCK_ERASED); status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &temp_erase_count, 1); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* Write the final initial erase count for the block. */ status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &erase_count, 1); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* Update parameters of this flash. */ nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + obsolete_sectors; nor_flash -> lx_nor_flash_obsolete_physical_sectors = nor_flash -> lx_nor_flash_obsolete_physical_sectors - obsolete_sectors; }if (obsolete_sectors == nor_flash -> lx_nor_flash_physical_sectors_per_block) { ... } else { /* Calculate the number of free sectors in this block. */ free_sectors = nor_flash -> lx_nor_flash_physical_sectors_per_block - (obsolete_sectors + mapped_sectors); /* Determine if there are enough free sectors outside of this block to reclaim this block. */ if (mapped_sectors <= (nor_flash -> lx_nor_flash_free_physical_sectors - free_sectors)) { /* Setup a pointer to the mapped list. */ list_word_ptr = block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_mapping_offset; /* Now search through the list to find mapped sectors to move. */ for (i = 0; i < nor_flash -> lx_nor_flash_physical_sectors_per_block; i++) { /* Pickup the mapped sector list entry. */ #ifdef LX_DIRECT_READ /* Read the word directly. */ list_word = *(list_word_ptr);/* ... */ #else status = _lx_nor_flash_driver_read(nor_flash, list_word_ptr, &list_word, 1); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* ... */#endif /* Determine if the entry hasn't been used. */ if (list_word == LX_NOR_PHYSICAL_SECTOR_FREE) { /* Since allocations are done sequentially in the block, we know nothing else exists after this point. *//* ... */ break; }if (list_word == LX_NOR_PHYSICAL_SECTOR_FREE) { ... } /* Is this entry mapped? */ if (list_word & LX_NOR_PHYSICAL_SECTOR_VALID) { /* Pickup the logical sector associated with this mapped physical sector. */ logical_sector = list_word & LX_NOR_LOGICAL_SECTOR_MASK; /* Invalidate the old sector mapping cache entry. */ _lx_nor_flash_sector_mapping_cache_invalidate(nor_flash, logical_sector); /* Allocate a new physical sector for this write. */ _lx_nor_flash_physical_sector_allocate(nor_flash, logical_sector, &new_mapping_address, &new_sector_address); /* Check to see if the new sector is also in the erase block. */ if ((new_sector_address >= block_word_ptr) && (new_sector_address < (block_word_ptr + nor_flash -> lx_nor_flash_words_per_block))) { /* Yes, the new sector was found in the block to be erased. Simply move the search pointer to the block after the erase block and search for another sector from there. *//* ... */ nor_flash -> lx_nor_flash_free_block_search = erase_block + 1; /* Check for wrap condition. */ if (nor_flash -> lx_nor_flash_free_block_search >= nor_flash -> lx_nor_flash_total_blocks) nor_flash -> lx_nor_flash_free_block_search = 0; /* Allocate a new physical sector for this write. */ _lx_nor_flash_physical_sector_allocate(nor_flash, logical_sector, &new_mapping_address, &new_sector_address); /* Check again for the new sector inside of the block to erase. This should be impossible, since we check previously if there are enough free sectors outside of this block needed to reclaim this block. *//* ... */ if ((new_sector_address >= block_word_ptr) && (new_sector_address < (block_word_ptr + LX_NOR_SECTOR_SIZE))) { /* System error, a new sector is not available outside of the erase block. Clear the new sector so we fall through to the error handling. *//* ... */ new_mapping_address = LX_NULL; }if ((new_sector_address >= block_word_ptr) && (new_sector_address < (block_word_ptr + LX_NOR_SECTOR_SIZE))) { ... } }if ((new_sector_address >= block_word_ptr) && (new_sector_address < (block_word_ptr + nor_flash -> lx_nor_flash_words_per_block))) { ... } /* Determine if the new sector allocation was successful. */ if (new_mapping_address) { /* Yes, we were able to allocate a new physical sector. */ #ifdef LX_DIRECT_READ /* First, write the sector data to the new physical sector. */ status = _lx_nor_flash_driver_write(nor_flash, new_sector_address, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_offset) + (i * LX_NOR_SECTOR_SIZE), LX_NOR_SECTOR_SIZE); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* ... */#else /* First, read the sector data into the internal memory of the NOR flash instance. This internal memory is supplied by the underlying driver during initialization. *//* ... */ status = _lx_nor_flash_driver_read(nor_flash, (block_word_ptr + nor_flash -> lx_nor_flash_block_physical_sector_offset) + (i * LX_NOR_SECTOR_SIZE), nor_flash -> lx_nor_flash_sector_buffer, LX_NOR_SECTOR_SIZE); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* Next, write the sector data from the internal buffer to the new physical sector. */ status = _lx_nor_flash_driver_write(nor_flash, new_sector_address, nor_flash -> lx_nor_flash_sector_buffer, LX_NOR_SECTOR_SIZE); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* ... */#endif /* Now deprecate the old sector mapping. */ /* Clear bit 30, which indicates this sector is superceded. */ list_word = list_word & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED); /* Write the value back to the flash to clear bit 30. */ status = _lx_nor_flash_driver_write(nor_flash, list_word_ptr, &list_word, 1); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* Now build the new mapping entry - with the not valid bit set initially. */ new_mapping_entry = ((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID) | ((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED) | (ULONG) LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID | logical_sector; /* Write out the new mapping entry. */ status = _lx_nor_flash_driver_write(nor_flash, new_mapping_address, &new_mapping_entry, 1); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* Now clear the not valid bit to make this sector mapping valid. This is done because the writing of the extra bytes itself can be interrupted and we need to make sure this can be detected when the flash is opened again. *//* ... */ new_mapping_entry = new_mapping_entry & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_MAPPING_NOT_VALID); /* Clear the not valid bit. */ status = _lx_nor_flash_driver_write(nor_flash, new_mapping_address, &new_mapping_entry, 1); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* Now clear bit 31, which indicates this sector is now obsoleted. */ list_word = list_word & ~((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID); /* Write the value back to the flash to clear bit 31. */ status = _lx_nor_flash_driver_write(nor_flash, list_word_ptr, &list_word, 1); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } }if (new_mapping_address) { ... } else { /* Call system error handler - the allocation should always succeed at this point. */ _lx_nor_flash_system_error(nor_flash, LX_SYSTEM_ALLOCATION_FAILED); /* Return the error. */ return(status); }else { ... } /* Decrement the number of mapped sectors. */ mapped_sectors--; /* Determine if we are done. */ if (mapped_sectors == 0) break; }if (list_word & LX_NOR_PHYSICAL_SECTOR_VALID) { ... } /* Move the list pointer ahead. */ list_word_ptr++; }for (i = 0; i < nor_flash -> lx_nor_flash_physical_sectors_per_block; i++) { ... } /* Write the erased started indication. */ erase_started_value = LX_BLOCK_ERASE_STARTED; status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &erase_started_value, 1); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* Erase the entire block. */ status = _lx_nor_flash_driver_block_erase(nor_flash, erase_block, erase_count+1); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* Increment the erase count. */ erase_count++; /* Determine if the new erase count exceeds the maximum. */ if (erase_count > ((ULONG) LX_BLOCK_ERASE_COUNT_MAX)) { /* Yes, erase count is in overflow. Stay at the maximum count. */ erase_count = ((ULONG) LX_BLOCK_ERASE_COUNT_MAX); }if (erase_count > ((ULONG) LX_BLOCK_ERASE_COUNT_MAX)) { ... } /* Determine if we need to update the maximum erase count. */ if (erase_count > nor_flash -> lx_nor_flash_maximum_erase_count) { /* Yes, a new maximum is present. */ nor_flash -> lx_nor_flash_maximum_erase_count = erase_count; }if (erase_count > nor_flash -> lx_nor_flash_maximum_erase_count) { ... } /* Setup the free bit map that corresponds to the free physical sectors in this block. Note that we only need to setup the portion of the free bit map that doesn't have sectors associated with it. *//* ... */ status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr+(nor_flash -> lx_nor_flash_block_free_bit_map_offset + (nor_flash -> lx_nor_flash_block_bit_map_words - 1)) , &(nor_flash -> lx_nor_flash_block_bit_map_mask), 1); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* Write the initial erase count for the block with the upper bit set. */ temp_erase_count = (erase_count | LX_BLOCK_ERASED); status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &temp_erase_count, 1); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* Write the final initial erase count for the block. */ status = _lx_nor_flash_driver_write(nor_flash, block_word_ptr, &erase_count, 1); /* Check for an error from flash driver. Drivers should never return an error.. */ if (status) { /* Call system error handler. */ _lx_nor_flash_system_error(nor_flash, status); /* Return the error. */ return(status); }if (status) { ... } /* Update parameters of this flash. */ nor_flash -> lx_nor_flash_free_physical_sectors = nor_flash -> lx_nor_flash_free_physical_sectors + obsolete_sectors; nor_flash -> lx_nor_flash_obsolete_physical_sectors = nor_flash -> lx_nor_flash_obsolete_physical_sectors - obsolete_sectors; }if (mapped_sectors <= (nor_flash -> lx_nor_flash_free_physical_sectors - free_sectors)) { ... } }else { ... } /* Return status. */ return(LX_SUCCESS); }{ ... }