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 Antmicro.Renode.Peripherals.Bus;
8 using Antmicro.Renode.Core;
9 using System.Collections.Generic;
10 using Antmicro.Renode.Core.Structure.Registers;
11 
12 namespace Antmicro.Renode.Peripherals.UART
13 {
14     public class XMC4XXX_UART : UARTBase, IDoubleWordPeripheral, IKnownSize
15     {
XMC4XXX_UART(IMachine machine)16         public XMC4XXX_UART(IMachine machine) : base(machine)
17         {
18             var registersMap = new Dictionary<long, DoubleWordRegister>();
19 
20             registersMap.Add((long)Registers.KernelStateConfiguration, new DoubleWordRegister(this)
21                 .WithFlag(0, name: "MODEN - Module Enable")
22                 .WithTaggedFlag("BPMODEN - Bit Protection for MODEN", 1)
23                 .WithReservedBits(2, 2)
24                 .WithTag("NOMCFG - Normal Operation Mode Configuration", 4, 2)
25                 .WithReservedBits(6, 1)
26                 .WithTaggedFlag("BPNOM - Bit Protection for NOMCFG", 7)
27                 .WithTag("SUMCFG - Suspend Mode Configuration", 8, 2)
28                 .WithReservedBits(10, 1)
29                 .WithTaggedFlag("BPSUM - Bit Protection for SUMCFG", 11)
30                 .WithReservedBits(12, 20)
31             );
32 
33             registersMap.Add((long)Registers.TransmitBufferInput0, new DoubleWordRegister(this)
34                 .WithValueField(0, 16, name: "TDATA - Transmit Data", writeCallback: (_, v) => TransmitCharacter((byte)v))
35                 .WithReservedBits(16, 16)
36             );
37 
38             TxInterrupt = new GPIO();
39             RxInterrupt = new GPIO();
40 
41             registers = new DoubleWordRegisterCollection(this, registersMap);
42         }
43 
Reset()44         public override void Reset()
45         {
46             base.Reset();
47             registers.Reset();
48         }
49 
ReadDoubleWord(long offset)50         public uint ReadDoubleWord(long offset)
51         {
52             return registers.Read(offset);
53         }
54 
WriteDoubleWord(long offset, uint val)55         public void WriteDoubleWord(long offset, uint val)
56         {
57             registers.Write(offset, val);
58         }
59 
60         public GPIO TxInterrupt { get; }
61         public GPIO RxInterrupt { get; }
62 
63         public override Bits StopBits => Bits.One;
64 
65         public override Parity ParityBit => Parity.None;
66 
67         public override uint BaudRate => 115200;
68 
69         public long Size => 0x200;
70 
CharWritten()71         protected override void CharWritten()
72         {
73             // intentionally left blank
74         }
75 
QueueEmptied()76         protected override void QueueEmptied()
77         {
78             // intentionally left blank
79         }
80 
81         private readonly DoubleWordRegisterCollection registers;
82 
83         private enum Registers
84         {
85             KernelStateConfiguration = 0xC,
86             TransmitBufferInput0 = 0x80,
87         }
88     }
89 }
90