1 //
2 // Copyright (c) 2010-2022 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 Antmicro.Migrant;
9 using Antmicro.Renode.Logging;
10 using Antmicro.Renode.Peripherals.Bus;
11 
12 namespace Antmicro.Renode.Peripherals.UART
13 {
14     /// <summary>
15     /// Trivial UART peripheral. Contains a single 32-bit register which can only be written to. Only the lowest 8 bytes matter.
16     /// </summary>
17     [AllowedTranslations(AllowedTranslation.ByteToDoubleWord | AllowedTranslation.WordToDoubleWord)]
18     public class TrivialUart : IDoubleWordPeripheral, IUART, IKnownSize
19     {
TrivialUart()20         public TrivialUart()
21         {
22             Reset();
23         }
24 
ReadDoubleWord(long offset)25         public uint ReadDoubleWord(long offset)
26         {
27             this.LogUnhandledRead(offset);
28             return 0x0;
29         }
30 
Reset()31         public void Reset()
32         {
33             // Intentionally left empty.
34         }
35 
WriteChar(byte value)36         public void WriteChar(byte value)
37         {
38             // Intentionally left empty. This UART provides only a one-way communication.
39         }
40 
WriteDoubleWord(long offset, uint value)41         public void WriteDoubleWord(long offset, uint value)
42         {
43             this.NoisyLog("Received 0x{0:X}", value);
44             CharReceived?.Invoke((byte)value);
45         }
46 
47         public uint BaudRate => 0;
48         public Parity ParityBit => Parity.None;
49         public long Size => 0x4;
50         public Bits StopBits => Bits.None;
51 
52         [field: Transient]
53         public event Action<byte> CharReceived;
54     }
55 }
56 
57