#include "general.h"
#include "platform.h"
#include "gdb_if.h"
#include "gdb_main.h"
#include "target.h"
#include "exception.h"
#include "gdb_packet.h"
#include "morse.h"
#include "command.h"
#ifdef ENABLE_RTT
#include "rtt.h"
#endif
static char pbuf[GDB_PACKET_BUFFER_SIZE + 1U] __attribute__((aligned(8)));
char *gdb_packet_buffer()
{
return pbuf;
}
static void bmp_poll_loop(void)
{
SET_IDLE_STATE(false);
while (gdb_target_running && cur_target) {
gdb_poll_target();
if (!gdb_target_running || !cur_target)
break;
char c = gdb_if_getchar_to(0);
if (c == '\x03' || c == '\x04')
target_halt_request(cur_target);
platform_pace_poll();
#ifdef ENABLE_RTT
if (rtt_enabled)
poll_rtt(cur_target);
#endif
}
SET_IDLE_STATE(true);
size_t size = gdb_getpacket(pbuf, GDB_PACKET_BUFFER_SIZE);
if (pbuf[0] != '\x04' || cur_target)
SET_IDLE_STATE(false);
gdb_main(pbuf, GDB_PACKET_BUFFER_SIZE, size);
}
int main(int argc, char **argv)
{
#if PC_HOSTED == 1
platform_init(argc, argv);
#else
(void)argc;
(void)argv;
platform_init();
#endif
while (true) {
volatile exception_s e;
TRY_CATCH (e, EXCEPTION_ALL) {
bmp_poll_loop();
}
if (e.type) {
gdb_putpacketz("EFF");
target_list_free();
gdb_outf("Uncaught exception: %s\n", e.msg);
morse("TARGET LOST.", true);
}
#if PC_HOSTED == 1
if (shutdown_bmda)
break;
#endif
}
target_list_free();
return 0;
}