|
@@ -37,23 +37,14 @@
|
|
|
#include <hardware/structs/usb.h>
|
|
#include <hardware/structs/usb.h>
|
|
|
#include "scsi_accel_target.h"
|
|
#include "scsi_accel_target.h"
|
|
|
|
|
|
|
|
-#ifdef __MBED__
|
|
|
|
|
-# include <platform/mbed_error.h>
|
|
|
|
|
-#endif // __MBED__
|
|
|
|
|
-
|
|
|
|
|
-#ifndef __MBED__
|
|
|
|
|
#ifndef PIO_FRAMEWORK_ARDUINO_NO_USB
|
|
#ifndef PIO_FRAMEWORK_ARDUINO_NO_USB
|
|
|
# include <SerialUSB.h>
|
|
# include <SerialUSB.h>
|
|
|
# include <class/cdc/cdc_device.h>
|
|
# include <class/cdc/cdc_device.h>
|
|
|
#endif
|
|
#endif
|
|
|
-#else
|
|
|
|
|
-# include <USB/PluggableUSBSerial.h>
|
|
|
|
|
-#endif // __MBED__
|
|
|
|
|
|
|
|
|
|
-#ifndef ZULUSCSI_NETWORK
|
|
|
|
|
-# include <multicore.h>
|
|
|
|
|
-#else
|
|
|
|
|
-# include <pico/multicore.h>
|
|
|
|
|
|
|
+#include <pico/multicore.h>
|
|
|
|
|
+
|
|
|
|
|
+#ifdef ZULUSCSI_NETWORK
|
|
|
extern "C" {
|
|
extern "C" {
|
|
|
# include <pico/cyw43_arch.h>
|
|
# include <pico/cyw43_arch.h>
|
|
|
}
|
|
}
|
|
@@ -70,10 +61,6 @@ static bool g_scsi_initiator = false;
|
|
|
static uint32_t g_flash_chip_size = 0;
|
|
static uint32_t g_flash_chip_size = 0;
|
|
|
static bool g_uart_initialized = false;
|
|
static bool g_uart_initialized = false;
|
|
|
|
|
|
|
|
-#ifdef __MBED__
|
|
|
|
|
-void mbed_error_hook(const mbed_error_ctx * error_context);
|
|
|
|
|
-#endif // __MBED__
|
|
|
|
|
-
|
|
|
|
|
/***************/
|
|
/***************/
|
|
|
/* GPIO init */
|
|
/* GPIO init */
|
|
|
/***************/
|
|
/***************/
|
|
@@ -225,9 +212,6 @@ void platform_init()
|
|
|
g_uart_initialized = true;
|
|
g_uart_initialized = true;
|
|
|
#endif // DISABLE_SWO
|
|
#endif // DISABLE_SWO
|
|
|
|
|
|
|
|
-#ifdef __MBED__
|
|
|
|
|
- mbed_set_error_hook(mbed_error_hook);
|
|
|
|
|
-#endif // __MBED__
|
|
|
|
|
logmsg("Platform: ", g_platform_name);
|
|
logmsg("Platform: ", g_platform_name);
|
|
|
logmsg("FW Version: ", g_log_firmwareversion);
|
|
logmsg("FW Version: ", g_log_firmwareversion);
|
|
|
|
|
|
|
@@ -366,11 +350,10 @@ void platform_late_init()
|
|
|
gpio_conf(SCSI_IN_ATN, GPIO_FUNC_SIO, true, false, false, true, false);
|
|
gpio_conf(SCSI_IN_ATN, GPIO_FUNC_SIO, true, false, false, true, false);
|
|
|
gpio_conf(SCSI_IN_RST, GPIO_FUNC_SIO, true, false, false, true, false);
|
|
gpio_conf(SCSI_IN_RST, GPIO_FUNC_SIO, true, false, false, true, false);
|
|
|
|
|
|
|
|
-#ifndef __MBED__
|
|
|
|
|
-# ifndef PIO_FRAMEWORK_ARDUINO_NO_USB
|
|
|
|
|
|
|
+#ifndef PIO_FRAMEWORK_ARDUINO_NO_USB
|
|
|
Serial.begin();
|
|
Serial.begin();
|
|
|
-# endif
|
|
|
|
|
-#endif // __MBED__
|
|
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
|
|
|
#ifdef ENABLE_AUDIO_OUTPUT
|
|
#ifdef ENABLE_AUDIO_OUTPUT
|
|
|
// one-time control setup for DMA channels and second core
|
|
// one-time control setup for DMA channels and second core
|
|
@@ -424,7 +407,6 @@ extern uint32_t __StackTop;
|
|
|
void platform_emergency_log_save()
|
|
void platform_emergency_log_save()
|
|
|
{
|
|
{
|
|
|
platform_set_sd_callback(NULL, NULL);
|
|
platform_set_sd_callback(NULL, NULL);
|
|
|
-
|
|
|
|
|
SD.begin(SD_CONFIG_CRASH);
|
|
SD.begin(SD_CONFIG_CRASH);
|
|
|
FsFile crashfile = SD.open(CRASHFILE, O_WRONLY | O_CREAT | O_TRUNC);
|
|
FsFile crashfile = SD.open(CRASHFILE, O_WRONLY | O_CREAT | O_TRUNC);
|
|
|
|
|
|
|
@@ -444,21 +426,31 @@ void platform_emergency_log_save()
|
|
|
crashfile.close();
|
|
crashfile.close();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-#ifdef __MBED__
|
|
|
|
|
-void mbed_error_hook(const mbed_error_ctx * error_context)
|
|
|
|
|
|
|
+
|
|
|
|
|
+static void usb_log_poll();
|
|
|
|
|
+
|
|
|
|
|
+__attribute__((noinline))
|
|
|
|
|
+void show_hardfault(uint32_t *sp)
|
|
|
{
|
|
{
|
|
|
|
|
+ uint32_t pc = sp[6];
|
|
|
|
|
+ uint32_t lr = sp[5];
|
|
|
|
|
+
|
|
|
logmsg("--------------");
|
|
logmsg("--------------");
|
|
|
logmsg("CRASH!");
|
|
logmsg("CRASH!");
|
|
|
logmsg("Platform: ", g_platform_name);
|
|
logmsg("Platform: ", g_platform_name);
|
|
|
logmsg("FW Version: ", g_log_firmwareversion);
|
|
logmsg("FW Version: ", g_log_firmwareversion);
|
|
|
- logmsg("error_status: ", (uint32_t)error_context->error_status);
|
|
|
|
|
- logmsg("error_address: ", error_context->error_address);
|
|
|
|
|
- logmsg("error_value: ", error_context->error_value);
|
|
|
|
|
logmsg("scsiDev.cdb: ", bytearray(scsiDev.cdb, 12));
|
|
logmsg("scsiDev.cdb: ", bytearray(scsiDev.cdb, 12));
|
|
|
logmsg("scsiDev.phase: ", (int)scsiDev.phase);
|
|
logmsg("scsiDev.phase: ", (int)scsiDev.phase);
|
|
|
- scsi_accel_log_state();
|
|
|
|
|
|
|
+ logmsg("SP: ", (uint32_t)sp);
|
|
|
|
|
+ logmsg("PC: ", pc);
|
|
|
|
|
+ logmsg("LR: ", lr);
|
|
|
|
|
+ logmsg("R0: ", sp[0]);
|
|
|
|
|
+ logmsg("R1: ", sp[1]);
|
|
|
|
|
+ logmsg("R2: ", sp[2]);
|
|
|
|
|
+ logmsg("R3: ", sp[3]);
|
|
|
|
|
+
|
|
|
|
|
+ uint32_t *p = (uint32_t*)((uint32_t)sp & ~3);
|
|
|
|
|
|
|
|
- uint32_t *p = (uint32_t*)((uint32_t)error_context->thread_current_sp & ~3);
|
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
for (int i = 0; i < 8; i++)
|
|
|
{
|
|
{
|
|
|
if (p == &__StackTop) break; // End of stack
|
|
if (p == &__StackTop) break; // End of stack
|
|
@@ -471,24 +463,33 @@ void mbed_error_hook(const mbed_error_ctx * error_context)
|
|
|
|
|
|
|
|
while (1)
|
|
while (1)
|
|
|
{
|
|
{
|
|
|
|
|
+ usb_log_poll();
|
|
|
// Flash the crash address on the LED
|
|
// Flash the crash address on the LED
|
|
|
// Short pulse means 0, long pulse means 1
|
|
// Short pulse means 0, long pulse means 1
|
|
|
- int base_delay = 1000;
|
|
|
|
|
|
|
+ int base_delay = 500;
|
|
|
for (int i = 31; i >= 0; i--)
|
|
for (int i = 31; i >= 0; i--)
|
|
|
{
|
|
{
|
|
|
LED_OFF();
|
|
LED_OFF();
|
|
|
- for (int j = 0; j < base_delay; j++) delay_ns(100000);
|
|
|
|
|
|
|
+ for (int j = 0; j < base_delay; j++) busy_wait_ms(1);
|
|
|
|
|
|
|
|
- int delay = (error_context->error_address & (1 << i)) ? (3 * base_delay) : base_delay;
|
|
|
|
|
|
|
+ int delay = (pc & (1 << i)) ? (3 * base_delay) : base_delay;
|
|
|
LED_ON();
|
|
LED_ON();
|
|
|
- for (int j = 0; j < delay; j++) delay_ns(100000);
|
|
|
|
|
|
|
+ for (int j = 0; j < delay; j++) busy_wait_ms(1);
|
|
|
LED_OFF();
|
|
LED_OFF();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- for (int j = 0; j < base_delay * 10; j++) delay_ns(100000);
|
|
|
|
|
|
|
+ for (int j = 0; j < base_delay * 10; j++) busy_wait_ms(1);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-#endif // __MBED__
|
|
|
|
|
|
|
+
|
|
|
|
|
+__attribute__((naked, interrupt))
|
|
|
|
|
+void isr_hardfault(void)
|
|
|
|
|
+{
|
|
|
|
|
+ // Copies stack pointer into first argument
|
|
|
|
|
+ asm("mrs r0, msp\n"
|
|
|
|
|
+ "bl show_hardfault": : : "r0");
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
|
|
|
/*****************************************/
|
|
/*****************************************/
|
|
|
/* Debug logging and watchdog */
|
|
/* Debug logging and watchdog */
|
|
@@ -505,9 +506,8 @@ void mbed_error_hook(const mbed_error_ctx * error_context)
|
|
|
// but does not unnecessarily delay normal execution.
|
|
// but does not unnecessarily delay normal execution.
|
|
|
static void usb_log_poll()
|
|
static void usb_log_poll()
|
|
|
{
|
|
{
|
|
|
|
|
+#ifndef PIO_FRAMEWORK_ARDUINO_NO_USB
|
|
|
static uint32_t logpos = 0;
|
|
static uint32_t logpos = 0;
|
|
|
-#ifndef __MBED__
|
|
|
|
|
-# ifndef PIO_FRAMEWORK_ARDUINO_NO_USB
|
|
|
|
|
if (Serial.availableForWrite())
|
|
if (Serial.availableForWrite())
|
|
|
{
|
|
{
|
|
|
// Retrieve pointer to log start and determine number of bytes available.
|
|
// Retrieve pointer to log start and determine number of bytes available.
|
|
@@ -524,26 +524,7 @@ static void usb_log_poll()
|
|
|
actual = Serial.write(data, len);
|
|
actual = Serial.write(data, len);
|
|
|
logpos -= available - actual;
|
|
logpos -= available - actual;
|
|
|
}
|
|
}
|
|
|
-# endif // PIO_FRAMEWORK_ARDUINO_NO_USB
|
|
|
|
|
-#else
|
|
|
|
|
- if (_SerialUSB.ready())
|
|
|
|
|
- {
|
|
|
|
|
- // Retrieve pointer to log start and determine number of bytes available.
|
|
|
|
|
- uint32_t available = 0;
|
|
|
|
|
- const char *data = log_get_buffer(&logpos, &available);
|
|
|
|
|
-
|
|
|
|
|
- // Limit to CDC packet size
|
|
|
|
|
- uint32_t len = available;
|
|
|
|
|
- if (len == 0) return;
|
|
|
|
|
- if (len > CDC_MAX_PACKET_SIZE) len = CDC_MAX_PACKET_SIZE;
|
|
|
|
|
-
|
|
|
|
|
- // Update log position by the actual number of bytes sent
|
|
|
|
|
- // If USB CDC buffer is full, this may be 0
|
|
|
|
|
- uint32_t actual = 0;
|
|
|
|
|
- _SerialUSB.send_nb((uint8_t*)data, len, &actual);
|
|
|
|
|
- logpos -= available - actual;
|
|
|
|
|
- }
|
|
|
|
|
-#endif // __MBED__
|
|
|
|
|
|
|
+#endif // PIO_FRAMEWORK_ARDUINO_NO_USB
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -638,11 +619,8 @@ static void watchdog_callback(unsigned alarm_num)
|
|
|
logmsg("scsiDev.phase: ", (int)scsiDev.phase);
|
|
logmsg("scsiDev.phase: ", (int)scsiDev.phase);
|
|
|
scsi_accel_log_state();
|
|
scsi_accel_log_state();
|
|
|
|
|
|
|
|
-#ifdef __MBED__
|
|
|
|
|
- uint32_t *p = (uint32_t*)__get_PSP();
|
|
|
|
|
-#else
|
|
|
|
|
uint32_t *p = (uint32_t*)__get_MSP();
|
|
uint32_t *p = (uint32_t*)__get_MSP();
|
|
|
-#endif
|
|
|
|
|
|
|
+
|
|
|
for (int i = 0; i < 8; i++)
|
|
for (int i = 0; i < 8; i++)
|
|
|
{
|
|
{
|
|
|
if (p == &__StackTop) break; // End of stack
|
|
if (p == &__StackTop) break; // End of stack
|
|
@@ -665,11 +643,8 @@ static void watchdog_callback(unsigned alarm_num)
|
|
|
logmsg("scsiDev.cdb: ", bytearray(scsiDev.cdb, 12));
|
|
logmsg("scsiDev.cdb: ", bytearray(scsiDev.cdb, 12));
|
|
|
logmsg("scsiDev.phase: ", (int)scsiDev.phase);
|
|
logmsg("scsiDev.phase: ", (int)scsiDev.phase);
|
|
|
|
|
|
|
|
-#ifdef __MBED__
|
|
|
|
|
- uint32_t *p = (uint32_t*)__get_PSP();
|
|
|
|
|
-#else
|
|
|
|
|
uint32_t *p = (uint32_t*)__get_MSP();
|
|
uint32_t *p = (uint32_t*)__get_MSP();
|
|
|
-#endif
|
|
|
|
|
|
|
+
|
|
|
for (int i = 0; i < 8; i++)
|
|
for (int i = 0; i < 8; i++)
|
|
|
{
|
|
{
|
|
|
if (p == &__StackTop) break; // End of stack
|
|
if (p == &__StackTop) break; // End of stack
|
|
@@ -786,15 +761,12 @@ bool platform_rewrite_flash_page(uint32_t offset, uint8_t buffer[PLATFORM_FLASH_
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-#ifdef __MBED__
|
|
|
|
|
- if (NVIC_GetEnableIRQ(USBCTRL_IRQn))
|
|
|
|
|
|
|
+ if (NVIC_GetEnableIRQ(USBCTRL_IRQ_IRQn))
|
|
|
{
|
|
{
|
|
|
logmsg("Disabling USB during firmware flashing");
|
|
logmsg("Disabling USB during firmware flashing");
|
|
|
- NVIC_DisableIRQ(USBCTRL_IRQn);
|
|
|
|
|
|
|
+ NVIC_DisableIRQ(USBCTRL_IRQ_IRQn);
|
|
|
usb_hw->main_ctrl = 0;
|
|
usb_hw->main_ctrl = 0;
|
|
|
}
|
|
}
|
|
|
-#endif // __MBED__
|
|
|
|
|
|
|
|
|
|
dbgmsg("Writing flash at offset ", offset, " data ", bytearray(buffer, 4));
|
|
dbgmsg("Writing flash at offset ", offset, " data ", bytearray(buffer, 4));
|
|
|
assert(offset % PLATFORM_FLASH_PAGE_SIZE == 0);
|
|
assert(offset % PLATFORM_FLASH_PAGE_SIZE == 0);
|
|
@@ -1026,33 +998,3 @@ const uint16_t g_scsi_parity_check_lookup[512] __attribute__((aligned(1024), sec
|
|
|
#undef X
|
|
#undef X
|
|
|
|
|
|
|
|
} /* extern "C" */
|
|
} /* extern "C" */
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-#ifdef __MBED__
|
|
|
|
|
-/* Logging from mbed */
|
|
|
|
|
-
|
|
|
|
|
-static class LogTarget: public mbed::FileHandle {
|
|
|
|
|
-public:
|
|
|
|
|
- virtual ssize_t read(void *buffer, size_t size) { return 0; }
|
|
|
|
|
- virtual ssize_t write(const void *buffer, size_t size)
|
|
|
|
|
- {
|
|
|
|
|
- // A bit inefficient but mbed seems to write() one character
|
|
|
|
|
- // at a time anyways.
|
|
|
|
|
- for (int i = 0; i < size; i++)
|
|
|
|
|
- {
|
|
|
|
|
- char buf[2] = {((const char*)buffer)[i], 0};
|
|
|
|
|
- log_raw(buf);
|
|
|
|
|
- }
|
|
|
|
|
- return size;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- virtual off_t seek(off_t offset, int whence = SEEK_SET) { return offset; }
|
|
|
|
|
- virtual int close() { return 0; }
|
|
|
|
|
- virtual off_t size() { return 0; }
|
|
|
|
|
-} g_LogTarget;
|
|
|
|
|
-
|
|
|
|
|
-mbed::FileHandle *mbed::mbed_override_console(int fd)
|
|
|
|
|
-{
|
|
|
|
|
- return &g_LogTarget;
|
|
|
|
|
-}
|
|
|
|
|
-#endif // __MBED__
|
|
|