software/liblitedram: fix an off-by-1 error when write leveling

When finding the longest 1 window when write leveling, if the last tap
is 1, it won't be correctly handle because the end condition force to
judge it as 0.

Add one more iteration and force 0 in that one to handle the last 1.

Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
This commit is contained in:
Icenowy Zheng 2022-11-10 11:22:45 +08:00
parent 8a74eba4d5
commit 7c7b7f7818
1 changed files with 3 additions and 3 deletions

View File

@ -671,9 +671,9 @@ static int sdram_write_leveling_scan(int *delays, int loops, int show)
one_window_best_start = 0; one_window_best_start = 0;
one_window_best_count = -1; one_window_best_count = -1;
delays[i] = -1; delays[i] = -1;
for(j=0;j<err_ddrphy_wdly;j++) { for(j=0;j<err_ddrphy_wdly+1;j++) {
if (one_window_active) { if (one_window_active) {
if ((taps_scan[j] == 0) | (j == err_ddrphy_wdly - 1)) { if ((j == err_ddrphy_wdly) || (taps_scan[j] == 0)) {
one_window_active = 0; one_window_active = 0;
one_window_count = j - one_window_start; one_window_count = j - one_window_start;
if (one_window_count > one_window_best_count) { if (one_window_count > one_window_best_count) {
@ -682,7 +682,7 @@ static int sdram_write_leveling_scan(int *delays, int loops, int show)
} }
} }
} else { } else {
if (taps_scan[j]) { if (j != err_ddrphy_wdly && taps_scan[j]) {
one_window_active = 1; one_window_active = 1;
one_window_start = j; one_window_start = j;
} }