[RFC 0/1] Implement AVR WDT (watchdog timer)

Michael Rolnik posted 1 patch 3 years ago
Only 0 patches received!
There is a newer version of this series
hw/avr/Kconfig                |   1 +
hw/avr/atmega.c               |  15 ++-
hw/avr/atmega.h               |   2 +
hw/watchdog/Kconfig           |   3 +
hw/watchdog/avr_wdt.c         | 188 ++++++++++++++++++++++++++++++++++
hw/watchdog/meson.build       |   2 +
hw/watchdog/trace-events      |   5 +
include/hw/watchdog/avr_wdt.h |  47 +++++++++
target/avr/cpu.c              |   3 +
target/avr/cpu.h              |   1 +
target/avr/helper.c           |   7 +-
11 files changed, 269 insertions(+), 5 deletions(-)
create mode 100644 hw/watchdog/avr_wdt.c
create mode 100644 include/hw/watchdog/avr_wdt.h
[RFC 0/1] Implement AVR WDT (watchdog timer)
Posted by Michael Rolnik 3 years ago
1.  Initial implementation of AVR WDT
    There are two issues with this implementation so I need your help here
    a. when I configure the WDT to fire an interrupt every 15ms it actually happens every 6 instructions
    b. when I specify --icount shift=0 qemu stucks

Michael Rolnik (1):
  Implement AVR watchdog timer

 hw/avr/Kconfig                |   1 +
 hw/avr/atmega.c               |  15 ++-
 hw/avr/atmega.h               |   2 +
 hw/watchdog/Kconfig           |   3 +
 hw/watchdog/avr_wdt.c         | 188 ++++++++++++++++++++++++++++++++++
 hw/watchdog/meson.build       |   2 +
 hw/watchdog/trace-events      |   5 +
 include/hw/watchdog/avr_wdt.h |  47 +++++++++
 target/avr/cpu.c              |   3 +
 target/avr/cpu.h              |   1 +
 target/avr/helper.c           |   7 +-
 11 files changed, 269 insertions(+), 5 deletions(-)
 create mode 100644 hw/watchdog/avr_wdt.c
 create mode 100644 include/hw/watchdog/avr_wdt.h

-- 
2.25.1


Re: [RFC 0/1] Implement AVR WDT (watchdog timer)
Posted by Fred Konrad 3 years ago
Hi Michael,

Le 5/2/21 à 10:10 PM, Michael Rolnik a écrit :
> 1.  Initial implementation of AVR WDT

Nice!

>      There are two issues with this implementation so I need your help here
>      a. when I configure the WDT to fire an interrupt every 15ms it actually happens every 6 instructions

Tested with the maximal prescaler: I've ~8 seconds which seems expected
according to the documentation, I don't know how much time it takes to run
through all the timers and go back in the execution loop, maybe 15ms is just too
low?

>      b. when I specify --icount shift=0 qemu stucks

For me it just crashes:
   qemu-system-avr: Bad icount read

(gdb) bt
#0  icount_get_raw_locked () at ../src/softmmu/icount.c:117
#1  0x00000000004e1801 in icount_get_locked () at ../src/softmmu/icount.c:128
#2  0x00000000004e187a in icount_get () at ../src/softmmu/icount.c:154
#3  0x00000000004bc8ff in cpus_get_virtual_clock () at ../src/softmmu/cpus.c:217
#4  0x00000000006f5bd5 in qemu_clock_get_ns (type=QEMU_CLOCK_VIRTUAL) at 
../src/util/qemu-timer.c:637
#5  0x00000000005422d7 in avr_wdt_reset_alarm (wdt=0xe14040) at 
../src/hw/watchdog/avr_wdt.c:74
#6  0x0000000000542536 in avr_wdt_write (opaque=0xe14040, offset=0, val64=57, 
size=1) at ../src/hw/watchdog/avr_wdt.c:134
#7  0x00000000004cdeaa in memory_region_write_accessor (mr=0xe14360, addr=0, 
value=0x7fff76ae9378, size=1, shift=0, mask=255, attrs=...) at 
../src/softmmu/memory.c:491
#8  0x00000000004ce0cd in access_with_adjusted_size (addr=0, 
value=0x7fff76ae9378, size=1, access_size_min=1, access_size_max=1,
     access_fn=0x4cddc7 <memory_region_write_accessor>, mr=0xe14360, attrs=...) 
at ../src/softmmu/memory.c:552


     if (cpu && cpu->running) {
         if (!cpu->can_do_io) {
             error_report("Bad icount read");
             exit(1);
HERE.
         }

I'm not sure icount is supported on avr?  ie: I don't see any gen_io_start();
in target/avr?

> 
> Michael Rolnik (1):
>    Implement AVR watchdog timer
> 
>   hw/avr/Kconfig                |   1 +
>   hw/avr/atmega.c               |  15 ++-
>   hw/avr/atmega.h               |   2 +
>   hw/watchdog/Kconfig           |   3 +
>   hw/watchdog/avr_wdt.c         | 188 ++++++++++++++++++++++++++++++++++
>   hw/watchdog/meson.build       |   2 +
>   hw/watchdog/trace-events      |   5 +
>   include/hw/watchdog/avr_wdt.h |  47 +++++++++
>   target/avr/cpu.c              |   3 +
>   target/avr/cpu.h              |   1 +
>   target/avr/helper.c           |   7 +-
>   11 files changed, 269 insertions(+), 5 deletions(-)
>   create mode 100644 hw/watchdog/avr_wdt.c
>   create mode 100644 include/hw/watchdog/avr_wdt.h
>