1 //
2 // Copyright (c) 2010-2024 Antmicro
3 // Copyright (c) 2011-2015 Realtime Embedded
4 //
5 // This file is licensed under the MIT License.
6 // Full license text is available in 'licenses/MIT.txt'.
7 //
8 using Antmicro.Renode.Peripherals.SPI;
9 using Antmicro.Renode.Core.Structure;
10 using Antmicro.Renode.Core;
11 using System;
12 
13 namespace Antmicro.Renode.Peripherals.SD
14 {
15     public static class SDCardExtensions
16     {
SdCardFromFile(this IMachine machine, string file, IPeripheralRegister<DeprecatedSDCard, NullRegistrationPoint> attachTo, long size, bool persistent = true, string name = null)17         public static void SdCardFromFile(this IMachine machine, string file, IPeripheralRegister<DeprecatedSDCard, NullRegistrationPoint> attachTo, long size, bool persistent = true, string name = null)
18         {
19             var card = new DeprecatedSDCard(file, size, persistent);
20             attachTo.Register(card, NullRegistrationPoint.Instance);
21             machine.SetLocalName(card, name ?? "sdCard");
22         }
23 
SdCardFromFile(this IMachine machine, string file, IPeripheralRegister<SDCard, NullRegistrationPoint> attachTo, long size, bool persistent = true, string name = null)24         public static void SdCardFromFile(this IMachine machine, string file, IPeripheralRegister<SDCard, NullRegistrationPoint> attachTo, long size, bool persistent = true, string name = null)
25         {
26             var card = new SDCard(file, size, persistent);
27             attachTo.Register(card, NullRegistrationPoint.Instance);
28             machine.SetLocalName(card, name ?? "sdCard");
29         }
30 
SdCardFromFile(this IMachine machine, string file, IPeripheralRegister<ISPIPeripheral, NullRegistrationPoint> attachTo, long size, bool persistent = true, string name = null)31         public static void SdCardFromFile(this IMachine machine, string file, IPeripheralRegister<ISPIPeripheral, NullRegistrationPoint> attachTo, long size, bool persistent = true, string name = null)
32         {
33             var card = new SDCard(file, size, persistent, spiMode: true);
34             attachTo.Register(card, NullRegistrationPoint.Instance);
35             machine.SetLocalName(card, name ?? "sdCard");
36         }
37 
SdCardFromFile(this IMachine machine, string file, IPeripheralRegister<ISPIPeripheral, NumberRegistrationPoint<int>> attachTo, int port, long size, bool persistent = true, string name = null)38         public static void SdCardFromFile(this IMachine machine, string file, IPeripheralRegister<ISPIPeripheral, NumberRegistrationPoint<int>> attachTo, int port, long size, bool persistent = true, string name = null)
39         {
40             var card = new SDCard(file, size, persistent, spiMode: true);
41             attachTo.Register(card, new NumberRegistrationPoint<int>(port));
42             machine.SetLocalName(card, name ?? "sdCard");
43         }
44 
EmptySdCard(this IMachine machine, IPeripheralRegister<ISPIPeripheral, NumberRegistrationPoint<int>> attachTo, int port, long size, string name = null)45         public static void EmptySdCard(this IMachine machine, IPeripheralRegister<ISPIPeripheral, NumberRegistrationPoint<int>> attachTo, int port, long size, string name = null)
46         {
47             var card = new SDCard(size, spiMode: true);
48             attachTo.Register(card, new NumberRegistrationPoint<int>(port));
49             machine.SetLocalName(card, name ?? "sdCard");
50         }
51     }
52 }
53 
54