S
Stephen
Guest
I am looking for a synthesizable means to represent typical control
registers found in a microcontroller. In typical use, I would select
the register to read or write to and then write or read data from the
bus.
For example, consider SFR0, an eight bit register defined as:
7 - 6: reserved bits.
5: Enable A bit.
4: reserved bit.
3: Flag 1 bit.
2: Enable B bit.
1 - 0: Status bits.
I could represent this in SystemVerilog as a function for writing
purposes, as such:
// Begin example code. //
function [7:0] SFR0
(
input EnableA,
input Flag1,
input EnableB,
input [1:0] Status
);
SFR0 = { 2'bzz,
EnableA,
1'bz,
Flag1,
EnableB,
Status };
endfunction
module Foo
(
);
// ... Code.
always_ff @ (posedge Clock)
begin
// ... Code
// Else, tell the microcontroller to enable A and reset everything
else:
SFR0Register <= SFR0
(
.EnableA(1), // Enable A.
.Flag1(0), // Clear our flag 1.
.EnableB(0), // Disable B.
.Status(0) // Clear out the Status
bits.
);
// ... Code.
end
// ... Code.
endmodule
// End example code. //
But it wouldn't be of much help in setting or clearing individual
bits, so I thought I would use a stuct, perhaps as such:
// Begin example code. //
typedef struct packed
{
reg [1:0];
reg EnableA;
reg;
reg Flag1,
EnableB;
reg [1:0] Status;
} SFR0;
// End example code. //
Unfortunately, it seems I cannot have anonymous struct members, and I
also cannot seem to have constant members, such as:
// Begin example code. //
typedef struct packed
{
const reg [1:0] = 2'bzz;
reg EnableA;
const reg = 1'bz;
reg Flag1,
EnableB;
reg [1:0] Status;
} SFR0;
// End example code. //
I've considered using macros, but this would remove the ability to
access bits through their names ( .EnableA(1) ), which defeats my main
purpose readability. In addition, I would like to avoid code along
the lines of extending EnableA to occupy four bits or giving dummy
names to the reserved bits. I would much appreciate any advice.
registers found in a microcontroller. In typical use, I would select
the register to read or write to and then write or read data from the
bus.
For example, consider SFR0, an eight bit register defined as:
7 - 6: reserved bits.
5: Enable A bit.
4: reserved bit.
3: Flag 1 bit.
2: Enable B bit.
1 - 0: Status bits.
I could represent this in SystemVerilog as a function for writing
purposes, as such:
// Begin example code. //
function [7:0] SFR0
(
input EnableA,
input Flag1,
input EnableB,
input [1:0] Status
);
SFR0 = { 2'bzz,
EnableA,
1'bz,
Flag1,
EnableB,
Status };
endfunction
module Foo
(
);
// ... Code.
always_ff @ (posedge Clock)
begin
// ... Code
// Else, tell the microcontroller to enable A and reset everything
else:
SFR0Register <= SFR0
(
.EnableA(1), // Enable A.
.Flag1(0), // Clear our flag 1.
.EnableB(0), // Disable B.
.Status(0) // Clear out the Status
bits.
);
// ... Code.
end
// ... Code.
endmodule
// End example code. //
But it wouldn't be of much help in setting or clearing individual
bits, so I thought I would use a stuct, perhaps as such:
// Begin example code. //
typedef struct packed
{
reg [1:0];
reg EnableA;
reg;
reg Flag1,
EnableB;
reg [1:0] Status;
} SFR0;
// End example code. //
Unfortunately, it seems I cannot have anonymous struct members, and I
also cannot seem to have constant members, such as:
// Begin example code. //
typedef struct packed
{
const reg [1:0] = 2'bzz;
reg EnableA;
const reg = 1'bz;
reg Flag1,
EnableB;
reg [1:0] Status;
} SFR0;
// End example code. //
I've considered using macros, but this would remove the ability to
access bits through their names ( .EnableA(1) ), which defeats my main
purpose readability. In addition, I would like to avoid code along
the lines of extending EnableA to occupy four bits or giving dummy
names to the reserved bits. I would much appreciate any advice.