From: Jean THOMAS Date: Thu, 30 Jul 2020 16:27:33 +0000 (+0200) Subject: Add rdly auto calibration X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9f5a88c555c1de5e0d3ee86b69ac7fc176d39ccb;p=gram.git Add rdly auto calibration --- diff --git a/examples/firmware/main.c b/examples/firmware/main.c index 6344848..32a53ca 100644 --- a/examples/firmware/main.c +++ b/examples/firmware/main.c @@ -80,6 +80,18 @@ int main(void) { gram_init(&ctx, &profile, (void*)0x10000000, (void*)0x00009000, (void*)0x00008000); uart_writestr("done\n"); + uart_writestr("Auto calibrating... "); + gram_generate_calibration(&ctx, &profile); + gram_load_calibration(&ctx, &profile); + uart_writestr("done\n"); + + uart_writestr("Auto calibration profile:"); + uart_writestr("p0 rdly:"); + uart_writeuint32(profile.rdly_p0); + uart_writestr(" p1 rdly:"); + uart_writeuint32(profile.rdly_p1); + uart_writestr("\n"); + uart_writestr("DRAM test... \n"); volatile uint32_t *ram = 0x10000000; for (size_t i = 0; i < kNumIterations; i++) { diff --git a/libgram/src/calibration.c b/libgram/src/calibration.c index e979dee..ce4b924 100644 --- a/libgram/src/calibration.c +++ b/libgram/src/calibration.c @@ -69,23 +69,74 @@ bool gram_read_burstdet(const struct gramCtx *ctx, int phase) { } int gram_generate_calibration(const struct gramCtx *ctx, struct gramProfile *profile) { - unsigned char rdly_p0, rdly_p1; + unsigned char rdly; unsigned char min_rdly_p0, min_rdly_p1; - unsigned char max_rdly_p0, max_rdly_p1; + unsigned char max_rdly_p0 = 7, max_rdly_p1 = 7; + uint32_t tmp; + volatile uint32_t *ram = ctx->ddr_base; + size_t i; dfii_setsw(ctx, true); // Find minimal rdly - for (rdly_p0 = 0; rdly_p0 < 8; rdly_p0++) { - for (rdly_p1 = 0; rdly_p1 < 8; rdly_p1++) { + for (rdly = 0; rdly < 8; rdly++) { + profile->rdly_p0 = rdly; + gram_load_calibration(ctx, profile); + gram_reset_burstdet(ctx); + for (i = 0; i < 128; i++) { + tmp = ram[i]; + } + + if (gram_read_burstdet(&ctx, 0)) { + min_rdly_p0 = rdly; + break; + } + } + + for (rdly = 0; rdly < 8; rdly++) { + profile->rdly_p1 = rdly; + gram_load_calibration(ctx, profile); + gram_reset_burstdet(ctx); + + for (i = 0; i < 128; i++) { + tmp = ram[i]; + } + + if (gram_read_burstdet(&ctx, 1)) { + min_rdly_p1 = rdly; + break; } } // Find maximal rdly - for (rdly_p0 = 0; rdly_p0 < 8; rdly_p0++) { - for (rdly_p1 = 0; rdly_p1 < 8; rdly_p1++) { + for (rdly = min_rdly_p0; rdly < 8; rdly++) { + profile->rdly_p0 = rdly; + gram_load_calibration(ctx, profile); + gram_reset_burstdet(ctx); + + for (i = 0; i < 128; i++) { + tmp = ram[i]; + } + + if (!gram_read_burstdet(&ctx, 0)) { + max_rdly_p0 = rdly - 1; + break; + } + } + + for (rdly = 0; rdly < 8; rdly++) { + profile->rdly_p1 = rdly; + gram_load_calibration(ctx, profile); + gram_reset_burstdet(ctx); + + for (i = 0; i < 128; i++) { + tmp = ram[i]; + } + if (!gram_read_burstdet(&ctx, 1)) { + max_rdly_p1 = rdly - 1; + break; } }