1 // 2 // Copyright (c) 2010-2023 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 System.Collections.Generic; 9 using Antmicro.Migrant; 10 using Antmicro.Renode.Core; 11 using Antmicro.Renode.Logging; 12 using Antmicro.Renode.Peripherals.Bus; 13 using Antmicro.Renode.Core.Structure.Registers; 14 15 namespace Antmicro.Renode.Peripherals.UART 16 { 17 public class SmartbondUART : UARTBase, IDoubleWordPeripheral, IKnownSize 18 { SmartbondUART(IMachine machine)19 public SmartbondUART(IMachine machine) : base(machine) 20 { 21 IRQ = new GPIO(); 22 23 var registersMap = new Dictionary<long, DoubleWordRegister>(); 24 25 registersMap.Add((long)Registers.TransmitReceiveBuffer, new DoubleWordRegister(this) 26 .WithValueField(0, 8, name: "RBR_THR_DLL", writeCallback: (_, v) => TransmitCharacter((byte)v)) 27 .WithReservedBits(8, 24) 28 ); 29 30 registersMap.Add((long)Registers.StatusRegister, new DoubleWordRegister(this) 31 .WithFlag(0, FieldMode.Read, name: "UART_BUSY - UART Busy", valueProviderCallback: _ => false) 32 .WithFlag(1, FieldMode.Read, name: "UART_TFNF - Transmit FIFO Not Full", valueProviderCallback: _ => true) 33 .WithFlag(2, FieldMode.Read, name: "UART_TFE - Transmit FIFO Empty", valueProviderCallback: _ => true) 34 .WithFlag(3, FieldMode.Read, name: "UART_RFNE - Receive FIFO Not Empty", valueProviderCallback: _ => Count > 0) 35 .WithFlag(4, FieldMode.Read, name: "UART_RFFE - Receive FIFO Full", valueProviderCallback: _ => Count >= MaxFifoCount) 36 .WithReservedBits(5, 27) 37 ); 38 39 registers = new DoubleWordRegisterCollection(this, registersMap); 40 } 41 Reset()42 public override void Reset() 43 { 44 base.Reset(); 45 registers.Reset(); 46 } 47 ReadDoubleWord(long offset)48 public uint ReadDoubleWord(long offset) 49 { 50 return registers.Read(offset); 51 } 52 WriteDoubleWord(long offset, uint value)53 public void WriteDoubleWord(long offset, uint value) 54 { 55 registers.Write(offset, value); 56 } 57 58 public override uint BaudRate => 0; 59 public override Parity ParityBit => Parity.None; 60 public override Bits StopBits => Bits.None; 61 62 public long Size => 0x100; 63 64 public GPIO IRQ { get; } 65 CharWritten()66 protected override void CharWritten() 67 { 68 // intentionally left blank 69 } 70 QueueEmptied()71 protected override void QueueEmptied() 72 { 73 // intentionally left blank 74 } 75 76 private readonly DoubleWordRegisterCollection registers; 77 78 private const int MaxFifoCount = 16; 79 80 private enum Registers 81 { 82 TransmitReceiveBuffer = 0x0, 83 StatusRegister = 0x7C 84 } 85 } 86 } 87 88