Accessing peripheral registers - the next version
Timo Sintonen via D.gnu
d.gnu at puremagic.com
Sun Aug 28 02:28:24 PDT 2016
On Sunday, 28 August 2016 at 08:34:15 UTC, Johannes Pfau wrote:
> Am Sat, 27 Aug 2016 08:05:08 +0000
> schrieb Timo Sintonen <t.sintonen at luukku.com>:
>
>
> The Volatile!T code you posted does not show how to map such a
> Volatile!T instance to a certain address. The code in 2) could
> be placed into a @property, but some stuff might still not work
> correctly (like using & to get the address). I think I'll add a
> @attribute("address", 0xABCD) to GDC which can be used for all
> extern variables. Then you could simply do this:
>
> extern Volatile!int PORTA @address(0xABCD);
>
I just translated my sample program and everything seems to work
in my limited tests. Here is a simplified example of an uart:
alias uarttype = uartreg*;
enum uarttype uart1=cast (uarttype)0x40011000;
enum uarttype uart2=cast (uarttype)0x40004400;
alias console = uart1;
struct uartreg {
Volatile!uint sr;
Volatile!uint dr;
Volatile!uint brr;
Volatile!uint cr1;
Volatile!uint cr2;
Volatile!uint cr3;
Volatile!uint gtpr;
// send a byte to the uart
void send(int t) {
while ((sr&0x80)==0) // wait for tx ready flag
{ }
dr=t; // write to data register
}
}
void test() {
foreach(c;" abcde ")
console.send(c);
}
>> what would be the preferred name for this type? Also what
>> would you think should be the module and file name?
>>
>
> As Mike already posted, Volatile!T is a good name (as this
> exactly explains what the type does for anyone already knowing
> the C volatile meaning).
>
> However, for accessing peripheral registers I'd use something
> more high
> level and name it Register!(...) or something like that.
Then let it be Volatile and we can alias that later.
Because GDC is only at 2.068, it seems we can not name the module
as 'volatile'.
More information about the D.gnu
mailing list