mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
hw/timer: avr: Add limited support for 16-bit timer peripheral
These were designed to facilitate testing but should provide enough function to be useful in other contexts. Only a subset of the functions of each peripheral is implemented, mainly due to the lack of a standard way to handle electrical connections (like GPIO pins). [AM: Remove word 'Atmel' from filenames and all elements of code] Suggested-by: Aleksandar Markovic <aleksandar.m.mail@gmail.com> Signed-off-by: Sarah Harris <S.E.Harris@kent.ac.uk> Signed-off-by: Ed Robbins <E.J.C.Robbins@kent.ac.uk> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> [rth: Squash info mtree fixes and a file rename from f4bug] Signed-off-by: Richard Henderson <richard.henderson@linaro.org> [PMD: Use qemu_log_mask(LOG_UNIMP), replace goto by return] Signed-off-by: Aleksandar Markovic <aleksandar.m.mail@gmail.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Thomas Huth <huth@tuxfamily.org> Message-Id: <20200705140315.260514-21-huth@tuxfamily.org> [PMD: Check cpu-frequency-hz property in realize()] Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
This commit is contained in:
committed by
Philippe Mathieu-Daudé
parent
429ca9d665
commit
8ff47bc1a0
@@ -985,6 +985,8 @@ S: Maintained
|
||||
F: default-configs/avr-softmmu.mak
|
||||
F: include/hw/char/avr_usart.h
|
||||
F: hw/char/avr_usart.c
|
||||
F: include/hw/timer/avr_timer16.h
|
||||
F: hw/timer/avr_timer16.c
|
||||
|
||||
CRIS Machines
|
||||
-------------
|
||||
|
||||
@@ -41,3 +41,6 @@ config RENESAS_TMR
|
||||
|
||||
config RENESAS_CMT
|
||||
bool
|
||||
|
||||
config AVR_TIMER16
|
||||
bool
|
||||
|
||||
@@ -37,3 +37,5 @@ common-obj-$(CONFIG_CMSDK_APB_TIMER) += cmsdk-apb-timer.o
|
||||
common-obj-$(CONFIG_CMSDK_APB_DUALTIMER) += cmsdk-apb-dualtimer.o
|
||||
common-obj-$(CONFIG_MSF2) += mss-timer.o
|
||||
common-obj-$(CONFIG_RASPI) += bcm2835_systmr.o
|
||||
|
||||
obj-$(CONFIG_AVR_TIMER16) += avr_timer16.o
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -75,3 +75,15 @@ nrf51_timer_set_count(uint8_t timer_id, uint8_t counter_id, uint32_t value) "tim
|
||||
bcm2835_systmr_irq(bool enable) "timer irq state %u"
|
||||
bcm2835_systmr_read(uint64_t offset, uint64_t data) "timer read: offset 0x%" PRIx64 " data 0x%" PRIx64
|
||||
bcm2835_systmr_write(uint64_t offset, uint64_t data) "timer write: offset 0x%" PRIx64 " data 0x%" PRIx64
|
||||
|
||||
# avr_timer16.c
|
||||
avr_timer16_read(uint8_t addr, uint8_t value) "timer16 read addr:%u value:%u"
|
||||
avr_timer16_read_ifr(uint8_t value) "timer16 read addr:ifr value:%u"
|
||||
avr_timer16_read_imsk(uint8_t value) "timer16 read addr:imsk value:%u"
|
||||
avr_timer16_write(uint8_t addr, uint8_t value) "timer16 write addr:%u value:%u"
|
||||
avr_timer16_write_ifr(uint8_t value) "timer16 write addr:ifr value:%u"
|
||||
avr_timer16_write_imsk(uint8_t value) "timer16 write addr:imsk value:%u"
|
||||
avr_timer16_interrupt_count(uint8_t cnt) "count: %u"
|
||||
avr_timer16_interrupt_overflow(const char *reason) "overflow: %s"
|
||||
avr_timer16_next_alarm(uint64_t delay_ns) "next alarm: %" PRIu64 " ns from now"
|
||||
avr_timer16_clksrc_update(uint64_t freq_hz, uint64_t period_ns, uint64_t delay_s) "timer frequency: %" PRIu64 " Hz, period: %" PRIu64 " ns (%" PRId64 " us)"
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* AVR 16-bit timer
|
||||
*
|
||||
* Copyright (c) 2018 University of Kent
|
||||
* Author: Ed Robbins
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, see
|
||||
* <http://www.gnu.org/licenses/lgpl-2.1.html>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Driver for 16 bit timers on 8 bit AVR devices.
|
||||
* Note:
|
||||
* On ATmega640/V-1280/V-1281/V-2560/V-2561/V timers 1, 3, 4 and 5 are 16 bit
|
||||
*/
|
||||
|
||||
#ifndef HW_TIMER_AVR_TIMER16_H
|
||||
#define HW_TIMER_AVR_TIMER16_H
|
||||
|
||||
#include "hw/sysbus.h"
|
||||
#include "qemu/timer.h"
|
||||
#include "hw/hw.h"
|
||||
|
||||
enum NextInterrupt {
|
||||
OVERFLOW,
|
||||
COMPA,
|
||||
COMPB,
|
||||
COMPC,
|
||||
CAPT
|
||||
};
|
||||
|
||||
#define TYPE_AVR_TIMER16 "avr-timer16"
|
||||
#define AVR_TIMER16(obj) \
|
||||
OBJECT_CHECK(AVRTimer16State, (obj), TYPE_AVR_TIMER16)
|
||||
|
||||
typedef struct AVRTimer16State {
|
||||
/* <private> */
|
||||
SysBusDevice parent_obj;
|
||||
|
||||
/* <public> */
|
||||
MemoryRegion iomem;
|
||||
MemoryRegion imsk_iomem;
|
||||
MemoryRegion ifr_iomem;
|
||||
QEMUTimer *timer;
|
||||
qemu_irq capt_irq;
|
||||
qemu_irq compa_irq;
|
||||
qemu_irq compb_irq;
|
||||
qemu_irq compc_irq;
|
||||
qemu_irq ovf_irq;
|
||||
|
||||
bool enabled;
|
||||
|
||||
/* registers */
|
||||
uint8_t cra;
|
||||
uint8_t crb;
|
||||
uint8_t crc;
|
||||
uint8_t cntl;
|
||||
uint8_t cnth;
|
||||
uint8_t icrl;
|
||||
uint8_t icrh;
|
||||
uint8_t ocral;
|
||||
uint8_t ocrah;
|
||||
uint8_t ocrbl;
|
||||
uint8_t ocrbh;
|
||||
uint8_t ocrcl;
|
||||
uint8_t ocrch;
|
||||
/*
|
||||
* Reads and writes to CNT and ICR utilise a bizarre temporary
|
||||
* register, which we emulate
|
||||
*/
|
||||
uint8_t rtmp;
|
||||
uint8_t imsk;
|
||||
uint8_t ifr;
|
||||
|
||||
uint8_t id;
|
||||
uint64_t cpu_freq_hz;
|
||||
uint64_t freq_hz;
|
||||
uint64_t period_ns;
|
||||
uint64_t reset_time_ns;
|
||||
enum NextInterrupt next_interrupt;
|
||||
} AVRTimer16State;
|
||||
|
||||
#endif /* HW_TIMER_AVR_TIMER16_H */
|
||||
Reference in New Issue
Block a user