Bladeren bron

Debrand bluelog/bluedbg > log/debuglog

androda 2 jaren geleden
bovenliggende
commit
306fb0e1f0

+ 34 - 34
lib/BlueSCSI_platform_RP2040/BlueSCSI_platform.cpp

@@ -72,19 +72,19 @@ void platform_init()
     g_uart_initialized = true;
     mbed_set_error_hook(mbed_error_hook);
 
-    //bluelog("DIP switch settings: debug log ", (int)dbglog, ", termination ", (int)termination);
-    bluelog("Platform: ", g_platform_name);
-    bluelog("FW Version: ", g_bluelog_firmwareversion);
+    //log("DIP switch settings: debug log ", (int)dbglog, ", termination ", (int)termination);
+    log("Platform: ", g_platform_name);
+    log("FW Version: ", g_log_firmwareversion);
 
-    g_bluelog_debug = false; // Debug logging can be handled with a debug firmware, very easy to reflash
+    g_log_debug = false; // Debug logging can be handled with a debug firmware, very easy to reflash
 
     // if (termination)  // Termination is handled by hardware jumper
     // {
-    //     bluelog("SCSI termination is enabled");
+    //     log("SCSI termination is enabled");
     // }
     // else
     // {
-    //     bluelog("NOTE: SCSI termination is disabled");
+    //     log("NOTE: SCSI termination is disabled");
     // }
 
     // Get flash chip size
@@ -92,7 +92,7 @@ void platform_init()
     uint8_t response_jedec[4] = {0};
     flash_do_cmd(cmd_read_jedec_id, response_jedec, 4);
     g_flash_chip_size = (1 << response_jedec[3]);
-    bluelog("Flash chip size: ", (int)(g_flash_chip_size / 1024), " kB");
+    log("Flash chip size: ", (int)(g_flash_chip_size / 1024), " kB");
 
     // SD card pins
     // Card is used in SDIO mode for main program, and in SPI mode for crash handler & bootloader.
@@ -156,12 +156,12 @@ void platform_late_init()
     if (read_initiator_dip_switch())
     {
         g_scsi_initiator = true;
-        bluelog("SCSI initiator mode selected by DIP switch, expecting SCSI disks on the bus");
+        log("SCSI initiator mode selected by DIP switch, expecting SCSI disks on the bus");
     }
     else
     {
         g_scsi_initiator = false;
-        bluelog("SCSI target/disk mode selected by DIP switch, acting as a SCSI disk");
+        log("SCSI target/disk mode selected by DIP switch, acting as a SCSI disk");
     }
 
     /* Initialize SCSI pins to required modes.
@@ -238,7 +238,7 @@ void platform_disable_led(void)
 {   
     //        pin      function       pup   pdown  out    state fast
     gpio_conf(LED_PIN, GPIO_FUNC_SIO, false,false, false, false, false);
-    bluelog("Disabling status LED");
+    log("Disabling status LED");
 }
 
 /*****************************************/
@@ -265,28 +265,28 @@ void platform_emergency_log_save()
     }
 
     uint32_t startpos = 0;
-    crashfile.write(bluelog_get_buffer(&startpos));
-    crashfile.write(bluelog_get_buffer(&startpos));
+    crashfile.write(log_get_buffer(&startpos));
+    crashfile.write(log_get_buffer(&startpos));
     crashfile.flush();
     crashfile.close();
 }
 
 void mbed_error_hook(const mbed_error_ctx * error_context)
 {
-    bluelog("--------------");
-    bluelog("CRASH!");
-    bluelog("Platform: ", g_platform_name);
-    bluelog("FW Version: ", g_bluelog_firmwareversion);
-    bluelog("error_status: ", (uint32_t)error_context->error_status);
-    bluelog("error_address: ", error_context->error_address);
-    bluelog("error_value: ", error_context->error_value);
+    log("--------------");
+    log("CRASH!");
+    log("Platform: ", g_platform_name);
+    log("FW Version: ", g_log_firmwareversion);
+    log("error_status: ", (uint32_t)error_context->error_status);
+    log("error_address: ", error_context->error_address);
+    log("error_value: ", error_context->error_value);
 
     uint32_t *p = (uint32_t*)((uint32_t)error_context->thread_current_sp & ~3);
     for (int i = 0; i < 8; i++)
     {
         if (p == &__StackTop) break; // End of stack
 
-        bluelog("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
+        log("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
         p += 4;
     }
 
@@ -336,16 +336,16 @@ static void watchdog_callback(unsigned alarm_num)
     {
         if (!scsiDev.resetFlag || !g_scsiHostPhyReset)
         {
-            bluelog("--------------");
-            bluelog("WATCHDOG TIMEOUT, attempting bus reset");
-            bluelog("GPIO states: out ", sio_hw->gpio_out, " oe ", sio_hw->gpio_oe, " in ", sio_hw->gpio_in);
+            log("--------------");
+            log("WATCHDOG TIMEOUT, attempting bus reset");
+            log("GPIO states: out ", sio_hw->gpio_out, " oe ", sio_hw->gpio_oe, " in ", sio_hw->gpio_in);
 
             uint32_t *p = (uint32_t*)__get_PSP();
             for (int i = 0; i < 8; i++)
             {
                 if (p == &__StackTop) break; // End of stack
 
-                bluelog("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
+                log("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
                 p += 4;
             }
 
@@ -355,18 +355,18 @@ static void watchdog_callback(unsigned alarm_num)
 
         if (g_watchdog_timeout <= 0)
         {
-            bluelog("--------------");
-            bluelog("WATCHDOG TIMEOUT!");
-            bluelog("Platform: ", g_platform_name);
-            bluelog("FW Version: ", g_bluelog_firmwareversion);
-            bluelog("GPIO states: out ", sio_hw->gpio_out, " oe ", sio_hw->gpio_oe, " in ", sio_hw->gpio_in);
+            log("--------------");
+            log("WATCHDOG TIMEOUT!");
+            log("Platform: ", g_platform_name);
+            log("FW Version: ", g_log_firmwareversion);
+            log("GPIO states: out ", sio_hw->gpio_out, " oe ", sio_hw->gpio_oe, " in ", sio_hw->gpio_in);
 
             uint32_t *p = (uint32_t*)__get_PSP();
             for (int i = 0; i < 8; i++)
             {
                 if (p == &__StackTop) break; // End of stack
 
-                bluelog("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
+                log("STACK ", (uint32_t)p, ":    ", p[0], " ", p[1], " ", p[2], " ", p[3]);
                 p += 4;
             }
 
@@ -410,12 +410,12 @@ bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_
     {
         if (buffer[3] != 0x20 || buffer[7] != 0x10)
         {
-            bluelog("Invalid firmware file, starts with: ", bytearray(buffer, 16));
+            log("Invalid firmware file, starts with: ", bytearray(buffer, 16));
             return false;
         }
     }
 
-    bluedbg("Writing flash at offset ", offset, " data ", bytearray(buffer, 4));
+    debuglog("Writing flash at offset ", offset, " data ", bytearray(buffer, 4));
     assert(offset % PLATFORM_FLASH_PAGE_SIZE == 0);
     assert(offset >= PLATFORM_BOOTLOADER_SIZE);
 
@@ -442,7 +442,7 @@ bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_
 
         if (actual != expected)
         {
-            bluelog("Flash verify failed at offset ", offset + i * 4, " got ", actual, " expected ", expected);
+            log("Flash verify failed at offset ", offset + i * 4, " got ", actual, " expected ", expected);
             return false;
         }
     }
@@ -657,7 +657,7 @@ public:
         for (int i = 0; i < size; i++)
         {
             char buf[2] = {((const char*)buffer)[i], 0};
-            bluelog_raw(buf);
+            log_raw(buf);
         }
         return size;
     }

+ 16 - 16
lib/BlueSCSI_platform_RP2040/rp2040_sdio.cpp

@@ -134,7 +134,7 @@ uint64_t sdio_crc16_4bit_checksum(uint32_t *data, uint32_t num_words)
 
 static void sdio_send_command(uint8_t command, uint32_t arg, uint8_t response_bits)
 {
-    // bluedbg("SDIO Command: ", (int)command, " arg ", arg);
+    // debuglog("SDIO Command: ", (int)command, " arg ", arg);
 
     // Format the arguments in the way expected by the PIO code.
     uint32_t word0 =
@@ -183,7 +183,7 @@ sdio_status_t rp2040_sdio_command_R1(uint8_t command, uint32_t arg, uint32_t *re
         {
             if (command != 8) // Don't log for missing SD card
             {
-                bluedbg("Timeout waiting for response in rp2040_sdio_command_R1(", (int)command, "), ",
+                debuglog("Timeout waiting for response in rp2040_sdio_command_R1(", (int)command, "), ",
                     "PIO PC: ", (int)pio_sm_get_pc(SDIO_PIO, SDIO_CMD_SM) - (int)g_sdio.pio_cmd_clk_offset,
                     " RXF: ", (int)pio_sm_get_rx_fifo_level(SDIO_PIO, SDIO_CMD_SM),
                     " TXF: ", (int)pio_sm_get_tx_fifo_level(SDIO_PIO, SDIO_CMD_SM));
@@ -201,7 +201,7 @@ sdio_status_t rp2040_sdio_command_R1(uint8_t command, uint32_t arg, uint32_t *re
         // Read out response packet
         uint32_t resp0 = pio_sm_get(SDIO_PIO, SDIO_CMD_SM);
         uint32_t resp1 = pio_sm_get(SDIO_PIO, SDIO_CMD_SM);
-        // bluedbg("SDIO R1 response: ", resp0, " ", resp1);
+        // debuglog("SDIO R1 response: ", resp0, " ", resp1);
 
         // Calculate response checksum
         uint8_t crc = 0;
@@ -214,14 +214,14 @@ sdio_status_t rp2040_sdio_command_R1(uint8_t command, uint32_t arg, uint32_t *re
         uint8_t actual_crc = ((resp1 >> 0) & 0xFE);
         if (crc != actual_crc)
         {
-            bluedbg("rp2040_sdio_command_R1(", (int)command, "): CRC error, calculated ", crc, " packet has ", actual_crc);
+            debuglog("rp2040_sdio_command_R1(", (int)command, "): CRC error, calculated ", crc, " packet has ", actual_crc);
             return SDIO_ERR_RESPONSE_CRC;
         }
 
         uint8_t response_cmd = ((resp0 >> 24) & 0xFF);
         if (response_cmd != command && command != 41)
         {
-            bluedbg("rp2040_sdio_command_R1(", (int)command, "): received reply for ", (int)response_cmd);
+            debuglog("rp2040_sdio_command_R1(", (int)command, "): received reply for ", (int)response_cmd);
             return SDIO_ERR_RESPONSE_CODE;
         }
 
@@ -255,7 +255,7 @@ sdio_status_t rp2040_sdio_command_R2(uint8_t command, uint32_t arg, uint8_t resp
     {
         if ((uint32_t)(millis() - start) > 2)
         {
-            bluedbg("Timeout waiting for response in rp2040_sdio_command_R2(", (int)command, "), ",
+            debuglog("Timeout waiting for response in rp2040_sdio_command_R2(", (int)command, "), ",
                   "PIO PC: ", (int)pio_sm_get_pc(SDIO_PIO, SDIO_CMD_SM) - (int)g_sdio.pio_cmd_clk_offset,
                   " RXF: ", (int)pio_sm_get_rx_fifo_level(SDIO_PIO, SDIO_CMD_SM),
                   " TXF: ", (int)pio_sm_get_tx_fifo_level(SDIO_PIO, SDIO_CMD_SM));
@@ -298,14 +298,14 @@ sdio_status_t rp2040_sdio_command_R2(uint8_t command, uint32_t arg, uint8_t resp
     uint8_t actual_crc = response[15] & 0xFE;
     if (crc != actual_crc)
     {
-        bluedbg("rp2040_sdio_command_R2(", (int)command, "): CRC error, calculated ", crc, " packet has ", actual_crc);
+        debuglog("rp2040_sdio_command_R2(", (int)command, "): CRC error, calculated ", crc, " packet has ", actual_crc);
         return SDIO_ERR_RESPONSE_CRC;
     }
 
     uint8_t response_cmd = ((response_buf[0] >> 24) & 0xFF);
     if (response_cmd != 0x3F)
     {
-        bluedbg("rp2040_sdio_command_R2(", (int)command, "): Expected reply code 0x3F");
+        debuglog("rp2040_sdio_command_R2(", (int)command, "): Expected reply code 0x3F");
         return SDIO_ERR_RESPONSE_CODE;
     }
 
@@ -323,7 +323,7 @@ sdio_status_t rp2040_sdio_command_R3(uint8_t command, uint32_t arg, uint32_t *re
     {
         if ((uint32_t)(millis() - start) > 2)
         {
-            bluedbg("Timeout waiting for response in rp2040_sdio_command_R3(", (int)command, "), ",
+            debuglog("Timeout waiting for response in rp2040_sdio_command_R3(", (int)command, "), ",
                   "PIO PC: ", (int)pio_sm_get_pc(SDIO_PIO, SDIO_CMD_SM) - (int)g_sdio.pio_cmd_clk_offset,
                   " RXF: ", (int)pio_sm_get_rx_fifo_level(SDIO_PIO, SDIO_CMD_SM),
                   " TXF: ", (int)pio_sm_get_tx_fifo_level(SDIO_PIO, SDIO_CMD_SM));
@@ -339,7 +339,7 @@ sdio_status_t rp2040_sdio_command_R3(uint8_t command, uint32_t arg, uint32_t *re
     uint32_t resp0 = pio_sm_get(SDIO_PIO, SDIO_CMD_SM);
     uint32_t resp1 = pio_sm_get(SDIO_PIO, SDIO_CMD_SM);
     *response = ((resp0 & 0xFFFFFF) << 8) | ((resp1 >> 8) & 0xFF);
-    // bluedbg("SDIO R3 response: ", resp0, " ", resp1);
+    // debuglog("SDIO R3 response: ", resp0, " ", resp1);
 
     return SDIO_OK;
 }
@@ -432,7 +432,7 @@ static void sdio_verify_rx_checksums(uint32_t maxcount)
             g_sdio.checksum_errors++;
             if (g_sdio.checksum_errors == 1)
             {
-                bluelog("SDIO checksum error in reception: block ", blockidx,
+                log("SDIO checksum error in reception: block ", blockidx,
                       " calculated ", checksum, " expected ", expected);
             }
         }
@@ -482,7 +482,7 @@ sdio_status_t rp2040_sdio_rx_poll(uint32_t *bytes_complete)
     }
     else if ((uint32_t)(millis() - g_sdio.transfer_start_time) > 1000)
     {
-        bluedbg("rp2040_sdio_rx_poll() timeout, "
+        debuglog("rp2040_sdio_rx_poll() timeout, "
             "PIO PC: ", (int)pio_sm_get_pc(SDIO_PIO, SDIO_DATA_SM) - (int)g_sdio.pio_data_rx_offset,
             " RXF: ", (int)pio_sm_get_rx_fifo_level(SDIO_PIO, SDIO_DATA_SM),
             " TXF: ", (int)pio_sm_get_tx_fifo_level(SDIO_PIO, SDIO_DATA_SM),
@@ -604,17 +604,17 @@ sdio_status_t check_sdio_write_response(uint32_t card_response)
     }
     else if (wr_status == 5)
     {
-        bluelog("SDIO card reports write CRC error, status ", card_response);
+        log("SDIO card reports write CRC error, status ", card_response);
         return SDIO_ERR_WRITE_CRC;
     }
     else if (wr_status == 6)
     {
-        bluelog("SDIO card reports write failure, status ", card_response);
+        log("SDIO card reports write failure, status ", card_response);
         return SDIO_ERR_WRITE_FAIL;
     }
     else
     {
-        bluelog("SDIO card reports unknown write status ", card_response);
+        log("SDIO card reports unknown write status ", card_response);
         return SDIO_ERR_WRITE_FAIL;
     }
 }
@@ -704,7 +704,7 @@ sdio_status_t rp2040_sdio_tx_poll(uint32_t *bytes_complete)
     }
     else if ((uint32_t)(millis() - g_sdio.transfer_start_time) > 1000)
     {
-        bluedbg("rp2040_sdio_tx_poll() timeout, "
+        debuglog("rp2040_sdio_tx_poll() timeout, "
             "PIO PC: ", (int)pio_sm_get_pc(SDIO_PIO, SDIO_DATA_SM) - (int)g_sdio.pio_data_tx_offset,
             " RXF: ", (int)pio_sm_get_rx_fifo_level(SDIO_PIO, SDIO_DATA_SM),
             " TXF: ", (int)pio_sm_get_tx_fifo_level(SDIO_PIO, SDIO_DATA_SM),

+ 5 - 5
lib/BlueSCSI_platform_RP2040/scsiHostPhy.cpp

@@ -44,7 +44,7 @@ bool scsiHostPhySelect(int target_id)
 
         if (SCSI_IN_DATA() != 0)
         {
-            bluedbg("scsiHostPhySelect: bus is busy");
+            debuglog("scsiHostPhySelect: bus is busy");
             scsiLogInitiatorPhaseChange(BUS_FREE);
             SCSI_RELEASE_OUTPUTS();
             return false;
@@ -53,7 +53,7 @@ bool scsiHostPhySelect(int target_id)
 
     // Selection phase
     scsiLogInitiatorPhaseChange(SELECTION);
-    bluedbg("------ SELECTING ", target_id);
+    debuglog("------ SELECTING ", target_id);
     SCSI_OUT(SEL, 1);
     delayMicroseconds(5);
     SCSI_OUT_DATA(1 << target_id);
@@ -179,7 +179,7 @@ static inline uint8_t scsiHostReadOneByte(int* parityError)
 
     if (parityError && r != (g_scsi_parity_lookup[r & 0xFF] ^ SCSI_IO_DATA_MASK))
     {
-        bluelog("Parity error in scsiReadOneByte(): ", (uint32_t)r);
+        log("Parity error in scsiReadOneByte(): ", (uint32_t)r);
         *parityError = 1;
     }
 
@@ -200,7 +200,7 @@ uint32_t scsiHostWrite(const uint8_t *data, uint32_t count)
             if (g_scsiHostPhyReset || SCSI_IN(IO) || SCSI_IN(CD) != cd_start || SCSI_IN(MSG) != msg_start)
             {
                 // Target switched out of DATA_OUT mode
-                bluelog("scsiHostWrite: sent ", (int)i, " bytes, expected ", (int)count);
+                log("scsiHostWrite: sent ", (int)i, " bytes, expected ", (int)count);
                 return i;
             }
         }
@@ -251,7 +251,7 @@ uint32_t scsiHostRead(uint8_t *data, uint32_t count)
     {
         if (count < fullcount)
         {
-            bluelog("scsiHostRead: received ", (int)count, " bytes, expected ", (int)fullcount);
+            log("scsiHostRead: received ", (int)count, " bytes, expected ", (int)fullcount);
         }
 
         return count;

+ 2 - 2
lib/BlueSCSI_platform_RP2040/scsiPhy.cpp

@@ -110,7 +110,7 @@ static void scsi_rst_assert_interrupt()
 
     if (rst1 && rst2)
     {
-        bluedbg("BUS RESET");
+        debuglog("BUS RESET");
         scsiDev.resetFlag = 1;
     }
 }
@@ -329,7 +329,7 @@ static inline uint8_t scsiReadOneByte(int* parityError)
 
     if (parityError && r != (g_scsi_parity_lookup[r & 0xFF] ^ SCSI_IO_DATA_MASK))
     {
-        bluedbg("Parity error in scsiReadOneByte(): ", (uint32_t)r);
+        debuglog("Parity error in scsiReadOneByte(): ", (uint32_t)r);
         *parityError = 1;
     }
 

+ 1 - 1
lib/BlueSCSI_platform_RP2040/scsi_accel_host.cpp

@@ -110,7 +110,7 @@ uint32_t scsi_accel_host_read(uint8_t *buf, uint32_t count, int *parityError, vo
     uint8_t byte1 = ~(paritycheck >> 16);
     if (paritycheck != ((g_scsi_parity_lookup[byte1] << 16) | g_scsi_parity_lookup[byte0]))
     {
-        bluelog("Parity error in scsi_accel_host_read(): ", paritycheck);
+        log("Parity error in scsi_accel_host_read(): ", paritycheck);
         *parityError = 1;
     }
 

+ 4 - 4
lib/BlueSCSI_platform_RP2040/scsi_accel_rp2040.cpp

@@ -345,7 +345,7 @@ static void scsi_accel_rp2040_stopWrite(volatile int *resetFlag)
     {
         if ((uint32_t)(millis() - start) > 5000)
         {
-            bluelog("scsi_accel_rp2040_stopWrite() timeout, FIFO levels ",
+            log("scsi_accel_rp2040_stopWrite() timeout, FIFO levels ",
                 (int)pio_sm_get_tx_fifo_level(SCSI_DMA_PIO, SCSI_DATA_SM), " ",
                 (int)pio_sm_get_rx_fifo_level(SCSI_DMA_PIO, SCSI_DATA_SM), " PC ",
                 (int)pio_sm_get_pc(SCSI_DMA_PIO, SCSI_DATA_SM));
@@ -374,7 +374,7 @@ void scsi_accel_rp2040_finishWrite(volatile int *resetFlag)
     {
         if ((uint32_t)(millis() - start) > 5000)
         {
-            bluelog("scsi_accel_rp2040_finishWrite() timeout,"
+            log("scsi_accel_rp2040_finishWrite() timeout,"
              " state: ", (int)g_scsi_dma_state, " ", (int)g_scsi_dma.dma_bytes, "/", (int)g_scsi_dma.app_bytes, ", ", (int)g_scsi_dma.next_app_bytes,
              " PIO PC: ", (int)pio_sm_get_pc(SCSI_DMA_PIO, SCSI_DATA_SM), " ", (int)pio_sm_get_pc(SCSI_DMA_PIO, SCSI_SYNC_SM),
              " PIO FIFO: ", (int)pio_sm_get_tx_fifo_level(SCSI_DMA_PIO, SCSI_DATA_SM), " ", (int)pio_sm_get_tx_fifo_level(SCSI_DMA_PIO, SCSI_SYNC_SM),
@@ -666,7 +666,7 @@ void scsi_accel_rp2040_finishRead(const uint8_t *data, uint32_t count, int *pari
     {
         if ((uint32_t)(millis() - start) > 5000)
         {
-            bluelog("scsi_accel_rp2040_finishRead timeout,"
+            log("scsi_accel_rp2040_finishRead timeout,"
              " state: ", (int)g_scsi_dma_state, " ", (int)g_scsi_dma.dma_bytes, "/", (int)g_scsi_dma.app_bytes, ", ", (int)g_scsi_dma.next_app_bytes,
              " PIO PC: ", (int)pio_sm_get_pc(SCSI_DMA_PIO, SCSI_DATA_SM), " ", (int)pio_sm_get_pc(SCSI_DMA_PIO, SCSI_SYNC_SM),
              " PIO FIFO: ", (int)pio_sm_get_rx_fifo_level(SCSI_DMA_PIO, SCSI_DATA_SM), " ", (int)pio_sm_get_tx_fifo_level(SCSI_DMA_PIO, SCSI_DATA_SM),
@@ -686,7 +686,7 @@ void scsi_accel_rp2040_finishRead(const uint8_t *data, uint32_t count, int *pari
     // Check if any parity errors have been detected during the transfer so far
     if (SCSI_DMA_PIO->irq & 1)
     {
-        bluedbg("scsi_accel_rp2040_finishRead(", bytearray(data, count), ") detected parity error");
+        debuglog("scsi_accel_rp2040_finishRead(", bytearray(data, count), ") detected parity error");
         *parityError = true;
     }
 }

+ 23 - 23
lib/BlueSCSI_platform_RP2040/sd_card_sdio.cpp

@@ -23,7 +23,7 @@ static uint32_t g_sdio_sector_count;
 static bool logSDError(int line)
 {
     g_sdio_error_line = line;
-    bluelog("SDIO SD card error on line ", line, ", error code ", (int)g_sdio_error);
+    log("SDIO SD card error on line ", line, ", error code ", (int)g_sdio_error);
     return false;
 }
 
@@ -54,7 +54,7 @@ static sd_callback_t get_stream_callback(const uint8_t *buf, uint32_t count, con
         }
         else
         {
-            bluedbg("SD card ", accesstype, "(", (int)sector,
+            debuglog("SD card ", accesstype, "(", (int)sector,
                   ") slow transfer, buffer", (uint32_t)buf, " vs. ", (uint32_t)(m_stream_buffer + m_stream_count));
             return NULL;
         }
@@ -87,7 +87,7 @@ bool SdioCard::begin(SdioConfig sdioConfig)
 
     if (reply != 0x1AA || status != SDIO_OK)
     {
-        // bluedbg("SDIO not responding to CMD8 SEND_IF_COND, status ", (int)status, " reply ", reply);
+        // debuglog("SDIO not responding to CMD8 SEND_IF_COND, status ", (int)status, " reply ", reply);
         return false;
     }
 
@@ -103,7 +103,7 @@ bool SdioCard::begin(SdioConfig sdioConfig)
 
         if ((uint32_t)(millis() - start) > 1000)
         {
-            bluelog("SDIO card initialization timeout");
+            log("SDIO card initialization timeout");
             return false;
         }
     } while (!(g_sdio_ocr & (1 << 31)));
@@ -111,21 +111,21 @@ bool SdioCard::begin(SdioConfig sdioConfig)
     // Get CID
     if (!checkReturnOk(rp2040_sdio_command_R2(CMD2, 0, (uint8_t*)&g_sdio_cid)))
     {
-        bluedbg("SDIO failed to read CID");
+        debuglog("SDIO failed to read CID");
         return false;
     }
 
     // Get relative card address
     if (!checkReturnOk(rp2040_sdio_command_R1(CMD3, 0, &g_sdio_rca)))
     {
-        bluedbg("SDIO failed to get RCA");
+        debuglog("SDIO failed to get RCA");
         return false;
     }
 
     // Get CSD
     if (!checkReturnOk(rp2040_sdio_command_R2(CMD9, g_sdio_rca, (uint8_t*)&g_sdio_csd)))
     {
-        bluedbg("SDIO failed to read CSD");
+        debuglog("SDIO failed to read CSD");
         return false;
     }
 
@@ -134,7 +134,7 @@ bool SdioCard::begin(SdioConfig sdioConfig)
     // Select card
     if (!checkReturnOk(rp2040_sdio_command_R1(CMD7, g_sdio_rca, &reply)))
     {
-        bluedbg("SDIO failed to select card");
+        debuglog("SDIO failed to select card");
         return false;
     }
 
@@ -142,7 +142,7 @@ bool SdioCard::begin(SdioConfig sdioConfig)
     if (!checkReturnOk(rp2040_sdio_command_R1(CMD55, g_sdio_rca, &reply)) ||
         !checkReturnOk(rp2040_sdio_command_R1(ACMD6, 2, &reply)))
     {
-        bluedbg("SDIO failed to set bus width");
+        debuglog("SDIO failed to set bus width");
         return false;
     }
 
@@ -198,19 +198,19 @@ bool SdioCard::readOCR(uint32_t* ocr)
 
 bool SdioCard::readData(uint8_t* dst)
 {
-    bluelog("SdioCard::readData() called but not implemented!");
+    log("SdioCard::readData() called but not implemented!");
     return false;
 }
 
 bool SdioCard::readStart(uint32_t sector)
 {
-    bluelog("SdioCard::readStart() called but not implemented!");
+    log("SdioCard::readStart() called but not implemented!");
     return false;
 }
 
 bool SdioCard::readStop()
 {
-    bluelog("SdioCard::readStop() called but not implemented!");
+    log("SdioCard::readStop() called but not implemented!");
     return false;
 }
 
@@ -252,7 +252,7 @@ bool SdioCard::stopTransmission(bool blocking)
         }
         if (isBusy())
         {
-            bluelog("SdioCard::stopTransmission() timeout");
+            log("SdioCard::stopTransmission() timeout");
             return false;
         }
         else
@@ -277,35 +277,35 @@ uint8_t SdioCard::type() const
 
 bool SdioCard::writeData(const uint8_t* src)
 {
-    bluelog("SdioCard::writeData() called but not implemented!");
+    log("SdioCard::writeData() called but not implemented!");
     return false;
 }
 
 bool SdioCard::writeStart(uint32_t sector)
 {
-    bluelog("SdioCard::writeStart() called but not implemented!");
+    log("SdioCard::writeStart() called but not implemented!");
     return false;
 }
 
 bool SdioCard::writeStop()
 {
-    bluelog("SdioCard::writeStop() called but not implemented!");
+    log("SdioCard::writeStop() called but not implemented!");
     return false;
 }
 
 bool SdioCard::erase(uint32_t firstSector, uint32_t lastSector)
 {
-    bluelog("SdioCard::erase() not implemented");
+    log("SdioCard::erase() not implemented");
     return false;
 }
 
 bool SdioCard::cardCMD6(uint32_t arg, uint8_t* status) {
-    bluelog("SdioCard::cardCMD6() not implemented");
+    log("SdioCard::cardCMD6() not implemented");
     return false;
 }
 
 bool SdioCard::readSCR(scr_t* scr) {
-    bluelog("SdioCard::readSCR() not implemented");
+    log("SdioCard::readSCR() not implemented");
     return false;
 }
 
@@ -343,7 +343,7 @@ bool SdioCard::writeSector(uint32_t sector, const uint8_t* src)
 
     if (g_sdio_error != SDIO_OK)
     {
-        bluelog("SdioCard::writeSector(", sector, ") failed: ", (int)g_sdio_error);
+        log("SdioCard::writeSector(", sector, ") failed: ", (int)g_sdio_error);
     }
 
     return g_sdio_error == SDIO_OK;
@@ -388,7 +388,7 @@ bool SdioCard::writeSectors(uint32_t sector, const uint8_t* src, size_t n)
 
     if (g_sdio_error != SDIO_OK)
     {
-        bluelog("SdioCard::writeSectors(", sector, ",...,", (int)n, ") failed: ", (int)g_sdio_error);
+        log("SdioCard::writeSectors(", sector, ",...,", (int)n, ") failed: ", (int)g_sdio_error);
         stopTransmission(true);
         return false;
     }
@@ -429,7 +429,7 @@ bool SdioCard::readSector(uint32_t sector, uint8_t* dst)
 
     if (g_sdio_error != SDIO_OK)
     {
-        bluelog("SdioCard::readSector(", sector, ") failed: ", (int)g_sdio_error);
+        log("SdioCard::readSector(", sector, ") failed: ", (int)g_sdio_error);
     }
 
     if (dst != real_dst)
@@ -477,7 +477,7 @@ bool SdioCard::readSectors(uint32_t sector, uint8_t* dst, size_t n)
 
     if (g_sdio_error != SDIO_OK)
     {
-        bluelog("SdioCard::readSectors(", sector, ",...,", (int)n, ") failed: ", (int)g_sdio_error);
+        log("SdioCard::readSectors(", sector, ",...,", (int)n, ") failed: ", (int)g_sdio_error);
         stopTransmission(true);
         return false;
     }

+ 1 - 1
lib/BlueSCSI_platform_template/scsiPhy.cpp

@@ -93,7 +93,7 @@ static void scsi_rst_assert_interrupt()
 
     if (rst1 && rst2)
     {
-        bluedbg("BUS RESET");
+        debuglog("BUS RESET");
         scsiDev.resetFlag = 1;
     }
 }

+ 31 - 31
src/BlueSCSI.cpp

@@ -72,15 +72,15 @@ void save_logfile(bool always = false)
   static uint32_t prev_log_pos = 0;
   static uint32_t prev_log_len = 0;
   static uint32_t prev_log_save = 0;
-  uint32_t loglen = bluelog_get_buffer_len();
+  uint32_t loglen = log_get_buffer_len();
 
   if (loglen != prev_log_len && g_sdcard_present)
   {
     // When debug is off, save log at most every LOG_SAVE_INTERVAL_MS
     // When debug is on, save after every SCSI command.
-    if (always || g_bluelog_debug || (LOG_SAVE_INTERVAL_MS > 0 && (uint32_t)(millis() - prev_log_save) > LOG_SAVE_INTERVAL_MS))
+    if (always || g_log_debug || (LOG_SAVE_INTERVAL_MS > 0 && (uint32_t)(millis() - prev_log_save) > LOG_SAVE_INTERVAL_MS))
     {
-      g_logfile.write(bluelog_get_buffer(&prev_log_pos));
+      g_logfile.write(log_get_buffer(&prev_log_pos));
       g_logfile.flush();
 
       prev_log_len = loglen;
@@ -98,7 +98,7 @@ void init_logfile()
   g_logfile = SD.open(LOGFILE, flags);
   if (!g_logfile.isOpen())
   {
-    bluelog("Failed to open log file: ", SD.sdErrorCode());
+    log("Failed to open log file: ", SD.sdErrorCode());
   }
   save_logfile(true);
 
@@ -108,19 +108,19 @@ void init_logfile()
 void print_sd_info()
 {
   uint64_t size = (uint64_t)SD.vol()->clusterCount() * SD.vol()->bytesPerCluster();
-  bluelog("SD card detected, FAT", (int)SD.vol()->fatType(),
+  log("SD card detected, FAT", (int)SD.vol()->fatType(),
           " volume size: ", (int)(size / 1024 / 1024), " MB");
 
   cid_t sd_cid;
 
   if(SD.card()->readCID(&sd_cid))
   {
-    bluelog("SD MID: ", (uint8_t)sd_cid.mid, ", OID: ", (uint8_t)sd_cid.oid[0], " ", (uint8_t)sd_cid.oid[1]);
+    log("SD MID: ", (uint8_t)sd_cid.mid, ", OID: ", (uint8_t)sd_cid.oid[0], " ", (uint8_t)sd_cid.oid[1]);
 
     char sdname[6] = {sd_cid.pnm[0], sd_cid.pnm[1], sd_cid.pnm[2], sd_cid.pnm[3], sd_cid.pnm[4], 0};
-    bluelog("SD Name: ", sdname);
-    bluelog("SD Date: ", (int)sd_cid.mdtMonth(), "/", sd_cid.mdtYear());
-    bluelog("SD Serial: ", sd_cid.psn());
+    log("SD Name: ", sdname);
+    log("SD Date: ", (int)sd_cid.mdtMonth(), "/", sd_cid.mdtYear());
+    log("SD Serial: ", sd_cid.psn());
   }
 }
 
@@ -135,13 +135,13 @@ bool findHDDImages()
   ini_gets("SCSI", "Dir", "/", imgdir, sizeof(imgdir), CONFIGFILE);
   int dirindex = 0;
 
-  bluelog("Finding HDD images in directory ", imgdir, ":");
+  log("Finding HDD images in directory ", imgdir, ":");
 
   SdFile root;
   root.open(imgdir);
   if (!root.isOpen())
   {
-    bluelog("Could not open directory: ", imgdir);
+    log("Could not open directory: ", imgdir);
   }
 
   SdFile file;
@@ -166,11 +166,11 @@ bool findHDDImages()
 
       if (imgdir[0] != '\0')
       {
-        bluelog("Finding HDD images in additional directory Dir", (int)dirindex, " = \"", imgdir, "\":");
+        log("Finding HDD images in additional directory Dir", (int)dirindex, " = \"", imgdir, "\":");
         root.open(imgdir);
         if (!root.isOpen())
         {
-          bluelog("-- Could not open directory: ", imgdir);
+          log("-- Could not open directory: ", imgdir);
         }
         continue;
       }
@@ -218,7 +218,7 @@ bool findHDDImages()
 
         if (is_compressed)
         {
-          bluelog("-- Ignoring compressed file ", name);
+          log("-- Ignoring compressed file ", name);
           continue;
         }
 
@@ -290,7 +290,7 @@ bool findHDDImages()
         // Check whether this SCSI ID has been configured yet
         if (s2s_getConfigById(id))
         {
-          bluelog("-- Ignoring ", fullname, ", SCSI ID ", id, " is already in use!");
+          log("-- Ignoring ", fullname, ", SCSI ID ", id, " is already in use!");
           continue;
         }
 
@@ -306,7 +306,7 @@ bool findHDDImages()
         // Open the image file
         if (id < NUM_SCSIID && is_romdrive)
         {
-          bluelog("-- Loading ROM drive from ", fullname, " for id:", id);
+          log("-- Loading ROM drive from ", fullname, " for id:", id);
           imageReady = scsiDiskProgramRomDrive(fullname, id, blk, type);
           
           if (imageReady)
@@ -315,7 +315,7 @@ bool findHDDImages()
           }
         }
         else if(id < NUM_SCSIID && lun < NUM_SCSILUN) {
-          bluelog("-- Opening ", fullname, " for id:", id, " lun:", lun);
+          log("-- Opening ", fullname, " for id:", id, " lun:", lun);
 
           imageReady = scsiDiskOpenHDDImage(id, fullname, id, lun, blk, type);
           if(imageReady)
@@ -324,17 +324,17 @@ bool findHDDImages()
           }
           else
           {
-            bluelog("---- Failed to load image");
+            log("---- Failed to load image");
           }
         } else {
-          bluelog("-- Invalid lun or id for image ", fullname);
+          log("-- Invalid lun or id for image ", fullname);
         }
       }
     }
   }
 
   if(usedDefaultId > 0) {
-    bluelog("Some images did not specify a SCSI ID. Last file will be used at ID ", usedDefaultId);
+    log("Some images did not specify a SCSI ID. Last file will be used at ID ", usedDefaultId);
   }
   root.close();
 
@@ -348,7 +348,7 @@ bool findHDDImages()
     if (cfg && (cfg->scsiId & S2S_CFG_TARGET_ENABLED))
     {
       int capacity_kB = ((uint64_t)cfg->scsiSectors * cfg->bytesPerSector) / 1024;
-      bluelog("SCSI ID:", (int)(cfg->scsiId & 7),
+      log("SCSI ID:", (int)(cfg->scsiId & 7),
             " BlockSize:", (int)cfg->bytesPerSector,
             " Type:", (int)cfg->deviceType,
             " Quirks:", (int)cfg->quirks,
@@ -399,7 +399,7 @@ static void reinitSCSI()
 {
   if (ini_getbool("SCSI", "Debug", 0, CONFIGFILE))
   {
-    g_bluelog_debug = true;
+    g_log_debug = true;
   }
 
 #ifdef PLATFORM_HAS_INITIATOR_MODE
@@ -430,11 +430,11 @@ static void reinitSCSI()
   else
   {
 #if RAW_FALLBACK_ENABLE
-    bluelog("No images found, enabling RAW fallback partition");
+    log("No images found, enabling RAW fallback partition");
     scsiDiskOpenHDDImage(RAW_FALLBACK_SCSI_ID, "RAW:0:0xFFFFFFFF", RAW_FALLBACK_SCSI_ID, 0,
                          RAW_FALLBACK_BLOCKSIZE);
 #else
-    bluelog("No valid image files found!");
+    log("No valid image files found!");
 #endif
     blinkStatus(BLINK_ERROR_NO_IMAGES);
   }
@@ -454,7 +454,7 @@ extern "C" void bluescsi_setup(void)
 
   if(!g_sdcard_present)
   {
-    bluelog("SD card init failed, sdErrorCode: ", (int)SD.sdErrorCode(),
+    log("SD card init failed, sdErrorCode: ", (int)SD.sdErrorCode(),
            " sdErrorData: ", (int)SD.sdErrorData());
     
     blinkStatus(BLINK_ERROR_NO_SD_CARD);
@@ -464,7 +464,7 @@ extern "C" void bluescsi_setup(void)
       reinitSCSI();
       if (g_romdrive_active)
       {
-        bluelog("Enabled ROM drive without SD card");
+        log("Enabled ROM drive without SD card");
         return;
       }
     }
@@ -476,14 +476,14 @@ extern "C" void bluescsi_setup(void)
       platform_reset_watchdog();
       g_sdcard_present = mountSDCard();
     } while (!g_sdcard_present);
-    bluelog("SD card init succeeded after retry");
+    log("SD card init succeeded after retry");
   }
 
   if (g_sdcard_present)
   {
     if (SD.clusterCount() == 0)
     {
-      bluelog("SD card without filesystem!");
+      log("SD card without filesystem!");
     }
 
     print_sd_info();
@@ -491,7 +491,7 @@ extern "C" void bluescsi_setup(void)
     reinitSCSI();
   }
 
-  bluelog("Initialization complete!");
+  log("Initialization complete!");
 
   if (g_sdcard_present)
   {
@@ -542,7 +542,7 @@ extern "C" void bluescsi_main_loop(void)
         if (!SD.card()->readOCR(&ocr))
         {
           g_sdcard_present = false;
-          bluelog("SD card removed, trying to reinit");
+          log("SD card removed, trying to reinit");
         }
       }
     }
@@ -557,7 +557,7 @@ extern "C" void bluescsi_main_loop(void)
 
       if (g_sdcard_present)
       {
-        bluelog("SD card reinit succeeded");
+        log("SD card reinit succeeded");
         print_sd_info();
 
         reinitSCSI();

+ 12 - 12
src/BlueSCSI_bootloader.cpp

@@ -27,7 +27,7 @@ bool find_firmware_image(FsFile &file, char name[MAX_FILE_PATH + 1])
             strncasecmp(name + namelen - 3, "bin", 3) == 0)
         {
             root.close();
-            bluelog("Found firmware file: ", name);
+            log("Found firmware file: ", name);
             return true;
         }
 
@@ -49,13 +49,13 @@ bool program_firmware(FsFile &file)
 
     if (fwsize > PLATFORM_FLASH_TOTAL_SIZE)
     {
-        bluelog("Firmware too large: ", (int)fwsize, " flash size ", (int)PLATFORM_FLASH_TOTAL_SIZE);
+        log("Firmware too large: ", (int)fwsize, " flash size ", (int)PLATFORM_FLASH_TOTAL_SIZE);
         return false;
     }
 
     if (!file.seek(PLATFORM_BOOTLOADER_SIZE))
     {
-        bluelog("Seek failed");
+        log("Seek failed");
         return false;
     }
 
@@ -68,13 +68,13 @@ bool program_firmware(FsFile &file)
 
         if (file.read(buffer, PLATFORM_FLASH_PAGE_SIZE) <= 0)
         {
-            bluelog("Firmware file read failed on page ", i);
+            log("Firmware file read failed on page ", i);
             return false;
         }
 
         if (!platform_rewrite_flash_page(PLATFORM_BOOTLOADER_SIZE + i * PLATFORM_FLASH_PAGE_SIZE, buffer))
         {
-            bluelog("Flash programming failed on page ", i);
+            log("Flash programming failed on page ", i);
             return false;
         }
     }
@@ -104,9 +104,9 @@ extern "C"
 int bootloader_main(void)
 {
     platform_init();
-    g_bluelog_debug = true;
+    g_log_debug = true;
 
-    bluelog("Bootloader version: " __DATE__ " " __TIME__ " " PLATFORM_NAME);
+    log("Bootloader version: " __DATE__ " " __TIME__ " " PLATFORM_NAME);
 
     if (mountSDCard() || mountSDCard())
     {
@@ -116,16 +116,16 @@ int bootloader_main(void)
         {
             if (program_firmware(fwfile))
             {
-                bluelog("Firmware update successful!");
+                log("Firmware update successful!");
                 fwfile.close();
                 if (!SD.remove(name))
                 {
-                    bluelog("Failed to remove firmware file");
+                    log("Failed to remove firmware file");
                 }
             }
             else
             {
-                bluelog("Firmware update failed!");
+                log("Firmware update failed!");
                 platform_emergency_log_save();
             }
 
@@ -133,10 +133,10 @@ int bootloader_main(void)
     }
     else
     {
-        bluelog("Bootloader SD card init failed");
+        log("Bootloader SD card init failed");
     }
 
-    bluelog("Bootloader continuing to main firmware");
+    log("Bootloader continuing to main firmware");
     platform_boot_to_main_firmware();
 
     return 0;

+ 62 - 62
src/BlueSCSI_disk.cpp

@@ -120,27 +120,27 @@ static bool check_romdrive(romdrive_hdr_t *hdr)
 bool scsiDiskProgramRomDrive(const char *filename, int scsi_id, int blocksize, S2S_CFG_TYPE type)
 {
 #ifndef PLATFORM_HAS_ROM_DRIVE
-    bluelog("---- Platform does not support ROM drive");
+    log("---- Platform does not support ROM drive");
     return false;
 #endif
 
     FsFile file = SD.open(filename, O_RDONLY);
     if (!file.isOpen())
     {
-        bluelog("---- Failed to open: ", filename);
+        log("---- Failed to open: ", filename);
         return false;
     }
 
     uint64_t filesize = file.size();
     uint32_t maxsize = platform_get_romdrive_maxsize() - PLATFORM_ROMDRIVE_PAGE_SIZE;
 
-    bluelog("---- SCSI ID: ", scsi_id, " blocksize ", blocksize, " type ", (int)type);
-    bluelog("---- ROM drive maximum size is ", (int)maxsize,
+    log("---- SCSI ID: ", scsi_id, " blocksize ", blocksize, " type ", (int)type);
+    log("---- ROM drive maximum size is ", (int)maxsize,
           " bytes, image file is ", (int)filesize, " bytes");
     
     if (filesize > maxsize)
     {
-        bluelog("---- Image size exceeds ROM space, not loading");
+        log("---- Image size exceeds ROM space, not loading");
         file.close();
         return false;
     }
@@ -155,7 +155,7 @@ bool scsiDiskProgramRomDrive(const char *filename, int scsi_id, int blocksize, S
     // Program the drive metadata header
     if (!platform_write_romdrive((const uint8_t*)&hdr, 0, PLATFORM_ROMDRIVE_PAGE_SIZE))
     {
-        bluelog("---- Failed to program ROM drive header");
+        log("---- Failed to program ROM drive header");
         file.close();
         return false;
     }
@@ -172,7 +172,7 @@ bool scsiDiskProgramRomDrive(const char *filename, int scsi_id, int blocksize, S
         if (file.read(scsiDev.data, PLATFORM_ROMDRIVE_PAGE_SIZE) <= 0 ||
             !platform_write_romdrive(scsiDev.data, (i + 1) * PLATFORM_ROMDRIVE_PAGE_SIZE, PLATFORM_ROMDRIVE_PAGE_SIZE))
         {
-            bluelog("---- Failed to program ROM drive page ", (int)i);
+            log("---- Failed to program ROM drive page ", (int)i);
             file.close();
             return false;
         }
@@ -186,7 +186,7 @@ bool scsiDiskProgramRomDrive(const char *filename, int scsi_id, int blocksize, S
     strlcat(newname, filename, sizeof(newname));
     strlcat(newname, "_loaded", sizeof(newname));
     SD.rename(filename, newname);
-    bluelog("---- ROM drive programming successful, image file renamed to ", newname);
+    log("---- ROM drive programming successful, image file renamed to ", newname);
 
     return true;
 }
@@ -205,18 +205,18 @@ bool scsiDiskActivateRomDrive()
 #endif
 
     uint32_t maxsize = platform_get_romdrive_maxsize() - PLATFORM_ROMDRIVE_PAGE_SIZE;
-    bluelog("-- Platform supports ROM drive up to ", (int)(maxsize / 1024), " kB");
+    log("-- Platform supports ROM drive up to ", (int)(maxsize / 1024), " kB");
 
     romdrive_hdr_t hdr = {};
     if (!check_romdrive(&hdr))
     {
-        bluelog("---- ROM drive image not detected");
+        log("---- ROM drive image not detected");
         return false;
     }
 
     if (ini_getbool("SCSI", "DisableROMDrive", 0, CONFIGFILE))
     {
-        bluelog("---- ROM drive disabled in ini file, not enabling");
+        log("---- ROM drive disabled in ini file, not enabling");
         return false;
     }
 
@@ -224,23 +224,23 @@ bool scsiDiskActivateRomDrive()
     if (rom_scsi_id >= 0 && rom_scsi_id <= 7)
     {
         hdr.scsi_id = rom_scsi_id;
-        bluelog("---- ROM drive SCSI id overriden in ini file, changed to ", (int)hdr.scsi_id);
+        log("---- ROM drive SCSI id overriden in ini file, changed to ", (int)hdr.scsi_id);
     }
 
     if (s2s_getConfigById(hdr.scsi_id))
     {
-        bluelog("---- ROM drive SCSI id ", (int)hdr.scsi_id, " is already in use, not enabling");
+        log("---- ROM drive SCSI id ", (int)hdr.scsi_id, " is already in use, not enabling");
         return false;
     }
 
 
 
-    bluelog("---- Activating ROM drive, SCSI id ", (int)hdr.scsi_id, " size ", (int)(hdr.imagesize / 1024), " kB");
+    log("---- Activating ROM drive, SCSI id ", (int)hdr.scsi_id, " size ", (int)(hdr.imagesize / 1024), " kB");
     bool status = scsiDiskOpenHDDImage(hdr.scsi_id, "ROM:", hdr.scsi_id, 0, hdr.blocksize, hdr.drivetype);
 
     if (!status)
     {
-        bluelog("---- ROM drive activation failed");
+        log("---- ROM drive activation failed");
         return false;
     }
     else
@@ -286,13 +286,13 @@ public:
 
             if (*endptr != ':' || *endptr2 != '\0')
             {
-                bluelog("Invalid format for raw filename: ", filename);
+                log("Invalid format for raw filename: ", filename);
                 return;
             }
 
             if ((scsi_block_size % SD_SECTOR_SIZE) != 0)
             {
-                bluelog("SCSI block size ", (int)scsi_block_size, " is not supported for RAW partitions (must be divisible by 512 bytes)");
+                log("SCSI block size ", (int)scsi_block_size, " is not supported for RAW partitions (must be divisible by 512 bytes)");
                 return;
             }
 
@@ -302,7 +302,7 @@ public:
             uint32_t sectorCount = SD.card()->sectorCount();
             if (m_endsector >= sectorCount)
             {
-                bluelog("Limiting RAW image mapping to SD card sector count: ", (int)sectorCount);
+                log("Limiting RAW image mapping to SD card sector count: ", (int)sectorCount);
                 m_endsector = sectorCount - 1;
             }
         }
@@ -335,10 +335,10 @@ public:
                 if (end != begin + sectorcount)
                 {
                     uint32_t allocsize = end - begin + 1;
-                    bluelog("---- NOTE: File ", filename, " has FAT allocated size of ", (int)allocsize, " sectors and file size of ", (int)sectorcount, " sectors");
-                    bluelog("---- Due to issue #80 in BlueSCSI version 1.0.8 and 1.0.9 the allocated size was mistakenly reported to SCSI controller.");
-                    bluelog("---- If the drive was formatted using those versions, you may have problems accessing it with newer firmware.");
-                    bluelog("---- The old behavior can be restored with setting  [SCSI] UseFATAllocSize = 1 in " CONFIGFILE);
+                    log("---- NOTE: File ", filename, " has FAT allocated size of ", (int)allocsize, " sectors and file size of ", (int)sectorcount, " sectors");
+                    log("---- Due to issue #80 in BlueSCSI version 1.0.8 and 1.0.9 the allocated size was mistakenly reported to SCSI controller.");
+                    log("---- If the drive was formatted using those versions, you may have problems accessing it with newer firmware.");
+                    log("---- The old behavior can be restored with setting  [SCSI] UseFATAllocSize = 1 in " CONFIGFILE);
 
                     if (ini_getbool("SCSI", "UseFATAllocSize", 0, CONFIGFILE))
                     {
@@ -503,7 +503,7 @@ public:
         }
         else if (m_isrom)
         {
-            bluelog("ERROR: attempted to write to ROM drive");
+            log("ERROR: attempted to write to ROM drive");
             return 0;
         }
         else
@@ -722,7 +722,7 @@ bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int
 
         if (img.scsiSectors == 0)
         {
-            bluelog("---- Error: image file ", filename, " is empty");
+            log("---- Error: image file ", filename, " is empty");
             img.file.close();
             return false;
         }
@@ -734,36 +734,36 @@ bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int
         }
         else if (img.file.contiguousRange(&sector_begin, &sector_end))
         {
-            bluelog("---- Image file is contiguous, SD card sectors ", (int)sector_begin, " to ", (int)sector_end);
+            log("---- Image file is contiguous, SD card sectors ", (int)sector_begin, " to ", (int)sector_end);
         }
         else
         {
-            bluelog("---- WARNING: file ", filename, " is not contiguous. This will increase read latency.");
+            log("---- WARNING: file ", filename, " is not contiguous. This will increase read latency.");
         }
 
         if (type == S2S_CFG_OPTICAL)
         {
-            bluelog("---- Configuring as CD-ROM drive based on image name");
+            log("---- Configuring as CD-ROM drive based on image name");
             img.deviceType = S2S_CFG_OPTICAL;
         }
         else if (type == S2S_CFG_FLOPPY_14MB)
         {
-            bluelog("---- Configuring as floppy drive based on image name");
+            log("---- Configuring as floppy drive based on image name");
             img.deviceType = S2S_CFG_FLOPPY_14MB;
         }
         else if (type == S2S_CFG_MO)
         {
-            bluelog("---- Configuring as magneto-optical based on image name");
+            log("---- Configuring as magneto-optical based on image name");
             img.deviceType = S2S_CFG_MO;
         }
         else if (type == S2S_CFG_REMOVEABLE)
         {
-            bluelog("---- Configuring as removable drive based on image name");
+            log("---- Configuring as removable drive based on image name");
             img.deviceType = S2S_CFG_REMOVEABLE;
         }
         else if (type == S2S_CFG_SEQUENTIAL)
         {
-            bluelog("---- Configuring as tape drive based on image name");
+            log("---- Configuring as tape drive based on image name");
             img.deviceType = S2S_CFG_SEQUENTIAL;
         }
 
@@ -775,11 +775,11 @@ bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int
 
         if (img.prefetchbytes > 0)
         {
-            bluelog("---- Read prefetch enabled: ", (int)img.prefetchbytes, " bytes");
+            log("---- Read prefetch enabled: ", (int)img.prefetchbytes, " bytes");
         }
         else
         {
-            bluelog("---- Read prefetch disabled");
+            log("---- Read prefetch disabled");
         }
 
         return true;
@@ -795,7 +795,7 @@ static void checkDiskGeometryDivisible(image_config_t &img)
         uint32_t sectorsPerHeadTrack = img.sectorsPerTrack * img.headsPerCylinder;
         if (img.scsiSectors % sectorsPerHeadTrack != 0)
         {
-            bluelog("WARNING: Host used command ", scsiDev.cdb[0],
+            log("WARNING: Host used command ", scsiDev.cdb[0],
                 " which is affected by drive geometry. Current settings are ",
                 (int)img.sectorsPerTrack, " sectors x ", (int)img.headsPerCylinder, " heads = ",
                 (int)sectorsPerHeadTrack, " but image size of ", (int)img.scsiSectors,
@@ -887,7 +887,7 @@ void scsiDiskLoadConfig(int target_idx)
     {
         image_config_t &img = g_DiskImages[target_idx];
         int blocksize = (img.deviceType == S2S_CFG_OPTICAL) ? 2048 : 512;
-        bluelog("-- Opening ", filename, " for id:", target_idx, ", specified in " CONFIGFILE);
+        log("-- Opening ", filename, " for id:", target_idx, ", specified in " CONFIGFILE);
         scsiDiskOpenHDDImage(target_idx, filename, target_idx, 0, blocksize);
     }
 }
@@ -914,14 +914,14 @@ void s2s_configInit(S2S_BoardCfg* config)
 {
     if (SD.exists(CONFIGFILE))
     {
-        bluelog("Reading configuration from " CONFIGFILE);
+        log("Reading configuration from " CONFIGFILE);
     }
     else
     {
-        bluelog("Config file " CONFIGFILE " not found, using defaults");
+        log("Config file " CONFIGFILE " not found, using defaults");
     }
 
-    bluelog("Active configuration:");
+    log("Active configuration:");
     memset(config, 0, sizeof(S2S_BoardCfg));
     memcpy(config->magic, "BCFG", 4);
     config->flags = 0;
@@ -936,40 +936,40 @@ void s2s_configInit(S2S_BoardCfg* config)
     else if (maxSyncSpeed < 10 && config->scsiSpeed > S2S_CFG_SPEED_SYNC_5)
         config->scsiSpeed = S2S_CFG_SPEED_SYNC_5;
 
-    bluelog("-- SelectionDelay: ", (int)config->selectionDelay);
+    log("-- SelectionDelay: ", (int)config->selectionDelay);
 
     if (ini_getbool("SCSI", "EnableUnitAttention", false, CONFIGFILE))
     {
-        bluelog("-- EnableUnitAttention is on");
+        log("-- EnableUnitAttention is on");
         config->flags |= S2S_CFG_ENABLE_UNIT_ATTENTION;
     }
 
     if (ini_getbool("SCSI", "EnableSCSI2", true, CONFIGFILE))
     {
-        bluelog("-- EnableSCSI2 is on");
+        log("-- EnableSCSI2 is on");
         config->flags |= S2S_CFG_ENABLE_SCSI2;
     }
 
     if (ini_getbool("SCSI", "EnableSelLatch", false, CONFIGFILE))
     {
-        bluelog("-- EnableSelLatch is on");
+        log("-- EnableSelLatch is on");
         config->flags |= S2S_CFG_ENABLE_SEL_LATCH;
     }
 
     if (ini_getbool("SCSI", "MapLunsToIDs", false, CONFIGFILE))
     {
-        bluelog("-- MapLunsToIDs is on");
+        log("-- MapLunsToIDs is on");
         config->flags |= S2S_CFG_MAP_LUNS_TO_IDS;
     }
 
     if (ini_getbool("SCSI", "Parity", true, CONFIGFILE))
     {
-        bluelog("-- Parity is enabled");
+        log("-- Parity is enabled");
         config->flags |= S2S_CFG_ENABLE_PARITY;
     }
     else
     {
-        bluelog("-- Parity is disabled");
+        log("-- Parity is disabled");
     }
 }
 
@@ -1161,7 +1161,7 @@ static bool checkNextCDImage()
 
     if (filename[0] != '\0')
     {
-        bluelog("Switching to next CD-ROM image for ", target_idx, ": ", filename);
+        log("Switching to next CD-ROM image for ", target_idx, ": ", filename);
         image_config_t &img = g_DiskImages[target_idx];
         img.file.close();
         bool status = scsiDiskOpenHDDImage(target_idx, filename, target_idx, 0, 2048);
@@ -1336,14 +1336,14 @@ static void doWrite(uint32_t lba, uint32_t blocks)
     uint32_t bytesPerSector = scsiDev.target->liveCfg.bytesPerSector;
     uint32_t capacity = img.file.size() / bytesPerSector;
 
-    bluedbg("------ Write ", (int)blocks, "x", (int)bytesPerSector, " starting at ", (int)lba);
+    debuglog("------ Write ", (int)blocks, "x", (int)bytesPerSector, " starting at ", (int)lba);
 
     if (unlikely(blockDev.state & DISK_WP) ||
         unlikely(scsiDev.target->cfg->deviceType == S2S_CFG_OPTICAL) ||
         unlikely(!img.file.isWritable()))
 
     {
-        bluelog("WARNING: Host attempted write to read-only drive ID ", (int)(img.scsiId & S2S_CFG_TARGET_ID_BITS));
+        log("WARNING: Host attempted write to read-only drive ID ", (int)(img.scsiId & S2S_CFG_TARGET_ID_BITS));
         scsiDev.status = CHECK_CONDITION;
         scsiDev.target->sense.code = ILLEGAL_REQUEST;
         scsiDev.target->sense.asc = WRITE_PROTECTED;
@@ -1351,7 +1351,7 @@ static void doWrite(uint32_t lba, uint32_t blocks)
     }
     else if (unlikely(((uint64_t) lba) + blocks > capacity))
     {
-        bluelog("WARNING: Host attempted write at sector ", (int)lba, "+", (int)blocks,
+        log("WARNING: Host attempted write at sector ", (int)lba, "+", (int)blocks,
               ", exceeding image size ", (int)capacity, " sectors (",
               (int)bytesPerSector, "B/sector)");
         scsiDev.status = CHECK_CONDITION;
@@ -1378,7 +1378,7 @@ static void doWrite(uint32_t lba, uint32_t blocks)
         image_config_t &img = *(image_config_t*)scsiDev.target->cfg;
         if (!img.file.seek((uint64_t)transfer.lba * bytesPerSector))
         {
-            bluelog("Seek to ", transfer.lba, " failed for SCSI ID", (int)scsiDev.target->targetId);
+            log("Seek to ", transfer.lba, " failed for SCSI ID", (int)scsiDev.target->targetId);
             scsiDev.status = CHECK_CONDITION;
             scsiDev.target->sense.code = MEDIUM_ERROR;
             scsiDev.target->sense.asc = NO_SEEK_COMPLETE;
@@ -1429,7 +1429,7 @@ void diskDataOut_callback(uint32_t bytes_complete)
         if (len == 0)
             return;
 
-        // bluedbg("SCSI read ", (int)start, " + ", (int)len);
+        // debuglog("SCSI read ", (int)start, " + ", (int)len);
         scsiStartRead(&scsiDev.data[start], len, &g_disk_transfer.parityError);
         g_disk_transfer.bytes_scsi_started += len;
     }
@@ -1529,11 +1529,11 @@ void diskDataOut()
             // when buffer space is freed.
             uint8_t *buf = &scsiDev.data[start];
             g_disk_transfer.sd_transfer_start = start;
-            // bluedbg("SD write ", (int)start, " + ", (int)len, " ", bytearray(buf, len));
+            // debuglog("SD write ", (int)start, " + ", (int)len, " ", bytearray(buf, len));
             platform_set_sd_callback(&diskDataOut_callback, buf);
             if (img.file.write(buf, len) != len)
             {
-                bluelog("SD card write failed: ", SD.sdErrorCode());
+                log("SD card write failed: ", SD.sdErrorCode());
                 scsiDev.status = CHECK_CONDITION;
                 scsiDev.target->sense.code = MEDIUM_ERROR;
                 scsiDev.target->sense.asc = WRITE_ERROR_AUTO_REALLOCATION_FAILED;
@@ -1575,11 +1575,11 @@ static void doRead(uint32_t lba, uint32_t blocks)
     uint32_t bytesPerSector = scsiDev.target->liveCfg.bytesPerSector;
     uint32_t capacity = img.file.size() / bytesPerSector;
 
-    bluedbg("------ Read ", (int)blocks, "x", (int)bytesPerSector, " starting at ", (int)lba);
+    debuglog("------ Read ", (int)blocks, "x", (int)bytesPerSector, " starting at ", (int)lba);
 
     if (unlikely(((uint64_t) lba) + blocks > capacity))
     {
-        bluelog("WARNING: Host attempted read at sector ", (int)lba, "+", (int)blocks,
+        log("WARNING: Host attempted read at sector ", (int)lba, "+", (int)blocks,
               ", exceeding image size ", (int)capacity, " sectors (",
               (int)bytesPerSector, "B/sector)");
         scsiDev.status = CHECK_CONDITION;
@@ -1610,7 +1610,7 @@ static void doRead(uint32_t lba, uint32_t blocks)
             uint32_t count = sectors_in_prefetch - start_offset;
             if (count > transfer.blocks) count = transfer.blocks;
             scsiStartWrite(g_scsi_prefetch.buffer + start_offset * bytesPerSector, count * bytesPerSector);
-            bluedbg("------ Found ", (int)count, " sectors in prefetch cache");
+            debuglog("------ Found ", (int)count, " sectors in prefetch cache");
             transfer.currentBlock += count;
         }
 
@@ -1622,7 +1622,7 @@ static void doRead(uint32_t lba, uint32_t blocks)
 
         if (!img.file.seek((uint64_t)(transfer.lba + transfer.currentBlock) * bytesPerSector))
         {
-            bluelog("Seek to ", transfer.lba, " failed for SCSI ID", (int)scsiDev.target->targetId);
+            log("Seek to ", transfer.lba, " failed for SCSI ID", (int)scsiDev.target->targetId);
             scsiDev.status = CHECK_CONDITION;
             scsiDev.target->sense.code = MEDIUM_ERROR;
             scsiDev.target->sense.asc = NO_SEEK_COMPLETE;
@@ -1681,7 +1681,7 @@ static void start_dataInTransfer(uint8_t *buffer, uint32_t count)
     {
         if ((uint32_t)(millis() - start) > 5000)
         {
-            bluelog("start_dataInTransfer() timeout waiting for previous to finish");
+            log("start_dataInTransfer() timeout waiting for previous to finish");
             scsiDev.resetFlag = 1;
         }
     }
@@ -1693,7 +1693,7 @@ static void start_dataInTransfer(uint8_t *buffer, uint32_t count)
 
     if (img.file.read(buffer, count) != count)
     {
-        bluelog("SD card read failed: ", SD.sdErrorCode());
+        log("SD card read failed: ", SD.sdErrorCode());
         scsiDev.status = CHECK_CONDITION;
         scsiDev.target->sense.code = MEDIUM_ERROR;
         scsiDev.target->sense.asc = UNRECOVERED_READ_ERROR;
@@ -1771,7 +1771,7 @@ static void diskDataIn()
             int status = img.file.read(g_disk_transfer.buffer, bytesPerSector);
             if (status <= 0)
             {
-                bluelog("Prefetch read failed");
+                log("Prefetch read failed");
                 prefetch_sectors = 0;
                 break;
             }
@@ -1810,13 +1810,13 @@ int scsiDiskCommand()
         {
             if (start)
             {
-                bluedbg("------ CDROM close tray");
+                debuglog("------ CDROM close tray");
                 img.ejected = false;
                 img.cdrom_events = 2; // New media
             }
             else
             {
-                bluedbg("------ CDROM open tray");
+                debuglog("------ CDROM open tray");
                 img.ejected = true;
                 img.cdrom_events = 3; // Media removal
             }

+ 38 - 38
src/BlueSCSI_initiator.cpp

@@ -141,35 +141,35 @@ void scsiInitiatorMainLoop()
 
             if (readcapok)
             {
-                bluelog("SCSI id ", g_initiator_state.target_id,
+                log("SCSI id ", g_initiator_state.target_id,
                     " capacity ", (int)g_initiator_state.sectorcount,
                     " sectors x ", (int)g_initiator_state.sectorsize, " bytes");
 
                 g_initiator_state.sectorcount_all = g_initiator_state.sectorcount;
 
                 uint64_t total_bytes = (uint64_t)g_initiator_state.sectorcount * g_initiator_state.sectorsize;
-                bluelog("Drive total size is ", (int)(total_bytes / (1024 * 1024)), " MiB");
+                log("Drive total size is ", (int)(total_bytes / (1024 * 1024)), " MiB");
                 if (total_bytes >= 0xFFFFFFFF && SD.fatType() != FAT_TYPE_EXFAT)
                 {
                     // Note: the FAT32 limit is 4 GiB - 1 byte
-                    bluelog("Image files equal or larger than 4 GiB are only possible on exFAT filesystem");
-                    bluelog("Please reformat the SD card with exFAT format to image this drive fully");
+                    log("Image files equal or larger than 4 GiB are only possible on exFAT filesystem");
+                    log("Please reformat the SD card with exFAT format to image this drive fully");
 
                     g_initiator_state.sectorcount = (uint32_t)0xFFFFFFFF / g_initiator_state.sectorsize;
-                    bluelog("Will image first 4 GiB - 1 = ", (int)g_initiator_state.sectorcount, " sectors");
+                    log("Will image first 4 GiB - 1 = ", (int)g_initiator_state.sectorcount, " sectors");
                 }
             }
             else if (startstopok)
             {
-                bluelog("SCSI id ", g_initiator_state.target_id, " responds but ReadCapacity command failed");
-                bluelog("Possibly SCSI-1 drive? Attempting to read up to 1 GB.");
+                log("SCSI id ", g_initiator_state.target_id, " responds but ReadCapacity command failed");
+                log("Possibly SCSI-1 drive? Attempting to read up to 1 GB.");
                 g_initiator_state.sectorsize = 512;
                 g_initiator_state.sectorcount = g_initiator_state.sectorcount_all = 2097152;
                 g_initiator_state.max_sector_per_transfer = 128;
             }
             else
             {
-                bluedbg("Failed to connect to SCSI id ", g_initiator_state.target_id);
+                debuglog("Failed to connect to SCSI id ", g_initiator_state.target_id);
                 g_initiator_state.sectorsize = 0;
                 g_initiator_state.sectorcount = g_initiator_state.sectorcount_all = 0;
             }
@@ -193,7 +193,7 @@ void scsiInitiatorMainLoop()
                 g_initiator_state.target_file = SD.open(filename, O_RDWR | O_CREAT | O_TRUNC);
                 if (!g_initiator_state.target_file.isOpen())
                 {
-                    bluelog("Failed to open file for writing: ", filename);
+                    log("Failed to open file for writing: ", filename);
                     return;
                 }
 
@@ -201,11 +201,11 @@ void scsiInitiatorMainLoop()
                 {
                     // Only preallocate on exFAT, on FAT32 preallocating can result in false garbage data in the
                     // file if write is interrupted.
-                    bluelog("Preallocating image file");
+                    log("Preallocating image file");
                     g_initiator_state.target_file.preAllocate((uint64_t)g_initiator_state.sectorcount * g_initiator_state.sectorsize);
                 }
 
-                bluelog("Starting to copy drive data to ", filename);
+                log("Starting to copy drive data to ", filename);
                 g_initiator_state.imaging = true;
             }
         }
@@ -216,13 +216,13 @@ void scsiInitiatorMainLoop()
         if (g_initiator_state.sectors_done >= g_initiator_state.sectorcount)
         {
             scsiStartStopUnit(g_initiator_state.target_id, false);
-            bluelog("Finished imaging drive with id ", g_initiator_state.target_id);
+            log("Finished imaging drive with id ", g_initiator_state.target_id);
             LED_OFF();
 
             if (g_initiator_state.sectorcount != g_initiator_state.sectorcount_all)
             {
-                bluelog("NOTE: Image size was limited to first 4 GiB due to SD card filesystem limit");
-                bluelog("Please reformat the SD card with exFAT format to image this drive fully");
+                log("NOTE: Image size was limited to first 4 GiB due to SD card filesystem limit");
+                log("Please reformat the SD card with exFAT format to image this drive fully");
             }
 
             g_initiator_state.drives_imaged |= (1 << g_initiator_state.target_id);
@@ -249,11 +249,11 @@ void scsiInitiatorMainLoop()
 
         if (!status)
         {
-            bluelog("Failed to transfer ", numtoread, " sectors starting at ", (int)g_initiator_state.sectors_done);
+            log("Failed to transfer ", numtoread, " sectors starting at ", (int)g_initiator_state.sectors_done);
 
             if (g_initiator_state.retrycount < 5)
             {
-                bluelog("Retrying.. ", g_initiator_state.retrycount, "/5");
+                log("Retrying.. ", g_initiator_state.retrycount, "/5");
                 delay(200);
                 scsiHostPhyReset();
                 delay(200);
@@ -263,13 +263,13 @@ void scsiInitiatorMainLoop()
 
                 if (g_initiator_state.retrycount > 1 && numtoread > 1)
                 {
-                    bluelog("Multiple failures, retrying sector-by-sector");
+                    log("Multiple failures, retrying sector-by-sector");
                     g_initiator_state.failposition = g_initiator_state.sectors_done + numtoread;
                 }
             }
             else
             {
-                bluelog("Retry limit exceeded, skipping one sector");
+                log("Retry limit exceeded, skipping one sector");
                 g_initiator_state.retrycount = 0;
                 g_initiator_state.sectors_done++;
                 g_initiator_state.target_file.seek((uint64_t)g_initiator_state.sectors_done * g_initiator_state.sectorsize);
@@ -282,7 +282,7 @@ void scsiInitiatorMainLoop()
             g_initiator_state.target_file.flush();
 
             int speed_kbps = numtoread * g_initiator_state.sectorsize / (millis() - time_start);
-            bluelog("SCSI read succeeded, sectors done: ",
+            log("SCSI read succeeded, sectors done: ",
                   (int)g_initiator_state.sectors_done, " / ", (int)g_initiator_state.sectorcount,
                   " speed ", speed_kbps, " kB/s");
         }
@@ -301,7 +301,7 @@ int scsiInitiatorRunCommand(int target_id,
 {
     if (!scsiHostPhySelect(target_id))
     {
-        bluedbg("------ Target ", target_id, " did not respond");
+        debuglog("------ Target ", target_id, " did not respond");
         scsiHostPhyRelease();
         return -1;
     }
@@ -329,14 +329,14 @@ int scsiInitiatorRunCommand(int target_id,
             if (returnDataPhase) return 0;
             if (bufInLen == 0)
             {
-                bluelog("DATA_IN phase but no data to receive!");
+                log("DATA_IN phase but no data to receive!");
                 status = -3;
                 break;
             }
 
             if (scsiHostRead(bufIn, bufInLen) == 0)
             {
-                bluelog("scsiHostRead failed, tried to read ", (int)bufInLen, " bytes");
+                log("scsiHostRead failed, tried to read ", (int)bufInLen, " bytes");
                 status = -2;
                 break;
             }
@@ -346,14 +346,14 @@ int scsiInitiatorRunCommand(int target_id,
             if (returnDataPhase) return 0;
             if (bufOutLen == 0)
             {
-                bluelog("DATA_OUT phase but no data to send!");
+                log("DATA_OUT phase but no data to send!");
                 status = -3;
                 break;
             }
 
             if (scsiHostWrite(bufOut, bufOutLen) < bufOutLen)
             {
-                bluelog("scsiHostWrite failed, was writing ", bytearray(bufOut, bufOutLen));
+                log("scsiHostWrite failed, was writing ", bytearray(bufOut, bufOutLen));
                 status = -2;
                 break;
             }
@@ -363,7 +363,7 @@ int scsiInitiatorRunCommand(int target_id,
             uint8_t tmp = -1;
             scsiHostRead(&tmp, 1);
             status = tmp;
-            bluedbg("------ STATUS: ", tmp);
+            debuglog("------ STATUS: ", tmp);
         }
     }
 
@@ -401,7 +401,7 @@ bool scsiInitiatorReadCapacity(int target_id, uint32_t *sectorcount, uint32_t *s
     {
         uint8_t sense_key;
         scsiRequestSense(target_id, &sense_key);
-        bluelog("READ CAPACITY on target ", target_id, " failed, sense key ", sense_key);
+        log("READ CAPACITY on target ", target_id, " failed, sense key ", sense_key);
         return false;
     }
     else
@@ -422,7 +422,7 @@ bool scsiRequestSense(int target_id, uint8_t *sense_key)
                                          response, sizeof(response),
                                          NULL, 0);
 
-    bluedbg("RequestSense response: ", bytearray(response, 18));
+    debuglog("RequestSense response: ", bytearray(response, 18));
 
     *sense_key = response[2];
     return status == 0;
@@ -445,7 +445,7 @@ bool scsiStartStopUnit(int target_id, bool start)
     {
         uint8_t sense_key;
         scsiRequestSense(target_id, &sense_key);
-        bluelog("START STOP UNIT on target ", target_id, " failed, sense key ", sense_key);
+        log("START STOP UNIT on target ", target_id, " failed, sense key ", sense_key);
     }
 
     return status == 0;
@@ -490,18 +490,18 @@ bool scsiTestUnitReady(int target_id)
             if (sense_key == 6)
             {
                 uint8_t inquiry[36];
-                bluelog("Target ", target_id, " reports UNIT_ATTENTION, running INQUIRY");
+                log("Target ", target_id, " reports UNIT_ATTENTION, running INQUIRY");
                 scsiInquiry(target_id, inquiry);
             }
             else if (sense_key == 2)
             {
-                bluelog("Target ", target_id, " reports NOT_READY, running STARTSTOPUNIT");
+                log("Target ", target_id, " reports NOT_READY, running STARTSTOPUNIT");
                 scsiStartStopUnit(target_id, true);
             }
         }
         else
         {
-            bluelog("Target ", target_id, " TEST UNIT READY response: ", status);
+            log("Target ", target_id, " TEST UNIT READY response: ", status);
         }
     }
 
@@ -571,10 +571,10 @@ static void initiatorReadSDCallback(uint32_t bytes_complete)
         if (len == 0)
             return;
 
-        // bluedbg("SCSI read ", (int)start, " + ", (int)len, ", sd ready cnt ", (int)sd_ready_cnt, " ", (int)bytes_complete, ", scsi done ", (int)g_initiator_transfer.bytes_scsi_done);
+        // debuglog("SCSI read ", (int)start, " + ", (int)len, ", sd ready cnt ", (int)sd_ready_cnt, " ", (int)bytes_complete, ", scsi done ", (int)g_initiator_transfer.bytes_scsi_done);
         if (scsiHostRead(&scsiDev.data[start], len) != len)
         {
-            bluelog("Read failed at byte ", (int)g_initiator_transfer.bytes_scsi_done);
+            log("Read failed at byte ", (int)g_initiator_transfer.bytes_scsi_done);
             g_initiator_transfer.all_ok = false;
         }
         g_initiator_transfer.bytes_scsi_done += len;
@@ -595,7 +595,7 @@ static void scsiInitiatorWriteDataToSd(FsFile &file, bool use_callback)
 
     // Start writing to SD card and simultaneously reading more from SCSI bus
     uint8_t *buf = &scsiDev.data[start];
-    // bluedbg("SD write ", (int)start, " + ", (int)len);
+    // debuglog("SD write ", (int)start, " + ", (int)len);
 
     if (use_callback)
     {
@@ -605,7 +605,7 @@ static void scsiInitiatorWriteDataToSd(FsFile &file, bool use_callback)
     g_initiator_transfer.bytes_sd_scheduled = g_initiator_transfer.bytes_sd + len;
     if (file.write(buf, len) != len)
     {
-        bluelog("scsiInitiatorReadDataToFile: SD card write failed");
+        log("scsiInitiatorReadDataToFile: SD card write failed");
         g_initiator_transfer.all_ok = false;
     }
     platform_set_sd_callback(NULL, NULL);
@@ -652,7 +652,7 @@ bool scsiInitiatorReadDataToFile(int target_id, uint32_t start_sector, uint32_t
         uint8_t sense_key;
         scsiRequestSense(target_id, &sense_key);
 
-        bluelog("scsiInitiatorReadDataToFile: READ failed: ", status, " sense key ", sense_key);
+        log("scsiInitiatorReadDataToFile: READ failed: ", status, " sense key ", sense_key);
         scsiHostPhyRelease();
         return false;
     }
@@ -695,7 +695,7 @@ bool scsiInitiatorReadDataToFile(int target_id, uint32_t start_sector, uint32_t
 
     if (g_initiator_transfer.bytes_sd != g_initiator_transfer.bytes_scsi)
     {
-        bluelog("SCSI read from sector ", (int)start_sector, " was incomplete: expected ",
+        log("SCSI read from sector ", (int)start_sector, " was incomplete: expected ",
              (int)g_initiator_transfer.bytes_scsi, " got ", (int)g_initiator_transfer.bytes_sd, " bytes");
         g_initiator_transfer.all_ok = false;
     }
@@ -717,7 +717,7 @@ bool scsiInitiatorReadDataToFile(int target_id, uint32_t start_sector, uint32_t
             uint8_t tmp = 0;
             scsiHostRead(&tmp, 1);
             status = tmp;
-            bluedbg("------ STATUS: ", tmp);
+            debuglog("------ STATUS: ", tmp);
         }
     }
 

+ 17 - 17
src/BlueSCSI_log.cpp

@@ -2,8 +2,8 @@
 #include "BlueSCSI_config.h"
 #include "BlueSCSI_platform.h"
 
-const char *g_bluelog_firmwareversion = BLUESCSI_FW_VERSION " " __DATE__ " " __TIME__;
-bool g_bluelog_debug = true;
+const char *g_log_firmwareversion = BLUESCSI_FW_VERSION " " __DATE__ " " __TIME__;
+bool g_log_debug = true;
 
 // This memory buffer can be read by debugger and is also saved to log.txt
 #define LOGBUFMASK (LOGBUFSIZE - 1)
@@ -14,7 +14,7 @@ uint32_t g_log_magic;
 char g_logbuffer[LOGBUFSIZE + 1];
 uint32_t g_logpos;
 
-void bluelog_raw(const char *str)
+void log_raw(const char *str)
 {
     // Keep log from reboot / bootloader if magic matches expected value
     if (g_log_magic != 0xAA55AA55)
@@ -37,7 +37,7 @@ void bluelog_raw(const char *str)
 }
 
 // Log byte as hex
-void bluelog_raw(uint8_t value)
+void log_raw(uint8_t value)
 {
     const char *nibble = "0123456789ABCDEF";
     char hexbuf[5] = {
@@ -45,11 +45,11 @@ void bluelog_raw(uint8_t value)
         nibble[(value >>  4) & 0xF], nibble[(value >>  0) & 0xF],
         0
     };
-    bluelog_raw(hexbuf);
+    log_raw(hexbuf);
 }
 
 // Log integer as hex
-void bluelog_raw(uint32_t value)
+void log_raw(uint32_t value)
 {
     const char *nibble = "0123456789ABCDEF";
     char hexbuf[11] = {
@@ -60,11 +60,11 @@ void bluelog_raw(uint32_t value)
         nibble[(value >>  4) & 0xF], nibble[(value >>  0) & 0xF],
         0
     };
-    bluelog_raw(hexbuf);
+    log_raw(hexbuf);
 }
 
 // Log integer as hex
-void bluelog_raw(uint64_t value)
+void log_raw(uint64_t value)
 {
     const char *nibble = "0123456789ABCDEF";
     char hexbuf[19] = {
@@ -79,11 +79,11 @@ void bluelog_raw(uint64_t value)
         nibble[(value >>  4) & 0xF], nibble[(value >>  0) & 0xF],
         0
     };
-    bluelog_raw(hexbuf);
+    log_raw(hexbuf);
 }
 
 // Log integer as decimal
-void bluelog_raw(int value)
+void log_raw(int value)
 {
     char decbuf[16] = {0};
     char *p = &decbuf[14];
@@ -99,29 +99,29 @@ void bluelog_raw(int value)
         *--p = '-';
     }
 
-    bluelog_raw(p);
+    log_raw(p);
 }
 
-void bluelog_raw(bytearray array)
+void log_raw(bytearray array)
 {
     for (size_t i = 0; i < array.len; i++)
     {
-        bluelog_raw(array.data[i]);
-        bluelog_raw(" ");
+        log_raw(array.data[i]);
+        log_raw(" ");
         if (i > 32)
         {
-            bluelog_raw("... (total ", (int)array.len, ")");
+            log_raw("... (total ", (int)array.len, ")");
             break;
         }
     }
 }
 
-uint32_t bluelog_get_buffer_len()
+uint32_t log_get_buffer_len()
 {
     return g_logpos;
 }
 
-const char *bluelog_get_buffer(uint32_t *startpos)
+const char *log_get_buffer(uint32_t *startpos)
 {
     uint32_t default_pos = 0;
     if (startpos == NULL)

+ 24 - 24
src/BlueSCSI_log.h

@@ -6,32 +6,32 @@
 #include <stddef.h>
 
 // Get total number of bytes that have been written to log
-uint32_t bluelog_get_buffer_len();
+uint32_t log_get_buffer_len();
 
 // Get log as a string.
 // If startpos is given, continues log reading from previous position and updates the position.
-const char *bluelog_get_buffer(uint32_t *startpos);
+const char *log_get_buffer(uint32_t *startpos);
 
 // Whether to enable debug messages
-extern bool g_bluelog_debug;
+extern bool g_log_debug;
 
 // Firmware version string
-extern const char *g_bluelog_firmwareversion;
+extern const char *g_log_firmwareversion;
 
 // Log string
-void bluelog_raw(const char *str);
+void log_raw(const char *str);
 
 // Log byte as hex
-void bluelog_raw(uint8_t value);
+void log_raw(uint8_t value);
 
 // Log integer as hex
-void bluelog_raw(uint32_t value);
+void log_raw(uint32_t value);
 
 // Log integer as hex
-void bluelog_raw(uint64_t value);
+void log_raw(uint64_t value);
 
 // Log integer as decimal
-void bluelog_raw(int value);
+void log_raw(int value);
 
 // Log array of bytes
 struct bytearray {
@@ -39,9 +39,9 @@ struct bytearray {
     const uint8_t *data;
     size_t len;
 };
-void bluelog_raw(bytearray array);
+void log_raw(bytearray array);
 
-inline void bluelog_raw()
+inline void log_raw()
 {
     // End of template recursion
 }
@@ -50,30 +50,30 @@ extern "C" unsigned long millis();
 
 // Variadic template for printing multiple items
 template<typename T, typename T2, typename... Rest>
-inline void bluelog_raw(T first, T2 second, Rest... rest)
+inline void log_raw(T first, T2 second, Rest... rest)
 {
-    bluelog_raw(first);
-    bluelog_raw(second);
-    bluelog_raw(rest...);
+    log_raw(first);
+    log_raw(second);
+    log_raw(rest...);
 }
 
 // Format a complete log message
 template<typename... Params>
-inline void bluelog(Params... params)
+inline void log(Params... params)
 {
-    bluelog_raw("[", (int)millis(), "ms] ");
-    bluelog_raw(params...);
-    bluelog_raw("\n");
+    log_raw("[", (int)millis(), "ms] ");
+    log_raw(params...);
+    log_raw("\n");
 }
 
 // Format a complete debug message
 template<typename... Params>
-inline void bluedbg(Params... params)
+inline void debuglog(Params... params)
 {
-    if (g_bluelog_debug)
+    if (g_log_debug)
     {
-        bluelog_raw("[", (int)millis(), "ms] DBG ");
-        bluelog_raw(params...);
-        bluelog_raw("\n");
+        log_raw("[", (int)millis(), "ms] DBG ");
+        log_raw(params...);
+        log_raw("\n");
     }
 }

+ 26 - 26
src/BlueSCSI_log_trace.cpp

@@ -65,7 +65,7 @@ static void printNewPhase(int phase, bool initiator = false)
 {
     g_LogData = false;
     g_LogInitiatorCommand = false;
-    if (!g_bluelog_debug)
+    if (!g_log_debug)
     {
         return;
     }
@@ -73,45 +73,45 @@ static void printNewPhase(int phase, bool initiator = false)
     switch(phase)
     {
         case BUS_FREE:
-            bluedbg("-- BUS_FREE");
+            debuglog("-- BUS_FREE");
             break;
 
         case BUS_BUSY:
-            bluedbg("-- BUS_BUSY");
+            debuglog("-- BUS_BUSY");
             break;
 
         case ARBITRATION:
-            bluedbg("---- ARBITRATION");
+            debuglog("---- ARBITRATION");
             break;
 
         case SELECTION:
             if (initiator)
-                bluedbg("---- SELECTION");
+                debuglog("---- SELECTION");
             else
-                bluedbg("---- SELECTION: ", (int)(*SCSI_STS_SELECTED & 7));
+                debuglog("---- SELECTION: ", (int)(*SCSI_STS_SELECTED & 7));
             break;
 
         case RESELECTION:
-            bluedbg("---- RESELECTION");
+            debuglog("---- RESELECTION");
             break;
 
         case STATUS:
             if (initiator)
             {
-                bluedbg("---- STATUS");
+                debuglog("---- STATUS");
                 g_LogData = true;
             }
             else if (scsiDev.status == GOOD)
             {
-                bluedbg("---- STATUS: 0 GOOD");
+                debuglog("---- STATUS: 0 GOOD");
             }
             else if (scsiDev.status == CHECK_CONDITION && scsiDev.target)
             {
-                bluedbg("---- STATUS: 2 CHECK_CONDITION, sense ", (uint32_t)scsiDev.target->sense.asc);
+                debuglog("---- STATUS: 2 CHECK_CONDITION, sense ", (uint32_t)scsiDev.target->sense.asc);
             }
             else
             {
-                bluedbg("---- STATUS: ", (int)scsiDev.status);
+                debuglog("---- STATUS: ", (int)scsiDev.status);
             }
             break;
 
@@ -122,32 +122,32 @@ static void printNewPhase(int phase, bool initiator = false)
 
         case DATA_IN:
             if (!initiator && scsiDev.target->syncOffset > 0)
-                bluedbg("---- DATA_IN, syncOffset ", (int)scsiDev.target->syncOffset,
+                debuglog("---- DATA_IN, syncOffset ", (int)scsiDev.target->syncOffset,
                                    " syncPeriod ", (int)scsiDev.target->syncPeriod);
             else
-                bluedbg("---- DATA_IN");
+                debuglog("---- DATA_IN");
             break;
 
         case DATA_OUT:
             if (!initiator && scsiDev.target->syncOffset > 0)
-                bluedbg("---- DATA_OUT, syncOffset ", (int)scsiDev.target->syncOffset,
+                debuglog("---- DATA_OUT, syncOffset ", (int)scsiDev.target->syncOffset,
                                     " syncPeriod ", (int)scsiDev.target->syncPeriod);
             else
-                bluedbg("---- DATA_OUT");
+                debuglog("---- DATA_OUT");
             break;
 
         case MESSAGE_IN:
-            bluedbg("---- MESSAGE_IN");
+            debuglog("---- MESSAGE_IN");
             g_LogData = true;
             break;
 
         case MESSAGE_OUT:
-            bluedbg("---- MESSAGE_OUT");
+            debuglog("---- MESSAGE_OUT");
             g_LogData = true;
             break;
 
         default:
-            bluedbg("---- PHASE: ", phase);
+            debuglog("---- PHASE: ", phase);
             break;
     }
 }
@@ -162,7 +162,7 @@ void scsiLogPhaseChange(int new_phase)
     {
         if (old_phase == DATA_IN || old_phase == DATA_OUT)
         {
-            bluedbg("---- Total IN: ", g_InByteCount, " OUT: ", g_OutByteCount, " CHECKSUM: ", (int)g_DataChecksum);
+            debuglog("---- Total IN: ", g_InByteCount, " OUT: ", g_OutByteCount, " CHECKSUM: ", (int)g_DataChecksum);
         }
         g_InByteCount = g_OutByteCount = 0;
         g_DataChecksum = 0;
@@ -176,7 +176,7 @@ void scsiLogPhaseChange(int new_phase)
             int syncper = scsiDev.target->syncPeriod;
             int syncoff = scsiDev.target->syncOffset;
             int mbyte_per_s = (1000 + syncper * 2) / (syncper * 4);
-            bluelog("SCSI ID ", (int)scsiDev.target->targetId,
+            log("SCSI ID ", (int)scsiDev.target->targetId,
                   " negotiated synchronous mode ", mbyte_per_s, " MB/s ",
                   "(period 4x", syncper, " ns, offset ", syncoff, " bytes)");
         }
@@ -196,7 +196,7 @@ void scsiLogInitiatorPhaseChange(int new_phase)
     {
         if (old_phase == DATA_IN || old_phase == DATA_OUT)
         {
-            bluedbg("---- Total IN: ", g_InByteCount, " OUT: ", g_OutByteCount, " CHECKSUM: ", (int)g_DataChecksum);
+            debuglog("---- Total IN: ", g_InByteCount, " OUT: ", g_OutByteCount, " CHECKSUM: ", (int)g_DataChecksum);
         }
         g_InByteCount = g_OutByteCount = 0;
         g_DataChecksum = 0;
@@ -210,10 +210,10 @@ void scsiLogDataIn(const uint8_t *buf, uint32_t length)
 {
     if (g_LogData)
     {
-        bluedbg("------ IN: ", bytearray(buf, length));
+        debuglog("------ IN: ", bytearray(buf, length));
     }
 
-    if (g_bluelog_debug)
+    if (g_log_debug)
     {
         // BSD checksum algorithm
         for (uint32_t i = 0; i < length; i++)
@@ -230,15 +230,15 @@ void scsiLogDataOut(const uint8_t *buf, uint32_t length)
 {
     if (buf == scsiDev.cdb || g_LogInitiatorCommand)
     {
-        bluedbg("---- COMMAND: ", getCommandName(buf[0]));
+        debuglog("---- COMMAND: ", getCommandName(buf[0]));
     }
 
     if (g_LogData)
     {
-        bluedbg("------ OUT: ", bytearray(buf, length));
+        debuglog("------ OUT: ", bytearray(buf, length));
     }
 
-    if (g_bluelog_debug)
+    if (g_log_debug)
     {
         // BSD checksum algorithm
         for (uint32_t i = 0; i < length; i++)