18ff47bc1SMichael Rolnik /* 28ff47bc1SMichael Rolnik * AVR 16-bit timer 38ff47bc1SMichael Rolnik * 48ff47bc1SMichael Rolnik * Copyright (c) 2018 University of Kent 58ff47bc1SMichael Rolnik * Author: Ed Robbins 68ff47bc1SMichael Rolnik * 78ff47bc1SMichael Rolnik * This library is free software; you can redistribute it and/or 88ff47bc1SMichael Rolnik * modify it under the terms of the GNU Lesser General Public 98ff47bc1SMichael Rolnik * License as published by the Free Software Foundation; either 108ff47bc1SMichael Rolnik * version 2.1 of the License, or (at your option) any later version. 118ff47bc1SMichael Rolnik * 128ff47bc1SMichael Rolnik * This library is distributed in the hope that it will be useful, 138ff47bc1SMichael Rolnik * but WITHOUT ANY WARRANTY; without even the implied warranty of 148ff47bc1SMichael Rolnik * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 158ff47bc1SMichael Rolnik * Lesser General Public License for more details. 168ff47bc1SMichael Rolnik * 178ff47bc1SMichael Rolnik * You should have received a copy of the GNU Lesser General Public 188ff47bc1SMichael Rolnik * License along with this library; if not, see 198ff47bc1SMichael Rolnik * <http://www.gnu.org/licenses/lgpl-2.1.html> 208ff47bc1SMichael Rolnik */ 218ff47bc1SMichael Rolnik 228ff47bc1SMichael Rolnik /* 238ff47bc1SMichael Rolnik * Driver for 16 bit timers on 8 bit AVR devices. 248ff47bc1SMichael Rolnik * Note: 258ff47bc1SMichael Rolnik * On ATmega640/V-1280/V-1281/V-2560/V-2561/V timers 1, 3, 4 and 5 are 16 bit 268ff47bc1SMichael Rolnik */ 278ff47bc1SMichael Rolnik 288ff47bc1SMichael Rolnik #ifndef HW_TIMER_AVR_TIMER16_H 298ff47bc1SMichael Rolnik #define HW_TIMER_AVR_TIMER16_H 308ff47bc1SMichael Rolnik 318ff47bc1SMichael Rolnik #include "hw/sysbus.h" 328ff47bc1SMichael Rolnik #include "qemu/timer.h" 33db1015e9SEduardo Habkost #include "qom/object.h" 348ff47bc1SMichael Rolnik 358ff47bc1SMichael Rolnik enum NextInterrupt { 368ff47bc1SMichael Rolnik OVERFLOW, 378ff47bc1SMichael Rolnik COMPA, 388ff47bc1SMichael Rolnik COMPB, 398ff47bc1SMichael Rolnik COMPC, 408ff47bc1SMichael Rolnik CAPT 418ff47bc1SMichael Rolnik }; 428ff47bc1SMichael Rolnik 438ff47bc1SMichael Rolnik #define TYPE_AVR_TIMER16 "avr-timer16" 44*8063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(AVRTimer16State, AVR_TIMER16) 458ff47bc1SMichael Rolnik 46db1015e9SEduardo Habkost struct AVRTimer16State { 478ff47bc1SMichael Rolnik /* <private> */ 488ff47bc1SMichael Rolnik SysBusDevice parent_obj; 498ff47bc1SMichael Rolnik 508ff47bc1SMichael Rolnik /* <public> */ 518ff47bc1SMichael Rolnik MemoryRegion iomem; 528ff47bc1SMichael Rolnik MemoryRegion imsk_iomem; 538ff47bc1SMichael Rolnik MemoryRegion ifr_iomem; 548ff47bc1SMichael Rolnik QEMUTimer *timer; 558ff47bc1SMichael Rolnik qemu_irq capt_irq; 568ff47bc1SMichael Rolnik qemu_irq compa_irq; 578ff47bc1SMichael Rolnik qemu_irq compb_irq; 588ff47bc1SMichael Rolnik qemu_irq compc_irq; 598ff47bc1SMichael Rolnik qemu_irq ovf_irq; 608ff47bc1SMichael Rolnik 618ff47bc1SMichael Rolnik bool enabled; 628ff47bc1SMichael Rolnik 638ff47bc1SMichael Rolnik /* registers */ 648ff47bc1SMichael Rolnik uint8_t cra; 658ff47bc1SMichael Rolnik uint8_t crb; 668ff47bc1SMichael Rolnik uint8_t crc; 678ff47bc1SMichael Rolnik uint8_t cntl; 688ff47bc1SMichael Rolnik uint8_t cnth; 698ff47bc1SMichael Rolnik uint8_t icrl; 708ff47bc1SMichael Rolnik uint8_t icrh; 718ff47bc1SMichael Rolnik uint8_t ocral; 728ff47bc1SMichael Rolnik uint8_t ocrah; 738ff47bc1SMichael Rolnik uint8_t ocrbl; 748ff47bc1SMichael Rolnik uint8_t ocrbh; 758ff47bc1SMichael Rolnik uint8_t ocrcl; 768ff47bc1SMichael Rolnik uint8_t ocrch; 778ff47bc1SMichael Rolnik /* 788ff47bc1SMichael Rolnik * Reads and writes to CNT and ICR utilise a bizarre temporary 798ff47bc1SMichael Rolnik * register, which we emulate 808ff47bc1SMichael Rolnik */ 818ff47bc1SMichael Rolnik uint8_t rtmp; 828ff47bc1SMichael Rolnik uint8_t imsk; 838ff47bc1SMichael Rolnik uint8_t ifr; 848ff47bc1SMichael Rolnik 858ff47bc1SMichael Rolnik uint8_t id; 868ff47bc1SMichael Rolnik uint64_t cpu_freq_hz; 878ff47bc1SMichael Rolnik uint64_t freq_hz; 888ff47bc1SMichael Rolnik uint64_t period_ns; 898ff47bc1SMichael Rolnik uint64_t reset_time_ns; 908ff47bc1SMichael Rolnik enum NextInterrupt next_interrupt; 91db1015e9SEduardo Habkost }; 928ff47bc1SMichael Rolnik 938ff47bc1SMichael Rolnik #endif /* HW_TIMER_AVR_TIMER16_H */ 94