Skip to content

Commit

Permalink
Merge pull request #27 from 1a2m3/20220805
Browse files Browse the repository at this point in the history
20220806 update
  • Loading branch information
1a2m3 authored Aug 6, 2022
2 parents d266bbd + 36430da commit 6934169
Show file tree
Hide file tree
Showing 8 changed files with 463 additions and 723 deletions.
26 changes: 13 additions & 13 deletions src/SpdReaderWriter/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ public static void Example_BasicUse() {
myDevice.ProbeAddress(); // You can omit the address if myDevice already has "I2CAddress" set

// Set SPD size to DDR4's EEPROM size (512 bytes)
myDevice.SpdSize = Ram.SpdSize.DDR4;
myDevice.DataLength = Spd.DataLength.DDR4;

// The device can also be initialized in one line, like so:
Arduino myOtherDevice = new Arduino(ReaderSettings, PortName, 80, Ram.SpdSize.DDR4);
Arduino myOtherDevice = new Arduino(ReaderSettings, PortName, 80, Spd.DataLength.DDR4);

// Read first byte at offset 0
byte firstByte = Eeprom.ReadByte(myDevice, 0);

// Read last byte (located at offset 511, not 512!)
byte lastByte = Eeprom.ReadByte(myDevice, (ushort)(myDevice.SpdSize - 1));
byte lastByte = Eeprom.ReadByte(myDevice, (ushort)(myDevice.DataLength - 1));

// Read the entire EEPROM, 1 byte at a time
byte[] spdDump = new byte[(int)myDevice.SpdSize];
for (ushort i = 0; i < (int)myDevice.SpdSize; i++) {
byte[] spdDump = new byte[(int)myDevice.DataLength];
for (ushort i = 0; i < (int)myDevice.DataLength; i++) {
spdDump[i] = Eeprom.ReadByte(myDevice, i);
}

Expand Down Expand Up @@ -100,7 +100,7 @@ public static void Example_TestRealDevice() {
realDevice.Scan(); //{ 80 }

// Test a real device
Arduino myReader = new Arduino(ReaderSettings, PortName, 0x50, Ram.SpdSize.DDR4);
Arduino myReader = new Arduino(ReaderSettings, PortName, 0x50, Spd.DataLength.DDR4);
myReader.Test(); //true
}

Expand All @@ -109,15 +109,15 @@ public static void Example_TestRealDevice() {
/// </summary>
public static void Example_DuplicateRam() {
// Copy SPD contents from one DIMM to another
Arduino source = new Arduino(ReaderSettings, "COM1", 80, Ram.SpdSize.DDR4);
Arduino destination = new Arduino(ReaderSettings, "COM4", 82, source.SpdSize);
Arduino source = new Arduino(ReaderSettings, "COM1", 80, Spd.DataLength.DDR4);
Arduino destination = new Arduino(ReaderSettings, "COM4", 82, source.DataLength);

for (ushort i = 0; i < (int)source.SpdSize; i++) {
for (ushort i = 0; i < (int)source.DataLength; i++) {
Eeprom.WriteByte(destination, i, Eeprom.ReadByte(source, i));
}

// Verify contents
for (ushort i = 0; i < (int)source.SpdSize; i++) {
for (ushort i = 0; i < (int)source.DataLength; i++) {
if (Eeprom.ReadByte(source, i) != Eeprom.ReadByte(destination, i)) {
// Mismatched contents detected
}
Expand All @@ -129,7 +129,7 @@ public static void Example_DuplicateRam() {
/// </summary>
public static void Example_FixCRC() {

Arduino myReader = new Arduino(ReaderSettings, PortName, 0x52, Ram.SpdSize.DDR4);
Arduino myReader = new Arduino(ReaderSettings, PortName, 0x52, Spd.DataLength.DDR4);

// Read first 126 bytes
byte[] spdHeader = Eeprom.ReadByte(myReader, 0, 126);
Expand Down Expand Up @@ -158,8 +158,8 @@ public static void Example_FixCRC() {
/// Erase SPD contents (fill with 0xFF's)
/// </summary>
public static void Example_EraseSPD() {
Arduino myReader = new Arduino(ReaderSettings, PortName, 0x50, Ram.SpdSize.DDR4);
for (ushort i = 0; i <= (int)myReader.SpdSize; i++) {
Arduino myReader = new Arduino(ReaderSettings, PortName, 0x50, Spd.DataLength.DDR4);
for (ushort i = 0; i <= (int)myReader.DataLength; i++) {
Eeprom.UpdateByte(myReader, i, 0xFF);
Console.WriteLine(i.ToString());
}
Expand Down
8 changes: 4 additions & 4 deletions src/SpdReaderWriter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ private static void WriteEeprom() {
Reader.I2CAddress);

if (inputFile.Length > (int)Spd.GetSpdSize(Reader)) {
throw new Exception($"File \"{filePath}\" is larger than {Reader.SpdSize} bytes.");
throw new Exception($"File \"{filePath}\" is larger than {Reader.DataLength} bytes.");
}

int bytesWritten = 0;
Expand Down Expand Up @@ -425,7 +425,7 @@ private static void EnableRswp() {

}
else { // No block number specified, protect all available
if (Spd.GetRamType(Reader) == Ram.Type.DDR4) {
if (Spd.GetRamType(Reader) == Spd.RamType.DDR4) {
block = new[] { 0, 1, 2, 3 };
}
else { // DDR3 + DDR2
Expand Down Expand Up @@ -583,10 +583,10 @@ static void ConsoleDisplayByte(int pos, byte b, int bpr = 16, bool showOffset =
ConsoleColor[] colors = {
ConsoleColor.DarkGray,
ConsoleColor.Gray,
ConsoleColor.Red,
ConsoleColor.DarkRed,
ConsoleColor.DarkYellow,
ConsoleColor.Red,
ConsoleColor.Yellow,
ConsoleColor.DarkYellow,
ConsoleColor.Green,
ConsoleColor.DarkGreen,
ConsoleColor.DarkCyan,
Expand Down
Loading

0 comments on commit 6934169

Please sign in to comment.