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.Utilities;
8 using Antmicro.Renode.Logging;
9 using static Antmicro.Renode.Peripherals.SPI.Cadence_xSPI;
10 
11 namespace Antmicro.Renode.Peripherals.SPI.Cadence_xSPICommands
12 {
13     internal abstract class AutoCommand : Command
14     {
CreateAutoCommand(Cadence_xSPI controller, CommandPayload payload)15         static public AutoCommand CreateAutoCommand(Cadence_xSPI controller, CommandPayload payload)
16         {
17             var commandMode = DecodeCommandMode(payload);
18             switch(commandMode)
19             {
20                 case CommandMode.PIO:
21                     return PIOCommand.CreatePIOCommand(controller, payload);
22                 default:
23                     controller.Log(LogLevel.Warning, "Unable to create the auto command, unknown command mode 0x{0:x}", commandMode);
24                     return null;
25             }
26         }
27 
AutoCommand(Cadence_xSPI controller, CommandPayload payload)28         public AutoCommand(Cadence_xSPI controller, CommandPayload payload) : base(controller)
29         {
30             mode = DecodeCommandMode(payload);
31             ChipSelect = BitHelper.GetValue(payload[0], 20, 3);
32         }
33 
ToString()34         public override string ToString()
35         {
36             return $"{base.ToString()}, commandMode = {mode}";
37         }
38 
39         public override uint ChipSelect { get; }
40 
41         protected CommandMode mode;
42 
DecodeCommandMode(CommandPayload payload)43         static private CommandMode DecodeCommandMode(CommandPayload payload)
44         {
45             return (CommandMode)BitHelper.GetValue(payload[0], 30, 2);
46         }
47 
48         protected enum CommandMode
49         {
50             PIO = 0x1
51         }
52     }
53 }
54