Configurable line hz

This commit is contained in:
folkert van heusden 2024-05-20 21:50:14 +02:00
parent c32a75ee24
commit 2153fedd8d
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
3 changed files with 51 additions and 4 deletions

View file

@ -710,6 +710,14 @@ void deserdc11(console *const cnsl, bus *const b)
cnsl->put_string_lf(format("Deserialized " SERIAL_CFG_FILE)); cnsl->put_string_lf(format("Deserialized " SERIAL_CFG_FILE));
} }
void set_kw11_l_interrupt_freq(console *const cnsl, bus *const b, const int freq)
{
if (freq >= 1 && freq < 1000)
b->getKW11_L()->set_interrupt_frequency(freq);
else
cnsl->put_string_lf("Frequency out of range");
}
void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const stop_event) void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const stop_event)
{ {
int32_t trace_start_addr = -1; int32_t trace_start_addr = -1;
@ -1062,6 +1070,10 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
continue; continue;
} }
#endif #endif
else if (parts[0] == "setinthz" && parts.size() == 2) {
set_kw11_l_interrupt_freq(cnsl, b, std::stoi(parts.at(1)));
continue;
}
else if (parts[0] == "setsl" && parts.size() == 3) { else if (parts[0] == "setsl" && parts.size() == 3) {
if (setloghost(parts.at(1).c_str(), parse_ll(parts[2])) == false) if (setloghost(parts.at(1).c_str(), parse_ll(parts[2])) == false)
cnsl->put_string_lf("Failed parsing IP address"); cnsl->put_string_lf("Failed parsing IP address");
@ -1183,6 +1195,7 @@ void debugger(console *const cnsl, bus *const b, std::atomic_uint32_t *const sto
"setpc x - set PC to value", "setpc x - set PC to value",
"setmem ... - set memory (a=) to value (v=), both in octal, one byte", "setmem ... - set memory (a=) to value (v=), both in octal, one byte",
"toggle ... - set switch (s=, 0...15 (decimal)) of the front panel to state (t=, 0 or 1)", "toggle ... - set switch (s=, 0...15 (decimal)) of the front panel to state (t=, 0 or 1)",
"setinthz x - set KW11-L interrupt frequency (Hz)",
"cls - clear screen", "cls - clear screen",
"dir - list files", "dir - list files",
"bic x - run BIC/LDA file", "bic x - run BIC/LDA file",

View file

@ -92,15 +92,31 @@ void kw11_l::operator()()
if (*cnsl->get_running_flag()) { if (*cnsl->get_running_flag()) {
myusleep(1000000 / 100); // 100 Hz myusleep(1000000 / 100); // 100 Hz
int cur_int_freq = 1;
{
#if defined(BUILD_FOR_RP2040)
xSemaphoreTake(lf_csr_lock, portMAX_DELAY);
#else
std::unique_lock<std::mutex> lck(lf_csr_lock);
#endif
cur_int_freq = int_frequency;
#if defined(BUILD_FOR_RP2040)
xSemaphoreGive(lf_csr_lock);
#endif
}
uint64_t current_cycle_count = b->getCpu()->get_instructions_executed_count(); uint64_t current_cycle_count = b->getCpu()->get_instructions_executed_count();
uint32_t took_ms = b->getCpu()->get_effective_run_time(current_cycle_count - prev_cycle_count); uint32_t took_ms = b->getCpu()->get_effective_run_time(current_cycle_count - prev_cycle_count);
auto now = get_ms(); auto now = get_ms();
// - 50 Hz depending on instrution count // - 50 Hz depending on instruction count ('cur_int_freq')
// - nothing executed in interval // - nothing executed in interval
// - 10 Hz minimum // - 2 Hz minimum
auto t_diff = now - prev_tick; auto t_diff = now - prev_tick;
if (took_ms >= 1000 / 50 || current_cycle_count - interval_prev_cycle_count == 0 || t_diff >= 100) { if (took_ms >= 1000 / cur_int_freq || current_cycle_count - interval_prev_cycle_count == 0 || t_diff >= 500) {
do_interrupt(); do_interrupt();
prev_cycle_count = current_cycle_count; prev_cycle_count = current_cycle_count;
@ -137,12 +153,27 @@ uint16_t kw11_l::read_word(const uint16_t a)
uint16_t temp = lf_csr; uint16_t temp = lf_csr;
#if defined(BUILD_FOR_RP2040) #if defined(BUILD_FOR_RP2040)
xSemaphoreGive(lf_csr_lock); xSemaphoreGive(lf_csr_lock);
#endif #endif
return temp; return temp;
} }
void kw11_l::set_interrupt_frequency(const int Hz)
{
#if defined(BUILD_FOR_RP2040)
xSemaphoreTake(lf_csr_lock, portMAX_DELAY);
#else
std::unique_lock<std::mutex> lck(lf_csr_lock);
#endif
int_frequency = Hz;
#if defined(BUILD_FOR_RP2040)
xSemaphoreGive(lf_csr_lock);
#endif
}
void kw11_l::write_byte(const uint16_t addr, const uint8_t value) void kw11_l::write_byte(const uint16_t addr, const uint8_t value)
{ {
if (addr != ADDR_LFC) { if (addr != ADDR_LFC) {

View file

@ -23,6 +23,7 @@ private:
std::thread *th { nullptr }; std::thread *th { nullptr };
std::mutex lf_csr_lock; std::mutex lf_csr_lock;
#endif #endif
int int_frequency { 50 };
uint16_t lf_csr { 0 }; uint16_t lf_csr { 0 };
int64_t t_diff_sum { 0 }; int64_t t_diff_sum { 0 };
@ -43,6 +44,8 @@ public:
void show_state(console *const cnsl) const override; void show_state(console *const cnsl) const override;
void set_interrupt_frequency(const int Hz);
JsonDocument serialize(); JsonDocument serialize();
static kw11_l *deserialize(const JsonVariantConst j, bus *const b, console *const cnsl); static kw11_l *deserialize(const JsonVariantConst j, bus *const b, console *const cnsl);