}
void printAvailableCommands (struct StartParameters ¶ms) {
- printf(" b (break), c (continue), s (stack), r (reset), p (power), q (quit)\n");
+ printf("----------------------------------------------------------------------\n");
+ printf("available commands:\n");
+ printf(" h (help)\n");
+ printf(" b (break), n (stepi), c (continue), s (stack), r (reset), p (power), q (quit)\n");
if (params.board == BoardNano644) {
printf(" 1 (SW2 not pressed), 2 (SW2 pressed)\n");
} else if (params.board == BoardSure) {
printf(" 1 (SW1 not pressed), 2 (SW1 pressed), 3 (SW2 not pressed), 4 (SW2 pressed)\n");
}
+ printf("----------------------------------------------------------------------\n");
+}
+
+EnumSimAvrCommand parseSimAvrCommand (struct StartParameters& params, char c) {
+ switch (c) {
+ case 'h': return CommandHelp;
+ case 'b': return CommandBreak;
+ case 'n': return CommandStepi;
+ case 'c': return CommandContinue;
+ case 's': return CommandStack;
+ case 'r': return CommandReset;
+ case 'p': return CommandPower;
+ case 'q': return CommandPower;
+ case '1': {
+ switch (params.board) {
+ case BoardSure: return CommandSW1Released;
+ case BoardNano644: return CommandSW2Released;
+ default: break;
+ }
+ }
+ case '2': {
+ switch (params.board) {
+ case BoardSure: return CommandSW1Pressed;
+ case BoardNano644: return CommandSW2Pressed;
+ default: break;
+ }
+ }
+ case '3': {
+ switch (params.board) {
+ case BoardSure: return CommandSW2Released;
+ default: break;
+ }
+ }
+ case '4': {
+ switch (params.board) {
+ case BoardSure: return CommandSW2Pressed;
+ default: break;
+ }
+ }
+ default: return ReadyForNewCommand;
+ }
}
struct SimUcInit {
return 1;
}
printf("----------------------------------------------------------------------\n");
- printf("available commands:\n");
+ printf("init done\n");
printAvailableCommands(params);
+ printf("start simulator with command b (break)\n");
+ printf("ready for avr-gdb -> (gdb) target remote :%d\n", params.gdbPort);
printf("----------------------------------------------------------------------\n");
- printf("init done - press key to start\n");
- char c = getchar();
- if (c != '\n') {
- getchar(); // remove line feed from stdin
- }
- printf("----------------------------------------------------------------------\n");
-
- switch (c) {
- case 'b': start(CommandBreak, NULL); break;
- case 's': start(CommandStack, NULL); break;
- case 'r': start(CommandReset, NULL); break;
- case 'p': start(CommandPower, NULL); break;
- case 'q': return 0;
- case '1': case '2': {
- if (params.board == BoardNano644) {
- break;
- }
- }
- default: start(ReadyForNewCommand, NULL); break;
- }
-
- // int cnt = 0;
+ EnumSimAvrCommand cmd = CommandBreak;
+ start(CommandBreak, NULL);
+ EnumSimAvrCommand lastCmd = cmd;
+
char *line = NULL;
size_t size = 0;
int quit = 0;
while (!quit) {
- // struct SimAvrEvent ev = waitForEvent();
- // printf("%10.03lf: event %s (%d) received \r", ev.cycle / 20E6, eventText((EnumSimEvent)ev.event), ev.event);
- // fflush(stdout);
- // if (++cnt == 10000) {
- // stop();
- // shutdown();
- // break;
- // }
-
if (getline(&line, &size, stdin) > 0) {
try {
- EnumSimAvrCommand simCmd = ReadyForNewCommand;
-
- switch (params.board) {
- case BoardNano644: {
- if (strcmp(line, "1\n") == 0) {
- simCmd = CommandSW2Released;
- } else if (strcmp(line, "2\n") == 0) {
- simCmd = CommandSW2Pressed;
- }
- break;
- }
- case BoardSure: {
- if (strcmp(line, "1\n") == 0) {
- simCmd = CommandSW1Released;
- } else if (strcmp(line, "2\n") == 0) {
- simCmd = CommandSW1Pressed;
- } else if (strcmp(line, "3\n") == 0) {
- simCmd = CommandSW2Released;
- } else if (strcmp(line, "4\n") == 0) {
- simCmd = CommandSW2Pressed;
- }
- break;
- }
- default: break;
- }
- if (simCmd != ReadyForNewCommand) {
- const char *commands[] = { "quit", "break", "continue", "stack", "reset", "power" };
- int foundIndex = -1;
- int foundCnt = 0;
- size_t length = strlen(line) - 1;
- if (length > 0 && size >= (length + 1)) {
- line[length] = 0;
- for (long unsigned int i = 0; i < sizeof(commands) / sizeof(commands[0]); i++) {
- const char *cmd = commands[i];
- size_t max = strlen(cmd);
- bool ok = true;
- for (size_t j = 0; j < length; j++) {
- if (j >= max || line[j] != cmd[j]) {
- ok = false;
- break;
- }
- }
- if (ok) {
- foundCnt++;
- foundIndex = i;
- }
- }
+ EnumSimAvrCommand cmd = ReadyForNewCommand;
+ if (strnlen(line, size) == 1) { // Enter pressed
+ switch (lastCmd) {
+ case CommandStepi: cmd = CommandStepi; break;
+ default: cmd = CommandStatus;
}
-
- // printf("foundCnt=%d foundIndex=%d command=%s\n", foundCnt, foundIndex, foundIndex >= 0 ? commands[foundIndex] : "");
- if (foundCnt == 1 || length == 0) {
- simCmd = (EnumSimAvrCommand)(foundCnt > 0 ? foundIndex + 2 : 1);
+ } else if (strnlen(line, size) == 2) {
+ cmd = parseSimAvrCommand(params, line[0]);
+ lastCmd = cmd;
+ if (cmd == CommandHelp) {
+ printAvailableCommands(params);
+ continue;
}
}
- if (simCmd != ReadyForNewCommand) {
+ if (cmd != ReadyForNewCommand) {
struct SimAvrStatus status = getStatus();
- if (simCmd == CommandStatus && status.state == StateStopped) {
+ if (cmd == CommandStatus && status.state == StateStopped) {
// ignore status command, because status was already printed
// only line feed visible on screen
} else {
- setCommand(simCmd, NULL);
+ setCommand(cmd, NULL);
while (1) {
struct SimAvrEvent ev = waitForEvent();
- if (ev.event == EventShutdown || (simCmd == CommandQuit && ev.event == EventCommandExecuted)) {
+ if (ev.event == EventShutdown || (cmd == CommandQuit && ev.event == EventCommandExecuted)) {
quit = 1;
break;
}
}
}
- // while (1) {
- // struct SimAvrEvent ev = waitForEvent();
- // printf("event %s (%d) received\n", eventText((EnumSimEvent)ev.event), ev.event);
- // if (ev.event == EventShutdown) {
- // break;
- // }
- // }
if (simUcInit != NULL) {
for (int i = 0; i < simUcInit->argc; i++) {