#include "simavr/simavr.h"
void printVersion () {
- printf("simuc V0.0.7 (%s,%s)\n", __DATE__, __TIME__);
+ printf("simuc V0.0.8 (%s,%s)\n", __DATE__, __TIME__);
}
void printHelp () {
printf("usage: simuc [options] elf-file [elf-file ...]\n\n");
printf(" available options (you can use file .simucinit instead):\n");
printf(" --port ... listining port for gdb (default 1234)\n");
- printf(" --board ... set board (arduino, sure, evws1)\n");
+ printf(" --board ... set board (arduino, nano-644, sure, evws1)\n");
printf(" --nosync do not sync elapsed µC-time with real time\n");
printf(" --mmcu ... set target device type\n");
printf(" --frequency ... set target frequency in Hz\n");
params.vcc = 5000;
params.avcc = 5000;
params.aref = 2500;
+
+ } else if (strcmp("nano-644", argv[i]) == 0) {
+ params.board = BoardNano644;
+ params.mmcu = "atmega644p";
+ params.frequency = 12000000;
+ params.vcc = 3300;
+ params.avcc = 3300;
+ params.aref = 1100;
+
} else if (strcmp("sure", argv[i]) == 0) {
params.board = BoardSure;
params.mmcu = "atmega16";
std::vector<uint8_t> gdbToUartBuffer;
__attribute__((unused)) static void fromGdbUart (uint8_t b) {
+ printf("\n\rgdb-uart OUT -> %02X", b);
+ if (b > 32 && b < 127) {
+ printf(" %c\n", b);
+ } else {
+ printf("\n");
+ }
static int cnt = 0;
if (b == '$') {
cnt = 1;
}
__attribute__((unused)) static void toGdbUart (uint8_t b) {
+ printf("\n\rgdb-uart IN <-- %02X", b);
+ if (b > 32 && b < 127) {
+ printf(" %c\n", b);
+ } else {
+ printf("\n");
+ }
+
static int cnt = 0;
if (b == '$') {
cnt = 1;
// simavr.registerIoWrite(PORTB, handleWritePortB);
simavr.setUartPtyEnabled(0, true);
int uartCnt = 1;
- if (strcmp(simavr.getTargetDeviceName(), "atmega324p") == 0) {
+ if (strcmp(simavr.getTargetDeviceName(), "atmega16") == 0) {
+ // simavr.setUartPtyHook(0, fromGdbUart, toGdbUart);
+ }
+ if (strcmp(simavr.getTargetDeviceName(), "atmega324p") == 0 || strcmp(simavr.getTargetDeviceName(), "atmega644p") == 0) {
simavr.setUartPtyEnabled(1, true);
simavr.setUartPtyHook(1, fromGdbUart, toGdbUart);
uartCnt = 2;
uint16_t nanos = time % 1000; time = time / 1000;
uint16_t micros = time % 1000; time = time / 1000;
uint16_t millis = time % 1000; time = time / 1000;
- uint16_t seconds = time % 1000; time = time / 1000;
- printf("cycle %" PRIu64 " = %ds %03dms %03dµs %03dns", avr->cycle, seconds, millis, micros, nanos);
+ uint16_t seconds = time % 60; time = time / 60;
+ uint16_t minutes = time % 60; time = time / 60;
+ uint32_t hours = (uint32_t)time; // time has after divisions max. 23 Bit
+ if (hours == 0) {
+ printf("cycle %010" PRIu64 " = %2dmin %2ds %03dms %03dµs %03dns", avr->cycle, minutes, seconds, millis, micros, nanos);
+ } else {
+ printf("cycle %010" PRIu64 " = %dhrs %2dmin %2ds %03dms %03dµs %03dns", avr->cycle, hours, minutes, seconds, millis, micros, nanos);
+ }
}
bool SimAvr::sprintfLedStatus (char *s, size_t size, bool onlyOnChange) {
int8_t nextLedL = -1;
if (ddrb & 0x20) {
nextLedL = portb & 0x20 ? 1 : 0;
+ } else {
+ nextLedL = -1;
}
if (!onlyOnChange || nextLedL != ledL) {
+ char c;
+ switch (nextLedL) {
+ case -1: c = '-'; break;
+ case 0: c = '.'; break;
+ case 1: c = 'X'; break;
+ default: c = '?'; break;
+ }
ledL = nextLedL;
- snprintf(s, size, "LED L = %c", ledL == 1 ? 'X' : '.');
+ snprintf(s, size, "LED L = %c", c);
rv = true;
}
break;
}
+ case BoardNano644: {
+ static int8_t led[3] = { -1, -1, -1 }; // pin floating
+ static uint8_t mask[3] = { 0x04, 0x08, 0x10 }; // Bitmask for LED Red, Yellow, Green
+ int nextLed[3] = { -1, -1, -1 };
+ char cLed[3];
+ uint8_t ddrc = avr->data[0x27];
+ uint8_t portc = avr->data[0x28];
+ int change = 0;
+ for (int i = 0; i < 3; i++) {
+ if (ddrc & mask[i]) {
+ nextLed[i] = portc & mask[i] ? 1 : 0;
+ } else {
+ nextLed[i] = -1;
+ }
+ if (!onlyOnChange || nextLed[i] != led[i]) {
+ change++;
+ rv = true;
+ }
+ }
+ int l = 0;
+ if (change) {
+ l += snprintf(s, size, "LED RGB = ");
+ for (int i = 0; i < 3; i++) {
+ switch (nextLed[i]) {
+ case -1: cLed[i] = '-'; break;
+ case 0: cLed[i] = '.'; break;
+ case 1: cLed[i] = 'X'; break;
+ default: cLed[i] = '?'; break;
+ }
+ l += snprintf(&s[l], size - l, "%c", cLed[i]);
+ }
+ for (int i = 0; i < 3; i++) {
+ if (nextLed[i] != led[i]) {
+ led[i] = nextLed[i];
+ switch (i) {
+ case 0: l += snprintf(&s[l], l, " -> Red = %c", cLed[i]); break;
+ case 1: l += snprintf(&s[l], l, " -> Yellow = %c", cLed[i]); break;
+ case 2: l += snprintf(&s[l], l, " -> Green = %c", cLed[i]); break;
+ }
+ }
+ }
+ }
+ break;
+ }
+
case BoardSure: {
static int8_t led[4] = { -1, -1, -1, -1 }; // pin floating
+ static uint8_t mask[4] = { 0x08, 0x04, 0x02, 0x01 }; // Bitmask for LED PA3, PA2, PA1, PA0
+ int nextLed[4] = { -1, -1, -1, -1 };
+ char cLed[4];
uint8_t ddra = avr->data[0x3a];
uint8_t porta = avr->data[0x3b];
int change = 0;
for (int i = 0; i < 4; i++) {
- int8_t nextLed = -1;
- if (ddra & (1 << i)) {
- nextLed = porta & (1 << i) ? 0 : 1; // port output
+ if (ddra & mask[i]) {
+ nextLed[i] = porta & mask[i] ? 1 : 0;
} else {
- nextLed = 0; // port input _> led is off
+ nextLed[i] = -1;
}
- if (nextLed != led[i]) {
- change = 1;
- led[i] = nextLed;
+ if (!onlyOnChange || nextLed[i] != led[i]) {
+ change++;
+ rv = true;
}
}
- if (!onlyOnChange || change) {
- int n = snprintf(s, size, "LED PA[3210] =");
- for (int i = 3; i >= 0; i--) {
- n += snprintf(s + n, size - n, " %c", led[i] == 1 ? 'X' : '.');
+ int l = 0;
+ if (change) {
+ l += snprintf(s, size, "LED PA3:0 = ");
+ for (int i = 0; i < 4; i++) {
+ switch (nextLed[i]) {
+ case -1: cLed[i] = '-'; break;
+ case 0: cLed[i] = '.'; break;
+ case 1: cLed[i] = 'X'; break;
+ default: cLed[i] = '?'; break;
+ }
+ l += snprintf(&s[l], size - l, "%c", cLed[i]);
+ }
+ for (int i = 0; i < 4; i++) {
+ if (nextLed[i] != led[i]) {
+ led[i] = nextLed[i];
+ switch (i) {
+ case 0: l += snprintf(&s[l], l, " -> PA3 = %c", cLed[i]); break;
+ case 1: l += snprintf(&s[l], l, " -> PA2 = %c", cLed[i]); break;
+ case 2: l += snprintf(&s[l], l, " -> PA1 = %c", cLed[i]); break;
+ case 3: l += snprintf(&s[l], l, " -> PA0 = %c", cLed[i]); break;
+ }
+
+ }
}
- rv = true;
}
break;
}