SWV tracing for diagnosing hangs.
[SCSI2SD.git] / software / SCSI2SD / src / main.c
index 779f112..e62b9c4 100755 (executable)
@@ -14,6 +14,8 @@
 //\r
 //     You should have received a copy of the GNU General Public License\r
 //     along with SCSI2SD.  If not, see <http://www.gnu.org/licenses/>.\r
+#pragma GCC push_options\r
+#pragma GCC optimize("-flto")\r
 \r
 #include "device.h"\r
 #include "scsi.h"\r
 #include "config.h"\r
 #include "disk.h"\r
 #include "led.h"\r
+#include "time.h"\r
+#include "trace.h"\r
 \r
 const char* Notice = "Copyright (C) 2014 Michael McMaster <michael@codesrc.com>";\r
 \r
+uint8_t testData[512];\r
+\r
 int main()\r
 {\r
+       timeInit();\r
        ledInit();\r
+       traceInit();\r
 \r
        // Enable global interrupts.\r
        // Needed for RST and ATN interrupt handlers.\r
@@ -41,6 +49,12 @@ int main()
        scsiInit();\r
        scsiDiskInit();\r
 \r
+       uint32_t lastSDPoll = getTime_ms();\r
+       sdPoll();\r
+\r
+\r
+\r
+\r
        while (1)\r
        {\r
                scsiDev.watchdogTick++;\r
@@ -48,7 +62,22 @@ int main()
                scsiPoll();\r
                scsiDiskPoll();\r
                configPoll();\r
+\r
+               if (unlikely(scsiDev.phase == BUS_FREE))\r
+               {\r
+                       if (unlikely(elapsedTime_ms(lastSDPoll) > 200))\r
+                       {\r
+                               lastSDPoll = getTime_ms();\r
+                               sdPoll();\r
+                       }\r
+                       else\r
+                       {\r
+                               // Wait for our 1ms timer to save some power.\r
+                               __WFI();\r
+                       }\r
+               }\r
        }\r
        return 0;\r
 }\r
 \r
+#pragma GCC pop_options\r