volatile struct definition for peripheral control registers
Josh Holtrop
jholtrop at gmail.com
Tue Dec 3 05:20:44 UTC 2024
Just to follow up, I introduced the `Volatile` struct to my
project and had to add a couple extra functions to make
everything happy:
```d
module myproj.volatile;
import core.volatile;
struct Volatile(T)
{
private T value;
public @property T read()
{
return volatileLoad(&value);
}
alias read this;
public void opAssign(T value)
{
volatileStore(&this.value, value);
}
public T opUnary(string s)()
{
T v = read();
mixin(s ~ "v;");
volatileStore(&this.value, v);
return v;
}
public T opOpAssign(string s)(T rhs)
{
T v = read();
mixin("v " ~ s ~ "= rhs;");
volatileStore(&this.value, v);
return v;
}
}
```
So far it is working great!
More information about the Digitalmars-d-learn
mailing list