public void Reset() { GoToIdle(); var sdCapacityParameters = SDCapacity.SeekForCapacityParametes(dataBackend.Length); blockLengthInBytes = (uint)(1 << sdCapacityParameters.BlockSize); }
public SDCard(string imageFile, long?size = null, bool persistent = false, bool spiMode = false) { this.spiMode = spiMode; spiContext = new SpiContext(); isIdle = true; dataBackend = DataStorage.Create(imageFile, size, persistent); var sdCapacityParameters = SDCapacity.SeekForCapacityParametes(dataBackend.Length); dataBackend.SetLength(sdCapacityParameters.MemoryCapacity); cardStatusGenerator = new VariableLengthValue(32) .DefineFragment(5, 1, () => (treatNextCommandAsAppCommand ? 1 : 0u), name: "APP_CMD bit") .DefineFragment(8, 1, 1, name: "READY_FOR_DATA bit"); operatingConditionsGenerator = new VariableLengthValue(32) .DefineFragment(31, 1, 1, name: "Card power up status bit (busy)") ; cardSpecificDataGenerator = new VariableLengthValue(128) .DefineFragment(47, 3, (uint)sdCapacityParameters.Multiplier, name: "device size multiplier") .DefineFragment(62, 12, (ulong)sdCapacityParameters.DeviceSize, name: "device size") .DefineFragment(80, 4, (uint)sdCapacityParameters.BlockSize, name: "max read data block length") .DefineFragment(84, 12, (uint)CardCommandClass.Class0, name: "card command classes") .DefineFragment(96, 3, (uint)TransferRate.Transfer10Mbit, name: "transfer rate unit") .DefineFragment(99, 4, (uint)TransferMultiplier.Multiplier2_5, name: "transfer multiplier") ; cardIdentificationGenerator = new VariableLengthValue(128) .DefineFragment(8, 4, 8, name: "manufacturer date code - month") .DefineFragment(12, 8, 18, name: "manufacturer date code - year") .DefineFragment(64, 8, (uint)'D', name: "product name 5") .DefineFragment(72, 8, (uint)'O', name: "product name 4") .DefineFragment(80, 8, (uint)'N', name: "product name 3") .DefineFragment(88, 8, (uint)'E', name: "product name 2") .DefineFragment(96, 8, (uint)'R', name: "product name 1") .DefineFragment(120, 8, 0xab, name: "manufacturer ID") ; }
public SDCard(string imageFile, long?size = null, bool persistent = false, bool spiMode = false) { this.spiMode = spiMode; spiContext = new SpiContext(); dataBackend = DataStorage.Create(imageFile, size, persistent); var sdCapacityParameters = SDCapacity.SeekForCapacityParametes(dataBackend.Length); dataBackend.SetLength(sdCapacityParameters.MemoryCapacity); blockLengthInBytes = (uint)(1 << sdCapacityParameters.BlockSize); cardStatusGenerator = new VariableLengthValue(32) .DefineFragment(5, 1, () => (treatNextCommandAsAppCommand ? 1 : 0u), name: "APP_CMD bit") .DefineFragment(8, 1, 1, name: "READY_FOR_DATA bit") .DefineFragment(9, 4, () => (uint)state, name: "CURRENT_STATE"); operatingConditionsGenerator = new VariableLengthValue(32) .DefineFragment(8, 1, 1, name: "VDD voltage window 2.0 - 2.1") .DefineFragment(9, 1, 1, name: "VDD voltage window 2.1 - 2.2") .DefineFragment(10, 1, 1, name: "VDD voltage window 2.2 - 2.3") .DefineFragment(11, 1, 1, name: "VDD voltage window 2.3 - 2.4") .DefineFragment(12, 1, 1, name: "VDD voltage window 2.4 - 2.5") .DefineFragment(13, 1, 1, name: "VDD voltage window 2.5 - 2.6") .DefineFragment(14, 1, 1, name: "VDD voltage window 2.6 - 2.7") .DefineFragment(15, 1, 1, name: "VDD voltage window 2.7 - 2.8") .DefineFragment(16, 1, 1, name: "VDD voltage window 2.8 - 2.9") .DefineFragment(17, 1, 1, name: "VDD voltage window 2.9 - 3.0") .DefineFragment(18, 1, 1, name: "VDD voltage window 3.0 - 3.1") .DefineFragment(19, 1, 1, name: "VDD voltage window 3.1 - 3.2") .DefineFragment(20, 1, 1, name: "VDD voltage window 3.2 - 3.3") .DefineFragment(21, 1, 1, name: "VDD voltage window 3.3 - 3.4") .DefineFragment(22, 1, 1, name: "VDD voltage window 3.4 - 3.5") .DefineFragment(23, 1, 1, name: "VDD voltage window 3.5 - 3.6") .DefineFragment(30, 1, () => highCapacityMode ? 1 : 0u, name: "Card Capacity Status") .DefineFragment(31, 1, 1, name: "Card power up status bit (busy)") ; cardSpecificDataGenerator = new VariableLengthValue(128) .DefineFragment(47, 3, (uint)sdCapacityParameters.Multiplier, name: "device size multiplier") .DefineFragment(62, 12, (ulong)sdCapacityParameters.DeviceSize, name: "device size") .DefineFragment(80, 4, (uint)sdCapacityParameters.BlockSize, name: "max read data block length") .DefineFragment(84, 12, (uint)( CardCommandClass.Class0 | CardCommandClass.Class2 | CardCommandClass.Class4 ), name: "card command classes") .DefineFragment(96, 3, (uint)TransferRate.Transfer10Mbit, name: "transfer rate unit") .DefineFragment(99, 4, (uint)TransferMultiplier.Multiplier2_5, name: "transfer multiplier") ; cardIdentificationGenerator = new VariableLengthValue(128) .DefineFragment(8, 4, 8, name: "manufacturer date code - month") .DefineFragment(12, 8, 18, name: "manufacturer date code - year") .DefineFragment(64, 8, (uint)'D', name: "product name 5") .DefineFragment(72, 8, (uint)'O', name: "product name 4") .DefineFragment(80, 8, (uint)'N', name: "product name 3") .DefineFragment(88, 8, (uint)'E', name: "product name 2") .DefineFragment(96, 8, (uint)'R', name: "product name 1") .DefineFragment(120, 8, 0xab, name: "manufacturer ID") ; }
public SDCard(string imageFile, long?size = null, bool persistent = false, bool spiMode = false, bool highCapacityMode = false) { this.spiMode = spiMode; this.highCapacityMode = highCapacityMode; spiContext = new SpiContext(); dataBackend = DataStorage.Create(imageFile, size, persistent); var sdCapacityParameters = SDCapacity.SeekForCapacityParametes(dataBackend.Length); dataBackend.SetLength(sdCapacityParameters.MemoryCapacity); blockLengthInBytes = (uint)(1 << sdCapacityParameters.BlockSize); cardStatusGenerator = new VariableLengthValue(32) .DefineFragment(5, 1, () => (treatNextCommandAsAppCommand ? 1 : 0u), name: "APP_CMD bit") .DefineFragment(8, 1, 1, name: "READY_FOR_DATA bit") .DefineFragment(9, 4, () => (uint)state, name: "CURRENT_STATE") ; operatingConditionsGenerator = new VariableLengthValue(32) .DefineFragment(8, 1, 1, name: "VDD voltage window 2.0 - 2.1") .DefineFragment(9, 1, 1, name: "VDD voltage window 2.1 - 2.2") .DefineFragment(10, 1, 1, name: "VDD voltage window 2.2 - 2.3") .DefineFragment(11, 1, 1, name: "VDD voltage window 2.3 - 2.4") .DefineFragment(12, 1, 1, name: "VDD voltage window 2.4 - 2.5") .DefineFragment(13, 1, 1, name: "VDD voltage window 2.5 - 2.6") .DefineFragment(14, 1, 1, name: "VDD voltage window 2.6 - 2.7") .DefineFragment(15, 1, 1, name: "VDD voltage window 2.7 - 2.8") .DefineFragment(16, 1, 1, name: "VDD voltage window 2.8 - 2.9") .DefineFragment(17, 1, 1, name: "VDD voltage window 2.9 - 3.0") .DefineFragment(18, 1, 1, name: "VDD voltage window 3.0 - 3.1") .DefineFragment(19, 1, 1, name: "VDD voltage window 3.1 - 3.2") .DefineFragment(20, 1, 1, name: "VDD voltage window 3.2 - 3.3") .DefineFragment(21, 1, 1, name: "VDD voltage window 3.3 - 3.4") .DefineFragment(22, 1, 1, name: "VDD voltage window 3.4 - 3.5") .DefineFragment(23, 1, 1, name: "VDD voltage window 3.5 - 3.6") .DefineFragment(30, 1, () => this.highCapacityMode ? 1 : 0u, name: "Card Capacity Status") .DefineFragment(31, 1, 1, name: "Card power up status bit (busy)") ; cardSpecificDataGenerator = new VariableLengthValue(128) .DefineFragment(47, 3, (uint)sdCapacityParameters.Multiplier, name: "device size multiplier") .DefineFragment(62, 12, (ulong)sdCapacityParameters.DeviceSize, name: "device size") .DefineFragment(80, 4, (uint)sdCapacityParameters.BlockSize, name: "max read data block length") .DefineFragment(84, 12, (uint)( CardCommandClass.Class0 | CardCommandClass.Class2 | CardCommandClass.Class4 ), name: "card command classes") .DefineFragment(96, 3, (uint)TransferRate.Transfer10Mbit, name: "transfer rate unit") .DefineFragment(99, 4, (uint)TransferMultiplier.Multiplier2_5, name: "transfer multiplier") ; extendedCardSpecificDataGenerator = new VariableLengthValue(4096) .DefineFragment((120), 8, 1, name: "command queue enabled") .DefineFragment((1472), 8, 1, name: "es support") .DefineFragment((1480), 8, 1, name: "hw hs timing") .DefineFragment((1568), 8, (uint)DeviceType.SDR50Mhz, name: "device type") .DefineFragment((2464), 8, 1, name: "command queue support") ; cardIdentificationGenerator = new VariableLengthValue(128) .DefineFragment(8, 4, 8, name: "manufacturer date code - month") .DefineFragment(12, 8, 18, name: "manufacturer date code - year") .DefineFragment(64, 8, (uint)'D', name: "product name 5") .DefineFragment(72, 8, (uint)'O', name: "product name 4") .DefineFragment(80, 8, (uint)'N', name: "product name 3") .DefineFragment(88, 8, (uint)'E', name: "product name 2") .DefineFragment(96, 8, (uint)'R', name: "product name 1") .DefineFragment(120, 8, 0xab, name: "manufacturer ID") ; switchFunctionStatusGenerator = new VariableLengthValue(512) .DefineFragment(128, 1, 0x1, name: "Function Number/Status Code") ; cardConfigurationGenerator = new VariableLengthValue(64) .DefineFragment(0, 32, 0, name: "reserved") .DefineFragment(32, 16, 0, name: "reserved") .DefineFragment(48, 4, 5, name: "DAT Bus width supported") // DAT0 (1-bit) and DAT0-3 (4-bit) .DefineFragment(52, 3, 0, name: "SD Security Support") // 0: No security .DefineFragment(55, 1, 0, name: "data_status_after erases") .DefineFragment(56, 4, 0, name: "SD Card - Spec. Version") // 0: Version 1.0-1.01 .DefineFragment(60, 4, 0, name: "SCR Structure") // 0: SCR version No 1.0 ; }