Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

machine/z80scc.cpp: Added support for RTxC transmit/receive clock source #12050

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 32 additions & 7 deletions src/devices/machine/z80scc.cpp
Expand Up @@ -2092,7 +2092,7 @@ void z80scc_channel::do_sccreg_wr11(uint8_t data)
/RTxC pin.*/
switch (data & WR11_RCVCLK_SRC_MASK)
{
case WR11_RCVCLK_SRC_RTXC: LOG("Receive clock source is RTxC - not implemented\n"); break;
case WR11_RCVCLK_SRC_RTXC: LOG("Receive clock source is RTxC\n"); break;
case WR11_RCVCLK_SRC_TRXC: LOG("Receive clock source is TRxC - not implemented\n"); break;
case WR11_RCVCLK_SRC_BR: LOG("Receive clock source is Baudrate Generator\n"); break;
case WR11_RCVCLK_SRC_DPLL: LOG("Receive clock source is DPLL - not implemented\n"); break;
Expand All @@ -2106,7 +2106,7 @@ void z80scc_channel::do_sccreg_wr11(uint8_t data)
source of the transmit clocks.*/
switch (data & WR11_TRACLK_SRC_MASK)
{
case WR11_TRACLK_SRC_RTXC: LOG("Transmit clock source is RTxC - not implemented\n"); break;
case WR11_TRACLK_SRC_RTXC: LOG("Transmit clock source is RTxC\n"); break;
case WR11_TRACLK_SRC_TRXC: LOG("Transmit clock source is TRxC - not implemented\n"); break;
case WR11_TRACLK_SRC_BR: LOG("Transmit clock source is Baudrate Generator\n"); break;
case WR11_TRACLK_SRC_DPLL: LOG("Transmit clock source is DPLL - not implemented\n"); break;
Expand Down Expand Up @@ -2136,6 +2136,8 @@ void z80scc_channel::do_sccreg_wr11(uint8_t data)
}
else
LOG("TRxC pin is Input\n");

update_serial();
}

/*WR12 contains the lower byte of the time constant for the baud rate generator. The time constant
Expand Down Expand Up @@ -2795,18 +2797,30 @@ unsigned int z80scc_channel::get_brg_rate()
if (m_wr14 & WR14_BRG_SOURCE) // Do we use the PCLK as baudrate source
{
rate = owner()->clock() / (brg_const == 0 ? 1 : brg_const);
LOG(" - Source bit rate (%d) = PCLK (%d) / (%d)\n", rate, owner()->clock(), brg_const);
LOG(" - BRG Source bit rate (%d) = PCLK (%d) / (%d)\n", rate, owner()->clock(), brg_const);
}
else // Else we use the RTxC as BRG source
{
unsigned int source = (m_index == z80scc_device::CHANNEL_A) ? m_uart->m_rxca : m_uart->m_rxcb;
rate = source / (brg_const == 0 ? 1 : brg_const);
LOG(" - Source bit rate (%d) = RTxC (%d) / (%d)\n", rate, source, brg_const);
LOG(" - BRG Source bit rate (%d) = RTxC (%d) / (%d)\n", rate, source, brg_const);
}

return (rate / (2 * get_clock_mode()));
}

//-------------------------------------------------
// get_rtxc_rate
//-------------------------------------------------
unsigned int z80scc_channel::get_rtxc_rate()
{
unsigned int rate;
unsigned int source = (m_index == z80scc_device::CHANNEL_A) ? m_uart->m_rxca : m_uart->m_rxcb;
rate = source / get_clock_mode();
LOG(" - RTxC Source bit rate (%d) = RTxC (%d) / (%d)\n", rate, source, get_clock_mode());
return rate;
}

void z80scc_channel::update_baudtimer()
{
unsigned int rate;
Expand Down Expand Up @@ -2893,9 +2907,20 @@ void z80scc_channel::update_serial()
}
else
{
LOG("- BRG disabled\n");
set_rcv_rate(0);
set_tra_rate(0);
if ((m_wr11 & WR11_RCVCLK_SRC_MASK) == WR11_RCVCLK_SRC_RTXC &&
(m_wr11 & WR11_TRACLK_SRC_MASK) == WR11_TRACLK_SRC_RTXC)
{
m_brg_rate = get_rtxc_rate();
LOG("- BRG disabled, clock source RTxC (rate %d, clock %d)\n", m_brg_rate, get_clock_mode());
set_rcv_rate(m_brg_rate);
set_tra_rate(m_brg_rate);
}
else
{
LOG("- BRG disabled and RX/TX clock sources differ, unimplemented: stopping\n");
set_rcv_rate(0);
set_tra_rate(0);
}
}
// TODO: Check registers for use of RTxC and TRxC, if used as direct Tx and/or Rx clocks set them to value as programmed
// in m_uart->txca/txcb and rxca/rxcb respectivelly
Expand Down
1 change: 1 addition & 0 deletions src/devices/machine/z80scc.h
Expand Up @@ -233,6 +233,7 @@ class z80scc_channel : public device_t,
virtual void device_reset() override;

unsigned int get_brg_rate();
unsigned int get_rtxc_rate();
void update_baudtimer();

void scc_register_write(uint8_t reg, uint8_t data);
Expand Down