9#include <simavr/sim_avr.h>
10#include <simavr/sim_gdb.h>
11#include <simavr/avr_ioport.h>
12#include <simavr/sim_elf.h>
13#include <simavr/avr_uart.h>
39 FD_SET(STDIN_FILENO, &fds);
40 select(STDIN_FILENO+1, &fds,
NULL,
NULL, &tv);
46 if ((!avr && level <= LOG_WARNING) || (avr && avr->log >= level)) {
96 const char *irq_names[2] = {
"8<uart_in",
"8>uart_out"};
101 avr_ioctl(
g_avr, AVR_IOCTL_UART_GET_FLAGS(
'0'), &flags);
102 flags &= ~AVR_UART_FLAG_STDIO;
103 flags &= ~AVR_UART_FLAG_POLL_SLEEP;
104 avr_ioctl(
g_avr, AVR_IOCTL_UART_SET_FLAGS(
'0'), &flags);
106 avr_irq_t *src = avr_io_getirq(
g_avr, AVR_IOCTL_UART_GETIRQ(
'0'), UART_IRQ_OUTPUT);
107 avr_irq_t *dst = avr_io_getirq(
g_avr, AVR_IOCTL_UART_GETIRQ(
'0'), UART_IRQ_INPUT);
111 avr_irq_t *xon = avr_io_getirq(
g_avr, AVR_IOCTL_UART_GETIRQ(
'0'), UART_IRQ_OUT_XON);
112 avr_irq_t *xoff = avr_io_getirq(
g_avr, AVR_IOCTL_UART_GETIRQ(
'0'), UART_IRQ_OUT_XOFF);
125 g_avr = avr_make_mcu_by_name(
"atmega1284");
128 fprintf(
stderr,
"avr_make_mcu_by_name failed\n");
134 fprintf(
stderr,
"Usage: %s [-g] binary [args ...]\n",
argv[0]);
138 const char *filename =
argv[1];
139 bool enable_gdb =
false;
142 if (
strcmp(filename,
"-g") == 0)
149 elf_firmware_t firmware = {};
150 elf_read_firmware(filename, &firmware);
152 avr_load_firmware(
g_avr, &firmware);
153 g_avr->frequency = 8000000;
157 g_avr->state = cpu_Stopped;
158 g_avr->gdb_port = 1234;
169 for (
int i = 0; i <
g_args.argc; i++)
176 int state = avr_run(
g_avr);
177 if (state == cpu_Done)
180 if (state == cpu_Crashed)
182 fprintf(
stderr,
"CPU Crashed\n");
193 fprintf(
stderr,
"Received error status from simulation\n");
MOSAPI char * strncpy(char *__restrict dest, const char *__restrict src, size_t n)
MOSAPI s32 strcmp(const char *str1, const char *str2)
MOSAPI int fputc(int c, FILE *file)
MOSAPI const char *__restrict format
MOSAPI int vfprintf(FILE *__restrict file, const char *__restrict format, va_list ap)
MOSAPI int fgetc(FILE *file)
#define FD_SET(__fd, __set)
#define FD_ISSET(__fd, __set)
static bool stdin_can_read()
static void uart_xon_hook(struct avr_irq_t *irq, uint32_t value, void *param)
static void uart_tx_hook(struct avr_irq_t *irq, uint32_t value, void *param)
static void uart_xoff_hook(struct avr_irq_t *irq, uint32_t value, void *param)
static void status_ok_hook(struct avr_irq_t *irq, uint32_t value, void *param)
static void avr_logger(avr_t *avr, const int level, const char *format, va_list ap)
static avr_irq_t * g_uart_irq