#include "simavr/simavr.h"
void printVersion () {
- printf("simuc V0.0.6 (%s,%s)\n", __DATE__, __TIME__);
+ printf("simuc V0.0.7 (%s,%s)\n", __DATE__, __TIME__);
}
void printHelp () {
return 1;
}
+ printVersion();
printf("----------------------------------------------------------------------\n");
init(¶ms);
if (errno == 1) {
}
}
}
- printf("foundCnt=%d foundIndex=%d command=%s\n", foundCnt, foundIndex, foundIndex >= 0 ? commands[foundIndex] : "");
+ // printf("foundCnt=%d foundIndex=%d command=%s\n", foundCnt, foundIndex, foundIndex >= 0 ? commands[foundIndex] : "");
if (foundCnt == 1 || length == 0) {
EnumSimAvrCommand cmd = (EnumSimAvrCommand)(foundCnt > 0 ? foundIndex + 2 : 1);
- setCommand(cmd, NULL);
- while (1) {
- struct SimAvrEvent ev = waitForEvent();
- if (ev.event == EventShutdown || (cmd == CommandQuit && ev.event == EventCommandExecuted)) {
- quit = 1;
- break;
- }
- if (ev.event == EventCommandExecuted) {
- break;
+ struct SimAvrStatus status = getStatus();
+ if (cmd == CommandStatus && status.state == StateStopped) {
+ // ignore status command, because status was already printed
+ // only line feed visible on screen
+ } else {
+ setCommand(cmd, NULL);
+ while (1) {
+ struct SimAvrEvent ev = waitForEvent();
+ if (ev.event == EventShutdown || (cmd == CommandQuit && ev.event == EventCommandExecuted)) {
+ quit = 1;
+ break;
+ }
+ if (ev.event == EventCommandExecuted) {
+ break;
+ }
}
}
switch (avr->state) {
case cpu_Done: status.state = StateDone; break;
case cpu_Running: status.state = StateRunning; break;
+ case cpu_Stopped: status.state = StateStopped; break;
case cpu_Crashed: status.state = StateCrashed; break;
default: status.state = StateOthers; break;
}
cnt = 0;
}
+ EnumSimAvrCommand nextCommand = command;
+ bool updateState = false;
if (command != ReadyForNewCommand) {
switch (command) {
case CommandStatus: {
char s[80];
sprintfLedStatus(s, sizeof(s), false);
printf(" %s\n", s);
+ nextCommand = ReadyForNewCommand;
break;
}
case CommandBreak: {
if (avr->state == cpu_Running) {
avr->state = cpu_Stopped;
+ updateState = true;
}
+ nextCommand = ReadyForNewCommand;
break;
}
case CommandContinue: {
if (avr->state == cpu_Stopped) {
avr->state = cpu_Running;
+ updateState = true;
}
+ nextCommand = ReadyForNewCommand;
break;
}
case CommandStack: {
}
}
printf("\n");
+ nextCommand = ReadyForNewCommand;
break;
}
case CommandReset: {
reset(external);
+ if (avr->state == cpu_Running) {
+ avr->state = cpu_Stopped;
+ updateState = true;
+ }
printf("\n\n----------------------------------------------------------------\n");
printf("RESET done (registers set to init value, SRAM remains unchanged)\n");
- command = CommandBreak;
- continue;
+ nextCommand = CommandBreak;
+ break;
}
case CommandPower: {
reset(powerOn);
+ if (avr->state == cpu_Running) {
+ avr->state = cpu_Stopped;
+ updateState = true;
+ }
printf("\n\n-----------------------------------------------\n");
printf("Power-On done (SRAM cleared and power-on reset)\n");
- command = CommandBreak;
- continue;
+ nextCommand = CommandBreak;
+ break;
}
- default: break;
+ default: {
+ nextCommand = ReadyForNewCommand;
+ break;
+ }
+ }
+ command = nextCommand;
+ if (updateState) {
+ if (pthread_mutex_lock(&lock)) {
+ throw std::logic_error(error(AT, "avrRun() fails caused by mutex error (2)"));
+ }
+ try {
+ switch (avr->state) {
+ case cpu_Done: status.state = StateDone; break;
+ case cpu_Running: status.state = StateRunning; break;
+ case cpu_Stopped: status.state = StateStopped; break;
+ case cpu_Crashed: status.state = StateCrashed; break;
+ default: status.state = StateOthers; break;
+ }
+ pthread_mutex_unlock(&lock);
+ }
+ catch (std::exception& e) {
+ pthread_mutex_unlock(&lock);
+ status.state = StateError;
+ }
}
- command = ReadyForNewCommand;
addEvent(EventCommandExecuted);
}