From: Manfred Steiner Date: Fri, 19 Jul 2024 05:25:06 +0000 (+0200) Subject: bugfix push button handling board sure/nano-644 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=57664ee9e4ec484ced9e6817944424393367e0af;p=sx%2Fsimavr.git bugfix push button handling board sure/nano-644 --- diff --git a/examples/simuc/.vscode/settings.json b/examples/simuc/.vscode/settings.json index 263487d..a2774e8 100644 --- a/examples/simuc/.vscode/settings.json +++ b/examples/simuc/.vscode/settings.json @@ -1,6 +1,6 @@ { "cSpell.words": [], "cSpell.ignorePaths": [ - "**/*.json", "**/*.c", "**/*.h", "**/Makefile" + "**/*.json", "**/*.c", "**/*.h", "**/*.cpp", "**/*.hpp", "**/Makefile" ] } \ No newline at end of file diff --git a/examples/simuc/src/simavr/simavr.cpp b/examples/simuc/src/simavr/simavr.cpp index 6dceb8c..c678f48 100644 --- a/examples/simuc/src/simavr/simavr.cpp +++ b/examples/simuc/src/simavr/simavr.cpp @@ -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); } }