Commit 8c72ee63852a4a732116b950a15957cae7f36012
receivedWed, 30. Nov 2022, 16:30:53 (by user sx)
Wed, 30 Nov 2022 15:30:53 +0000 (16:30 +0100)
authorManfred Steiner <sx@htl-kaindorf.at>
Wed, 30 Nov 2022 15:30:00 +0000 (16:30 +0100)
committerManfred Steiner <sx@htl-kaindorf.at>
Wed, 30 Nov 2022 15:30:00 +0000 (16:30 +0100)
14 files changed:
README.md
examples/simuc/.gitignore
examples/simuc/.vscode/c_cpp_properties.json [new file with mode: 0644]
examples/simuc/.vscode/launch.json
examples/simuc/.vscode/settings.json
examples/simuc/Makefile
examples/simuc/README.md
examples/simuc/dpkg/.gitignore [new file with mode: 0644]
examples/simuc/dpkg/htl-simuc_version_arch/usr/share/doc/htl-simuc/readme [deleted file]
examples/simuc/include/parts [new symlink]
examples/simuc/include/simavr [new symlink]
examples/simuc/src/main.cpp
examples/simuc/src/simavr/simavr.cpp
examples/simuc/src/simavr/simavr.h

index 450d4db95ab904446f2db73d087f56ce291ae34a..5566debbda9852ffff32ade89f7ebebcb4a0acda 100644 (file)
--- a/README.md
+++ b/README.md
@@ -11,10 +11,10 @@ This repository is mirrored from [https://github.com/buserror/simavr.git](https:
 
 ### Prepare system
 ```sh
-$ sudo apt install gcc make gcc-avr avr-libc
+$ sudo apt install gcc make gcc-avr avr-libc git
 $ sudo apt install libelf-dev
 $ sudo apt install freeglut3 freeglut3-dev
-$ sudo apt install libncurses3
+$ sudo apt install libncurses5 libncurses5-dev
 ```
 
 ### Clone repository
@@ -40,8 +40,8 @@ The ... is a placeholder for the *architecture*, which is the result of `gcc -du
 * i386: `obj-i686-linux-gnu`
 * amd64: `obj-x86_64-linux-gnu`
 * arm64: `obj-aarch64-linux-gnu`
+* armhf: `arm-linux-gnueabihf`
 * ...
 
 
 Project examples available in folder `examples`
-
index 5489810b69a1e95135a248f267e7e79cba3d9c25..d45c0b1afcbb17fa07042a521d36471840738d86 100644 (file)
@@ -1,7 +1,3 @@
 dist/**
 build/**
-dpkg/**/*.deb
-dpkg/**/usr/share/htl-simuc/simuc
-dpkg/**/usr/share/htl-simuc/simavr
-dpkg/**/DEBIAN/control
 **/*.vcd
diff --git a/examples/simuc/.vscode/c_cpp_properties.json b/examples/simuc/.vscode/c_cpp_properties.json
new file mode 100644 (file)
index 0000000..ba80ed4
--- /dev/null
@@ -0,0 +1,14 @@
+{
+  "configurations": [
+    {
+      "name": "Linux",
+      "includePath": ["${workspaceFolder}/**", "${workspaceFolder}/include" ],
+      "defines": [],
+      "compilerPath": "/usr/bin/gcc",
+      "cStandard": "c11",
+      "cppStandard": "c++17",
+      "intelliSenseMode": "clang-x64"
+    }
+  ],
+  "version": 4
+}
index 64e527ce4dccffdf8faaa98b3987ae802bfad41f..c6fe1da95f0bc14b24f37315dabcd96e9c3dcd00 100644 (file)
             "request": "launch",
             "program": "${workspaceFolder}/dist/simuc",
             "args": [],
-            "stopAtEntry": false,
+            "stopAtEntry": true,
             "cwd": "${workspaceFolder}",
             "environment": [],
             "externalConsole": false,
             "MIMode": "gdb",
+            "miDebuggerPath": "/usr/bin/gdb",
+            "setupCommands": [
+                {
+                    "description": "Enable pretty-printing for gdb",
+                    "text": "-enable-pretty-printing",
+                    "ignoreFailures": true
+                }
+              ],
             "preLaunchTask": "build"
         }
     ]
index 189a43507a0ce52b955ef7b3e9324a297bceeb7f..cb0d49d32ce110ef793e205aa46020a9d6ee7aa4 100644 (file)
@@ -65,6 +65,7 @@
         "atmega",
         "avcc",
         "avrsim",
+        "ddra",
         "ddrb",
         "eeprom",
         "eesize",
         "lfcrlf",
         "lockbits",
         "megaavr",
+        "microcontroller",
+        "Microcontrollers",
         "millis",
         "mmcu",
         "picocom",
+        "porta",
         "PORTB",
         "ramend",
         "simavr",
         "simuc",
         "slavename",
         "SRAM",
-        "sreg"
+        "sreg",
+        "UART"
     ]
 }
\ No newline at end of file
index e06b0fef900cacb1778be8c14d0d214e8b5a8931..8a265acdccea800f117cd4bbaa38763c00597115 100644 (file)
@@ -4,25 +4,18 @@ $(shell mkdir -p build >/dev/null)
 PRJ="simuc"
 $(PRJ): dist/simuc
 
-start2: $(PRJ)
-       LD_LIBRARY_PATH=$(pwd);dist/simuc
-
 start: $(PRJ)
        dist/simuc
 
-CFLAGS = -Os -Wall
 #X_CFLAGS = -O0 -g -Wall
-X_CFLAGS = -Os -g -Wall
-
+CFLAGS = -Os -Wall -g
+CFLAGS += -isystem ./include
+#CFLAGS += -isystem ./include/parts
 
 dist/simuc: build/main.o build/sim.o build/simavr.o build/error.o build/uart_pty.o ../../simavr/obj-$(shell gcc -dumpmachine)/libsimavr.a
        #g++ -o $@ -g -Wall -gdwarf-2 $^ -Wl,-rpath,$(CURDIR) -L$(CURDIR) -lsimavr  -lpthread -lutil
        g++ -o $@ -g -Wall -gdwarf-2 $^ -lelf -lpthread -lutil
 
-
-#dist/libsim.so: build/sim.o build/simavr.o build/error.o build/uart_pty.o
-#      gcc -o $@ $(CFLAGS) -shared $^
-
 build/sim.o: src/sim/sim.cpp src/sim/sim.h src/sim/error.h src/simavr/simavr.h
        gcc -o $@ $(CFLAGS) -fPIC -c $<
 
@@ -36,44 +29,60 @@ build/uart_pty.o: src/simavr/parts/uart_pty.c src/simavr/parts/uart_pty.h src/si
        gcc -o $@ $(CFLAGS) -Wno-unused-result -fPIC -c $<
 
 build/main.o: src/main.cpp src/sim/sim.h src/simavr/simavr.h
-       g++ -o $@ $(X_CFLAGS) -c $<
+       g++ -o $@ $(CFLAGS) -c $<
 
 
 # ############################################
 # Debian Packet for htl-simuc_version_arch.deb
 # ############################################
 
-ARCH := $(shell arch)
-ifeq ($(ARCH), x86_64)
+ARCH := $(shell gcc -dumpmachine)
+ifeq ($(ARCH), x86_64-linux-gnu)
        DEBARCH="amd64"
        OBJARCH=""
 endif
-ifeq ($(ARCH), x86_32)
+ifeq ($(ARCH), i686_64-linux-gnu)
        DEBARCH="i386"
 endif
-ifeq ($(ARCH), aarch64)
+ifeq ($(ARCH), aarch64-linux-gnu)
        DEBARCH="arm64"
 endif
+ifeq ($(ARCH), arm-linux-gnueabihf)
+       DEBARCH="armhf"
+endif
 
-DEBVERSION := 0.0.1~1
+DEBVERSION := 0.0.2~1
 DEBNAME := dpkg/htl-simuc_version_arch
 DEBSRC := dpkg/htl-simuc_version_arch
+DEBARCH := $(shell dpkg --print-architecture)
 
 DEB := $(DEBNAME:%version=%$(DEBVERSION),%arch=%$(DEBARCH).deb)
+LIBC_NAME := libc6
+LIBC_VERSION := $(shell dpkg --list | grep ${LIBC_NAME}:${DEBARCH} | tr -s ' ' | cut -d" " -f 3 | cut -d"-" -f 1)
+LIBCXX_NAME := libstdc++6
+LIBCXX_VERSION := $(shell dpkg --list | grep ${LIBCXX_NAME}:${DEBARCH} | tr -s ' ' | cut -d" " -f 3 | cut -d"-" -f 1)
+LIBELF_NAME := libelf1
+LIBELF_VERSION := $(shell dpkg --list | grep ${LIBELF_NAME}:${DEBARCH} | tr -s ' ' | cut -d" " -f 3 | cut -d"-" -f 1)
+
 
 deb: dpkg $(DEBSRC)/DEBIAN/control $(DEBSRC)/usr/share/doc/htl-simuc/readme
        @dpkg-deb --root-owner-group --build $(DEBSRC) ${DEB}
+       @mv $(DEBSRC)/*.deb dpkg/
+       @chmod 644 dpkg/*.deb
 
 .PHONY: $(DEBSRC)/DEBIAN/control $(DEBSRC)/usr/share/doc/htl-simuc/readme
 
 $(DEBSRC)/DEBIAN/control:
-       echo "Package: htl-simuc" > $@
-       echo "Version:" ${DEBVERSION} >> $@
+       @test -n "${LIBC_NAME}" && test -n "${LIBC_VERSION}"
+       @test -n "${LIBCXX_NAME}" && test -n "${LIBCXX_VERSION}"
+       @test -n "${LIBELF_NAME}" && test -n "${LIBELF_VERSION}"
+       @echo "Package: htl-simuc" > $@
+       @echo "Version:" ${DEBVERSION} >> $@
        @echo "Section: devel" >> $@
-       echo "Architecture:" $(DEBARCH) >> $@
-       @echo "Depends: libelf1" >> $@
+       @echo "Architecture:" $(DEBARCH) >> $@
+       @echo "Depends:" ${LIBELF_NAME} "(>=" ${LIBELF_VERSION}")," ${LIBC_NAME} "(>=" ${LIBC_VERSION}")," ${LIBCXX_NAME} "(>=" ${LIBCXX_VERSION}")" >> $@
        @echo "Recommends: gcc-avr, avr-libc, gdb-avr, binutils-avr, avrdude" >> $@
-       echo "Installed-Size:" $(shell du -s $(DEBSRC) | cut -f1) >> $@
+       @echo "Installed-Size:" $(shell du -s $(DEBSRC) | cut -f1) >> $@
        @echo "Priority: optional" >> $@
        @echo "Maintainer: Manfred Steiner <sx@htl-kaindorf.at>" >> $@
        @echo "Description: megaavr microcontroller simulation" >> $@
@@ -85,6 +94,9 @@ $(DEBSRC)/usr/share/doc/htl-simuc/readme:
        @echo  >> $@
        @echo "$ git clone https://git.htl-mechatronik.at/public/sx/simavr.git" >> $@
        @echo "$ git checkout $(shell git rev-parse HEAD)" >> $@
+       @echo >> $@
+       @echo "git diff:" >> $@
+       @git diff >> $@
        @chmod 644 $@
 
 dpkg: $(PRJ) 
@@ -99,6 +111,7 @@ dpkg: $(PRJ)
        @find $(DEBSRC) -type d -exec chmod 755 {} \;
        @find $(DEBSRC)/usr/share/htl-simuc/ -type f -exec chmod 644 {} \;
        @chmod 755 $(DEBSRC)/usr/share/htl-simuc/simuc/simuc
+       ln -sf ../doc/htl-simuc/readme $(DEBSRC)/usr/share/htl-simuc/readme
        @touch $(DEBSRC)
 
 # #####################################################################
index 5dee7f872a08289ef3126f8803afcae1a46e5393..1453dd1ceb40591065c6e845ee103eb42dc03522 100644 (file)
@@ -10,7 +10,7 @@ If the cpu is stopped by command or `avr-gdb`, some information is printed on st
 * Stack pointer SP and stack content
 
 Commands available via standard input (keyboard):
-* *Enter* print current cycles and elapsed time
+* *Enter* print current cycles, elapsed time and LED status
 * `interrupt`: stop cpu
 * `continue`: continue cpu run
 * `stack`: print complete stack content on standard output
@@ -36,20 +36,27 @@ After start of `simuc` the program waits for an keyboard action to start simulat
 $ sudo apt install gcc make gcc-avr avr-libc
 $ sudo apt install libelf-dev
 $ sudo apt install freeglut3 freeglut3-dev
-$ sudo apt install libncurses3
+$ sudo apt install libncurses5 libncurses5-dev
 ```
 
 ### Clone repository
 
 ```sh
 user@host:~ $ git clone https://git.htl-mechatronik.at/public/sx/simavr.git
-user@host:~ $ cd simavr/examples/simuc
-user@host:~/simavr/examples/simuc $
 ```
 
+### Make complete simavr
+
+```sh
+user@host:~ $ cd ~/simavr
+user@host:~/simavr/ $ make
+``` 
+
 ### Make simuc executable
 
 ```sh
+user@host:~ $ cd ~/simavr/examples/simuc
+user@host:~/simavr/examples/simuc $
 user@host:~/simavr/examples/simuc $ make
 ``` 
 
@@ -58,6 +65,7 @@ Executable `simuc` available in folder `dist`
 ### Make debian packet `htl-simuc`
 
 ```sh
+user@host:~ $ cd ~/simavr/examples/simuc
 user@host:~/simavr/examples/simuc $ make deb
 ``` 
 
diff --git a/examples/simuc/dpkg/.gitignore b/examples/simuc/dpkg/.gitignore
new file mode 100644 (file)
index 0000000..9a5a4f7
--- /dev/null
@@ -0,0 +1,5 @@
+**/*.deb
+**/usr/share/doc/htl-simuc/readme
+**/usr/share/htl-simuc/simuc
+**/usr/share/htl-simuc/simavr
+**/DEBIAN/control
diff --git a/examples/simuc/dpkg/htl-simuc_version_arch/usr/share/doc/htl-simuc/readme b/examples/simuc/dpkg/htl-simuc_version_arch/usr/share/doc/htl-simuc/readme
deleted file mode 100644 (file)
index 06453d5..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-created: So 27 Nov 2022 16:21:49 CET
-https://git.htl-mechatronik.at/public/?p=sx/simavr.git;a=home
-
-git clone https://git.htl-mechatronik.at/public/sx/simavr.git
-git checkout 0a12726a5335284495e557078a73381dc5fc8599
diff --git a/examples/simuc/include/parts b/examples/simuc/include/parts
new file mode 120000 (symlink)
index 0000000..5d327bd
--- /dev/null
@@ -0,0 +1 @@
+../../parts
\ No newline at end of file
diff --git a/examples/simuc/include/simavr b/examples/simuc/include/simavr
new file mode 120000 (symlink)
index 0000000..4fc3864
--- /dev/null
@@ -0,0 +1 @@
+../../../simavr/sim
\ No newline at end of file
index 0af4178a1922a3f25fec2db3c1b9ea8a1c3eaf23..b75ab45b4fb575473de5e1c8d05fab6a79c0ed51 100644 (file)
@@ -6,7 +6,7 @@
 #include "simavr/simavr.h"
 
 void printHelp () {
-    printf("simuc V1.0.0 (%s,%s)\n", __DATE__, __TIME__);
+    printf("simuc V0.0.2 (%s,%s)\n", __DATE__, __TIME__);
     printf("usage: simuc [options] elf-file\n\n");
     printf("  available options:\n");
     printf("    --board ...        set board (arduino, sure, evws1)\n");
@@ -23,16 +23,17 @@ void printHelp () {
 }
 
 int main (int argc, char **argv) {
-    struct StartParameters params = {
-        filename: NULL,
-        gdbPort: -1,
-        frequency: -1,
-        mmcu: NULL,
-        board: BoardUnknown,
-        vcc: -1,
-        avcc: -1,
-        aref: -1
-    };
+    struct StartParameters params;
+    memset((void *)&params, 0, sizeof(params));
+    params.filename = NULL;
+    params.gdbPort = -1;
+    params.frequency = -1;
+    params.mmcu = NULL;
+    params.board = BoardUnknown;
+    params.vcc = -1;
+    params.avcc = -1;
+    params.aref = -1;
+    
 
     if (argc <= 1) {
         printHelp();
@@ -110,8 +111,11 @@ int main (int argc, char **argv) {
     if (errno == 1) {
         return 1;
     }
+    printf("available commands: i (interrupt), c (continue), s (stack)\n");
+    printf("----------------------------------------------------------\n");
     printf("init done - press key to start\n");
     getchar();
+    printf("----------------------------------------------------------\n");
     start();
     
     // int cnt = 0;
index 1945ad5d6f630a034156028fc2a54a84adba7108..444e671f8b5a5377e60cfdcd02ea806543ceba2a 100644 (file)
@@ -391,7 +391,7 @@ struct SimAvrEvent SimAvr::waitForEvent () {
                throw std::logic_error(error(AT, "waitForEvent() fails caused by mutex error"));
        }
        try {
-               struct SimAvrEvent rv = { epochMillis: 0, event: EventUnknown };
+               struct SimAvrEvent rv = { 0, EventUnknown };
                struct SimAvrEvent *p = NULL;
                if (events.size() > 0) {
                        p = events.front();
@@ -444,12 +444,84 @@ void SimAvr::printCyclesAndElapsedTime () {
        printf("cycle %" PRIu64 " = %ds %03dms %03dµs %03dns", avr->cycle, seconds, millis, micros, nanos);
 }
 
+bool SimAvr::sprintfLedStatus (char *s, size_t size, bool onlyOnChange) {
+       bool rv = false;
+       if (s != NULL && size > 0 && startParameters != NULL) {
+               s[0] = 0;
+               switch (startParameters->board) {
+                       case BoardNano: {
+                               static int8_t ledL = -1; // pin floating
+                               uint8_t ddrb = avr->data[0x24];
+                               uint8_t portb = avr->data[0x25];
+                               int8_t nextLedL = -1;
+                               if (ddrb & 0x20) {
+                                       nextLedL = portb & 0x20 ? 1 : 0;
+                               }
+                               if (!onlyOnChange || nextLedL != ledL) {
+                                       ledL = nextLedL;
+                                       snprintf(s, size, "LED L = %c", ledL ? 'X' : '.');
+                                       rv = true;
+                               }
+                               break;
+                       }
+                       case BoardSure: {
+                               static int8_t led[4] = { -1, -1, -1, -1 }; // pin floating
+                               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;
+                                       }
+                                       if (nextLed != led[i]) {
+                                               change = 1;
+                                               led[i] = nextLed;
+                                       }
+                               }
+                               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] ? 'X' : '.');
+                                       }
+                                       rv = true;
+                               }
+                               break;
+                       }
+                       case BoardEWS1: {
+                               static int8_t led = -1; // pin floating
+                               uint8_t ddrb = avr->data[0x24];
+                               uint8_t portb = avr->data[0x25];
+                               int8_t nextLed = -1;
+                               if (ddrb & 0x01) {
+                                       nextLed = portb & 0x01 ? 1 : 0;
+                               }
+                               if (!onlyOnChange || nextLed != led) {
+                                       led = nextLed;
+                                       snprintf(s, size, "LED1 (PB0) = %c", led ? 'X' : '.');
+                                       rv = true;
+                               }
+                               break;
+                       }
+                       default: break;
+               }
+       }
+       return rv;
+}
+
+
 void SimAvr::avrRun () {
        long cnt = 0;
        int lastAvrState = -1;
        _avr_sp_set(avr, 0);
+       char led[80];
        while (1) {
                try {
+                       if (sprintfLedStatus(led, sizeof(led), true)) {
+                               printCyclesAndElapsedTime();
+                               printf(":   %s\n", led);
+                       }
+
                        if (avr->state != lastAvrState) {
                                switch (avr->state) {
                                        case cpu_Stopped: {
@@ -498,11 +570,9 @@ void SimAvr::avrRun () {
 
                                                }
                                                printf(printHeader ? "\n" : "\n");
-                                               
-                                               printf("   Arduino LED L: ");
-                                               printf((avr->data[0x24] & 0x20) && (avr->data[0x25] & 0x20) ? "ON\n" : "OFF\n");
-
-                                               printf("\n");
+                                               char s[20];
+                                               sprintfLedStatus(s, sizeof(s), false);
+                                               printf("   %s\n", s);
                                                break;
                                        }
                                        case cpu_Sleeping: printf("cpu enter sleep mode at cycle %" PRIu64 "\n", avr->cycle); break;
@@ -516,67 +586,6 @@ void SimAvr::avrRun () {
                                lastAvrState = avr->state;
                        }
 
-                       if (startParameters != NULL) {
-                               switch (startParameters->board) {
-                                       case BoardNano: {
-                                               static int8_t ledL = -1; // pin floating
-                                               uint8_t ddrb = avr->data[0x24];
-                                               uint8_t portb = avr->data[0x25];
-                                               int8_t nextLedL = -1;
-                                               if (ddrb & 0x20) {
-                                                       nextLedL = portb & 0x20 ? 1 : 0;
-                                               }
-                                               if (nextLedL != ledL) {
-                                                       ledL = nextLedL;
-                                                       printCyclesAndElapsedTime();
-                                                       printf(": LED L = %c\n", ledL ? 'X' : '.');
-                                               }
-                                               break;
-                                       }
-                                       case BoardSure: {
-                                               static int8_t led[4] = { -1, -1, -1, -1 }; // pin floating
-                                               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;
-                                                       }
-                                                       if (nextLed != led[i]) {
-                                                               change = 1;
-                                                               led[i] = nextLed;
-                                                       }
-                                               }
-                                               if (change) {
-                                                       printCyclesAndElapsedTime(); printf(": ");
-                                                       printf(" LED PA[3210] =");
-                                                       for (int i = 3; i >= 0; i--) {
-                                                                       printf(" %c", led[i] ? 'X' : '.');
-                                                       }
-                                                       printf("\n");
-                                               }
-                                               break;
-                                       }
-                                       case BoardEWS1: {
-                                               static int8_t led = -1; // pin floating
-                                               uint8_t ddrb = avr->data[0x24];
-                                               uint8_t portb = avr->data[0x25];
-                                               int8_t nextLed = -1;
-                                               if (ddrb & 0x01) {
-                                                       nextLed = portb & 0x01 ? 1 : 0;
-                                               }
-                                               if (nextLed != led) {
-                                                       led = nextLed;
-                                                       printCyclesAndElapsedTime();
-                                                       printf(": LED1 (PB0) = %c\n", led ? 'X' : '.');
-                                               }
-                                               break;
-                                       }
-                                       default: break;
-                               }
-                       }
-
                        if (cnt <= 0) {
                                // usleep(10000);
                                if (pthread_mutex_lock(&lock)) {
@@ -679,7 +688,9 @@ void SimAvr::avrRun () {
                                switch (command) {
                                        case CommandStatus: {
                                                printCyclesAndElapsedTime();
-                                               printf("\n");
+                                               char s[80];
+                                               sprintfLedStatus(s, sizeof(s), false);
+                                               printf("   %s\n", s);
                                                break;
                                        }
                                        case CommandInterrupt: {
index e1455b7a621fe2af8cdb211e3c00de63c2b68f8d..3d8d8e7c2314897852fb8c2eae12da3fc00f75c4 100644 (file)
@@ -124,6 +124,7 @@ private:
        Semaphore eventCount;
        uart_pty_t *uartPty[2] = { NULL, NULL };
        void printCyclesAndElapsedTime ();
+       bool sprintfLedStatus (char *s, size_t size, bool onlyOnChange);
 };