Commit 57664ee9e4ec484ced9e6817944424393367e0af
receivedFri, 19. Jul 2024, 07:25:14 (by user sx)
Fri, 19 Jul 2024 05:25:14 +0000 (07:25 +0200)
authorManfred Steiner <sx@htl-kaindorf.at>
Fri, 19 Jul 2024 05:25:06 +0000 (07:25 +0200)
committerManfred Steiner <sx@htl-kaindorf.at>
Fri, 19 Jul 2024 05:25:06 +0000 (07:25 +0200)
2 files changed:
examples/simuc/.vscode/settings.json
examples/simuc/src/simavr/simavr.cpp

index 263487d361c307b5e01e0a0a721120158e4f0954..a2774e887c580decd81cd706fb18d0706d29ce44 100644 (file)
@@ -1,6 +1,6 @@
 {
     "cSpell.words": [],
     "cSpell.ignorePaths": [
-        "**/*.json", "**/*.c", "**/*.h", "**/Makefile"
+        "**/*.json", "**/*.c", "**/*.h", "**/*.cpp", "**/*.hpp", "**/Makefile"
     ]
 }
\ No newline at end of file
index 6dceb8c6265886df2d279399a7c7bad82ebce7d7..c678f48c0b52a99a40c1ade97c946dad48ef561f 100644 (file)
@@ -176,6 +176,19 @@ void SimAvr::load (struct StartParameters *params) {
                avr->gdb_port = params->gdbPort > 0 ? params->gdbPort : 1234;
                avr_gdb_init(avr);
 
+               switch (params->board) {
+                       case BoardSure: {
+                               // SW1 and SW2 have external pullup resistors
+                               avr_ioport_external_t io_ext = { 'C', 0xc0, 0xc0 }; // PC6 ... SW2, PC7...SW1
+                               avr_ioctl(avr, AVR_IOCTL_IOPORT_SET_EXTERNAL('C'), &io_ext);
+                               break;
+                       }
+                       default: break;
+
+               }
+               
+                                                               
+
                pthread_mutex_unlock(&lock);
 
        } catch (std::exception& e) {
@@ -958,13 +971,9 @@ void SimAvr::avrRun () {
                                        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);
+                                                       if ((ddrc & 0x80) == 0) {
+                                                               avr_raise_irq(avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 7), 0x80);
                                                        }
-                                                       uint8_t pinc2 = avr->data[0x33];
-                                                       printf("SW1 released, DDRC = 0x%02x, PINC 0x%02x -> 0x%02x\n", ddrc, pinc1, pinc2);
                                                }
                                                nextCommand = ReadyForNewCommand;
                                                break;
@@ -973,35 +982,25 @@ void SimAvr::avrRun () {
                                        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);
+                                                       if ( (ddrc & 0x80) == 0) {
+                                                               avr_raise_irq(avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 7), 0x00);
                                                        }
-                                                       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) {
                                                        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);
+                                                               avr_raise_irq(avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 5), 0x20);
                                                        }
                                                } 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);
+                                                       if ( (ddrc & 0x40) == 0) {
+                                                               avr_raise_irq(avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 6), 0x40);
                                                        }
                                                }
                                                nextCommand = ReadyForNewCommand;
@@ -1013,15 +1012,12 @@ void SimAvr::avrRun () {
                                                        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);
+                                                               avr_raise_irq(avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 5), 0x00);
                                                        }
                                                } 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);
+                                                               avr_raise_irq(avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 6), 0);
                                                        }
 
                                                }