public PicoRV_SPI(Machine machine) : base(machine) { bbHelper = new BitBangHelper(8, loggingParent: this, outputMsbFirst: true); var registers = new Dictionary <long, DoubleWordRegister> { { (long)Registers.Config1, new DoubleWordRegister(this) .WithFlag(0, out var data0, FieldMode.Write, name: "data0") .WithFlag(1, FieldMode.Write, name: "data1") // data 1-3 used in QSPI only .WithFlag(2, FieldMode.Write, name: "data2") .WithFlag(3, FieldMode.Write, name: "data3") .WithFlag(4, out var clock, FieldMode.Write, name: "clk") .WithFlag(5, out var chipSelectNegated, FieldMode.Write, name: "cs_n") .WithReservedBits(6, 2) .WithWriteCallback((_, val) => { if (memioEnable.Value) { this.Log(LogLevel.Warning, "MEMIO mode not enabled - bit banging not supported in this mode"); return; } if (qspiEnable.Value) { this.Log(LogLevel.Warning, "QSPI mode not yet supported"); return; } if (RegisteredPeripheral == null) { this.Log(LogLevel.Warning, "Trying to send bytes over SPI, but there is no device attached"); return; } if (chipSelectNegated.Value && !previousChipSelectNegated) { this.Log(LogLevel.Noisy, "ChipSelect signal down - finishing the transmission"); RegisteredPeripheral.FinishTransmission(); bbHelper.ResetOutput(); } previousChipSelectNegated = chipSelectNegated.Value; // do not latch bits when MEMIO is enabled or chipSelect is not set if (bbHelper.Update(clock.Value, data0.Value, !memioEnable.Value && !chipSelectNegated.Value)) { this.Log(LogLevel.Noisy, "Sending byte 0x{0:X}", bbHelper.DecodedOutput); var input = RegisteredPeripheral.Transmit((byte)bbHelper.DecodedOutput); this.Log(LogLevel.Noisy, "Received byte 0x{0:X}", input); bbHelper.SetInputBuffer(input); } }) },
public LiteX_SPI_Flash(Machine machine) : base(machine) { bbHelper = new BitBangHelper(8, loggingParent: this, outputMsbFirst: true); var registers = new Dictionary <long, DoubleWordRegister> { { (long)Registers.BitBang, new DoubleWordRegister(this) .WithFlag(0, out var valueSignal, FieldMode.Write, name: "value") .WithFlag(1, out var clockSignal, FieldMode.Write, name: "clk") .WithFlag(2, out var chipSelectNegatedSignal, FieldMode.Write, name: "cs_n") .WithFlag(3, out var dqInputSignal, FieldMode.Write, name: "dq_input") .WithWriteCallback((_, val) => { if (!bitBangEnabled.Value) { this.Log(LogLevel.Warning, "Write to not-enabled BitBang register ignored"); return; } if (RegisteredPeripheral == null) { this.Log(LogLevel.Warning, "Trying to send bytes over SPI, but there is no device attached"); return; } if (chipSelectNegatedSignal.Value && !previousChipSelectNegatedSignal) { this.Log(LogLevel.Noisy, "ChipSelect signal down - finishing the transmission"); RegisteredPeripheral.FinishTransmission(); } previousChipSelectNegatedSignal = chipSelectNegatedSignal.Value; // do not latch bits when dqInputSignal is set or chipSelect is not set if (bbHelper.Update(clockSignal.Value, valueSignal.Value, !dqInputSignal.Value && !chipSelectNegatedSignal.Value)) { this.Log(LogLevel.Noisy, "Sending byte 0x{0:X}", bbHelper.DecodedOutput); var input = RegisteredPeripheral.Transmit((byte)bbHelper.DecodedOutput); this.Log(LogLevel.Noisy, "Received byte 0x{0:X}", input); bbHelper.SetInputBuffer(input); } }) },
public LiteX_Ethernet(Machine machine, int numberOfWriteSlots = 2, int numberOfReadSlots = 2) : base(machine) { Interlocked.Add(ref NumberOfInstances, 1); MAC = MACAddress.Parse("10:e2:d5:00:00:00").Next(NumberOfInstances - 1); writeSlots = new Slot[numberOfWriteSlots]; readSlots = new Slot[numberOfReadSlots]; for (var i = 0; i < numberOfWriteSlots; i++) { writeSlots[i] = new Slot(); } for (var i = 0; i < numberOfReadSlots; i++) { readSlots[i] = new Slot(); } bbHelper = new BitBangHelper(width: 16, loggingParent: this); RegistersCollection = new DoubleWordRegisterCollection(this); DefineRegisters(); }