software/liblitedram: scale up values when finding CMD delay

The delay finding code is based on integers, and when divided by the
count, rounding error will be quite easy to happen.

Scale up all delay value by 256x to reduce rounding error.

Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
This commit is contained in:
Icenowy Zheng 2022-11-09 17:52:38 +08:00
parent a7a520695e
commit 8a74eba4d5
1 changed files with 3 additions and 3 deletions

View File

@ -773,7 +773,7 @@ static void sdram_write_leveling_find_cmd_delay(unsigned int *best_error, unsign
int delay_count = 0; int delay_count = 0;
for (int i=0; i < SDRAM_PHY_MODULES; ++i) { for (int i=0; i < SDRAM_PHY_MODULES; ++i) {
if (delays[i] != -1) { if (delays[i] != -1) {
delay_mean += delays[i] + _sdram_tck_taps/4; delay_mean += delays[i]*256 + _sdram_tck_taps*64;
delay_count += 1; delay_count += 1;
} }
} }
@ -781,7 +781,7 @@ static void sdram_write_leveling_find_cmd_delay(unsigned int *best_error, unsign
delay_mean /= delay_count; delay_mean /= delay_count;
/* We want the higher number of valid modules and delay to be centered */ /* We want the higher number of valid modules and delay to be centered */
int ideal_delay = (SDRAM_PHY_DELAYS - _sdram_tck_taps/4)/2; int ideal_delay = SDRAM_PHY_DELAYS*128 - _sdram_tck_taps*32;
int error = ideal_delay - delay_mean; int error = ideal_delay - delay_mean;
if (error < 0) if (error < 0)
error *= -1; error *= -1;
@ -794,7 +794,7 @@ static void sdram_write_leveling_find_cmd_delay(unsigned int *best_error, unsign
} }
} }
#ifdef SDRAM_WRITE_LEVELING_CMD_DELAY_DEBUG #ifdef SDRAM_WRITE_LEVELING_CMD_DELAY_DEBUG
printf("Delay mean: %d, ideal: %d\n", delay_mean, ideal_delay); printf("Delay mean: %d/256, ideal: %d/256\n", delay_mean, ideal_delay);
#else #else
printf("%d", ok); printf("%d", ok);
#endif #endif