1
10
13
14
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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
177
178
179
180
181
182
183
184
185
186
187
188
189
195
196
197
198
201
202
203
204
205
206
...
...
...
#define LX_SOURCE_CODE
#ifndef LX_DISABLE_ERROR_CHECKING
#define LX_DISABLE_ERROR_CHECKING
#endif
#include "lx_api.h"
...
...
UINT _lx_nor_flash_sector_read(LX_NOR_FLASH *nor_flash, ULONG logical_sector, VOID *buffer)
{
UINT status;
ULONG *mapping_address;
ULONG mapping_entry;
ULONG *sector_address;
#ifdef LX_THREAD_SAFE_ENABLE
tx_mutex_get(&nor_flash -> lx_nor_flash_mutex, TX_WAIT_FOREVER);/* ... */
#endif
nor_flash -> lx_nor_flash_read_requests++;
_lx_nor_flash_logical_sector_find(nor_flash, logical_sector, LX_FALSE, &mapping_address, §or_address);
if (mapping_address)
{
status = _lx_nor_flash_driver_read(nor_flash, sector_address, buffer, LX_NOR_SECTOR_SIZE);
if (status)
{
_lx_nor_flash_system_error(nor_flash, status);
status = LX_ERROR;
}if (status) { ... }
else
{
status = LX_SUCCESS;
}else { ... }
}if (mapping_address) { ... }
else
{
_lx_nor_flash_physical_sector_allocate(nor_flash, logical_sector, &mapping_address, §or_address);
if (mapping_address)
{
nor_flash -> lx_nor_flash_free_physical_sectors--;
status = _lx_nor_flash_driver_read(nor_flash, sector_address, buffer, LX_NOR_SECTOR_SIZE);
if (status)
{
_lx_nor_flash_system_error(nor_flash, status);
}if (status) { ... }
mapping_entry = ((ULONG) LX_NOR_PHYSICAL_SECTOR_VALID) | ((ULONG) LX_NOR_PHYSICAL_SECTOR_SUPERCEDED) | logical_sector;
status = _lx_nor_flash_driver_write(nor_flash, mapping_address, &mapping_entry, 1);
if (status)
{
_lx_nor_flash_system_error(nor_flash, status);
#ifdef LX_THREAD_SAFE_ENABLE
tx_mutex_put(&nor_flash -> lx_nor_flash_mutex);/* ... */
#endif
return(LX_ERROR);
}if (status) { ... }
nor_flash -> lx_nor_flash_mapped_physical_sectors++;
status = LX_SUCCESS;
}if (mapping_address) { ... }
else
{
status = LX_SECTOR_NOT_FOUND;
}else { ... }
}else { ... }
#ifdef LX_THREAD_SAFE_ENABLE
tx_mutex_put(&nor_flash -> lx_nor_flash_mutex);/* ... */
#endif
return(status);
}{ ... }