i2s: Fix buffer size off by one error

The FIFO ring buffer cursors were not incrementing and creating an
illusion of a false LIFO queue because the mask and size were off.
Additionally, to ease debugging, this replaces the square wave of
the original test data with a more deterministic, and somewhat
shorter sine wave that was programmatically generated without
aliasing.

Change-Id: I118cc73bca6d467b967f702465c5f3a758ff4d07
diff --git a/shodan_infrastructure/MatchaI2S.cs b/shodan_infrastructure/MatchaI2S.cs
index d6fc044..5ef67e2 100644
--- a/shodan_infrastructure/MatchaI2S.cs
+++ b/shodan_infrastructure/MatchaI2S.cs
@@ -93,9 +93,22 @@
             }
         }
 
+        public override string ToString()
+        {
+            string result = "[";
+
+            for (uint i = 0; i < FIFO_SIZE; i++) {
+                result += (i == cursor_r) ? "r" : " ";
+                result += (i == cursor_w) ? "w" : " ";
+                result += String.Format("{0:X8} ", fifo[i]);
+            }
+
+            return result + "]";
+        }
+
         public uint Count { get { lock(synclock) { return count; } } }
 
-        const uint FIFO_SIZE = 63;
+        const uint FIFO_SIZE = 64;
         const uint FIFO_MASK = FIFO_SIZE - 1;
 
         private uint cursor_r = 0;
@@ -245,7 +258,8 @@
             }
 
             rxBuffer.Write(sample);
-            this.Log(LogLevel.Noisy, "Added sample. Level: {0}", rxBuffer.Count);
+            this.Log(LogLevel.Noisy, "Added sample ({1:X}). Level: {0}", rxBuffer.Count, sample);
+            this.Log(LogLevel.Noisy, rxBuffer.ToString());
 
             if (rxBuffer.Count >= mappedRxTriggerLevel)
             {
@@ -316,7 +330,7 @@
                             this.Log(LogLevel.Noisy, "RX Watermark cleared");
                         }
                         RxOverflowIRQ.Set(false);
-                        this.Log(LogLevel.Noisy, "Removed sample. Level: {0}", rxBuffer.Count);
+                        this.Log(LogLevel.Noisy, "Removed sample ({1:X}). Level: {0}", rxBuffer.Count, sample);
 
                         return sample;
                     });
@@ -330,7 +344,7 @@
                             this.Log(LogLevel.Noisy, "TX Watermark cleared");
                         } 
                         TxEmptyIRQ.Set(false);
-                        this.Log(LogLevel.Noisy, "Added sample. Level: {0}", txBuffer.Count);
+                        this.Log(LogLevel.Noisy, "Added sample ({1:X}). Level: {0}", txBuffer.Count, val);
                     });
 
             Registers.FifoControl.Define32(this)
@@ -405,6 +419,10 @@
         public GPIO TxEmptyIRQ { get; }
         public GPIO RxOverflowIRQ { get; }
 
+        public string DumpFifos() {
+            return rxBuffer.ToString();
+        }
+
         private enum Events
         {
             TxWatermarkIRQ = 0,  // raised if the xmit FIFO is below the high watermark
diff --git a/shodan_infrastructure/test.raw b/shodan_infrastructure/test.raw
index d868cec..653f9a0 100644
--- a/shodan_infrastructure/test.raw
+++ b/shodan_infrastructure/test.raw
Binary files differ