1 //
2 // Copyright (c) 2010-2021 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.Renode.Core;
10 using Antmicro.Renode.Core.Structure.Registers;
11 using Antmicro.Renode.Peripherals.Bus;
12 
13 namespace Antmicro.Renode.Peripherals.UART
14 {
15     public class PULP_STDOUT : UARTBase, IDoubleWordPeripheral, IKnownSize
16     {
PULP_STDOUT(IMachine machine)17         public PULP_STDOUT(IMachine machine) : base(machine)
18         {
19             CreateRegisters();
20         }
21 
ReadDoubleWord(long offset)22         public uint ReadDoubleWord(long offset)
23         {
24             return registers.Read(offset);
25         }
26 
WriteDoubleWord(long offset, uint value)27         public void WriteDoubleWord(long offset, uint value)
28         {
29             registers.Write(offset, value);
30         }
31 
Reset()32         public override void Reset()
33         {
34             base.Reset();
35             registers.Reset();
36         }
37 
38         public long Size => 0x4;
39 
40         // None of those properties are used, we need them only to keep the compiler happy
41         public override Bits StopBits => Bits.One;
42         public override Parity ParityBit => Parity.None;
43         public override uint BaudRate => 0;
44 
CharWritten()45         protected override void CharWritten()
46         {
47             // intentionally left blank
48         }
49 
QueueEmptied()50         protected override void QueueEmptied()
51         {
52             // intentionally left blank
53         }
54 
CreateRegisters()55         private void CreateRegisters()
56         {
57             var registersMap = new Dictionary<long, DoubleWordRegister>
58             {
59                 {(long)Registers.StandardOutput, new DoubleWordRegister(this)
60                     .WithValueField(0, 16, FieldMode.Write, writeCallback: (_, val) => this.TransmitCharacter((byte)val), name: "STD_OUT")
61                     .WithReservedBits(16, 16)
62                 },
63             };
64             registers = new DoubleWordRegisterCollection(this, registersMap);
65         }
66 
67         private DoubleWordRegisterCollection registers;
68 
69         private enum Registers : long
70         {
71             StandardOutput = 0,
72         }
73     }
74 }
75