Skip to content

Commit

Permalink
Optimize reset condition
Browse files Browse the repository at this point in the history
  • Loading branch information
tgtakaoka committed May 28, 2024
1 parent 9128e9a commit ae0685e
Show file tree
Hide file tree
Showing 77 changed files with 425 additions and 652 deletions.
32 changes: 9 additions & 23 deletions debugger/cdp1802/pins_cdp1802.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,34 +86,20 @@ void negate_intr() {
digitalWriteFast(PIN_INTR, HIGH);
}

inline uint8_t signal_tpa() {
inline auto signal_tpa() {
return digitalReadFast(PIN_TPA);
}

void negate_wait() {
digitalWriteFast(PIN_WAIT, HIGH);
}

void assert_reset() {
// Drive RESET condition
digitalWriteFast(PIN_CLEAR, LOW);
negate_wait();
negate_intr();
digitalWriteFast(PIN_DMAIN, HIGH);
digitalWriteFast(PIN_DMAOUT, HIGH);
clock_lo();
}

void negate_reset() {
digitalWriteFast(PIN_CLEAR, HIGH);
}

const uint8_t PINS_LOW[] = {
constexpr uint8_t PINS_LOW[] = {
PIN_CLEAR,
PIN_CLOCK,
};

const uint8_t PINS_HIGH[] = {
constexpr uint8_t PINS_HIGH[] = {
PIN_INTR,
PIN_WAIT,
PIN_DMAIN,
Expand All @@ -124,7 +110,7 @@ const uint8_t PINS_HIGH[] = {
PIN_EF4,
};

const uint8_t PINS_INPUT[] = {
constexpr uint8_t PINS_INPUT[] = {
PIN_DBUS0,
PIN_DBUS1,
PIN_DBUS2,
Expand Down Expand Up @@ -163,14 +149,15 @@ inline void clock_cycle() {
} // namespace

void PinsCdp1802::reset() {
// Assert reset condition
pinsMode(PINS_LOW, sizeof(PINS_LOW), OUTPUT, LOW);
pinsMode(PINS_HIGH, sizeof(PINS_HIGH), OUTPUT, HIGH);
pinsMode(PINS_INPUT, sizeof(PINS_INPUT), INPUT);

assert_reset();
for (auto i = 0; i < 100; i++)
clock_cycle();
negate_reset();
Signals::resetCycles();
// The first machine cycle after termination of reset is an
// intialization cycle which requires 9 clock pulses.
for (auto i = 0; i < 20; i++) {
Expand Down Expand Up @@ -306,12 +293,12 @@ void PinsCdp1802::execInst(const uint8_t *inst, uint8_t len) {
execute(inst, len, nullptr, nullptr, 0);
}

uint8_t PinsCdp1802::captureWrites(const uint8_t *inst, uint8_t len,
void PinsCdp1802::captureWrites(const uint8_t *inst, uint8_t len,
uint16_t *addr, uint8_t *buf, uint8_t max) {
return execute(inst, len, addr, buf, max);
execute(inst, len, addr, buf, max);
}

uint8_t PinsCdp1802::execute(const uint8_t *inst, uint8_t len, uint16_t *addr,
void PinsCdp1802::execute(const uint8_t *inst, uint8_t len, uint16_t *addr,
uint8_t *buf, uint8_t max) {
uint8_t inj = 0;
uint8_t cap = 0;
Expand All @@ -337,7 +324,6 @@ uint8_t PinsCdp1802::execute(const uint8_t *inst, uint8_t len, uint16_t *addr,
break;
completeCycle(directCycle(s));
}
return cap;
}

void PinsCdp1802::idle() {
Expand Down
6 changes: 3 additions & 3 deletions debugger/cdp1802/pins_cdp1802.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct PinsCdp1802 final : Pins {
void printCycles() override;

void execInst(const uint8_t *inst, uint8_t len);
uint8_t captureWrites(const uint8_t *inst, uint8_t len, uint16_t *addr,
void captureWrites(const uint8_t *inst, uint8_t len, uint16_t *addr,
uint8_t *buf, uint8_t max);

private:
Expand All @@ -92,8 +92,8 @@ struct PinsCdp1802 final : Pins {
Signals *cycle(uint8_t data);
void loop();
bool rawStep();
uint8_t execute(const uint8_t *inst, uint8_t len, uint16_t *addr,
uint8_t *buf, uint8_t max);
void execute(const uint8_t *inst, uint8_t len, uint16_t *addr, uint8_t *buf,
uint8_t max);
bool skip(uint8_t inst);

void disassembleCycles() const;
Expand Down
8 changes: 4 additions & 4 deletions debugger/cdp1802/regs_cdp1802.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ void RegsCdp1802::print() const {
// clang-format off
// 0123456789012345678901234567890;
static constexpr char line1[] = "D=xx DF=x X=x P=x T=xx Q=x IE=1";
static constexpr char line2[] = " R0=xxxx R1=xxxx R2=xxxx R3=xxxx R4=xxxx R5=xxxx R6=xxxx R7=xxxx";
static constexpr char line3[] = " R8=xxxx R9=xxxx R10=xxxx R11=xxxx R12=xxxx R13=xxxx R14=xxxx R15=xxxx";
static constexpr char line2[] = "R0=xxxx R1=xxxx R2=xxxx R3=xxxx R4=xxxx R5=xxxx R6=xxxx R7=xxxx";
static constexpr char line3[] = "R8=xxxx R9=xxxx R10=xxxx R11=xxxx R12=xxxx R13=xxxx R14=xxxx R15=xxxx";
// clang-format on
static auto &buffer1 = *new CharBuffer(line1);
buffer1.hex8(2, _d);
Expand All @@ -70,11 +70,11 @@ void RegsCdp1802::print() const {
cli.println(buffer1);
static auto &buffer2 = *new CharBuffer(line2);
for (auto i = 0; i < 8; i++)
buffer2.hex16(4 + i * 9, _r[i]);
buffer2.hex16(3 + i * 9, _r[i]);
cli.println(buffer2);
static auto &buffer3 = *new CharBuffer(line3);
for (auto i = 0; i < 8; i++)
buffer3.hex16(4 + i * 9, _r[i + 8]);
buffer3.hex16(3 + i * 9, _r[i + 8]);
cli.println(buffer3);
}

Expand Down
14 changes: 8 additions & 6 deletions debugger/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,8 @@ void Debugger::exec(char c) {
target().reset();
if (_verbose)
target().printCycles();
goto regs;
target().printStatus();
break;
case 'd':
cli.print("Dump? ");
cli.readHex(handleDump, DUMP_ADDR, maxAddr);
Expand Down Expand Up @@ -617,9 +618,7 @@ void Debugger::exec(char c) {
break;
case 'r':
cli.println("Registers");
regs:
target().printRegisters();
target().disassembleNext();
target().printStatus();
break;
case '=':
cli.print("Set register? ");
Expand All @@ -633,7 +632,8 @@ void Debugger::exec(char c) {
} else {
target().step(true);
}
goto regs;
target().printStatus();
break;
case 'G':
cli.println("Go");
if (target().isOnBreakPoint()) {
Expand All @@ -642,7 +642,8 @@ void Debugger::exec(char c) {
break;
}
target().run();
goto regs;
target().printStatus();
break;
case 'F':
cli.print("Files? ");
cli.readLine(handleFileListing, 0, str_buffer, sizeof(str_buffer));
Expand Down Expand Up @@ -689,6 +690,7 @@ void Debugger::begin(Target &target_) {
_target = &target_;
target().begin();
usage();
target().printRegisters();
printPrompt();
}

Expand Down
26 changes: 10 additions & 16 deletions debugger/f3850/pins_f3850.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ inline void xtly_lo() {
digitalWriteFast(PIN_XTLY, LOW);
}

inline uint8_t signal_phi() {
inline auto signal_phi() {
return digitalReadFast(PIN_PHI);
}

inline uint8_t signal_write() {
inline auto signal_write() {
return digitalReadFast(PIN_WRITE);
}

Expand All @@ -80,21 +80,16 @@ void negate_intreq() {
digitalWriteFast(PIN_INTREQ, HIGH);
}

void assert_extres() {
negate_intreq();
digitalWriteFast(PIN_EXTRES, LOW);
}

void negate_extres() {
digitalWriteFast(PIN_EXTRES, HIGH);
}

const uint8_t PINS_LOW[] = {
constexpr uint8_t PINS_LOW[] = {
PIN_EXTRES,
PIN_XTLY,
};

const uint8_t PINS_HIGH[] = {
constexpr uint8_t PINS_HIGH[] = {
PIN_INTREQ,
PIN_IO1L0,
PIN_IO1L1,
Expand All @@ -106,7 +101,7 @@ const uint8_t PINS_HIGH[] = {
PIN_IO1H7,
};

const uint8_t PINS_INPUT[] = {
constexpr uint8_t PINS_INPUT[] = {
PIN_DB0,
PIN_DB1,
PIN_DB2,
Expand Down Expand Up @@ -149,19 +144,19 @@ inline void xtly_cycle_hi() {
} // namespace

void PinsF3850::reset() {
// Assert reset condition
pinsMode(PINS_LOW, sizeof(PINS_LOW), OUTPUT, LOW);
pinsMode(PINS_HIGH, sizeof(PINS_HIGH), OUTPUT, HIGH);
pinsMode(PINS_INPUT, sizeof(PINS_INPUT), INPUT);

Signals::resetCycles();
assert_extres();
for (auto i = 0; i < 10 * 4; ++i)
xtly_cycle();
while (signal_write() == LOW)
xtly_cycle();
// WRITE=H
negate_extres();
delayNanoseconds(xtly_hi_ns);
Signals::resetCycles();

cycle(); // IDLE
delayNanoseconds(xtly_idle_ns);
Expand Down Expand Up @@ -215,12 +210,12 @@ void PinsF3850::execInst(const uint8_t *inst, uint8_t len) {
execute(inst, len, nullptr, 0);
}

uint8_t PinsF3850::captureWrites(
void PinsF3850::captureWrites(
const uint8_t *inst, uint8_t len, uint8_t *buf, uint8_t max) {
return execute(inst, len, buf, max);
execute(inst, len, buf, max);
}

uint8_t PinsF3850::execute(
void PinsF3850::execute(
const uint8_t *inst, uint8_t len, uint8_t *buf, uint8_t max) {
uint8_t inj = 0;
uint8_t cap = 0;
Expand All @@ -239,7 +234,6 @@ uint8_t PinsF3850::execute(
buf[cap++] = signals->data;
}
}
return cap;
}

void PinsF3850::idle() {
Expand Down
10 changes: 5 additions & 5 deletions debugger/f3850/pins_f3850.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct PinsF3850 final : Pins {
void printCycles() override;

void execInst(const uint8_t *inst, uint8_t len);
uint8_t captureWrites(
void captureWrites(
const uint8_t *inst, uint8_t len, uint8_t *buf, uint8_t max);

private:
Expand All @@ -83,10 +83,10 @@ struct PinsF3850 final : Pins {
Signals *cycle(uint8_t data);
void loop();
bool rawStep();
uint8_t execute(
const uint8_t *inst, uint8_t len, uint8_t *buf, uint8_t max);

void disassembleCycles() const;};
void execute(const uint8_t *inst, uint8_t len, uint8_t *buf, uint8_t max);

void disassembleCycles() const;
};

extern struct PinsF3850 Pins;

Expand Down
12 changes: 2 additions & 10 deletions debugger/i8048/pins_i8048.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,6 @@ inline void negate_ss() {
digitalWriteFast(PIN_SS, HIGH);
}

void assert_reset() {
// Drive RESET condition
xtal1_hi();
digitalWriteFast(PIN_RESET, LOW);
negate_int();
negate_ss();
}

void negate_reset() {
digitalWriteFast(PIN_RESET, HIGH);
}
Expand Down Expand Up @@ -183,20 +175,20 @@ inline void xtal1_cycle() {
} // namespace

void PinsI8048::reset() {
// Assert reset condition
pinsMode(PINS_LOW, sizeof(PINS_LOW), OUTPUT, LOW);
pinsMode(PINS_HIGH, sizeof(PINS_HIGH), OUTPUT, HIGH);
pinsMode(PINS_PULLUP, sizeof(PINS_PULLUP), INPUT_PULLUP);
pinsMode(PINS_INPUT, sizeof(PINS_INPUT), INPUT);

assert_reset();
// Only 5 machine cycles are required if power is already on.
for (auto i = 0; i < 15 * (5 + 2); ++i)
xtal1_cycle();
while (signal_psen() != LOW)
xtal1_cycle();
negate_reset();
// #SS=L
Signals::resetCycles();
// #SS=L
_regs.save();
}

Expand Down
18 changes: 5 additions & 13 deletions debugger/i8051/pins_i8051.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,24 @@ void negate_reset() {
digitalWriteFast(PIN_RST, LOW);
}

const uint8_t PINS_LOW[] = {
constexpr uint8_t PINS_LOW[] = {
PIN_RST,
PIN_EA,
PIN_T0,
PIN_T1,
};

const uint8_t PINS_HIGH[] = {
constexpr uint8_t PINS_HIGH[] = {
PIN_INT0,
PIN_INT1,
};

const uint8_t PINS_PULLUP[] = {
constexpr uint8_t PINS_PULLUP[] = {
PIN_XTAL,
PIN_XTYPE,
};

const uint8_t PINS_INPUT[] = {
constexpr uint8_t PINS_INPUT[] = {
PIN_AD0,
PIN_AD1,
PIN_AD2,
Expand Down Expand Up @@ -176,14 +176,6 @@ void xtal1_hi() {
digitalWriteFast(PIN_XTAL, HIGH);
}

void PinsI8051::assert_reset() const {
// Drive RESET condition
xtal_lo();
digitalWriteFast(PIN_RST, HIGH);
negate_int0();
negate_int1();
}

inline void PinsI8051::xtal_cycle_lo() const {
xtal_hi();
delayNanoseconds(xtal_hi_ns);
Expand All @@ -198,6 +190,7 @@ inline void PinsI8051::xtal_cycle() const {
}

void PinsI8051::reset() {
// Assert reset condition
pinsMode(PINS_LOW, sizeof(PINS_LOW), OUTPUT, LOW);
pinsMode(PINS_HIGH, sizeof(PINS_HIGH), OUTPUT, HIGH);
pinsMode(PINS_PULLUP, sizeof(PINS_PULLUP), INPUT_PULLUP);
Expand All @@ -219,7 +212,6 @@ void PinsI8051::reset() {
pinMode(PIN_XTAL, OUTPUT);
xtal_lo();

assert_reset();
// A reset is accomplished by holding the RST pin high gfor at
// least two machine cycles (24 ocillator periods).
for (auto i = 0; i < 30; ++i)
Expand Down
Loading

0 comments on commit ae0685e

Please sign in to comment.