1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* |
4 |
|
|
* This program and the accompanying materials are made available under the |
5 |
|
|
* terms of the MIT License which is available at |
6 |
|
|
* https://opensource.org/licenses/MIT. |
7 |
|
|
* |
8 |
|
|
* SPDX-License-Identifier: MIT |
9 |
|
|
**************************************************************************/ |
10 |
|
|
|
11 |
|
|
|
12 |
|
|
/**************************************************************************/ |
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/** */ |
15 |
|
|
/** LevelX Component */ |
16 |
|
|
/** */ |
17 |
|
|
/** NAND Flash */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define LX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Disable ThreadX error checking. */ |
26 |
|
|
|
27 |
|
|
#ifndef LX_DISABLE_ERROR_CHECKING |
28 |
|
|
#define LX_DISABLE_ERROR_CHECKING |
29 |
|
|
#endif |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
/* Include necessary system files. */ |
33 |
|
|
|
34 |
|
|
#include "lx_api.h" |
35 |
|
|
|
36 |
|
|
|
37 |
|
|
/**************************************************************************/ |
38 |
|
|
/* */ |
39 |
|
|
/* FUNCTION RELEASE */ |
40 |
|
|
/* */ |
41 |
|
|
/* _lx_nand_flash_mapped_block_list_remove PORTABLE C */ |
42 |
|
|
/* 6.2.1 */ |
43 |
|
|
/* AUTHOR */ |
44 |
|
|
/* */ |
45 |
|
|
/* Xiuwen Cai, Microsoft Corporation */ |
46 |
|
|
/* */ |
47 |
|
|
/* DESCRIPTION */ |
48 |
|
|
/* */ |
49 |
|
|
/* This function removes mapped block from list. */ |
50 |
|
|
/* */ |
51 |
|
|
/* INPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* nand_flash NAND flash instance */ |
54 |
|
|
/* block_mapping_index Block mapping index */ |
55 |
|
|
/* */ |
56 |
|
|
/* OUTPUT */ |
57 |
|
|
/* */ |
58 |
|
|
/* return status */ |
59 |
|
|
/* */ |
60 |
|
|
/* CALLS */ |
61 |
|
|
/* */ |
62 |
|
|
/* None */ |
63 |
|
|
/* */ |
64 |
|
|
/* CALLED BY */ |
65 |
|
|
/* */ |
66 |
|
|
/* Internal LevelX */ |
67 |
|
|
/* */ |
68 |
|
|
/* RELEASE HISTORY */ |
69 |
|
|
/* */ |
70 |
|
|
/* DATE NAME DESCRIPTION */ |
71 |
|
|
/* */ |
72 |
|
|
/* 03-08-2023 Xiuwen Cai Initial Version 6.2.1 */ |
73 |
|
|
/* */ |
74 |
|
|
/**************************************************************************/ |
75 |
|
1142 |
UINT _lx_nand_flash_mapped_block_list_remove(LX_NAND_FLASH* nand_flash, ULONG block_mapping_index) |
76 |
|
|
{ |
77 |
|
|
|
78 |
|
|
ULONG search_position; |
79 |
|
|
|
80 |
|
|
|
81 |
|
|
/* Initialize the search pointer. */ |
82 |
|
1142 |
search_position = nand_flash -> lx_nand_flash_mapped_block_list_head + 1; |
83 |
|
|
|
84 |
|
|
/* Loop to search the block in the list. */ |
85 |
✓✗ |
52352 |
while (search_position < nand_flash -> lx_nand_flash_block_list_size) |
86 |
|
|
{ |
87 |
|
|
|
88 |
|
|
/* Check if there is a match in the list. */ |
89 |
✓✓ |
52352 |
if (nand_flash -> lx_nand_flash_block_list[search_position] == block_mapping_index) |
90 |
|
|
{ |
91 |
|
|
|
92 |
|
|
/* Get out of the loop. */ |
93 |
|
1142 |
break; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
/* Move to next position. */ |
97 |
|
51210 |
search_position++; |
98 |
|
|
} |
99 |
|
|
|
100 |
|
|
/* Check if the block is found. */ |
101 |
✓✗ |
1142 |
if (search_position < nand_flash -> lx_nand_flash_block_list_size) |
102 |
|
|
{ |
103 |
|
|
|
104 |
|
|
/* Remove one item from the list. */ |
105 |
|
1142 |
nand_flash -> lx_nand_flash_mapped_block_list_head++; |
106 |
|
|
|
107 |
|
|
/* Loop to move items in the list. */ |
108 |
✓✓ |
52352 |
while (search_position > nand_flash -> lx_nand_flash_mapped_block_list_head) |
109 |
|
|
{ |
110 |
|
|
|
111 |
|
|
/* Move the item in the list. */ |
112 |
|
51210 |
nand_flash -> lx_nand_flash_block_list[search_position] = nand_flash -> lx_nand_flash_block_list[search_position - 1]; |
113 |
|
51210 |
search_position--; |
114 |
|
|
} |
115 |
|
|
} |
116 |
|
|
else |
117 |
|
|
{ |
118 |
|
|
|
119 |
|
|
/* Return error. */ |
120 |
|
|
return(LX_NO_BLOCKS); |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
/* Return successful completion. */ |
124 |
|
1142 |
return(LX_SUCCESS); |
125 |
|
|
} |
126 |
|
|
|