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.Collections.Generic; 8 using Antmicro.Renode.Peripherals.Bus; 9 using Antmicro.Renode.Core; 10 using Antmicro.Renode.Core.Structure.Registers; 11 using Antmicro.Renode.Logging; 12 13 namespace Antmicro.Renode.Peripherals.UART 14 { 15 public class Infineon_SCBUART : UARTBase, IDoubleWordPeripheral, IKnownSize 16 { Infineon_SCBUART(IMachine machine)17 public Infineon_SCBUART(IMachine machine) : base(machine) 18 { 19 IRQ = new GPIO(); 20 21 var registersMap = new Dictionary<long, DoubleWordRegister>(); 22 registersMap.Add((long)Registers.TxFifoWrite, new DoubleWordRegister(this) 23 .WithValueField(0, 8, FieldMode.Write, name: "DATA - Data", 24 writeCallback: (_, v) => TransmitCharacter((byte)v)) 25 .WithReservedBits(8, 24) 26 ); 27 28 registers = new DoubleWordRegisterCollection(this, registersMap); 29 } 30 Reset()31 public override void Reset() 32 { 33 base.Reset(); 34 registers.Reset(); 35 } 36 ReadDoubleWord(long offset)37 public uint ReadDoubleWord(long offset) 38 { 39 return registers.Read(offset);; 40 } 41 WriteDoubleWord(long offset, uint value)42 public void WriteDoubleWord(long offset, uint value) 43 { 44 registers.Write(offset, value); 45 } 46 47 public GPIO IRQ { get; } 48 49 public override uint BaudRate => 115200; 50 public override Parity ParityBit => Parity.None; 51 public override Bits StopBits => Bits.One; 52 53 public long Size => 0x10000; 54 CharWritten()55 protected override void CharWritten() 56 { 57 // intentionally left blank 58 } 59 QueueEmptied()60 protected override void QueueEmptied() 61 { 62 // intentionally left blank 63 } 64 65 private readonly DoubleWordRegisterCollection registers; 66 67 private enum Registers 68 { 69 Control = 0x0, 70 UartControl = 0x40, 71 TxControl = 0x200, 72 TxFifoControl = 0x204, 73 TxFifoStatus = 0x208, 74 TxFifoWrite = 0x240, 75 RxControl = 0x300, 76 RxFifoControl = 0x304, 77 RxMatch = 0x310, 78 IntrTxMask = 0xF88, 79 IntrRxMask = 0xFC8, 80 } 81 } 82 } 83