aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2020-09-01 20:24:23 -0400
committerClyne Sullivan <clyne@bitgloo.com>2020-09-01 20:24:23 -0400
commita263d2ab4277f535f2a6edfd82ae0f67791e334a (patch)
tree8539a2fe76d2876c52d7f3de55b884e73dbe2f45
parent89ebe6413ef88398b54d956448e5762506f6f44f (diff)
add run status
-rw-r--r--source/main.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/source/main.cpp b/source/main.cpp
index 596991d..f55c801 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -19,6 +19,14 @@
#include <array>
+enum class RunStatus : char
+{
+ Idle = '1',
+ Converting
+};
+static RunStatus run_status = RunStatus::Idle;
+
+
static_assert(sizeof(adcsample_t) == sizeof(uint16_t));
static_assert(sizeof(dacsample_t) == sizeof(uint16_t));
@@ -65,6 +73,7 @@ int main()
}
break;
case 'R':
+ run_status = RunStatus::Converting;
dac_samples.fill(0);
adc::read_start(signal_operate, &adc_samples[0], adc_samples.size());
dac::write_start(&dac_samples[0], dac_samples.size());
@@ -76,6 +85,7 @@ int main()
case 'S':
dac::write_stop();
adc::read_stop();
+ run_status = RunStatus::Idle;
break;
case 'e':
if (usbserial::read(&cmd[1], 2) < 2)
@@ -101,6 +111,9 @@ int main()
case 'i': // Identify ourself as an stmdsp device
usbserial::write("stmdsp", 6);
break;
+ case 'I': // Info (i.e. run status)
+ usbserial::write(&run_status, 1);
+ break;
default:
break;
}
@@ -166,6 +179,7 @@ void conversion_abort()
dac::write_stop();
adc::read_stop();
signal_operate_done = true;
+ run_status = RunStatus::Idle;
}
extern "C" {
@@ -173,13 +187,17 @@ extern "C" {
__attribute__((naked))
void HardFault_Handler()
{
- uint32_t *stack;
- asm("mrs %0, msp" : "=r" (stack));
- stack[6] = stack[5];
- stack[7] |= (1 << 24);
-
asm("push {lr}");
- conversion_abort();
+
+ if (run_status == RunStatus::Converting) {
+ uint32_t *stack;
+ asm("mrs %0, msp" : "=r" (stack));
+ stack[6] = stack[5]; // Escape from elf_entry code
+ stack[7] |= (1 << 24); // Keep Thumb mode enabled
+
+ conversion_abort();
+ }
+
asm("pop {lr}; bx lr");
}