public static ushort ReadWordUsingDwordBigEndian(this IDoubleWordPeripheral peripheral, long address) { unchecked { var readAddress = address & (~3); var offset = 2 - (int)(address & 3); return((ushort)(peripheral.ReadDoubleWord(readAddress) >> offset * 8)); } }
public static byte ReadByteUsingDword(this IDoubleWordPeripheral peripheral, long address) { unchecked { var readAddress = address & (~3); var offset = (int)(address & 3); return((byte)(peripheral.ReadDoubleWord(readAddress) >> offset * 8)); } }
public static void WriteWordUsingDwordBigEndian(this IDoubleWordPeripheral peripheral, long address, ushort value) { unchecked { var alignedAddress = address & (~3); var offset = 2 - (int)(address & 3); var oldValue = peripheral.ReadDoubleWord(alignedAddress) & ~(0xFFFF << offset * 8); peripheral.WriteDoubleWord(alignedAddress, (uint)(oldValue | (uint)(value << 8 * offset))); } }
public static void WriteByteUsingDwordBigEndian(this IDoubleWordPeripheral peripheral, long address, byte value) { unchecked { var writeAddress = address & (~3); var offset = 3 - (int)(address & 3); var oldValue = peripheral.ReadDoubleWord(writeAddress) & ~(0xFF << offset * 8); peripheral.WriteDoubleWord(writeAddress, (uint)(oldValue | (uint)(value << 8 * offset))); } }
public static void WriteDoubleWordBigEndian(this IDoubleWordPeripheral peripheral, long address, uint value) { peripheral.WriteDoubleWord(address, Misc.SwapBytesUInt(value)); }
public static uint ReadDoubleWordBigEndian(this IDoubleWordPeripheral peripheral, long address) { return(Misc.SwapBytesUInt(peripheral.ReadDoubleWord(address))); }