Add rdly auto calibration
authorJean THOMAS <git0@pub.jeanthomas.me>
Thu, 30 Jul 2020 16:27:33 +0000 (18:27 +0200)
committerJean THOMAS <git0@pub.jeanthomas.me>
Thu, 30 Jul 2020 16:27:33 +0000 (18:27 +0200)
examples/firmware/main.c
libgram/src/calibration.c

index 6344848419fab5aaf3acdd6185232d2391cb5c8b..32a53caa8bed6ac2230983c789d229d0fd4af531 100644 (file)
@@ -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++) {
index e979dee82ea77e5d3fa703bf94fffa301aa6743e..ce4b924be2eb7d9a46fde8201c7bfc6fccd50061 100644 (file)
@@ -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;
                }
        }