From 77f14fa6384f6b2bed27def9d74cd152f2759748 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 23 Oct 2019 23:09:49 -0400 Subject: [PATCH] Starts trying to make sense of interrupts. --- Components/68901/MFP68901.cpp | 31 ++++++++++++++++++++++---- Components/68901/MFP68901.hpp | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/Components/68901/MFP68901.cpp b/Components/68901/MFP68901.cpp index 9cef37808..e0a127cf9 100644 --- a/Components/68901/MFP68901.cpp +++ b/Components/68901/MFP68901.cpp @@ -26,10 +26,18 @@ uint8_t MFP68901::read(int address) { case 0x02: LOG("Read: data direction " << PADHEX(2) << int(gpip_direction_)); return gpip_direction_; - case 0x03: LOG("Read: interrupt enable A"); break; - case 0x04: LOG("Read: interrupt enable B"); break; - case 0x05: LOG("Read: interrupt pending A"); break; - case 0x06: LOG("Read: interrupt pending B"); break; + case 0x03: + LOG("Read: interrupt enable A"); + return interrupt_enable_[0]; + case 0x04: + LOG("Read: interrupt enable B"); + return interrupt_enable_[1]; + case 0x05: + LOG("Read: interrupt pending A"); + return interrupt_pending_[0]; + case 0x06: + LOG("Read: interrupt pending B"); + return interrupt_pending_[1]; case 0x07: LOG("Read: interrupt in-service A"); break; case 0x08: LOG("Read: interrupt in-service B"); break; case 0x09: LOG("Read: interrupt mask A"); break; @@ -209,3 +217,18 @@ void MFP68901::reevaluate_gpip_interrupts() { } gpip_interrupt_state_ = gpip_state; } + + +// MARK: - Interrupts + +void MFP68901::begin_interrupt(Interrupt interrupt) { + // In service is always set. + interrupt_in_service_[interrupt >> 3] |= 1 << (interrupt & 7); + + // Pending is set only if the interrupt is enabled. +// interrupt_pending_[interrupt >> 3] |= +} + +void MFP68901::end_interrupt(Interrupt interrupt) { + // Reset in-service and pending. +} diff --git a/Components/68901/MFP68901.hpp b/Components/68901/MFP68901.hpp index f7dcf7978..e69519e49 100644 --- a/Components/68901/MFP68901.hpp +++ b/Components/68901/MFP68901.hpp @@ -63,6 +63,47 @@ class MFP68901 { uint8_t gpip_interrupt_state_ = 0; void reevaluate_gpip_interrupts(); + + // MARK: - Interrupts + + // Ad hoc documentation: there seems to be a four-stage process here. + // This is my current understanding: + // + // Interrupt in-service refers to whether the signal that would cause an + // interrupt is active. + // + // If the interrupt is in-service and enabled, it will be listed as pending. + // + // If a pending interrupt is enabled in the interrupt mask, it will generate + // a processor interrupt. + // + // So, the designers seem to have wanted to allow for polling and interrupts, + // and then also decided to have some interrupts be able to be completely + // disabled, so that don't even show up for polling. + uint8_t interrupt_in_service_[2] = {0, 0}; + uint8_t interrupt_enable_[2] = {0, 0}; + uint8_t interrupt_pending_[2] = {0, 0}; + uint8_t interrupt_mask_[2] = {0, 0}; + + enum Interrupt { + GPIP0 = 0, + GPIP1, + GPIP2, + GPIP3, + TimerD, + TimerC, + GPIP4, + GPIP5, + TimerB, + TransmitError, + TransmitBufferEmpty, + ReceiveError, + ReceiveBufferFull, + GPIP6, + GPIP7 + }; + void begin_interrupt(Interrupt interrupt); + void end_interrupt(Interrupt interrupt); }; }