printf(" b (break), 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");
printf("available commands:\n");
printAvailableCommands(params);
- // printf(" b (break), c (continue), s (stack), r (reset), p (power), q (quit)\n");
- // if (params.board == BoardNano644) {
- // printf(" 1 (SW2 not pressed), 2 (SW2 pressed)\n");
- // }
printf("----------------------------------------------------------------------\n");
printf("init done - press key to start\n");
char c = getchar();
try {
EnumSimAvrCommand simCmd = ReadyForNewCommand;
- if (strcmp(line, "1\n") == 0) {
- simCmd = CommandSW2Released;
-
- } else if (strcmp(line, "2\n") == 0) {
- simCmd = CommandSW2Pressed;
-
- } else {
+ 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;
}
}
-
}
// while (1) {
// struct SimAvrEvent ev = waitForEvent();
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
+ static int8_t sw[2] = { -1, -1 };
+ static uint8_t swMask[2] = { 0x80, 0x40 };
int nextLed[4] = { -1, -1, -1, -1 };
+ int nextSw[2] = { -1, -1 };
char cLed[4];
uint8_t ddra = avr->data[0x3a];
uint8_t porta = avr->data[0x3b];
+ uint8_t ddrc = avr->data[0x34];
+ uint8_t pinc = avr->data[0x33];
int change = 0;
for (int i = 0; i < 4; i++) {
if (ddra & mask[i]) {
rv = true;
}
}
+
+ for (int i = 0; i < 2; i++) {
+ if ((ddrc & swMask[i]) == 0) {
+ nextSw[i] = (pinc & swMask[i]) == 0 ? 1 : 0;
+ } else {
+ nextSw[i] = -1;
+ }
+ if (!onlyOnChange || nextSw[i] != sw[i]) {
+ change++;
+ rv = true;
+ }
+ }
+
int l = 0;
if (change) {
- l += snprintf(s, size, "LED PA3:0 = ");
+ char c[2];
+ for (int i = 0; i < 2; i++){
+ switch (nextSw[i]) {
+ case 0: c[i] = '.';break;
+ case 1: c[i] = 'X'; break;
+ default: c[i] = '?'; break;
+ }
+ }
+ l += snprintf(&s[l], size - l, "SW1:2 = %c%c", c[0], c[1]);
+
+ l += snprintf(&s[l], size - l, " LED PA3:0 = ");
for (int i = 0; i < 4; i++) {
switch (nextLed[i]) {
case -1: cLed[i] = '-'; break;
}
}
+ for (int i = 0; i < 2; i++) {
+ if (sw[i] != nextSw[i]) {
+ sw[i] = nextSw[i];
+ l += snprintf(&s[l], size - l, " SW%d %s", i + 1, nextSw[i] ? "pressed" : "not pressed");
+ }
+ }
}
break;
}
break;
}
+ case CommandSW1Released: {
+ if (startParameters->board == BoardSure) {
+ uint8_t ddrc = avr->data[0x34]; // Atmega16
+ uint8_t pinc1 = avr->data[0x33];
+ if ((ddrc & 0x80) == 0) { // external pullup on board
+ avr_ioport_external_t io_ext = { 'C', 0x80, 0x80 }; // PC7 ... SW1
+ avr_ioctl(avr, AVR_IOCTL_IOPORT_SET_EXTERNAL('C'), &io_ext);
+ }
+ uint8_t pinc2 = avr->data[0x33];
+ printf("SW1 released, DDRC = 0x%02x, PINC 0x%02x -> 0x%02x\n", ddrc, pinc1, pinc2);
+ }
+ nextCommand = ReadyForNewCommand;
+ break;
+ }
+
+ case CommandSW1Pressed: {
+ if (startParameters->board == BoardSure) {
+ uint8_t ddrc = avr->data[0x34]; // Atmega16
+ uint8_t pinc1 = avr->data[0x33];
+ if ( (ddrc & 0x80) == 0) { // external pullup on board
+ avr_ioport_external_t io_ext = { 'C', 0x80, 0x00 }; // PC7 ... SW1
+ avr_ioctl(avr, AVR_IOCTL_IOPORT_SET_EXTERNAL('C'), &io_ext);
+ }
+ uint8_t pinc2 = avr->data[0x33];
+ printf("SW1 pressed, DDRC = 0x%02x, PINC 0x%02x -> 0x%02x\n", ddrc, pinc1, pinc2);
+
+ }
+ nextCommand = ReadyForNewCommand;
+ break;
+ }
+
+
+
+
case CommandSW2Released: {
if (startParameters->board == BoardNano644) {
- avr_ioport_external_t io_ext = { 'C', 0x20, 0x20 }; // PC5 ... SW2
- avr_ioctl(avr, AVR_IOCTL_IOPORT_SET_EXTERNAL('C'), &io_ext);
+ uint8_t ddrc = avr->data[0x27]; // Atmega644P
+ uint8_t portc = avr->data[0x28]; // Atmega644P
+ if ( (ddrc & 0x20) == 0 && (portc & 0x20) == 0x20) { // internal pullup needed
+ avr_ioport_external_t io_ext = { 'C', 0x20, 0x20 }; // PC5 ... SW2
+ avr_ioctl(avr, AVR_IOCTL_IOPORT_SET_EXTERNAL('C'), &io_ext);
+ }
+ } else if (startParameters->board == BoardSure) {
+ uint8_t ddrc = avr->data[0x34]; // Atmega16
+ if ( (ddrc & 0x40) == 0) { // external pullup on board
+ avr_ioport_external_t io_ext = { 'C', 0x40, 0x40 }; // PC6 ... SW2
+ avr_ioctl(avr, AVR_IOCTL_IOPORT_SET_EXTERNAL('C'), &io_ext);
+ }
}
nextCommand = ReadyForNewCommand;
break;
case CommandSW2Pressed: {
if (startParameters->board == BoardNano644) {
- avr_ioport_external_t io_ext = { 'C', 0x20, 0x0 }; // PC5 ... SW2
- avr_ioctl(avr, AVR_IOCTL_IOPORT_SET_EXTERNAL('C'), &io_ext);
+ uint8_t ddrc = avr->data[0x27]; // Atmega644P
+ uint8_t portc = avr->data[0x28]; // Atmega644P
+ if ( (ddrc & 0x20) == 0 && (portc & 0x20) == 0x20) { // internal pullup needed
+ // vr_ioport_external_t p;
+ avr_ioport_external_t io_ext = { 'C', 0x20, 0x0 }; // PC5 ... SW2
+ avr_ioctl(avr, AVR_IOCTL_IOPORT_SET_EXTERNAL('C'), &io_ext);
+ }
+ } else if (startParameters->board == BoardSure) {
+ uint8_t ddrc = avr->data[0x34]; // Atmega16
+ if ( (ddrc & 0x80) == 0) { // external pullup on board
+ avr_ioport_external_t io_ext = { 'C', 0x40, 0x00 }; // PC6 ... SW2
+ avr_ioctl(avr, AVR_IOCTL_IOPORT_SET_EXTERNAL('C'), &io_ext);
+ }
+
}
nextCommand = ReadyForNewCommand;
break;