1 // 2 // Copyright (c) 2010-2018 Antmicro 3 // 4 // This file is licensed under the MIT License. 5 // Full license text is available in 'licenses/MIT.txt'. 6 // 7 using System.Collections.Generic; 8 using Antmicro.Renode.Peripherals.Bus; 9 using Antmicro.Renode.Core.Structure.Registers; 10 using Antmicro.Renode.Core; 11 using Antmicro.Renode.Logging; 12 13 namespace Antmicro.Renode.Peripherals.UART 14 { 15 public class PicoSoC_SimpleUART : UARTBase, IDoubleWordPeripheral, IKnownSize 16 { PicoSoC_SimpleUART(IMachine machine)17 public PicoSoC_SimpleUART(IMachine machine) : base(machine) 18 { 19 var registersMap = new Dictionary<long, DoubleWordRegister> 20 { 21 {(long)Registers.ClockDivider, new DoubleWordRegister(this) 22 .WithValueField(0, 32, name: "clkdiv") 23 }, 24 {(long)Registers.RxTx, new DoubleWordRegister(this) 25 .WithValueField(0, 32, writeCallback: (_, value) => this.TransmitCharacter((byte)value), 26 valueProviderCallback: _ => 27 { 28 if(!TryGetCharacter(out var character)) 29 { 30 return 0xFFFFFFFF; 31 } 32 return character; 33 }, name: "data") 34 }, 35 }; 36 registers = new DoubleWordRegisterCollection(this, registersMap); 37 } 38 ReadDoubleWord(long offset)39 public uint ReadDoubleWord(long offset) 40 { 41 return registers.Read(offset); 42 } 43 Reset()44 public override void Reset() 45 { 46 base.Reset(); 47 registers.Reset(); 48 } 49 WriteDoubleWord(long offset, uint value)50 public void WriteDoubleWord(long offset, uint value) 51 { 52 registers.Write(offset, value); 53 } 54 55 public long Size => 0x100; 56 57 public override Bits StopBits => Bits.One; 58 59 public override Parity ParityBit => Parity.None; 60 61 public override uint BaudRate => 115200; 62 CharWritten()63 protected override void CharWritten() 64 { 65 // intentionally left blank 66 } 67 QueueEmptied()68 protected override void QueueEmptied() 69 { 70 // intentionally left blank 71 } 72 73 private readonly DoubleWordRegisterCollection registers; 74 75 private enum Registers : long 76 { 77 ClockDivider = 0x0, 78 RxTx = 0x04, 79 } 80 } 81 } 82