avr_timer16.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * AVR 16-bit timer
  3. *
  4. * Copyright (c) 2018 University of Kent
  5. * Author: Ed Robbins
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, see
  19. * <http://www.gnu.org/licenses/lgpl-2.1.html>
  20. */
  21. /*
  22. * Driver for 16 bit timers on 8 bit AVR devices.
  23. * Note:
  24. * On ATmega640/V-1280/V-1281/V-2560/V-2561/V timers 1, 3, 4 and 5 are 16 bit
  25. */
  26. #ifndef HW_TIMER_AVR_TIMER16_H
  27. #define HW_TIMER_AVR_TIMER16_H
  28. #include "hw/sysbus.h"
  29. #include "qemu/timer.h"
  30. #include "qom/object.h"
  31. enum NextInterrupt {
  32. OVERFLOW,
  33. COMPA,
  34. COMPB,
  35. COMPC,
  36. CAPT
  37. };
  38. #define TYPE_AVR_TIMER16 "avr-timer16"
  39. OBJECT_DECLARE_SIMPLE_TYPE(AVRTimer16State, AVR_TIMER16)
  40. struct AVRTimer16State {
  41. /* <private> */
  42. SysBusDevice parent_obj;
  43. /* <public> */
  44. MemoryRegion iomem;
  45. MemoryRegion imsk_iomem;
  46. MemoryRegion ifr_iomem;
  47. QEMUTimer *timer;
  48. qemu_irq capt_irq;
  49. qemu_irq compa_irq;
  50. qemu_irq compb_irq;
  51. qemu_irq compc_irq;
  52. qemu_irq ovf_irq;
  53. bool enabled;
  54. /* registers */
  55. uint8_t cra;
  56. uint8_t crb;
  57. uint8_t crc;
  58. uint8_t cntl;
  59. uint8_t cnth;
  60. uint8_t icrl;
  61. uint8_t icrh;
  62. uint8_t ocral;
  63. uint8_t ocrah;
  64. uint8_t ocrbl;
  65. uint8_t ocrbh;
  66. uint8_t ocrcl;
  67. uint8_t ocrch;
  68. /*
  69. * Reads and writes to CNT and ICR utilise a bizarre temporary
  70. * register, which we emulate
  71. */
  72. uint8_t rtmp;
  73. uint8_t imsk;
  74. uint8_t ifr;
  75. uint8_t id;
  76. uint64_t cpu_freq_hz;
  77. uint64_t freq_hz;
  78. uint64_t period_ns;
  79. uint64_t reset_time_ns;
  80. enum NextInterrupt next_interrupt;
  81. };
  82. #endif /* HW_TIMER_AVR_TIMER16_H */