Commit 1b2e5a4715486ecc57996a7c506aaaaf124832b5
receivedThu, 18. Jul 2024, 16:23:20 (by user sx)
Thu, 18 Jul 2024 14:23:20 +0000 (16:23 +0200)
authorManfred Steiner <sx@htl-kaindorf.at>
Thu, 18 Jul 2024 14:23:13 +0000 (16:23 +0200)
committerManfred Steiner <sx@htl-kaindorf.at>
Thu, 18 Jul 2024 14:23:13 +0000 (16:23 +0200)
6 files changed:
examples/simuc/.vscode/c_cpp_properties.json
examples/simuc/.vscode/launch.json
examples/simuc/.vscode/settings.json
examples/simuc/src/main.cpp
examples/simuc/src/simavr/simavr.cpp
examples/simuc/src/simavr/simavr.h

index ba80ed41e973906967100d1c13adee4c2eb69a7d..e6ad2abacb13469a79f32c1720e8978ff868a2bb 100644 (file)
@@ -7,7 +7,7 @@
       "compilerPath": "/usr/bin/gcc",
       "cStandard": "c11",
       "cppStandard": "c++17",
-      "intelliSenseMode": "clang-x64"
+      "intelliSenseMode": "linux-gcc-x64"
     }
   ],
   "version": 4
index 4c40c7b04869fba69971bb7af3171ad204886949..447fd73745476b1560881330a3367cbe573e110d 100644 (file)
@@ -9,7 +9,7 @@
             "type": "cppdbg",
             "request": "launch",
             "program": "${workspaceFolder}/dist/simuc",
-            "args": [],
+            "args": [ "--board", "sure", "/work/4ahme/sx-la1/g2/turnus3/2_timer/dist/atmega16.elf"],
             "stopAtEntry": false,
             "cwd": "${workspaceFolder}",
             "environment": [],
index 4c1291f55dec43d8e2ffc89de9d93aecbbd05565..263487d361c307b5e01e0a0a721120158e4f0954 100644 (file)
@@ -1,99 +1,6 @@
 {
-    "files.associations": {
-        "cstdio": "cpp",
-        "array": "cpp",
-        "atomic": "cpp",
-        "bit": "cpp",
-        "*.tcc": "cpp",
-        "cctype": "cpp",
-        "chrono": "cpp",
-        "clocale": "cpp",
-        "cmath": "cpp",
-        "compare": "cpp",
-        "concepts": "cpp",
-        "condition_variable": "cpp",
-        "cstdarg": "cpp",
-        "cstddef": "cpp",
-        "cstdint": "cpp",
-        "cstdlib": "cpp",
-        "ctime": "cpp",
-        "cwchar": "cpp",
-        "cwctype": "cpp",
-        "deque": "cpp",
-        "list": "cpp",
-        "map": "cpp",
-        "string": "cpp",
-        "unordered_map": "cpp",
-        "vector": "cpp",
-        "exception": "cpp",
-        "algorithm": "cpp",
-        "functional": "cpp",
-        "iterator": "cpp",
-        "memory": "cpp",
-        "memory_resource": "cpp",
-        "numeric": "cpp",
-        "random": "cpp",
-        "ratio": "cpp",
-        "string_view": "cpp",
-        "system_error": "cpp",
-        "tuple": "cpp",
-        "type_traits": "cpp",
-        "utility": "cpp",
-        "future": "cpp",
-        "initializer_list": "cpp",
-        "iomanip": "cpp",
-        "iosfwd": "cpp",
-        "iostream": "cpp",
-        "istream": "cpp",
-        "limits": "cpp",
-        "mutex": "cpp",
-        "new": "cpp",
-        "numbers": "cpp",
-        "ostream": "cpp",
-        "semaphore": "cpp",
-        "sstream": "cpp",
-        "stdexcept": "cpp",
-        "stop_token": "cpp",
-        "streambuf": "cpp",
-        "thread": "cpp",
-        "cinttypes": "cpp",
-        "typeinfo": "cpp",
-        "variant": "cpp",
-        "iom324.h": "c",
-        "sim_megax4.h": "c",
-        "sim_core_declare.h": "c",
-        "iom328p.h": "c",
-        "iom16.h": "c",
-        "sim_avr.h": "c"
-    },
-    "cSpell.words": [
-        "aref",
-        "atmega",
-        "avcc",
-        "avrsim",
-        "ddra",
-        "ddrb",
-        "eeprom",
-        "eesize",
-        "evws",
-        "fusesize",
-        "ioend",
-        "lfcrlf",
-        "lockbits",
-        "megaavr",
-        "microcontroller",
-        "Microcontrollers",
-        "millis",
-        "mmcu",
-        "picocom",
-        "porta",
-        "PORTB",
-        "ramend",
-        "simavr",
-        "simuc",
-        "slavename",
-        "SRAM",
-        "sreg",
-        "UART"
+    "cSpell.words": [],
+    "cSpell.ignorePaths": [
+        "**/*.json", "**/*.c", "**/*.h", "**/Makefile"
     ]
 }
\ No newline at end of file
index 6123098a2431cf00ddfd3044e502f19915ba6a5b..cf4abba0b210ad5af3c14e9fc934d237b80e9805 100644 (file)
@@ -35,6 +35,8 @@ void printAvailableCommands (struct StartParameters &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");
+    } else if (params.board == BoardSure) {
+        printf(" 1 (SW1 not pressed), 2 (SW1 pressed), 3 (SW2 not pressed), 4 (SW2 pressed)\n");
     }
 }
 
@@ -224,10 +226,6 @@ int main (int argc, char **argv) {
     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();
@@ -270,13 +268,30 @@ int main (int argc, char **argv) {
             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;
@@ -337,7 +352,6 @@ int main (int argc, char **argv) {
             }
            
         }
-        
     }
     // while (1) {
     //     struct SimAvrEvent ev = waitForEvent();
index 29d2d0ee1fe3f0ff264e10b041185af6f858890f..6dceb8c6265886df2d279399a7c7bad82ebce7d7 100644 (file)
@@ -587,10 +587,15 @@ bool SimAvr::sprintfLedStatus (char *s, size_t size, bool onlyOnChange) {
                        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]) {
@@ -603,9 +608,32 @@ bool SimAvr::sprintfLedStatus (char *s, size_t size, bool onlyOnChange) {
                                                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;
@@ -627,6 +655,12 @@ bool SimAvr::sprintfLedStatus (char *s, size_t size, bool onlyOnChange) {
                                                        
                                                }
                                        }
+                                       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;
                        }
@@ -921,10 +955,54 @@ void SimAvr::avrRun () {
                                                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;
@@ -932,8 +1010,20 @@ void SimAvr::avrRun () {
 
                                        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;
index 999beb9ec9700896f2eba9b8ef83fee89b456eaf..d4ee0d0386b2baefdf0a0150914087a4236ae945 100644 (file)
@@ -65,6 +65,8 @@ typedef enum {
        CommandStack,
        CommandReset,
        CommandPower,
+       CommandSW1Released,
+       CommandSW1Pressed,
        CommandSW2Released,
        CommandSW2Pressed,
 } EnumSimAvrCommand;