summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu/h8/h8_watchdog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/cpu/h8/h8_watchdog.cpp')
-rw-r--r--src/devices/cpu/h8/h8_watchdog.cpp77
1 files changed, 52 insertions, 25 deletions
diff --git a/src/devices/cpu/h8/h8_watchdog.cpp b/src/devices/cpu/h8/h8_watchdog.cpp
index 0bab0b3267b..a8af865f2ab 100644
--- a/src/devices/cpu/h8/h8_watchdog.cpp
+++ b/src/devices/cpu/h8/h8_watchdog.cpp
@@ -1,12 +1,27 @@
+// license:BSD-3-Clause
+// copyright-holders:Olivier Galibert
+/***************************************************************************
+
+ h8_watchdog.cpp
+
+ H8 watchdog/timer
+
+ TODO:
+ - add RSTCSR for MCUs that have it (reset is only enabled when RSTI is 1)
+ - It will only clear the overflow flag when writing 0 after reading it
+ when it's set? It's how the databook explains it, similar to HD6301.
+
+***************************************************************************/
+
#include "emu.h"
#include "h8_watchdog.h"
DEFINE_DEVICE_TYPE(H8_WATCHDOG, h8_watchdog_device, "h8_watchdog", "H8 watchdog")
-const int h8_watchdog_device::div_bh[8] = { 1, 6, 7, 9, 11, 13, 15, 17 };
-const int h8_watchdog_device::div_s [8] = { 1, 5, 6, 7, 8, 9, 11, 12 };
+const int h8_watchdog_device::div_bh[8] = { 1, 5, 6, 7, 8, 9, 11, 12 };
+const int h8_watchdog_device::div_s [8] = { 1, 6, 7, 9, 11, 13, 15, 17 };
-h8_watchdog_device::h8_watchdog_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
+h8_watchdog_device::h8_watchdog_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock) :
device_t(mconfig, H8_WATCHDOG, tag, owner, clock),
m_cpu(*this, finder_base::DUMMY_TAG),
m_intc(*this, finder_base::DUMMY_TAG)
@@ -14,31 +29,38 @@ h8_watchdog_device::h8_watchdog_device(const machine_config &mconfig, const char
}
-uint64_t h8_watchdog_device::internal_update(uint64_t current_time)
+u64 h8_watchdog_device::internal_update(u64 current_time)
{
tcnt_update(current_time);
if(m_tcsr & TCSR_TME) {
int shift = (m_type == S ? div_s : div_bh)[m_tcsr & TCSR_CKS];
- uint64_t spos = m_tcnt_cycle_base >> shift;
+ u64 spos = m_tcnt_cycle_base >> shift;
return (spos + 0x100 - m_tcnt) << shift;
-
} else
return 0;
}
-void h8_watchdog_device::tcnt_update(uint64_t cur_time)
+void h8_watchdog_device::notify_standby(int state)
+{
+ if(state)
+ tcnt_update();
+ else
+ m_tcnt_cycle_base = m_cpu->total_cycles();
+}
+
+void h8_watchdog_device::tcnt_update(u64 cur_time)
{
if(m_tcsr & TCSR_TME) {
int shift = (m_type == S ? div_s : div_bh)[m_tcsr & TCSR_CKS];
if(!cur_time)
cur_time = m_cpu->total_cycles();
- uint64_t spos = m_tcnt_cycle_base >> shift;
- uint64_t epos = cur_time >> shift;
+ u64 spos = m_tcnt_cycle_base >> shift;
+ u64 epos = cur_time >> shift;
- int next_tcnt = m_tcnt + int(epos - spos);
+ u64 next_tcnt = m_tcnt + (epos - spos);
m_tcnt = next_tcnt;
m_tcnt_cycle_base = cur_time;
- // logerror("%10lld tcnt %02x -> %03x shift=%d\n", cur_time, m_tcnt, next_tcnt, shift);
+ //logerror("%10lld tcnt %02x -> %03x shift=%d\n", cur_time, m_tcnt, next_tcnt, shift);
if(next_tcnt >= 0x100) {
if(m_tcsr & TCSR_WT) {
@@ -56,17 +78,18 @@ void h8_watchdog_device::tcnt_update(uint64_t cur_time)
}
} else
m_tcnt = 0;
-
}
-uint16_t h8_watchdog_device::wd_r()
+u16 h8_watchdog_device::wd_r()
{
if(!machine().side_effects_disabled())
tcnt_update();
- return (m_tcsr << 8) | m_tcnt;
+
+ u8 tcsr_mask = m_type == B ? 0x10 : 0x18;
+ return ((m_tcsr | tcsr_mask) << 8) | m_tcnt;
}
-void h8_watchdog_device::wd_w(offs_t offset, uint16_t data, uint16_t mem_mask)
+void h8_watchdog_device::wd_w(offs_t offset, u16 data, u16 mem_mask)
{
if(mem_mask != 0xffff)
return;
@@ -75,8 +98,7 @@ void h8_watchdog_device::wd_w(offs_t offset, uint16_t data, uint16_t mem_mask)
tcnt_update();
if(!(m_tcsr & TCSR_TME) && (data & TCSR_TME))
m_tcnt_cycle_base = m_cpu->total_cycles();
- m_tcsr = data & 0xff;
- m_tcsr |= m_type == B ? 0x10 : 0x18;
+ m_tcsr = (m_tcsr & data & TCSR_OVF) | (data & 0x7f);
m_cpu->internal_update();
}
@@ -84,21 +106,26 @@ void h8_watchdog_device::wd_w(offs_t offset, uint16_t data, uint16_t mem_mask)
if(m_tcsr & TCSR_TME) {
m_tcnt = data & 0xff;
m_tcnt_cycle_base = m_cpu->total_cycles();
- // logerror("%10lld tcnt = %02x\n", m_tcnt_cycle_base, m_tcnt);
+ //logerror("%10lld tcnt = %02x\n", m_tcnt_cycle_base, m_tcnt);
}
m_cpu->internal_update();
}
}
-uint16_t h8_watchdog_device::rst_r()
+u16 h8_watchdog_device::rst_r()
{
if(!machine().side_effects_disabled())
logerror("rst_r\n");
- return 0;
+
+ u8 rst_mask = m_type == S ? 0x1f : 0x3f;
+ return m_rst | rst_mask;
}
-void h8_watchdog_device::rst_w(uint16_t data)
+void h8_watchdog_device::rst_w(offs_t offset, u16 data, u16 mem_mask)
{
+ if(mem_mask != 0xffff)
+ return;
+
if((data & 0xff00) == 0xa500)
logerror("wowf_w %02x\n", data & 0xff);
if((data & 0xff00) == 0x5a00)
@@ -108,15 +135,15 @@ void h8_watchdog_device::rst_w(uint16_t data)
void h8_watchdog_device::device_start()
{
save_item(NAME(m_tcnt));
- save_item(NAME(m_tcnt_cycle_base));
save_item(NAME(m_tcsr));
save_item(NAME(m_rst));
+ save_item(NAME(m_tcnt_cycle_base));
}
void h8_watchdog_device::device_reset()
{
- m_tcnt = 0x00;
m_tcnt_cycle_base = m_cpu->total_cycles();
- m_tcsr = m_type == B ? 0x10 : 0x18;
- m_rst = m_type == S ? 0x1f : 0x3f;
+ m_tcnt = 0x00;
+ m_tcsr = 0x00;
+ m_rst = 0x00;
}