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 LINFlexD_UART : UARTBase, IDoubleWordPeripheral, IKnownSize
16     {
LINFlexD_UART(IMachine machine)17         public LINFlexD_UART(IMachine machine) : base(machine)
18         {
19             IRQ = new GPIO();
20 
21             var registersMap = new Dictionary<long, DoubleWordRegister>();
22             registersMap.Add((long)Registers.BufferDataLS, new DoubleWordRegister(this)
23                 .WithValueField(0, 8, FieldMode.Write, name: "DATA - Data",
24                         writeCallback: (_, v) => TransmitCharacter((byte)v))
25                     .WithReservedBits(8, 24)
26                 );
27             registersMap.Add((long)Registers.UARTModeStatus, new DoubleWordRegister(this)
28                 .WithReservedBits(0,1)
29                 .WithFlag(1, FieldMode.Read, name: "DTFTFF", valueProviderCallback: _ => true)
30                 .WithReservedBits(2,30));
31 
32             registers = new DoubleWordRegisterCollection(this, registersMap);
33         }
34 
Reset()35         public override void Reset()
36         {
37             base.Reset();
38             registers.Reset();
39         }
40 
ReadDoubleWord(long offset)41         public uint ReadDoubleWord(long offset)
42         {
43             return registers.Read(offset);;
44         }
45 
WriteDoubleWord(long offset, uint value)46         public void WriteDoubleWord(long offset, uint value)
47         {
48             registers.Write(offset, value);
49         }
50 
51         public GPIO IRQ { get; }
52 
53         public override uint BaudRate => 115200;
54         public override Parity ParityBit => Parity.None;
55         public override Bits StopBits => Bits.One;
56 
57         public long Size => 0x1000;
58 
CharWritten()59         protected override void CharWritten()
60         {
61             // intentionally left blank
62         }
63 
QueueEmptied()64         protected override void QueueEmptied()
65         {
66             // intentionally left blank
67         }
68 
69         private readonly DoubleWordRegisterCollection registers;
70 
71         private enum Registers
72         {
73             LINControl1 = 0x0,
74             LINInterruptEnable = 0x4,
75             LINStatus = 0x8,
76             LINErrorStatus = 0xc,
77             UARTModeControl = 0x10,
78             UARTModeStatus = 0x14,
79             LINTimeOutControlStatus = 0x18,
80             LINOutputCompare = 0x1c,
81             LINTimeOutControl = 0x20,
82             LINFractionalBaudRate = 0x24,
83             LINIntegerBaudRate = 0x28,
84             LINChecksumField = 0x2c,
85             LINControl2 = 0x30,
86             BufferIdentifier = 0x34,
87             BufferDataLS = 0x38,
88             BufferDataMS = 0x3c,
89             GlobalControl = 0x4c,
90             UARTPresetTimeout = 0x50,
91             UARTCurrentTimeout = 0x54,
92             DMATXEnable = 0x58,
93             DMARXEnable = 0x5c
94         }
95     }
96 }
97