#include "fw.h"
#include "io.h"
#include "abcio.h"
#include "sys.h"
#include "console.h"

volatile bool dont_gc = false;	/* Keep things from linker gc */

void __hot main(void)
{
    unsigned int max_abc_latency = 0;
    unsigned int abc_latency;

    init();

    if (dont_gc)
	run_test_image();

    while (1) {
	wait_for_irq();

	if (unlikely(do_write_rtc))
	    write_rtc();

	abcdisk_io_poll();

	abc_latency = ABC_LATENCY;
	if (abc_latency > max_abc_latency) {
	    max_abc_latency = abc_latency;
	    con_printf("\nWorst ABC-bus latency: %u SDRAM cycles%s\n",
		       abc_latency & 255,
		       (abc_latency >> 8) ? " UNDERRUN" : "");
	}
    }
}
