add run status

pull/3/head
Clyne 4 years ago
parent 89ebe6413e
commit a263d2ab42

@ -19,6 +19,14 @@
#include <array> #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(adcsample_t) == sizeof(uint16_t));
static_assert(sizeof(dacsample_t) == sizeof(uint16_t)); static_assert(sizeof(dacsample_t) == sizeof(uint16_t));
@ -65,6 +73,7 @@ int main()
} }
break; break;
case 'R': case 'R':
run_status = RunStatus::Converting;
dac_samples.fill(0); dac_samples.fill(0);
adc::read_start(signal_operate, &adc_samples[0], adc_samples.size()); adc::read_start(signal_operate, &adc_samples[0], adc_samples.size());
dac::write_start(&dac_samples[0], dac_samples.size()); dac::write_start(&dac_samples[0], dac_samples.size());
@ -76,6 +85,7 @@ int main()
case 'S': case 'S':
dac::write_stop(); dac::write_stop();
adc::read_stop(); adc::read_stop();
run_status = RunStatus::Idle;
break; break;
case 'e': case 'e':
if (usbserial::read(&cmd[1], 2) < 2) if (usbserial::read(&cmd[1], 2) < 2)
@ -101,6 +111,9 @@ int main()
case 'i': // Identify ourself as an stmdsp device case 'i': // Identify ourself as an stmdsp device
usbserial::write("stmdsp", 6); usbserial::write("stmdsp", 6);
break; break;
case 'I': // Info (i.e. run status)
usbserial::write(&run_status, 1);
break;
default: default:
break; break;
} }
@ -166,6 +179,7 @@ void conversion_abort()
dac::write_stop(); dac::write_stop();
adc::read_stop(); adc::read_stop();
signal_operate_done = true; signal_operate_done = true;
run_status = RunStatus::Idle;
} }
extern "C" { extern "C" {
@ -173,13 +187,17 @@ extern "C" {
__attribute__((naked)) __attribute__((naked))
void HardFault_Handler() void HardFault_Handler()
{ {
asm("push {lr}");
if (run_status == RunStatus::Converting) {
uint32_t *stack; uint32_t *stack;
asm("mrs %0, msp" : "=r" (stack)); asm("mrs %0, msp" : "=r" (stack));
stack[6] = stack[5]; stack[6] = stack[5]; // Escape from elf_entry code
stack[7] |= (1 << 24); stack[7] |= (1 << 24); // Keep Thumb mode enabled
asm("push {lr}");
conversion_abort(); conversion_abort();
}
asm("pop {lr}; bx lr"); asm("pop {lr}; bx lr");
} }

Loading…
Cancel
Save