Test program running on MAX32625MBED. Control through USB Serial commands using a terminal emulator such as teraterm or putty.

Dependencies:   MaximTinyTester CmdLine MAX541 USBDevice

Revision:
82:9ea067fad5c3
Parent:
81:167dee56c45b
Child:
83:29bb86cc45bc
diff -r 167dee56c45b -r 9ea067fad5c3 MAX11043/MAX11043.cpp
--- a/MAX11043/MAX11043.cpp	Tue Feb 25 02:14:54 2020 +0000
+++ b/MAX11043/MAX11043.cpp	Tue Feb 25 12:37:29 2020 +0000
@@ -61,7 +61,13 @@
 #define MYONEOCTHREADEVENTFLAG_ENABLE_SPI (1UL << 0)
 EventFlags myOnEOCThread_event_flags;
 Thread myOnEOCThread;
-extern void myOnEOCThread_handler();
+#if MAX11043_EOC_INTERRUPT_POLLING
+// MAX11043 myOnEOCThread_POLLING_handler needs 18.80us, still too slow
+extern DigitalInOut digitalInOut2; // m_EOC_pin declared in Test_Main_MAX11043.cpp
+extern void myOnEOCThread_POLLING_handler();
+#else // MAX11043_EOC_INTERRUPT_POLLING
+extern void myOnEOCThread_EVENTFLAG_ENABLE_SPI_handler();
+#endif // MAX11043_EOC_INTERRUPT_POLLING
 #else // MAX11043_EOC_INTERRUPT_EVENTQUEUE
 #endif // MAX11043_EOC_INTERRUPT_EVENTQUEUE
 //--------------------------------------------------
@@ -242,9 +248,16 @@
     //
     // EOC Event Output from device
 // MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion
+#if MAX11043_ScopeTrigger_MAX32625MBED_D5
+    digitalInOut5.output(); // ScopeTrigger
+#endif // MAX11043_ScopeTrigger_MAX32625MBED_D5
 #if MAX11043_EOC_INTERRUPT_EVENTQUEUE
     // SPI is not interrupt-safe, so use EventQueue to defer execution to user context.
-    myOnEOCThread.start(myOnEOCThread_handler);
+#if MAX11043_EOC_INTERRUPT_POLLING
+    myOnEOCThread.start(myOnEOCThread_POLLING_handler);
+#else // MAX11043_EOC_INTERRUPT_POLLING
+    myOnEOCThread.start(myOnEOCThread_EVENTFLAG_ENABLE_SPI_handler);
+#endif // MAX11043_EOC_INTERRUPT_POLLING
 #else // MAX11043_EOC_INTERRUPT_EVENTQUEUE
 #endif // MAX11043_EOC_INTERRUPT_EVENTQUEUE
 // MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion
@@ -256,7 +269,6 @@
     // TODO: onEOCFallingEdge: interrupt handler requires global object extern MAX11043 g_MAX11043_device
     // InterruptIn interruptEOC(EOC_pin); // InterruptIn constructor requires PinName, not DigitalIn -- Error: No instance of constructor "mbed::InterruptIn::InterruptIn"  matches the argument list in "MAX11043/MAX11043.cpp", Line: 187, Col: 31
     // TODO: onEOCFallingEdge: replace DigitalIn &EOC_pin with PinName EOC_pin, so that I can create an InterruptIn(PinName:EOC_pin)
-    digitalInOut5.output(); // ScopeTrigger
     extern void onEOCFallingEdge(void);
     // interruptEOC.fall(&onEOCFallingEdge);
     EOC_pin.fall(&onEOCFallingEdge);
@@ -265,40 +277,93 @@
 
 // MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion
 // SPI is not interrupt-safe, so use EventQueue to defer execution to user context.
-// Waiting for EOC# fall to signal EventQueue is too slow, ~25us to handle event but events happen every 9us.
 #if MAX11043_EOC_INTERRUPT_EVENTQUEUE
-void myOnEOCThread_handler()
+#if MAX11043_EOC_INTERRUPT_POLLING
+void myOnEOCThread_POLLING_handler()
 {
     while (true) {
-#if MAX11043_EOC_INTERRUPT_POLLING
 // MAX11043 EOC End Of Conversion input should be InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge);
 // Workaround using DigitalIn(PinName:EOC_pin) polled to sync with EOC falling edge for ADC reads
         // poll m_EOC_pin if CONVRUN is high
-        if (m_CONVRUN_pin)
-        {
-            #warning "myOnEOCThread_handler() Potential infinite loop if EOC pin not connected"
+        //if (m_CONVRUN_pin)
+        //{
+            //#warning "myOnEOCThread_handler() Potential infinite loop if EOC pin not connected"
             // possible infinite loop; need a timeout or futility countdown to escape
-            for (int futility_countdown = 100;
-                ((futility_countdown > 0) &&
-                (m_EOC_pin != 1));
-                futility_countdown--)
-            {
-                // spinlock waiting for logic high pin state (start of new conversion)
-            }
-            for (int futility_countdown = 100;
-                ((futility_countdown > 0) &&
-                (m_EOC_pin != 0));
-                futility_countdown--)
+#if MAX11043_ScopeTrigger_MAX32625MBED_D5
+// Diagnostic: Use MAX32625MBED pin D5 as DigitalOut EOC#-detected
+        //~ digitalInOut5.write(0); // ScopeTrigger low -- waiting for EOC# high
+        //~ digitalInOut5.write(1); // ScopeTrigger
+        //~ digitalInOut5.write(0); // ScopeTrigger
+        //~ digitalInOut5.write(1); // ScopeTrigger
+#endif // MAX11043_ScopeTrigger_MAX32625MBED_D5
+            //for (int futility_countdown = 100;
+            //    ((futility_countdown > 0) &&
+            //    (m_EOC_pin != 1));
+            //    futility_countdown--)
+            //while (digitalInOut2.read() != 1) // digitalInOut2 m_EOC_pin
+            //{
+            //    // spinlock waiting for logic high pin state (start of new conversion)
+            //}
+#if MAX11043_ScopeTrigger_MAX32625MBED_D5
+// Diagnostic: Use MAX32625MBED pin D5 as DigitalOut EOC#-detected
+        //~ digitalInOut5.write(0); // ScopeTrigger
+        //~ digitalInOut5.write(1); // ScopeTrigger high -- waiting for EOC# falling edge
+        //~ digitalInOut5.write(0); // ScopeTrigger
+        //~ digitalInOut5.write(1); // ScopeTrigger
+#endif // MAX11043_ScopeTrigger_MAX32625MBED_D5
+            //for (int futility_countdown = 100;
+            //    ((futility_countdown > 0) &&
+            //    (m_EOC_pin != 0));
+            //    futility_countdown--)
+            while (digitalInOut2.read() != 0) // digitalInOut2 m_EOC_pin
             {
                 // spinlock waiting for logic low pin state (new data is available)
             }
-        }
-        else
-        {
-            // CONVRUN pin is being driven low, so conversion result will not change, EOC# remains high
-            continue;
-        }
+        //}
+        //else
+        //{
+        //    // CONVRUN pin is being driven low, so conversion result will not change, EOC# remains high
+        //    continue;
+        //}
+        //
+        //extern MAX11043 g_MAX11043_device;
+#if MAX11043_ScopeTrigger_MAX32625MBED_D5
+// Diagnostic: Use MAX32625MBED pin D5 as DigitalOut EOC#-detected
+        //~ digitalInOut5.write(0); // ScopeTrigger low -- EOC# falling edge detected, about to start SPI
+        //~ digitalInOut5.write(1); // ScopeTrigger
+        //~ digitalInOut5.write(0); // ScopeTrigger
+        //~ digitalInOut5.write(1); // ScopeTrigger
+#endif // MAX11043_ScopeTrigger_MAX32625MBED_D5
+        extern SPI spi; // declared in Test_Main_MAX11043.cpp
+        spi.write((char*)mosiData_onEOCFallingEdge, byteCount_onEOCFallingEdge, (char*)misoData_onEOCFallingEdge, byteCount_onEOCFallingEdge);
+        // Note: EOC# is high immediately after SPI read ADCabcd
+        // SPI timing: CS low 13.30us after EOC# falling edge
+        // SPI timing: SCLK first 14.60us after EOC# falling edge
+        // SPI timing: SCLK last 17.70us after EOC# falling edge
+        // SPI timing: CS high 17.70us after EOC# falling edge
+        //
+        // TODO1: update adca
+        //g_MAX11043_device.adca = (misoData_onEOCFallingEdge[1] << 8) | misoData_onEOCFallingEdge[2];
+        // TODO1: update adcb
+        //g_MAX11043_device.adcb = (misoData_onEOCFallingEdge[3] << 8) | misoData_onEOCFallingEdge[4];
+        // TODO1: update adcc
+        //g_MAX11043_device.adcc = (misoData_onEOCFallingEdge[5] << 8) | misoData_onEOCFallingEdge[6];
+        // TODO1: update adcd
+        //g_MAX11043_device.adcd = (misoData_onEOCFallingEdge[7] << 8) | misoData_onEOCFallingEdge[8];
+#if MAX11043_ScopeTrigger_MAX32625MBED_D5
+// Diagnostic: Use MAX32625MBED pin D5 as DigitalOut EOC#-detected
+        //~ digitalInOut5.write(0); // ScopeTrigger
+        //~ digitalInOut5.write(1); // ScopeTrigger high -- end of while loop
+        //~ digitalInOut5.write(0); // ScopeTrigger
+        //~ digitalInOut5.write(1); // ScopeTrigger
+#endif // MAX11043_ScopeTrigger_MAX32625MBED_D5
+    } // while (true)
+} // myOnEOCThread_POLLING_handler()
 #else // MAX11043_EOC_INTERRUPT_POLLING
+// Waiting for EOC# fall to signal EventQueue is too slow, ~25us to handle event but events happen every 9us.
+void myOnEOCThread_EVENTFLAG_ENABLE_SPI_handler()
+{
+    while (true) {
 // MAX11043 EOC End Of Conversion input is InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge);
 // Interrupt Handler: EOC Event Output from device
         // Wait for MYONEOCTHREADEVENTFLAG_ENABLE_SPI event sent from onEOCFallingEdge interrupt
@@ -306,9 +371,8 @@
         //flags_read = myOnEOCThread_event_flags.wait_any(MYONEOCTHREADEVENTFLAG_ENABLE_SPI);
         // myOnEOCThread_event_flags.wait_any(MYONEOCTHREADEVENTFLAG_ENABLE_SPI, osWaitForever, false); // clear=false: don't auto clear the flag
         myOnEOCThread_event_flags.wait_any(MYONEOCTHREADEVENTFLAG_ENABLE_SPI, osWaitForever, true); // clear=true: auto clear the flag
-#endif // MAX11043_EOC_INTERRUPT_POLLING
         //
-        extern MAX11043 g_MAX11043_device;
+        //extern MAX11043 g_MAX11043_device;
 #if MAX11043_ScopeTrigger_MAX32625MBED_D5
 // Diagnostic: Use MAX32625MBED pin D5 as DigitalOut EOC#-detected
         digitalInOut5.write(0); // ScopeTrigger happens at 1.8us after EOC# falling edge
@@ -339,8 +403,8 @@
         digitalInOut5.write(1); // ScopeTrigger
 #endif // MAX11043_ScopeTrigger_MAX32625MBED_D5
     } // while (true)
-} // myOnEOCThread_handler()
-#else // MAX11043_EOC_INTERRUPT_EVENTQUEUE
+} // myOnEOCThread_EVENTFLAG_ENABLE_SPI_handler()
+#endif // MAX11043_EOC_INTERRUPT_POLLING
 #endif // MAX11043_EOC_INTERRUPT_EVENTQUEUE
 
 // MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion