浏览代码

Separate main function to setup() and loop() for platforms using Arduino/mbed framework

Petteri Aimonen 3 年之前
父节点
当前提交
5fcf77885b
共有 2 个文件被更改,包括 52 次插入35 次删除
  1. 33 33
      src/ZuluSCSI.cpp
  2. 19 2
      src/ZuluSCSI_main.cpp

+ 33 - 33
src/ZuluSCSI.cpp

@@ -403,7 +403,7 @@ static void reinitSCSI()
   
 }
 
-extern "C" int zuluscsi_main(void)
+extern "C" void zuluscsi_setup(void)
 {
   azplatform_init();
   azplatform_late_init();
@@ -436,45 +436,45 @@ extern "C" int zuluscsi_main(void)
   azlog("FW Version: ", g_azlog_firmwareversion);
 
   init_logfile();
-  
-  uint32_t sd_card_check_time = 0;
+}
 
-  while (1)
-  {
-    azplatform_reset_watchdog();
-    scsiPoll();
-    scsiDiskPoll();
-    scsiLogPhaseChange(scsiDev.phase);
+extern "C" void zuluscsi_main_loop(void)
+{
+  static uint32_t sd_card_check_time = 0;
 
-    // Save log periodically during status phase if there are new messages.
-    if (scsiDev.phase == STATUS)
-    {
-      save_logfile();
-    }
+  azplatform_reset_watchdog();
+  scsiPoll();
+  scsiDiskPoll();
+  scsiLogPhaseChange(scsiDev.phase);
 
-    // Check SD card status for hotplug
-    if (scsiDev.phase == BUS_FREE &&
-        (uint32_t)(millis() - sd_card_check_time) > 5000)
+  // Save log periodically during status phase if there are new messages.
+  if (scsiDev.phase == STATUS)
+  {
+    save_logfile();
+  }
+
+  // Check SD card status for hotplug
+  if (scsiDev.phase == BUS_FREE &&
+      (uint32_t)(millis() - sd_card_check_time) > 5000)
+  {
+    sd_card_check_time = millis();
+    uint32_t ocr;
+    if (!SD.card()->readOCR(&ocr))
     {
-      sd_card_check_time = millis();
-      uint32_t ocr;
       if (!SD.card()->readOCR(&ocr))
       {
-        if (!SD.card()->readOCR(&ocr))
+        azlog("SD card removed, trying to reinit");
+        do
         {
-          azlog("SD card removed, trying to reinit");
-          do
-          {
-            blinkStatus(BLINK_ERROR_NO_SD_CARD);
-            delay(1000);
-            azplatform_reset_watchdog();
-          } while (!SD.begin(SD_CONFIG) && (!SD.card() || SD.sdErrorCode() != 0));
-          azlog("SD card reinit succeeded");
-          print_sd_info();
-
-          reinitSCSI();
-          init_logfile();
-        }
+          blinkStatus(BLINK_ERROR_NO_SD_CARD);
+          delay(1000);
+          azplatform_reset_watchdog();
+        } while (!SD.begin(SD_CONFIG) && (!SD.card() || SD.sdErrorCode() != 0));
+        azlog("SD card reinit succeeded");
+        print_sd_info();
+
+        reinitSCSI();
+        init_logfile();
       }
     }
   }

+ 19 - 2
src/ZuluSCSI_main.cpp

@@ -12,11 +12,28 @@ int main(void)
 
 #else
 
-extern "C" int zuluscsi_main(void);
+extern "C" void zuluscsi_setup(void);
+extern "C" void zuluscsi_main_loop(void);
 
+#ifdef USE_ARDUINO
+extern "C" void setup(void)
+{
+    zuluscsi_setup();
+}
+
+extern "C" void loop(void)
+{
+    zuluscsi_main_loop();
+}
+#else
 int main(void)
 {
-    return zuluscsi_main();
+    zuluscsi_setup();
+    while (1)
+    {
+        zuluscsi_main_loop();
+    }
 }
+#endif
 
 #endif