public STM32LTDC(Machine machine) : base(machine) { Reconfigure(format: PixelFormat.RGBX8888); IRQ = new GPIO(); this.machine = machine; internalLock = new object(); var activeWidthConfigurationRegister = new DoubleWordRegister(this); accumulatedActiveHeightField = activeWidthConfigurationRegister.DefineValueField(0, 11, FieldMode.Read | FieldMode.Write, name: "AAH"); accumulatedActiveWidthField = activeWidthConfigurationRegister.DefineValueField(16, 12, FieldMode.Read | FieldMode.Write, name: "AAW", writeCallback: (_, __) => HandleActiveDisplayChange()); var backPorchConfigurationRegister = new DoubleWordRegister(this); accumulatedVerticalBackPorchField = backPorchConfigurationRegister.DefineValueField(0, 11, FieldMode.Read | FieldMode.Write, name: "AVBP"); accumulatedHorizontalBackPorchField = backPorchConfigurationRegister.DefineValueField(16, 12, FieldMode.Read | FieldMode.Write, name: "AHBP", writeCallback: (_, __) => HandleActiveDisplayChange()); var backgroundColorConfigurationRegister = new DoubleWordRegister(this); backgroundColorBlueChannelField = backgroundColorConfigurationRegister.DefineValueField(0, 8, FieldMode.Read | FieldMode.Write, name: "BCBLUE"); backgroundColorGreenChannelField = backgroundColorConfigurationRegister.DefineValueField(8, 8, FieldMode.Read | FieldMode.Write, name: "BCGREEN"); backgroundColorRedChannelField = backgroundColorConfigurationRegister.DefineValueField(16, 8, FieldMode.Read | FieldMode.Write, name: "BCRED", writeCallback: (_, __) => HandleBackgroundColorChange()); var interruptEnableRegister = new DoubleWordRegister(this); lineInterruptEnableFlag = interruptEnableRegister.DefineFlagField(0, FieldMode.Read | FieldMode.Write, name: "LIE"); var interruptClearRegister = new DoubleWordRegister(this); interruptClearRegister.DefineFlagField(0, FieldMode.Write, name: "CLIF", writeCallback: (old, @new) => { if(@new) IRQ.Unset(); }); interruptClearRegister.DefineFlagField(3, FieldMode.Write, name: "CRRIF", writeCallback: (old, @new) => { if(@new) IRQ.Unset(); }); lineInterruptPositionConfigurationRegister = new DoubleWordRegister(this).WithValueField(0, 11, FieldMode.Read | FieldMode.Write, name: "LIPOS"); var registerMappings = new Dictionary<long, DoubleWordRegister> { { (long)Register.BackPorchConfigurationRegister, backPorchConfigurationRegister }, { (long)Register.ActiveWidthConfigurationRegister, activeWidthConfigurationRegister }, { (long)Register.BackgroundColorConfigurationRegister, backgroundColorConfigurationRegister }, { (long)Register.InterruptEnableRegister, interruptEnableRegister }, { (long)Register.InterruptClearRegister, interruptClearRegister }, { (long)Register.LineInterruptPositionConfigurationRegister, lineInterruptPositionConfigurationRegister } }; localLayerBuffer = new byte[2][]; layer = new Layer[2]; for(var i = 0; i < layer.Length; i++) { layer[i] = new Layer(this, i); var offset = 0x80 * i; registerMappings.Add(0x84 + offset, layer[i].ControlRegister); registerMappings.Add(0x88 + offset, layer[i].WindowHorizontalPositionConfigurationRegister); registerMappings.Add(0x8C + offset, layer[i].WindowVerticalPositionConfigurationRegister); registerMappings.Add(0x94 + offset, layer[i].PixelFormatConfigurationRegister); registerMappings.Add(0x98 + offset, layer[i].ConstantAlphaConfigurationRegister); registerMappings.Add(0xAC + offset, layer[i].ColorFrameBufferAddressRegister); } registers = new DoubleWordRegisterCollection(this, registerMappings); registers.Reset(); HandlePixelFormatChange(); }
public STM32F7_USART(Machine machine) { sync = new object(); this.machine = machine; IRQ = new GPIO(); receiveQueue = new Queue<byte>(); var controlRegister1 = new DoubleWordRegister(this); enabled = controlRegister1.DefineFlagField(0, name: "UE"); receiveEnabled = controlRegister1.DefineFlagField(2, name: "RE"); transmitEnabled = controlRegister1.DefineFlagField(3, name: "TE"); receiveInterruptEnabled = controlRegister1.DefineFlagField(5, name: "RXNEIE"); transmitQueueEmptyInterruptEnabled = controlRegister1.DefineFlagField(7, name: "TXEIE", writeCallback: delegate { RefreshInterrupt(); } ); controlRegister1.DefineFlagField(8, name: "PEIE"); paritySelection = controlRegister1.DefineFlagField(9, name: "PS"); parityControlEnabled = controlRegister1.DefineFlagField(10, name: "PCE"); var controlRegister2 = new DoubleWordRegister(this); stopBits = controlRegister2.DefineValueField(12, 2); registers = new DoubleWordRegisterCollection(this, new Dictionary<long, DoubleWordRegister> { { (long)Register.ControlRegister1, controlRegister1 }, { (long)Register.ControlRegister2, controlRegister2 }, { (long)Register.ControlRegister3, new DoubleWordRegister(this).WithFlag(0, name: "EIE") }, { (long)Register.InterruptAndStatus, new DoubleWordRegister(this, 0x200000C0) .WithFlag(5, FieldMode.Read, name: "RXNE", valueProviderCallback: delegate { return receiveQueue.Count > 0; }) .WithFlag(6, FieldMode.Read, name: "TC").WithFlag(7, FieldMode.Read, name: "TXE") .WithFlag(21, FieldMode.Read, name: "TEACK", valueProviderCallback: delegate { return transmitEnabled.Value; }) .WithFlag(22, FieldMode.Read, name: "REACK", valueProviderCallback: delegate { return receiveEnabled.Value; }) .WithValueField(23, 8, FieldMode.Read, name: "Reserved") } }); }
public CC2538RF() { rxLock = new object(); rxQueue = new Queue<Frame>(); txQueue = new Queue<byte>(); shortAddress = new Address(AddressingMode.ShortAddress); extendedAddress = new Address(AddressingMode.ExtendedAddress); random = new Random(); IRQ = new GPIO(); srcShortEnabled = new bool[24]; srcExtendedEnabled = new bool[12]; matchedSourceAddresses = new bool[24]; srcShortPendEnabled = new bool[24]; srcExtendedPendEnabled = new bool[12]; ffsmMemory = new uint[96]; irqHandler = new InterruptHandler<InterruptRegister, InterruptSource>(IRQ); irqHandler.RegisterInterrupt(InterruptRegister.IrqFlag0, InterruptSource.StartOfFrameDelimiter, 1); irqHandler.RegisterInterrupt(InterruptRegister.IrqFlag0, InterruptSource.FifoP, 2); irqHandler.RegisterInterrupt(InterruptRegister.IrqFlag0, InterruptSource.SrcMatchDone, 3); irqHandler.RegisterInterrupt(InterruptRegister.IrqFlag0, InterruptSource.SrcMatchFound, 4); irqHandler.RegisterInterrupt(InterruptRegister.IrqFlag0, InterruptSource.FrameAccepted, 5); irqHandler.RegisterInterrupt(InterruptRegister.IrqFlag0, InterruptSource.RxPktDone, 6); irqHandler.RegisterInterrupt(InterruptRegister.IrqFlag0, InterruptSource.RxMaskZero, 7); irqHandler.RegisterInterrupt(InterruptRegister.IrqFlag1, InterruptSource.TxAckDone, 0); irqHandler.RegisterInterrupt(InterruptRegister.IrqFlag1, InterruptSource.TxDone, 1); irqHandler.RegisterInterrupt(InterruptRegister.IrqFlag1, InterruptSource.RfIdle, 2); irqHandler.RegisterInterrupt(InterruptRegister.IrqFlag1, InterruptSource.CommandStrobeProcessorManualInterrupt, 3); irqHandler.RegisterInterrupt(InterruptRegister.IrqFlag1, InterruptSource.CommandStrobeProcessorStop, 4); irqHandler.RegisterInterrupt(InterruptRegister.IrqFlag1, InterruptSource.CommandStrobeProcessorWait, 5); var matchedSourceIndex = new DoubleWordRegister(this); matchedSourceIndexField = matchedSourceIndex.DefineValueField(0, 8, FieldMode.Read | FieldMode.Write); var srcResMask = CreateRegistersGroup(3, this, 0, 8, valueProviderCallback: ReadSrcResMaskRegister, writeCallback: WriteSrcResMaskRegister); var srcExtendedAddressPendingEnabled = CreateRegistersGroup(3, this, 0, 8, valueProviderCallback: ReadSrcExtendedAddressPendingEnabledRegister, writeCallback: WriteSrcExtendedAddressPendingEnabledRegister); var srcShortAddressPendingEnabled = CreateRegistersGroup(3, this, 0, 8, name: "SrcShortAddressPendingEnabled", valueProviderCallback: ReadSrcShortAddressPendingEnabledRegister, writeCallback: WriteSrcShortAddressPendingEnabledRegister); var extAddress = CreateRegistersGroup(8, this, 0, 8, valueProviderCallback: i => extendedAddress.Bytes[i], writeCallback: (i, @new) => extendedAddress.SetByte((byte)@new, i)); panId = CreateRegistersGroup(2, this, 0, 8); var shortAddressRegister = CreateRegistersGroup(2, this, 0, 8, valueProviderCallback: i => shortAddress.Bytes[i], writeCallback: (i, @new) => shortAddress.SetByte((byte)@new, i)); var sourceExtendedAddressEnable = CreateRegistersGroup(3, this, 0, 8, valueProviderCallback: ReadSourceExtendedAddressEnableRegister, writeCallback: WriteSourceExtendedAddressEnableRegister); var sourceShortAddressEnable = CreateRegistersGroup(3, this, 0, 8, valueProviderCallback: ReadSourceShortAddressEnableRegister, writeCallback: WriteSourceShortAddressEnableRegister); var frameHandling0 = new DoubleWordRegister(this, 0x40); autoAck = frameHandling0.DefineFlagField(5); autoCrc = frameHandling0.DefineFlagField(6); appendDataMode = frameHandling0.DefineFlagField(7); var frameHandling1 = new DoubleWordRegister(this, 0x1); pendingOr = frameHandling1.DefineFlagField(2); var sourceAddressMatching = new DoubleWordRegister(this, 0x7); sourceAddressMatchingEnabled = sourceAddressMatching.DefineFlagField(0); autoPendEnabled = sourceAddressMatching.DefineFlagField(1); pendDataRequestOnly = sourceAddressMatching.DefineFlagField(2); var radioStatus0 = new DoubleWordRegister(this, 0x81).WithValueField(0, 8, FieldMode.Read); var radioStatus1 = new DoubleWordRegister(this, 0).WithValueField(0, 8, FieldMode.Read, valueProviderCallback: ReadRadioStatus1Register); var rssiValidStatus = new DoubleWordRegister(this, 0x1).WithFlag(0, FieldMode.Read); var interruptMask = CreateRegistersGroup(2, this, 0, 8, valueProviderCallback: i => irqHandler.GetRegisterMask(InterruptRegisterHelper.GetMaskRegister(i)), writeCallback: (i, @new) => { irqHandler.SetRegisterMask(InterruptRegisterHelper.GetMaskRegister(i), @new); }); var randomData = new DoubleWordRegister(this, 0).WithValueField(0, 2, FieldMode.Read, valueProviderCallback: _ => (uint)(random.Next() & 3)); var frameFiltering0 = new DoubleWordRegister(this, 0xD); frameFilterEnabled = frameFiltering0.DefineFlagField(0); isPanCoordinator = frameFiltering0.DefineFlagField(1); maxFrameVersion = frameFiltering0.DefineValueField(2, 2); var frameFiltering1 = new DoubleWordRegister(this, 0x78); acceptBeaconFrames = frameFiltering1.DefineFlagField(3); acceptDataFrames = frameFiltering1.DefineFlagField(4); acceptAckFrames = frameFiltering1.DefineFlagField(5); acceptMacCmdFrames = frameFiltering1.DefineFlagField(6); var rfData = new DoubleWordRegister(this, 0).WithValueField(0, 8, valueProviderCallback: _ => DequeueData(), writeCallback: (_, @new) => { EnqueueData((byte)@new); }); var interruptFlag = CreateRegistersGroup(2, this, 0, 8, valueProviderCallback: i => irqHandler.GetRegisterValue(InterruptRegisterHelper.GetValueRegister(i)), writeCallback: (i, @new) => { irqHandler.SetRegisterValue(InterruptRegisterHelper.GetValueRegister(i), @new); }); var commandStrobeProcessor = new DoubleWordRegister(this, 0).WithValueField(0, 8, FieldMode.Write, writeCallback: (_, @new) => { HandleSFRInstruction(@new); }); var addresses = new Dictionary<long, DoubleWordRegister> { { (uint)Register.RfData, rfData }, { (uint)Register.CommandStrobeProcessor, commandStrobeProcessor }, { (uint)Register.FrameFiltering0, frameFiltering0 }, { (uint)Register.FrameFiltering1, frameFiltering1 }, { (uint)Register.SourceAddressMatching, sourceAddressMatching }, { (uint)Register.FrameHandling0, frameHandling0 }, { (uint)Register.FrameHandling1, frameHandling1 }, { (uint)Register.RadioStatus0, radioStatus0 }, { (uint)Register.RadioStatus1, radioStatus1 }, { (uint)Register.RssiValidStatus, rssiValidStatus }, { (uint)Register.RandomData, randomData }, { (uint)Register.SourceAddressMatchingResult, matchedSourceIndex } }; RegisterGroup(addresses, (uint)Register.InterruptFlag, interruptFlag); RegisterGroup(addresses, (uint)Register.SourceExtendedAdressEnable, sourceExtendedAddressEnable); RegisterGroup(addresses, (uint)Register.SourceShortAddressEnable, sourceShortAddressEnable); RegisterGroup(addresses, (uint)Register.InterruptMask, interruptMask); RegisterGroup(addresses, (uint)Register.SourceAddressMatchingResultMask, srcResMask); RegisterGroup(addresses, (uint)Register.SourceExtendedAddressPendingEnabled, srcExtendedAddressPendingEnabled); RegisterGroup(addresses, (uint)Register.SourceShortAddressPendingEnabled, srcShortAddressPendingEnabled); RegisterGroup(addresses, (uint)Register.ExtendedAddress, extAddress); RegisterGroup(addresses, (uint)Register.PanId, panId); RegisterGroup(addresses, (uint)Register.ShortAddressRegister, shortAddressRegister); registers = new DoubleWordRegisterCollection(this, addresses); Reset(); }
private void SetupRegisters() { var interruptPriorityRegisters = new Dictionary<long, DoubleWordRegister>(); priorities = new IValueRegisterField[64]; for(var i = 0; i < 8; i++) { var registerKey = (long)Registers.InterruptPriority0 + 4 * i; interruptPriorityRegisters.Add(registerKey, new DoubleWordRegister(this, 0x77777777)); for(var j = 0; j < 8; j++) { priorities[i * 8 + j] = interruptPriorityRegisters[registerKey].DefineValueField(4 * j, 3, writeCallback: (oldValue, newValue) => Update()); } } interruptPriorityRegisterCollection = new DoubleWordRegisterCollection(this, interruptPriorityRegisters); interruptOperationControl = new DoubleWordRegister(this); reflectMaskedFiq = interruptOperationControl.DefineFlagField(0, writeCallback: (oldValue, newValue) => Update()); reflectMaskedIrq = interruptOperationControl.DefineFlagField(1, writeCallback: (oldValue, newValue) => Update()); interruptOperationControl.DefineFlagField(2, changeCallback: (oldValue, newValue) => { if(newValue) { this.Log(LogLevel.Warning, "Unsupported delayed interrupt enable/disable mode was set."); } }); }
private void SetupRegisters() { commandRegister = new DoubleWordRegister(this); dmacStatusRegister = new DoubleWordRegister(this); startCommandFlag = commandRegister.DefineFlagField(31, changeCallback: OnStartCommand); sendInitSequence = commandRegister.DefineFlagField(15); transferDirection = commandRegister.DefineFlagField(10); dataTransfer = commandRegister.DefineFlagField(9); receiveResponse = commandRegister.DefineFlagField(6); commandIndex = commandRegister.DefineValueField(0, 6); responseRegisters = new uint[4]; receiveInterrupt = dmacStatusRegister.DefineFlagField(1, FieldMode.WriteOneToClear | FieldMode.Read); transmitInterrupt = dmacStatusRegister.DefineFlagField(0, FieldMode.WriteOneToClear | FieldMode.Read); generalRegisters = new DoubleWordRegisterCollection(this, new Dictionary<long, DoubleWordRegister>() { {(long)Registers.ControlRegister, new DoubleWordRegister(this).WithFlag(0, changeCallback: (oldValue, newValue) => {if(newValue) Reset();}).WithFlag(2).WithFlag(4).WithFlag(5)}, {(long)Registers.BlockSizeRegister, new DoubleWordRegister(this, 0x200).WithValueField(0, 16, changeCallback: (oldValue, newValue) => BlockSize = (int)newValue)}, {(long)Registers.DmacInterruptEnable, DoubleWordRegister.CreateRWRegister()}, }); }
private STM32DMA2D() { var controlRegister = new DoubleWordRegister(this); startFlag = controlRegister.DefineFlagField(0, FieldMode.Read | FieldMode.Write, name: "Start", changeCallback: (old, @new) => { if(@new) DoTransfer(); }); dma2dMode = controlRegister.DefineEnumField<Mode>(16, 2, FieldMode.Read | FieldMode.Write, name: "Mode"); var foregroundClutMemoryAddressRegister = new DoubleWordRegister(this).WithValueField(0, 32, FieldMode.Read | FieldMode.Write); var backgroundClutMemoryAddressRegister = new DoubleWordRegister(this).WithValueField(0, 32, FieldMode.Read | FieldMode.Write); var interruptFlagClearRegister = new DoubleWordRegister(this).WithFlag(1, FieldMode.Read | FieldMode.WriteOneToClear, name: "CTCIF", changeCallback: (old, @new) => { if(!@new) IRQ.Unset(); }); var numberOfLineRegister = new DoubleWordRegister(this); numberOfLineField = numberOfLineRegister.DefineValueField(0, 16, FieldMode.Read | FieldMode.Write, name: "NL"); pixelsPerLineField = numberOfLineRegister.DefineValueField(16, 14, FieldMode.Read | FieldMode.Write, name: "PL", writeCallback: (_, __) => { HandleOutputBufferSizeChange(); HandleBackgroundBufferSizeChange(); HandleForegroundBufferSizeChange(); }); outputMemoryAddressRegister = new DoubleWordRegister(this).WithValueField(0, 32, FieldMode.Read | FieldMode.Write); backgroundMemoryAddressRegister = new DoubleWordRegister(this).WithValueField(0, 32, FieldMode.Read | FieldMode.Write); foregroundMemoryAddressRegister = new DoubleWordRegister(this).WithValueField(0, 32, FieldMode.Read | FieldMode.Write); var outputPfcControlRegister = new DoubleWordRegister(this); outputColorModeField = outputPfcControlRegister.DefineEnumField<Dma2DColorMode>(0, 3, FieldMode.Read | FieldMode.Write, name: "CM", writeCallback: (_, __) => { HandlePixelFormatChange(); HandleOutputBufferSizeChange(); }); var foregroundPfcControlRegister = new DoubleWordRegister(this); foregroundColorModeField = foregroundPfcControlRegister.DefineEnumField<Dma2DColorMode>(0, 4, FieldMode.Read | FieldMode.Write, name: "CM", writeCallback: (_, __) => { HandlePixelFormatChange(); HandleForegroundBufferSizeChange(); }); var foregroundClutSizeField = foregroundPfcControlRegister.DefineValueField(8, 8, FieldMode.Read | FieldMode.Write, name: "CS"); foregroundClutColorModeField = foregroundPfcControlRegister.DefineEnumField<Dma2DColorMode>(4, 1, FieldMode.Read | FieldMode.Write, name: "CCM", changeCallback: (_, __) => { HandlePixelFormatChange(); }); foregroundPfcControlRegister.DefineFlagField(5, FieldMode.Read, name: "START", writeCallback: (_, value) => { if(!value) { return; } foregroundClut = new byte[(foregroundClutSizeField.Value + 1) * foregroundClutColorModeField.Value.ToPixelFormat().GetColorDepth()]; machine.SystemBus.ReadBytes(foregroundClutMemoryAddressRegister.Value, foregroundClut.Length, foregroundClut, 0, true); }); var backgroundPfcControlRegister = new DoubleWordRegister(this); backgroundColorModeField = backgroundPfcControlRegister.DefineEnumField<Dma2DColorMode>(0, 4, FieldMode.Read | FieldMode.Write, name: "CM", writeCallback: (_, __) => { HandlePixelFormatChange(); HandleBackgroundBufferSizeChange(); }); var backgroundClutSizeField = backgroundPfcControlRegister.DefineValueField(8, 8, FieldMode.Read | FieldMode.Write, name: "CS"); backgroundClutColorModeField = backgroundPfcControlRegister.DefineEnumField<Dma2DColorMode>(4, 1, FieldMode.Read | FieldMode.Write, name: "CCM", changeCallback: (_, __) => { HandlePixelFormatChange(); }); backgroundPfcControlRegister.DefineFlagField(5, FieldMode.Read, name: "START", writeCallback: (_, value) => { if(!value) { return; } backgroundClut = new byte[(backgroundClutSizeField.Value + 1) * backgroundClutColorModeField.Value.ToPixelFormat().GetColorDepth()]; machine.SystemBus.ReadBytes(backgroundClutMemoryAddressRegister.Value, backgroundClut.Length, backgroundClut, 0, true); }); outputColorRegister = new DoubleWordRegister(this).WithValueField(0, 32, FieldMode.Read | FieldMode.Write); var outputOffsetRegister = new DoubleWordRegister(this); outputLineOffsetField = outputOffsetRegister.DefineValueField(0, 14, FieldMode.Read | FieldMode.Write, name: "LO"); var foregroundOffsetRegister = new DoubleWordRegister(this); foregroundLineOffsetField = foregroundOffsetRegister.DefineValueField(0, 14, FieldMode.Read | FieldMode.Write, name: "LO"); var backgroundOffsetRegister = new DoubleWordRegister(this); backgroundLineOffsetField = backgroundOffsetRegister.DefineValueField(0, 14, FieldMode.Read | FieldMode.Write, name: "LO"); var regs = new Dictionary<long, DoubleWordRegister> { { (long)Register.ControlRegister, controlRegister }, { (long)Register.InterruptFlagClearRegister, interruptFlagClearRegister }, { (long)Register.ForegroundMemoryAddressRegister, foregroundMemoryAddressRegister }, { (long)Register.ForegroundOffsetRegister, foregroundOffsetRegister }, { (long)Register.BackgroundMemoryAddressRegister, backgroundMemoryAddressRegister }, { (long)Register.BackgroundOffsetRegister, backgroundOffsetRegister }, { (long)Register.ForegroundPfcControlRegister, foregroundPfcControlRegister }, { (long)Register.BackgroundPfcControlRegister, backgroundPfcControlRegister }, { (long)Register.OutputPfcControlRegister, outputPfcControlRegister }, { (long)Register.OutputColorRegister, outputColorRegister }, { (long)Register.OutputMemoryAddressRegister, outputMemoryAddressRegister }, { (long)Register.OutputOffsetRegister, outputOffsetRegister }, { (long)Register.NumberOfLineRegister, numberOfLineRegister }, { (long)Register.ForegroundClutMemoryAddressRegister, foregroundClutMemoryAddressRegister }, { (long)Register.BackgroundClutMemoryAddressRegister, backgroundClutMemoryAddressRegister } }; registers = new DoubleWordRegisterCollection(this, regs); }