From 7b7fdadd260f958093b3fafebeae2fd0fd06c131 Mon Sep 17 00:00:00 2001 From: Maciej Dudek Date: Thu, 13 Oct 2022 12:12:31 +0200 Subject: [PATCH] liblitedram: Move pattern testing to its own function Signed-off-by: Maciej Dudek --- litex/soc/software/liblitedram/sdram.c | 27 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/litex/soc/software/liblitedram/sdram.c b/litex/soc/software/liblitedram/sdram.c index a1e0bdde3..e80c0a4d6 100644 --- a/litex/soc/software/liblitedram/sdram.c +++ b/litex/soc/software/liblitedram/sdram.c @@ -370,6 +370,19 @@ static unsigned int sdram_write_read_check_test_pattern(int module, unsigned int return errors; } +static int _seed_array[] = {42, 84, 36, 72, 24, 48}; +static int _seed_array_length = sizeof(_seed_array) / sizeof(_seed_array[0]); + + +static int run_test_pattern(int module) +{ + int errors = 0; + for (int i = 0; i < _seed_array_length; i++) { + errors += sdram_write_read_check_test_pattern(module, _seed_array[i]); + } + return errors; +} + static void sdram_leveling_center_module( int module, int show_short, int show_long, delay_callback rst_delay, delay_callback inc_delay) { @@ -387,8 +400,7 @@ static void sdram_leveling_center_module( delay = 0; rst_delay(module); while(1) { - errors = sdram_write_read_check_test_pattern(module, 42); - errors += sdram_write_read_check_test_pattern(module, 84); + errors = run_test_pattern(module); working = errors == 0; show = show_long; #if SDRAM_PHY_DELAYS > 32 @@ -410,8 +422,7 @@ static void sdram_leveling_center_module( cur_delay_min = delay_min; /* Find largest working delay range */ while(1) { - errors = sdram_write_read_check_test_pattern(module, 42); - errors += sdram_write_read_check_test_pattern(module, 84); + errors = run_test_pattern(module); working = errors == 0; show = show_long; #if SDRAM_PHY_DELAYS > 32 @@ -467,8 +478,7 @@ static void sdram_leveling_center_module( } /* Check */ - errors = sdram_write_read_check_test_pattern(module, 42); - errors += sdram_write_read_check_test_pattern(module, 84); + errors = run_test_pattern(module); if (errors == 0) break; retries--; @@ -949,7 +959,7 @@ static void sdram_read_leveling_inc_bitslip(char m) static unsigned int sdram_read_leveling_scan_module(int module, int bitslip, int show) { - const unsigned int max_errors = 2*READ_CHECK_TEST_PATTERN_MAX_ERRORS; + const unsigned int max_errors = _seed_array_length * READ_CHECK_TEST_PATTERN_MAX_ERRORS; int i; unsigned int score; unsigned int errors; @@ -965,8 +975,7 @@ static unsigned int sdram_read_leveling_scan_module(int module, int bitslip, int #if SDRAM_PHY_DELAYS > 32 _show = (i%16 == 0) & show; #endif - errors = sdram_write_read_check_test_pattern(module, 42); - errors += sdram_write_read_check_test_pattern(module, 84); + errors = run_test_pattern(module); working = errors == 0; /* When any scan is working then the final score will always be higher then if no scan was working */ score += (working * max_errors*SDRAM_PHY_DELAYS) + (max_errors - errors);