Code clean up and handling FIFO errors

Revision:
39:e255f52072fc
Parent:
32:52445bef314d
Child:
50:d84305e5e1c0
--- a/common/utils.c	Thu Nov 21 09:40:32 2019 +0000
+++ b/common/utils.c	Thu Nov 21 13:36:43 2019 +0000
@@ -297,44 +297,44 @@
          * Wait until the next batch of 1 or more samples is ready, continuously
          * checking DATAREADY until it is asserted
          */
-        while (! (bDataReady || bError))
-            ;
+        while (! (bDataReady || bError));
 
-        if (!bError) {
-            /*
-             * Get data samples from the measurement cycle, if no error has occurred
-             */
-            bDataReady = false;
-            res = admw_GetData(hDevice, eMeasurementMode, pSampleBuffer,
-                               nBytesPerSample, nSamplesPerDataready,
-                               &nReturned);
-            if (res != ADMW_SUCCESS) {
-                if (res == ADMW_INCOMPLETE) {
-                    /*
-                     * This is expected in cases where cycleSkipCount may
-                     * be non-zero for some channels, resulting in
-                     * variable-length sequences
-                     */
-                    ADMW_LOG_DEBUG("Retrieved %u of %u requested data samples",
-                                   nReturned, nSamplesPerDataready);
-                } else {
-                    ADMW_LOG_WARN("Failed to get data samples from device");
-                    return res;
+            if (!bError) {
+                /*
+                 * Get data samples from the measurement cycle, if no error has occurred
+                 */
+                bDataReady = false;
+                res = admw_GetData(hDevice, eMeasurementMode, pSampleBuffer,
+                                   nBytesPerSample, nSamplesPerDataready,
+                                   &nReturned);
+                if (res != ADMW_SUCCESS) {
+                    if (res == ADMW_INCOMPLETE) {
+                        /*
+                         * This is expected in cases where cycleSkipCount may
+                         * be non-zero for some channels, resulting in
+                         * variable-length sequences
+                         */
+                        ADMW_LOG_DEBUG("Retrieved %u of %u requested data samples",
+                                       nReturned, nSamplesPerDataready);
+                        continue;
+                    } else {
+                        ADMW_LOG_WARN("Failed to get data samples from device");
+                        return res;
+                    }
                 }
+
+                /*
+                 * Display the data samples.
+                 *
+                 * NOTE: this requires a sufficient idle time between subsequent
+                 * DATAREADY pulses to allow printing to occur.  Otherwise,
+                 * subsequent samples may be missed if not retrieved promptly when
+                 * the next DATAREADY assertion occurs.
+                 */
+                utils_printSamples(pSampleBuffer, nReturned, eMeasurementMode);
+                nSampleCount += nReturned;
             }
 
-            /*
-             * Display the data samples.
-             *
-             * NOTE: this requires a sufficient idle time between subsequent
-             * DATAREADY pulses to allow printing to occur.  Otherwise,
-             * subsequent samples may be missed if not retrieved promptly when
-             * the next DATAREADY assertion occurs.
-             */
-            utils_printSamples(pSampleBuffer, nReturned, eMeasurementMode);
-            nSampleCount += nReturned;
-        }
-
         /*
          * Check and print device status if errors/alerts have been triggered
          */