Alinga.VirtualRegisterMap 1.2.0

dotnet add package Alinga.VirtualRegisterMap --version 1.2.0                
NuGet\Install-Package Alinga.VirtualRegisterMap -Version 1.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Alinga.VirtualRegisterMap" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Alinga.VirtualRegisterMap --version 1.2.0                
#r "nuget: Alinga.VirtualRegisterMap, 1.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Alinga.VirtualRegisterMap as a Cake Addin
#addin nuget:?package=Alinga.VirtualRegisterMap&version=1.2.0

// Install Alinga.VirtualRegisterMap as a Cake Tool
#tool nuget:?package=Alinga.VirtualRegisterMap&version=1.2.0                

Virtual Register Map

Access objects through a register map interface.

This library provides a convenient way of modeling hardware devices in c#.

using Alinga.VirtualRegisterMap;

public class MyClass
{
    // attach a register attribute to a property to make it accessible through a virtual register map interface
    // Memory map read/writes are automatically forwarded to the property getter/setter
    [Register(0x00)] public UInt32 AProperty { get; set; }

    // similarly we can create a 'command' register by attaching the RegisterAttribute to a method with a single argument
    [Register(0x10)] public void DoSomething(UInt32 value){
        Console.WriteLine($"something happended on register 0x10, value = {value:X8}");
    }
}

To get the register map interface, simply call CreateFromObject on the instance

var myclass = new MyClass();
IRegisterMap map = RegisterMapBuilder.CreateFromObject(myclass);

Access the object through the map is easy:

map.Write<UInt32>(0x00, 0x12345678);

var bytevalue = map.Read<byte>(0x00);

// read a 16 byte buffer from offset 0x00
Span<byte> buffer = new byte[16];
map.Read(0x00, buffer, IORequestFlags.None);

Example:

Below is a slightly more elaborate example of a composed object.

using Alinga.VirtualRegisterMap;

namespace Example;

/// <summary>
/// A reusable sub module
/// </summary>
public class MyModule
{
    // property mapped to address 0x00. Default register length = 4 bytes
    [Register(0x00)] public UInt32 AProperty { get; set; }

    // registers can have any length. This is a 1 byte register
    [Register(0x04, length:1)] public byte SingleByte { get; set; }

}

/// <summary>
/// A emulated device that has its own registers, and composed of two modules
/// </summary>
public class MyDevice
{
    [Register(0x00)] public UInt32 Reg0 { get; set; }
    [Register(0x04)] public UInt32 Reg1 { get; set; }
    [Register(0x08)] public UInt32 Reg2 { get; set; }
    
    // map moduleA to offset 0x100
    [Register(0x100)] public MyModule ModuleA { get; } = new MyModule();

    // map moduleB to offset 0x200
    [Register(0x200)] public MyModule ModuleB { get; } = new MyModule();
}


internal class Program
{
    static void Main(string[] args)
    {
        // create an instance of my device
        var system = new MyDevice();

        // create a register map interface to this device
        var map = RegisterMapBuilder.CreateFromObject(system);

        // write to moduleA
        map.Write<UInt32>(0x100, 0x12345678);

        // write to moduleB
        map.Write<UInt32>(0x200, 0xAABBCCDD);

        // create 12 byte buffer with values 0..11
        var buffer = Enumerable.Range(0, 4 * 3).Select(i => (byte)i).ToArray();

        // bulk write Reg0..2
        map.Write(0x00, buffer, IORequestFlags.None);
    }
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 158 8/30/2023
1.1.0 171 8/28/2023
1.0.0 161 8/23/2023