Skip to content

Commit b89e60b

Browse files
author
Veijo Pesonen
committed
SFDP: code readability improvements
1 parent eb01afb commit b89e60b

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

drivers/source/SFDP.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ int sfdp_parse_headers(Callback<int(bd_addr_t, void *, bd_size_t)> sfdp_reader,
210210
int hdr_status;
211211

212212
// Loop over Param Headers and parse them (currently supports Basic Param Table and Sector Region Map Table)
213-
for (int i_ind = 0; i_ind < number_of_param_headers; i_ind++) {
213+
for (int idx = 0; idx < number_of_param_headers; idx++) {
214214
status = sfdp_reader(addr, param_header, data_length);
215215
if (status < 0) {
216-
tr_error("Retrieving a parameter header %d failed", i_ind + 1);
216+
tr_error("Retrieving a parameter header %d failed", idx + 1);
217217
return -1;
218218
}
219219

@@ -335,27 +335,27 @@ int sfdp_detect_erase_types_inst_and_size(uint8_t *bptbl_ptr, sfdp_hdr_info &sfd
335335
// Erase 4K Inst is taken either from param table legacy 4K erase or superseded by erase Instruction for type of size 4K
336336
if (sfdp_info.bptbl.size > SFDP_BASIC_PARAM_TABLE_ERASE_TYPE_1_SIZE_BYTE) {
337337
// Loop Erase Types 1-4
338-
for (int i_ind = 0; i_ind < 4; i_ind++) {
339-
sfdp_info.smptbl.erase_type_inst_arr[i_ind] = -1; // Default for unsupported type
340-
sfdp_info.smptbl.erase_type_size_arr[i_ind] = 1
341-
<< bptbl_ptr[SFDP_BASIC_PARAM_TABLE_ERASE_TYPE_1_SIZE_BYTE + 2 * i_ind]; // Size is 2^N where N is the table value
342-
tr_debug("Erase Type(A) %d - Inst: 0x%xh, Size: %d", (i_ind + 1), sfdp_info.smptbl.erase_type_inst_arr[i_ind],
343-
sfdp_info.smptbl.erase_type_size_arr[i_ind]);
344-
if (sfdp_info.smptbl.erase_type_size_arr[i_ind] > 1) {
338+
for (int idx = 0; idx < 4; idx++) {
339+
sfdp_info.smptbl.erase_type_inst_arr[idx] = -1; // Default for unsupported type
340+
sfdp_info.smptbl.erase_type_size_arr[idx] = 1
341+
<< bptbl_ptr[SFDP_BASIC_PARAM_TABLE_ERASE_TYPE_1_SIZE_BYTE + 2 * idx]; // Size is 2^N where N is the table value
342+
tr_debug("Erase Type(A) %d - Inst: 0x%xh, Size: %d", (idx + 1), sfdp_info.smptbl.erase_type_inst_arr[idx],
343+
sfdp_info.smptbl.erase_type_size_arr[idx]);
344+
if (sfdp_info.smptbl.erase_type_size_arr[idx] > 1) {
345345
// if size==1 type is not supported
346-
sfdp_info.smptbl.erase_type_inst_arr[i_ind] = bptbl_ptr[SFDP_BASIC_PARAM_TABLE_ERASE_TYPE_1_BYTE
347-
+ 2 * i_ind];
346+
sfdp_info.smptbl.erase_type_inst_arr[idx] = bptbl_ptr[SFDP_BASIC_PARAM_TABLE_ERASE_TYPE_1_BYTE
347+
+ 2 * idx];
348348

349-
if ((sfdp_info.smptbl.erase_type_size_arr[i_ind] < sfdp_info.smptbl.regions_min_common_erase_size)
349+
if ((sfdp_info.smptbl.erase_type_size_arr[idx] < sfdp_info.smptbl.regions_min_common_erase_size)
350350
|| (sfdp_info.smptbl.regions_min_common_erase_size == 0)) {
351351
//Set default minimal common erase for signal region
352-
sfdp_info.smptbl.regions_min_common_erase_size = sfdp_info.smptbl.erase_type_size_arr[i_ind];
352+
sfdp_info.smptbl.regions_min_common_erase_size = sfdp_info.smptbl.erase_type_size_arr[idx];
353353
}
354354
sfdp_info.smptbl.region_erase_types_bitfld[0] |= bitfield; // If there's no region map, set region "0" types bitfield as default
355355
}
356356

357-
tr_debug("Erase Type %d - Inst: 0x%xh, Size: %d", (i_ind + 1), sfdp_info.smptbl.erase_type_inst_arr[i_ind],
358-
sfdp_info.smptbl.erase_type_size_arr[i_ind]);
357+
tr_debug("Erase Type %d - Inst: 0x%xh, Size: %d", (idx + 1), sfdp_info.smptbl.erase_type_inst_arr[idx],
358+
sfdp_info.smptbl.erase_type_size_arr[idx]);
359359
bitfield = bitfield << 1;
360360
}
361361
} else {
@@ -381,10 +381,10 @@ int sfdp_find_addr_region(bd_size_t offset, const sfdp_hdr_info &sfdp_info)
381381
return 0;
382382
}
383383

384-
for (int i_ind = sfdp_info.smptbl.region_cnt - 2; i_ind >= 0; i_ind--) {
384+
for (int idx = sfdp_info.smptbl.region_cnt - 2; idx >= 0; idx--) {
385385

386-
if (offset > sfdp_info.smptbl.region_high_boundary[i_ind]) {
387-
return (i_ind + 1);
386+
if (offset > sfdp_info.smptbl.region_high_boundary[idx]) {
387+
return (idx + 1);
388388
}
389389
}
390390
return -1;
@@ -400,10 +400,10 @@ int sfdp_iterate_next_largest_erase_type(uint8_t &bitfield,
400400
uint8_t type_mask = SFDP_ERASE_BITMASK_TYPE4;
401401
int largest_erase_type = 0;
402402

403-
int i_ind;
404-
for (i_ind = 3; i_ind >= 0; i_ind--) {
403+
int idx;
404+
for (idx = 3; idx >= 0; idx--) {
405405
if (bitfield & type_mask) {
406-
largest_erase_type = i_ind;
406+
largest_erase_type = idx;
407407
if ((size > (int)(smptbl.erase_type_size_arr[largest_erase_type])) &&
408408
((smptbl.region_high_boundary[region] - offset)
409409
> (int)(smptbl.erase_type_size_arr[largest_erase_type]))) {
@@ -415,7 +415,7 @@ int sfdp_iterate_next_largest_erase_type(uint8_t &bitfield,
415415
type_mask = type_mask >> 1;
416416
}
417417

418-
if (i_ind == -1) {
418+
if (idx == -1) {
419419
tr_error("No erase type was found for current region addr");
420420
}
421421
return largest_erase_type;

0 commit comments

Comments
 (0)