public DA1468x_OTPC(Machine machine) { var registersMap = new Dictionary <long, DoubleWordRegister> { { (long)Registers.Mode, new DoubleWordRegister(this, 0x0) .WithValueField(0, 3, name: "OTPC_MODE_MODE") .WithReservedBits(3, 1) .WithTaggedFlag("OTPC_MODE_USE_DMA", 4) .WithTaggedFlag("OTPC_MODE_FIFO_FLUSH", 5) .WithTaggedFlag("OTPC_MODE_ERR_RESP_DIS", 6) .WithReservedBits(7, 1) .WithTaggedFlag("OTPC_MODE_USE_SP_ROWS", 8) .WithTaggedFlag("OTPC_MODE_RLD_RR_REQ", 9) .WithReservedBits(10, 21) }, { (long)Registers.Stat, new DoubleWordRegister(this, 0x40) .WithFlag(0, name: "OTPC_STAT_PRDY", mode: FieldMode.Read) .WithFlag(1, name: "OTPC_STAT_PERR_UNC", mode: FieldMode.Read) .WithFlag(2, name: "OTPC_STAT_COR", mode: FieldMode.Read) .WithFlag(3, name: "OTPC_STAT_PZERO", mode: FieldMode.Read) .WithFlag(4, name: "OTPC_STAT_TRDY", mode: FieldMode.Read) .WithFlag(5, name: "OTPC_STAT_TERROR", mode: FieldMode.Read) .WithFlag(6, name: "OTPC_START_ARDY", mode: FieldMode.Read) .WithFlag(7, name: "OTPC_STAT_RERROR", mode: FieldMode.WriteOneToClear | FieldMode.ReadToClear) .WithValueField(8, 4, name: "OTPC_STAT_FWORDS", mode: FieldMode.Read) .WithReservedBits(12, 4) .WithValueField(16, 14, name: "OTPC_STAT_NWORDS", mode: FieldMode.Read) .WithReservedBits(30, 2) }, }; registers = new DoubleWordRegisterCollection(this, registersMap); }
private void GenerateRegisterCollection() { var registerDictionary = new Dictionary <long, DoubleWordRegister> { { controlOffset + (long)Registers.Width * accessAligment, new DoubleWordRegister(this, DefaultWidth) .WithValueField(0, 16, name: "Width", writeCallback: (_, x) => Reconfigure(setWidth: x), valueProviderCallback: _ => (uint)Width) }, { controlOffset + (long)Registers.Height * accessAligment, new DoubleWordRegister(this, DefaultHeight) .WithValueField(0, 16, name: "Height", writeCallback: (_, y) => Reconfigure(setHeight: y), valueProviderCallback: _ => (uint)Height) }, { controlOffset + (long)Registers.Format * accessAligment, new DoubleWordRegister(this, (uint)DefaultColor | ((uint)DefaultPacking << 4)) .WithEnumField <DoubleWordRegister, ColorMode>(0, 4, name: "Color", writeCallback: (_, c) => Reconfigure(setColor: c), valueProviderCallback: _ => colorMode) .WithEnumField <DoubleWordRegister, PixelPacking>(4, 4, name: "Packing", writeCallback: (_, c) => ChangePacking(c), valueProviderCallback: _ => pixelPacking) } }; if (is64bitAligned) { // Dormant registers for the high 32bit accesses of the 64bit registers, // just so there will not be logged any unimplemented accesses foreach (long registerIndex in Enum.GetValues(typeof(Registers))) { registerDictionary.Add( controlOffset + registerIndex * accessAligment + 4, new DoubleWordRegister(this, 0x0) .WithTag("Dormant upper 32bit of 64bit registers", 0, 32) ); } } registers = new DoubleWordRegisterCollection(this, registerDictionary); }
private void SetupRegisters() { autoReload = DoubleWordRegister.CreateRWRegister(0xFFFF, "TIMx_ARR"); var interruptEnableRegister = new DoubleWordRegister(this); updateInterruptEnable = interruptEnableRegister.DefineFlagField(0, name: "UIE"); var prescalerRegister = new DoubleWordRegister(this); prescaler = prescalerRegister.DefineValueField(0, 15); var controlRegister = new DoubleWordRegister(this) .WithEnumField <DoubleWordRegister, Direction>(4, 1, valueProviderCallback: _ => Direction, changeCallback: (_, value) => Direction = value, name: "DIR") .WithFlag(0, changeCallback: (_, value) => Enabled = value, valueProviderCallback: _ => Enabled, name: "CEN"); updateRequestSource = controlRegister.DefineFlagField(2, name: "URS"); updateDisable = controlRegister.DefineFlagField(1, name: "UDIS"); registers = new DoubleWordRegisterCollection(this, new Dictionary <long, DoubleWordRegister> { { (long)Registers.Control1, controlRegister }, { (long)Registers.DmaInterruptEnable, interruptEnableRegister }, { (long)Registers.Status, new DoubleWordRegister(this) // This write callback is here only to prevent from very frequent logging. .WithValueField(1, 31, FieldMode.WriteZeroToClear, writeCallback: (_, __) => {}) .WithFlag(0, FieldMode.ReadToClear | FieldMode.WriteZeroToClear, changeCallback: (_, __) => IRQ.Unset(), valueProviderCallback: _ => IRQ.IsSet) }, { (long)Registers.EventGeneration, new DoubleWordRegister(this).WithFlag(0, FieldMode.Write, writeCallback: UpdateGeneration) }, { (long)Registers.Prescaler, prescalerRegister }, { (long)Registers.AutoReload, autoReload }, { (long)Registers.Counter, new DoubleWordRegister(this).WithValueField(0, 16, name: "Counter", valueProviderCallback: _ => (uint)Value, writeCallback: (_, value) => { Value = value; }) } }); }
public EFR32_I2CController(Machine machine) : base(machine) { IRQ = new GPIO(); txBuffer = new Queue <byte>(); rxBuffer = new Queue <byte>(); interruptsManager = new InterruptManager <Interrupt>(this); var map = new Dictionary <long, DoubleWordRegister> { { (long)Registers.ReceiveBufferData, new DoubleWordRegister(this) .WithValueField(0, 8, FieldMode.Read, name: "RXDATA", valueProviderCallback: _ => { var result = rxBuffer.Dequeue(); interruptsManager.SetInterrupt(Interrupt.ReceiveDataValid, rxBuffer.Any()); return(result); }) }, { (long)Registers.ReceiveBufferDataPeek, new DoubleWordRegister(this) .WithValueField(0, 8, FieldMode.Read, name: "RXDATAP", valueProviderCallback: _ => rxBuffer.Peek()) }, { (long)Registers.Command, new DoubleWordRegister(this) .WithValueField(0, 8, FieldMode.Write, name: "COMMAND", writeCallback: (_, v) => HandleCommand((Command)v)) }, { (long)Registers.TransmitBufferData, new DoubleWordRegister(this) .WithValueField(0, 8, FieldMode.Write, name: "TXDATA", writeCallback: (_, v) => LoadTxData((byte)v)) } }; map.Add((long)Registers.InterruptFlag, interruptsManager.GetInterruptFlagRegister <DoubleWordRegister>()); map.Add((long)Registers.InterruptEnable, interruptsManager.GetInterruptEnableRegister <DoubleWordRegister>()); map.Add((long)Registers.InterruptFlagSet, interruptsManager.GetInterruptFlagRegister <DoubleWordRegister>()); map.Add((long)Registers.InterruptFlagClear, interruptsManager.GetInterruptClearRegister <DoubleWordRegister>()); registers = new DoubleWordRegisterCollection(this, map); }
public K6xF_SIM(uint?uniqueIdHigh = null, uint?uniqueIdMidHigh = null, uint?uniqueIdMidLow = null, uint?uniqueIdLow = null) { var rng = EmulationManager.Instance.CurrentEmulation.RandomGenerator; this.uniqueIdHigh = uniqueIdHigh.HasValue ? uniqueIdHigh.Value : (uint)rng.Next(); this.uniqueIdMidHigh = uniqueIdMidHigh.HasValue ? uniqueIdMidHigh.Value : (uint)rng.Next(); this.uniqueIdMidLow = uniqueIdMidLow.HasValue ? uniqueIdMidLow.Value : (uint)rng.Next(); this.uniqueIdLow = uniqueIdLow.HasValue ? uniqueIdLow.Value : (uint)rng.Next(); var registersMap = new Dictionary <long, DoubleWordRegister> { { (long)Registers.UniqueIdHigh, new DoubleWordRegister(this) .WithValueField(0, 32, FieldMode.Read, valueProviderCallback: _ => { return(this.uniqueIdHigh); }, name: "SIM_UIDH") }, { (long)Registers.UniqueIdMidHigh, new DoubleWordRegister(this) .WithValueField(0, 32, FieldMode.Read, valueProviderCallback: _ => { return(this.uniqueIdMidHigh); }, name: "SIM_UIDMH") }, { (long)Registers.UniqueIdMidLow, new DoubleWordRegister(this) .WithValueField(0, 32, FieldMode.Read, valueProviderCallback: _ => { return(this.uniqueIdMidLow); }, name: "SIM_UIDML") }, { (long)Registers.UniqueIdLow, new DoubleWordRegister(this) .WithValueField(0, 32, FieldMode.Read, valueProviderCallback: _ => { return(this.uniqueIdLow); }, name: "SIM_UIDL") } }; registers = new DoubleWordRegisterCollection(this, registersMap); }
public Quark_SystemControlSubsystem(Machine machine, Quark_GPIOController gpioPort) { this.gpioPort = gpioPort; this.alwaysOnCounter = new LimitTimer(machine.ClockSource, 32000, direction: Time.Direction.Ascending, enabled: true); var registerMap = new Dictionary <long, DoubleWordRegister> { { (long)Registers.HybridOscillatorStatus1, new DoubleWordRegister(this, 3) }, //use only reset value - means that oscillators are enabled { (long)Registers.AlwaysOnCounter, new DoubleWordRegister(this, 0).WithValueField(0, 32, FieldMode.Read, valueProviderCallback: (_) => (uint)alwaysOnCounter.Value) }, // These registers map directly to GPIO port. Only 6 LSBits are important. Offsets in SCSS are generally the same as in the gpio port + 0xB00, // but we keep it here for clarity, logging purposes and ease of defining field modes. { (long)Registers.PortAGPIOAlwaysOn, CreateAlwaysOnGPIORegister(Quark_GPIOController.Registers.PortAData) }, { (long)Registers.PortAGPIOAlwaysOnDirection, CreateAlwaysOnGPIORegister(Quark_GPIOController.Registers.PortADataDirection) }, { (long)Registers.InterruptEnable, CreateAlwaysOnGPIORegister(Quark_GPIOController.Registers.InterruptEnable) }, { (long)Registers.InterruptMask, CreateAlwaysOnGPIORegister(Quark_GPIOController.Registers.InterruptMask) }, { (long)Registers.InterruptType, CreateAlwaysOnGPIORegister(Quark_GPIOController.Registers.InterruptType) }, { (long)Registers.InterruptPolarity, CreateAlwaysOnGPIORegister(Quark_GPIOController.Registers.InterruptPolarity) }, { (long)Registers.InterruptStatus, CreateAlwaysOnGPIORegister(Quark_GPIOController.Registers.InterruptStatus, FieldMode.Read) }, { (long)Registers.RawInterruptStatus, CreateAlwaysOnGPIORegister(Quark_GPIOController.Registers.RawInterruptStatus, FieldMode.Read) }, { (long)Registers.ClearInterrupt, CreateAlwaysOnGPIORegister(Quark_GPIOController.Registers.ClearInterrupt) }, { (long)Registers.PortAExternalPort, CreateAlwaysOnGPIORegister(Quark_GPIOController.Registers.PortAExternalPort, FieldMode.Read) }, { (long)Registers.InterruptBothEdgeType, CreateAlwaysOnGPIORegister(Quark_GPIOController.Registers.InterruptBothEdgeType) }, }; registers = new DoubleWordRegisterCollection(this, registerMap); Reset(); }
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() }, }); }
public STM32F7_USART() { sync = new object(); 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 PULP_uDMA_Camera(Machine machine) : base(machine) { IRQ = new GPIO(); RegistersCollection = new DoubleWordRegisterCollection(this); DefineRegisters(); }
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."); } }); }
public K6xF_RNG(Machine machine) { IRQ = new GPIO(); var registerMap = new Dictionary <long, DoubleWordRegister> { { (long)Registers.Control, new DoubleWordRegister(this) .WithReservedBits(5, 26) .WithFlag(4, out sleep, name: "SLP") .WithTaggedFlag("CLRI", 3) .WithTaggedFlag("INTM", 2) .WithTaggedFlag("HA", 1) .WithFlag(0, out enable, name: "GO") }, { (long)Registers.Status, new DoubleWordRegister(this) .WithReservedBits(24, 8) .WithValueField(16, 8, name: "OREG_SIZE") .WithValueField(8, 8, FieldMode.Read, valueProviderCallback: _ => (enable.Value) ? 1u : 0u, name: "OREG_LVL") .WithReservedBits(5, 3) .WithTaggedFlag("SLP", 4) .WithTaggedFlag("ERRI", 3) .WithTaggedFlag("ORU", 2) .WithTaggedFlag("LRS", 1) .WithTaggedFlag("SECV", 0) }, { (long)Registers.Entropy, new DoubleWordRegister(this) .WithValueField(0, 32, name: "EXT_ENT") }, { (long)Registers.Output, new DoubleWordRegister(this) .WithValueField(0, 32, FieldMode.Read, valueProviderCallback: _ => (enable.Value) ? unchecked ((uint)rng.Next()) : 0u, name: "RNDOUT") } }; registers = new DoubleWordRegisterCollection(this, registerMap); rng = EmulationManager.Instance.CurrentEmulation.RandomGenerator; }
public STM32F4_RNG(Machine machine) { IRQ = new GPIO(); var registerMap = new Dictionary <long, DoubleWordRegister> { { (long)Registers.Control, new DoubleWordRegister(this) .WithReservedBits(0, 2) .WithFlag(2, out enable, changeCallback: (_, value) => Update(), name: "RNGEN") .WithFlag(3, out interruptEnable, changeCallback: (_, value) => Update(), name: "IE") .WithReservedBits(4, 28) }, { (long)Registers.Status, new DoubleWordRegister(this) .WithFlag(0, FieldMode.Read, valueProviderCallback: _ => enable.Value, name: "DRDY") .WithTag("CECS", 1, 1) .WithTag("SECS", 2, 1) .WithReservedBits(3, 2) .WithTag("CEIS", 5, 1) .WithTag("SEIS", 6, 1) .WithReservedBits(7, 25) }, { (long)Registers.Data, new DoubleWordRegister(this) .WithValueField(0, 32, FieldMode.Read, valueProviderCallback: _ => { if (enable.Value) { return(unchecked ((uint)rng.Next())); } else { return(0); } }, name: "RNDATA") }, }; registers = new DoubleWordRegisterCollection(this, registerMap); }
private void DefineDMARegisters() { dmaRegisters = new DoubleWordRegisterCollection(this); DMARegisters.Base.Define(dmaRegisters, resetOffset) .WithValueField(0, 32, out bufferRegister, name: "base"); DMARegisters.Enable.Define(dmaRegisters) .WithFlag(0, writeCallback: (_, val) => { if (val) { var height = (int)vres.Value; var width = (int)hres.Value; bufferAddress = bufferRegister.Value; var memoryBase = (uint)machine.SystemBus.GetRegistrationPoints(memory).First().Range.StartAddress; bufferAddress += memoryBase; this.Log(LogLevel.Debug, "Reconfiguring screen to {0}x{1}", width, height); Reconfigure(width, height, format); } else { // it stops the repainter by passing nulls Reconfigure(); } }); }
private void SetupRegisters() { var control2 = new DoubleWordRegister(this); txBufferEmptyInterruptEnable = control2.DefineFlagField(7); rxBufferNotEmptyInterruptEnable = control2.DefineFlagField(6); txDmaEnable = control2.DefineFlagField(1); rxDmaEnable = control2.DefineFlagField(0, writeCallback: (_, __) => Update()); var registerDictionary = new Dictionary <long, DoubleWordRegister> { { (long)Registers.Control1, new DoubleWordRegister(this).WithValueField(3, 3, name: "Baud").WithFlag(2, name: "Master") .WithFlag(8, name: "SSI").WithFlag(9, name: "SSM").WithFlag(6, changeCallback: (oldValue, newValue) => { if (!newValue) { IRQ.Unset(); } }, name: "SpiEnable") }, { (long)Registers.Status, new DoubleWordRegister(this, 2).WithFlag(1, FieldMode.Read, name: "TXE").WithFlag(0, FieldMode.Read, valueProviderCallback: _ => receiveBuffer.Count != 0, name: "RXNE") }, { (long)Registers.CRCPolynomial, new DoubleWordRegister(this, 7).WithValueField(0, 16, name: "CRCPoly") }, { (long)Registers.I2SConfiguration, new DoubleWordRegister(this, 0).WithFlag(10, FieldMode.Read | FieldMode.WriteOneToClear, writeCallback: (oldValue, newValue) => { // write one to clear to keep this bit 0 if (newValue) { this.Log(LogLevel.Warning, "Trying to enable not supported I2S mode."); } }, name: "I2SE") }, { (long)Registers.Control2, control2 } }; registers = new DoubleWordRegisterCollection(this, registerDictionary); }
public PULP_uDMA_SPI(Machine machine) : base(machine) { RxIRQ = new GPIO(); TxIRQ = new GPIO(); CmdIRQ = new GPIO(); var registers = new Dictionary <long, DoubleWordRegister> { { (long)Registers.RxTransferAddress, new DoubleWordRegister(this) .WithValueField(0, 32, out rxTransferAddress, name: "SPIM_RX_SADDR") }, { (long)Registers.RxTransferBufferSize, new DoubleWordRegister(this) .WithValueField(0, 20, out rxTransferBufferSize, name: "SPIM_RX_SIZE") .WithReservedBits(20, 12) }, { (long)Registers.RxTransferConfiguration, new DoubleWordRegister(this) .WithTag("CONTINOUS", 0, 1) .WithTag("DATASIZE", 1, 2) .WithReservedBits(3, 1) .WithFlag(4, out rxEnable, name: "EN") .WithTag("CLR/PENDING", 5, 1) .WithReservedBits(6, 26) .WithWriteCallback((_, __) => TryStartReception()) }, { (long)Registers.TxTransferAddress, new DoubleWordRegister(this) .WithValueField(0, 32, out txTransferAddress, name: "SPIM_TX_SADDR") }, { (long)Registers.TxTransferBufferSize, new DoubleWordRegister(this) .WithValueField(0, 20, out txTransferBufferSize, name: "SPIM_TX_SIZE") .WithReservedBits(20, 12) }, { (long)Registers.TxTransferConfiguration, new DoubleWordRegister(this) .WithTag("CONTINOUS", 0, 1) .WithTag("DATASIZE", 1, 2) .WithReservedBits(3, 1) .WithFlag(4, out txEnable, name: "EN") .WithTag("CLR/PENDING", 5, 1) .WithReservedBits(6, 26) .WithWriteCallback((_, __) => TryStartTransmission()) }, { (long)Registers.CommandTransferAddress, new DoubleWordRegister(this) .WithValueField(0, 32, out commandTransferAddress, name: "SPIM_CMD_SADDR") }, { (long)Registers.CommandTransferBufferSize, new DoubleWordRegister(this) .WithTag("CMD_SIZE", 0, 20) .WithReservedBits(20, 12) }, { (long)Registers.CommandTransferConfiguration, new DoubleWordRegister(this) .WithTag("CONTINOUS", 0, 1) .WithTag("DATASIZE", 1, 2) .WithReservedBits(3, 1) .WithFlag(4, out commandEnable, name: "EN") .WithTag("CLR/PENDING", 5, 1) .WithReservedBits(6, 26) .WithWriteCallback((_, __) => TryExecuteTransaction()) }, }; registersCollection = new DoubleWordRegisterCollection(this, registers); Reset(); }
public NRF52840_UART(Machine machine, bool easyDMA = false) : base(machine) { this.easyDMA = easyDMA; IRQ = new GPIO(); interruptManager = new InterruptManager <Interrupts>(this); registers = new DoubleWordRegisterCollection(this, DefineRegisters()); }
public PULP_uDMA_UART(Machine machine) : base(machine) { IRQ = new GPIO(); var registersMap = new Dictionary <long, DoubleWordRegister> { { (long)Registers.RxBaseAddress, new DoubleWordRegister(this) .WithValueField(0, 32, out rxBufferAddress, name: "RX_SADDR / Rx buffer base address") }, { (long)Registers.RxSize, new DoubleWordRegister(this) .WithValueField(0, 17, out rxBufferSize, name: "RX_SIZE / Rx buffer size") }, { (long)Registers.RxConfig, new DoubleWordRegister(this) .WithFlag(4, out rxStart, name: "EN / RX channel enable and start", writeCallback: (_, value) => { if (rxBufferSize.Value != 0) { var data = new byte[rxBufferSize.Value]; for (var i = 0; i < rxBufferSize.Value; i++) { TryGetCharacter(out data[i]); } machine.SystemBus.WriteBytes(data, rxBufferAddress.Value, (int)rxBufferSize.Value, 0); } }) }, { (long)Registers.TxBaseAddress, new DoubleWordRegister(this) .WithValueField(0, 32, out txBufferAddress, name: "TX_SADDR / Tx buffer base address") }, { (long)Registers.TxSize, new DoubleWordRegister(this) .WithValueField(0, 17, out txBufferSize, name: "TX_SIZE / Tx buffer size") }, { (long)Registers.TxConfig, new DoubleWordRegister(this) .WithFlag(4, out txStart, name: "EN / TX channel enable and start", writeCallback: (_, value) => { if (txBufferSize.Value != 0) { var data = new byte[txBufferSize.Value]; machine.SystemBus.ReadBytes(txBufferAddress.Value, (int)txBufferSize.Value, data, 0); foreach (var c in data) { TransmitCharacter(c); } } }) }, { (long)Registers.Status, new DoubleWordRegister(this) .WithFlag(0, FieldMode.Read, valueProviderCallback: _ => false, name: "TX busy") // tx is never busy .WithFlag(1, FieldMode.Read, valueProviderCallback: _ => false, name: "RX busy") // rx is never busy }, { (long)Registers.Setup, new DoubleWordRegister(this) .WithFlag(0, out parityEnable, name: "PARITY_ENA / Parity Enable") .WithValueField(1, 2, out bitLength, name: "BIT_LENGTH / Character length") .WithFlag(3, out stopBits, name: "STOP_BITS / Stop bits length") .WithFlag(4, out pollingEnabled, name: "POLLING_EN / Polling Enabled") .WithFlag(5, out cleanFIFO, name: "CLEAN_FIFO / Clean RX FIFO") .WithFlag(8, out txEnabled, name: "TX_ENA / TX enabled") .WithFlag(9, out rxEnabled, name: "RX_ENA / RX enabled") .WithValueField(16, 16, out clockDivider, name: "CLKDIV / Clock divider") }, }; registers = new DoubleWordRegisterCollection(this, registersMap); }
public NRF52840_SPI(Machine machine) : base(machine) { IRQ = new GPIO(); receiveFifo = new Queue <byte>(); RegistersCollection = new DoubleWordRegisterCollection(this); DefineRegisters(); Reset(); }
// this method should be visible for enums only, but... it's not possible in C# public static DoubleWordRegister Define(this IConvertible o, DoubleWordRegisterCollection c, uint resetValue = 0, string name = "") { if (!o.GetType().IsEnum) { throw new ArgumentException("This method should be called on enumerated type"); } return(c.DefineRegister(Convert.ToInt64(o), resetValue)); }
public PSE_SDController(Machine machine) : base(machine) { IRQ = new GPIO(); WakeupIRQ = new GPIO(); irqManager = new InterruptManager <Interrupts>(this); RegistersCollection = new DoubleWordRegisterCollection(this); InitializeRegisters(); }
private void PrepareRegisters() { registers = new DoubleWordRegisterCollection(this, new Dictionary <long, DoubleWordRegister> { { (long)Registers.PortData, new DoubleWordRegister(this) .WithValueField(0, 32, writeCallback: (_, val) => { var bits = BitHelper.GetBits(val); for (int i = 0; i < bits.Length; i++) { if (PortDataDirection[i] == PinDirection.Output) { Connections[i].Set(bits[i]); State[i] = bits[i]; } } }) }, { (long)Registers.PortADataDirection, new DoubleWordRegister(this) .WithValueField(0, 32, writeCallback: (_, val) => Array.Copy(BitHelper.GetBits(val).Select(x => x ? PinDirection.Output : PinDirection.Input).ToArray(), PortDataDirection, 32), valueProviderCallback: _ => BitHelper.GetValueFromBitsArray(PortDataDirection.Select(x => x == PinDirection.Output))) }, { (long)Registers.InterruptEnable, new DoubleWordRegister(this) .WithValueField(0, 32, writeCallback: (_, val) => { Array.Copy(BitHelper.GetBits(val), InterruptEnable, 32); RefreshInterrupts(); }, valueProviderCallback: _ => BitHelper.GetValueFromBitsArray(InterruptEnable)) }, { (long)Registers.InterruptType, new DoubleWordRegister(this) // true = edge sensitive; false = level sensitive .WithValueField(0, 32, out interruptTypeField, writeCallback: (_, val) => CalculateInterruptTypes()) }, { (long)Registers.InterruptPolarity, new DoubleWordRegister(this) // true = rising edge / active high; false = falling edge / active low .WithValueField(0, 32, out interruptPolarityField, writeCallback: (_, val) => CalculateInterruptTypes()) }, { (long)Registers.InterruptBothEdgeType, new DoubleWordRegister(this) .WithValueField(0, 32, out interruptBothEdgeField, writeCallback: (_, val) => CalculateInterruptTypes()) }, { (long)Registers.InterruptMask, new DoubleWordRegister(this) .WithValueField(0, 32, writeCallback: (_, val) => { Array.Copy(BitHelper.GetBits(val), InterruptMask, 32); RefreshInterrupts(); }, valueProviderCallback: _ => BitHelper.GetValueFromBitsArray(InterruptMask)) }, { (long)Registers.ExternalPort, new DoubleWordRegister(this) .WithValueField(0, 32, FieldMode.Read, valueProviderCallback: _ => BitHelper.GetValueFromBitsArray(State)) }, { (long)Registers.ClearInterrupt, new DoubleWordRegister(this) .WithValueField(0, 32, FieldMode.Write, writeCallback: (_, val) => { foreach (var bit in BitHelper.GetSetBits(val)) { activeInterrupts[bit] = false; } RefreshInterrupts(); }) }, { (long)Registers.InterruptStatus, new DoubleWordRegister(this) .WithValueField(0, 32, FieldMode.Read, valueProviderCallback: _ => BitHelper.GetValueFromBitsArray(activeInterrupts.Zip(InterruptMask, (isActive, isMasked) => isActive && !isMasked))) }, { (long)Registers.RawInterruptStatus, new DoubleWordRegister(this) .WithValueField(0, 32, FieldMode.Read, valueProviderCallback: _ => BitHelper.GetValueFromBitsArray(activeInterrupts)) } }); }
protected PCIeBasePeripheral(IPCIeRouter parent, HeaderType headerType) { if (!IsHeaderAcceptable(headerType)) { throw new ConstructionException($"Currently only devices of type {HeaderType.Bridge} or {HeaderType.Endpoint} are supported."); } this.parent = parent; this.HeaderType = headerType; this.baseAddressRegisters = new BaseAddressRegister[headerType.MaxNumberOfBARs()]; var registerMap = new Dictionary <long, DoubleWordRegister> { { (long)Registers.DeviceAndVendorId, new DoubleWordRegister(this) .WithValueField(0, 16, FieldMode.Read, valueProviderCallback: _ => VendorId) .WithValueField(16, 16, FieldMode.Read, valueProviderCallback: _ => DeviceId) }, { (long)Registers.StatusAndConfiguration, new DoubleWordRegister(this) //unsupported fields do not have to be implemented. Maybe we should move it to inheriting classes? //First 16 bits: command register. RW. Writing 0 to these fields should effectively disable all accesses but the configuration accesses .WithTaggedFlag("I/O Space", 0) .WithTaggedFlag("Memory Space", 1) .WithTaggedFlag("Bus Master", 2) .WithTaggedFlag("Special Cycles", 3) .WithTaggedFlag("Memory Write and Invalidate Enable", 4) .WithTaggedFlag("VGA Palette Snoop", 5) .WithTaggedFlag("Parity Error Response", 6) .WithReservedBits(7, 1) .WithTaggedFlag("SERR# Enable", 8) .WithTaggedFlag("Fast Back-to-Back Enable", 9) .WithTaggedFlag("Interrupt Disable", 10) .WithReservedBits(11, 8) //Second 16 bits: status register. W1C. .WithTaggedFlag("Interrupt Status", 19) .WithFlag(20, FieldMode.Read, valueProviderCallback: _ => capabilities.Any(), name: "Capabilities List") .WithTaggedFlag("66 MHz Capabale", 21) .WithReservedBits(22, 1) .WithTaggedFlag("Fast Back-to-Back capable", 23) .WithTaggedFlag("Master Data Parity Error", 24) .WithTag("DEVSEL Timing", 25, 2) .WithTaggedFlag("Signaled Target Abort", 27) .WithTaggedFlag("Received Target Abort", 28) .WithTaggedFlag("Received Master Abort", 29) .WithTaggedFlag("Signaled System Error", 30) .WithTaggedFlag("Detected Parity Error", 31) }, { (long)Registers.ClassCode, new DoubleWordRegister(this) .WithValueField(0, 8, FieldMode.Read, valueProviderCallback: _ => RevisionId) .WithValueField(16, 16, FieldMode.Read, valueProviderCallback: _ => ClassCode) }, { (long)Registers.Header, new DoubleWordRegister(this) .WithTag("Cacheline Size", 0, 8) .WithTag("Latency Timer", 8, 8) .WithEnumField(16, 8, FieldMode.Read, valueProviderCallback: (HeaderType _) => headerType) .WithTag("BIST", 24, 8) }, { (long)Registers.Capabilities, new DoubleWordRegister(this) .WithValueField(0, 8, FieldMode.Read, valueProviderCallback: _ => capabilities.FirstOrDefault().Key) }, }; registers = new DoubleWordRegisterCollection(this, registerMap); AddCapability(0x80, new PCIeCapability(this)); }
private void DefineVTGRegisters() { vtgRegisters = new DoubleWordRegisterCollection(this); VTGRegisters.Hres.Define(vtgRegisters, resetHres) .WithValueField(0, 16, out hres, name: "h_res").WithReservedBits(16, 16); VTGRegisters.Vres.Define(vtgRegisters, resetVres) .WithValueField(0, 16, out vres, name: "v_res").WithReservedBits(16, 16); }
public NRF52840_I2C(Machine machine) : base(machine) { IRQ = new GPIO(); slaveToMasterBuffer = new Queue <byte>(); masterToSlaveBuffer = new Queue <byte>(); RegistersCollection = new DoubleWordRegisterCollection(this); DefineRegisters(); }
private void CreateRegisters() { var registersMap = new Dictionary <long, DoubleWordRegister> { { (long)Registers.StandardOutput, new DoubleWordRegister(this) .WithValueField(0, 16, FieldMode.Write, writeCallback: (_, val) => this.TransmitCharacter((byte)val), name: "STD_OUT") .WithReservedBits(16, 16) }, }; registers = new DoubleWordRegisterCollection(this, registersMap); }
public LiteSDCard_CSR32(Machine machine) : base(machine) { phyRegistersCollection = new DoubleWordRegisterCollection(this); coreRegistersCollection = new DoubleWordRegisterCollection(this); readerRegistersCollection = new DoubleWordRegisterCollection(this); writerRegistersCollection = new DoubleWordRegisterCollection(this); DefineRegisters(); responseBuffer = new byte[ResponseBufferLength]; }
public IMXRT_GPIO(Machine machine) : base(machine, NumberOfPins) { locker = new object(); IRQ = new GPIO(); registers = new DoubleWordRegisterCollection(this, BuildRegisterMap()); data = new bool[NumberOfPins]; directionOutNotIn = new bool[NumberOfPins]; interruptEnabled = new bool[NumberOfPins]; interruptRequest = new bool[NumberOfPins]; edgeSelect = new bool[NumberOfPins]; interruptConfig = new InterruptConfig[NumberOfPins]; }
private void CreateRegisters() { var regs = new Dictionary <long, DoubleWordRegister>() { { (long)Registers.ExternalInterruptPortSelectLow, new DoubleWordRegister(this) .WithValueField(0, 32, changeCallback: (oldValue, newValue) => ReroutePort(oldValue, newValue, false), name: "EXTIPSEL") }, { (long)Registers.ExternalInterruptPortSelectHigh, new DoubleWordRegister(this) .WithValueField(0, 32, changeCallback: (oldValue, newValue) => ReroutePort(oldValue, newValue, true), name: "EXTIPSEL") }, { (long)Registers.ExternalInterruptPinSelectLow, new DoubleWordRegister(this, 0x32103210) .WithValueField(0, 32, changeCallback: (oldValue, newValue) => ReroutePin(oldValue, newValue, false), name: "EXTIPINSEL") }, { (long)Registers.ExternalInterruptPinSelectHigh, new DoubleWordRegister(this, 0x32103210) .WithValueField(0, 32, changeCallback: (oldValue, newValue) => ReroutePin(oldValue, newValue, true), name: "EXTIPINSEL") }, { (long)Registers.ExternalInterruptRisingEdgeTrigger, new DoubleWordRegister(this) .WithValueField(0, 16, changeCallback: (_, value) => SetEdgeSensitivity(value, InterruptTrigger.RisingEdge)) }, { (long)Registers.ExternalInterruptFallingEdgeTrigger, new DoubleWordRegister(this) .WithValueField(0, 16, changeCallback: (_, value) => SetEdgeSensitivity(value, InterruptTrigger.FallingEdge)) }, { (long)Registers.InterruptFlag, new DoubleWordRegister(this) .WithValueField(0, 16, FieldMode.Read, valueProviderCallback: (_) => BitHelper.GetValueFromBitsArray(externalInterrupt), name: "EXT") .WithTag("EM4WU", 16, 16) }, { (long)Registers.InterruptFlagSet, new DoubleWordRegister(this) .WithValueField(0, 16, FieldMode.Write, writeCallback: (_, value) => UpdateExternalInterruptBits(value, true), name: "EXT") .WithTag("EM4WU", 16, 16) }, { (long)Registers.InterruptFlagClear, new DoubleWordRegister(this) .WithValueField(0, 16, writeCallback: (_, value) => UpdateExternalInterruptBits(value, false), valueProviderCallback: (_) => { var result = BitHelper.GetValueFromBitsArray(externalInterrupt); for (var i = 0; i < NumberOfExternalInterrupts; ++i) { externalInterrupt[i] = false; } UpdateInterrupts(); return(result); }, name: "EXT") .WithTag("EM4WU", 16, 16) }, { (long)Registers.InterruptEnable, new DoubleWordRegister(this) .WithValueField(0, 16, writeCallback: (_, value) => { Array.Copy(BitHelper.GetBits(value), interruptEnable, NumberOfExternalInterrupts); UpdateInterrupts(); }, valueProviderCallback: (_) => BitHelper.GetValueFromBitsArray(interruptEnable), name: "EXT") .WithTag("EM4WU", 16, 16) }, { (long)Registers.ConfigurationLock, new DoubleWordRegister(this) .WithValueField(0, 16, writeCallback: (_, value) => configurationLocked = (value != UnlockCode), valueProviderCallback: (_) => configurationLocked ? 1 : 0u, name: "LOCKKEY") }, }; for (var i = 0; i < NumberOfPorts; ++i) { CreatePortRegisters(regs, i); } registers = new DoubleWordRegisterCollection(this, regs); }
private void CreateRegisters() { var control1 = new DoubleWordRegister(this).WithFlag(15, writeCallback: SoftwareResetWrite, name: "SWRST").WithFlag(9, FieldMode.Read, name: "StopGen", writeCallback: StopWrite) .WithFlag(8, FieldMode.Read, writeCallback: StartWrite, name: "StartGen").WithFlag(0, writeCallback: PeripheralEnableWrite, name: "PeriEn"); var control2 = new DoubleWordRegister(this).WithValueField(0, 6, name: "Freq"); var status1 = new DoubleWordRegister(this); var status2 = new DoubleWordRegister(this); data = new DoubleWordRegister(this); acknowledgeEnable = control1.DefineFlagField(10); bufferInterruptEnable = control2.DefineFlagField(10, changeCallback: InterruptEnableChange); eventInterruptEnable = control2.DefineFlagField(9, changeCallback: InterruptEnableChange); errorInterruptEnable = control2.DefineFlagField(8); dataRegister = data.DefineValueField(0, 8, readCallback: DataRead, writeCallback: DataWrite); acknowledgeFailed = status1.DefineFlagField(10, FieldMode.ReadToClear | FieldMode.WriteZeroToClear, changeCallback: (_, __) => Update()); dataRegisterEmpty = status1.DefineFlagField(7, FieldMode.Read); dataRegisterNotEmpty = status1.DefineFlagField(6, FieldMode.Read); byteTransferFinished = status1.DefineFlagField(2, FieldMode.Read); addressSentOrMatched = status1.DefineFlagField(1, FieldMode.Read, readCallback: (_, __) => { if (state == State.StartInitiated) { state = State.AwaitingAddress; } }); startBit = status1.DefineFlagField(0, FieldMode.Read); transmitterReceiver = status2.DefineFlagField(2, FieldMode.Read); masterSlave = status2.DefineFlagField(0, FieldMode.Read, readCallback: (_, __) => { addressSentOrMatched.Value = false; dataRegisterNotEmpty.Value |= state == State.HasDataToRead; Update(); }); var registerDictionary = new Dictionary <long, DoubleWordRegister> { { (long)Registers.RiseTime, DoubleWordRegister.CreateRWRegister(0x2) }, { (long)Registers.ClockControl, DoubleWordRegister.CreateRWRegister() }, { (long)Registers.OwnAddress1, DoubleWordRegister.CreateRWRegister() }, { (long)Registers.OwnAddress2, DoubleWordRegister.CreateRWRegister() }, { (long)Registers.NoiseFilter, DoubleWordRegister.CreateRWRegister() }, { (long)Registers.Control1, control1 }, { (long)Registers.Control2, control2 }, { (long)Registers.Status1, status1 }, { (long)Registers.Status2, status2 }, { (long)Registers.Data, data }, }; registers = new DoubleWordRegisterCollection(this, registerDictionary); }
public PULP_uDMA_I2C(Machine machine) : base(machine) { outputBuffer = new Queue <byte>(); RegistersCollection = new DoubleWordRegisterCollection(this); TxEvent = new GPIO(); RxEvent = new GPIO(); DefineRegisters(); Reset(); }