1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-09 01:29:44 +00:00

Transfer logging responsibility.

This commit is contained in:
Thomas Harte 2024-03-18 11:09:29 -04:00
parent 64e025484a
commit 612c9ce49a
3 changed files with 40 additions and 21 deletions

View File

@ -8,8 +8,16 @@
#include "I2C.hpp"
#include "../../Outputs/Log.hpp"
using namespace I2C;
namespace {
Log::Logger<Log::Source::I2C> logger;
}
void Bus::set_data(bool pulled) {
set_clock_data(clock_, pulled);
}
@ -34,6 +42,8 @@ void Bus::set_clock_data(bool clock_pulled, bool data_pulled) {
clock_ = clock_pulled;
data_ = data_pulled;
logger.info().append("C:%d D:%d", clock_, data_);
// Advance peripheral input from peripheral if clock
// transitions from high to low.
if(peripheral_bits_ && prior_clock && !clock_) {
@ -48,11 +58,18 @@ void Bus::set_clock_data(bool clock_pulled, bool data_pulled) {
}
};
const auto await_byte = [&] {
peripheral_response_ = 0;
peripheral_bits_ = 2;
phase_ = Phase::AwaitingByte;
logger.info().append("Waiting for byte");
};
// Check for stop condition at any time.
// "A LOW-to-HIGH transition of the data line
// while the clock is HIGH is defined as the STOP condition".
if(prior_data && !data_ && !clock_) {
printf("Stopped\n");
logger.info().append("Stopped");
phase_ = Phase::AwaitingStart;
}
@ -64,44 +81,44 @@ void Bus::set_clock_data(bool clock_pulled, bool data_pulled) {
phase_ = Phase::CollectingAddress;
input_count_ = 0;
input_ = 0;
printf("Waiting for [remainder of] address\n");
logger.info().append("Waiting for [remainder of] address");
}
break;
case Phase::CollectingAddress:
capture_bit();
if(input_count_ == 8) {
printf("Addressed %02x?\n", uint8_t(input_));
logger.info().append("Addressed %02x with %s?", uint8_t(input_) & 0xfe, input_ & 1 ? "read" : "write");
auto pair = peripherals_.find(uint8_t(input_));
auto pair = peripherals_.find(uint8_t(input_) & 0xfe);
if(pair != peripherals_.end()) {
active_peripheral_ = pair->second;
peripheral_response_ = 0;
peripheral_bits_ = 1;
phase_ = Phase::AwaitingByte;
printf("Waiting for byte\n");
await_byte();
} else {
phase_ = Phase::AwaitingStart;
printf("No device\n");
logger.info().append("No device; not acknowledging");
}
}
break;
case Phase::AwaitingByte:
// Run down the clock on the acknowledge bit.
if(!peripheral_bits_) {
printf("Beginning byte\n");
phase_ = Phase::CollectingByte;
input_count_ = 0;
if(peripheral_bits_) {
return;
}
break;
logger.info().append("Beginning byte");
phase_ = Phase::CollectingByte;
input_count_ = 0;
[[fallthrough]];
case Phase::CollectingByte:
capture_bit();
if(input_count_ == 8) {
printf("Got byte %02x?\n", uint8_t(input_));
phase_ = Phase::AwaitingByte;
logger.info().append("Got byte %02x?", uint8_t(input_));
await_byte();
}
break;
}

View File

@ -389,10 +389,10 @@ struct Interrupts {
break;
case 0x3200000 & AddressMask:
logger.error().append("TODO: IOC control read");
value = control_;
value = control_ | 0xc0;
value &= ~(i2c_.clock() ? 2 : 0);
value &= ~(i2c_.data() ? 1 : 0);
// logger.error().append("IOC control read: C:%d D:%d", !(value & 2), !(value & 1));
return true;
case 0x3200004 & AddressMask:
@ -472,11 +472,11 @@ struct Interrupts {
break;
case 0x320'0000 & AddressMask:
// TODO: does the rest of the control register relate to anything?
// logger.error().append("TODO: IOC control write: C:%d D:%d", !(value & 2), !(value & 1));
control_ = value;
i2c_.set_clock_data(!(value & 2), !(value & 1));
// TODO: rest relates to floppy control, maybe?
logger.error().append("TODO: IOC control write %02x", value);
return true;
case 0x320'0004 & AddressMask:

View File

@ -31,6 +31,7 @@ enum class Source {
DirectAccessDevice,
Enterprise,
i8272,
I2C,
IntelligentKeyboard,
IWM,
M50740,
@ -95,6 +96,7 @@ constexpr const char *prefix(Source source) {
case Source::DirectAccessDevice: return "Direct Access Device";
case Source::Enterprise: return "Enterprise";
case Source::i8272: return "i8272";
case Source::I2C: return "I2C";
case Source::IntelligentKeyboard: return "IKYB";
case Source::IWM: return "IWM";
case Source::M50740: return "M50740";