1 // 2 // Copyright (c) 2010-2024 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; 8 using Antmicro.Migrant; 9 using Antmicro.Renode.Core; 10 using Antmicro.Renode.Logging; 11 using Antmicro.Renode.Peripherals.Bus; 12 using Antmicro.Renode.Core.Structure.Registers; 13 14 namespace Antmicro.Renode.Peripherals.UART 15 { 16 [AllowedTranslations(AllowedTranslation.ByteToDoubleWord | AllowedTranslation.WordToDoubleWord)] 17 public class SI32_USART : UARTBase, IDoubleWordPeripheral, IKnownSize, IProvidesRegisterCollection<DoubleWordRegisterCollection> 18 { SI32_USART(IMachine machine)19 public SI32_USART(IMachine machine) : base(machine) 20 { 21 RegistersCollection = new DoubleWordRegisterCollection(this); 22 IRQ = new GPIO(); 23 DefineRegisters(); 24 25 Reset(); 26 } 27 Reset()28 public override void Reset() 29 { 30 RegistersCollection.Reset(); 31 base.Reset(); 32 } 33 ReadDoubleWord(long offset)34 public uint ReadDoubleWord(long offset) 35 { 36 return RegistersCollection.Read(offset); 37 } 38 WriteDoubleWord(long offset, uint value)39 public void WriteDoubleWord(long offset, uint value) 40 { 41 RegistersCollection.Write(offset, value); 42 } 43 44 // IRQ is not supported yet 45 public GPIO IRQ { get; } 46 47 public DoubleWordRegisterCollection RegistersCollection { get; } 48 49 public long Size => 0x100; 50 51 public override uint BaudRate => 0; 52 public override Parity ParityBit => Parity.None; 53 public override Bits StopBits => Bits.None; 54 CharWritten()55 protected override void CharWritten() 56 { 57 } 58 QueueEmptied()59 protected override void QueueEmptied() 60 { 61 } 62 DefineRegisters()63 private void DefineRegisters() 64 { 65 // in the current implementation we rely on the callbacks ordering 66 Registers.Data.Define(this) 67 .WithValueField(0, 8, name: "DATA", 68 valueProviderCallback: _ => 69 { 70 if(!TryGetCharacter(out var c)) 71 { 72 this.Log(LogLevel.Warning, "Tried to read an empty data register"); 73 } 74 return c; 75 }, 76 writeCallback: (_, value) => TransmitCharacter((byte)value)) 77 .WithReservedBits(8, 24); 78 } 79 80 private enum Registers 81 { 82 Config = 0x0, 83 ConfigSet = 0x4, 84 ConfigClr = 0x8, 85 Reserved0 = 0xc, 86 Mode = 0x10, 87 ModeSet = 0x14, 88 ModeClr = 0x18, 89 Reserved1 = 0x1c, 90 Flowcn = 0x20, 91 FlowcnSet = 0x24, 92 FlowcnClr = 0x28, 93 Reserved2 = 0x2c, 94 Control = 0x30, 95 ControlSet = 0x34, 96 ControlClr = 0x38, 97 Reserved3 = 0x3c, 98 IPDelay = 0x40, 99 Reserved4 = 0x44, 100 Reserved5 = 0x48, 101 Reserved6 = 0x4c, 102 Baudrate = 0x50, 103 Reserved7 = 0x54, 104 Reserved8 = 0x58, 105 Reserved9 = 0x5c, 106 FIFOCn = 0x60, 107 FIFOCnSet = 0x64, 108 FIFOCnClr = 0x68, 109 Reserved10 = 0x6c, 110 Data = 0x70, 111 Reserved11 = 0x74, 112 Reserved12 = 0x78, 113 Reserved13 = 0x7c, 114 } 115 } 116 } 117 118