可寻址配置的寄存器代码,是openofdm里面的文件,是ettus写的。
//
// Copyright 2011 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
module setting_reg
#(parameter my_addr = 0,
parameter width = 32,
parameter at_reset=32'd0)
(input clk, input rst, input strobe, input wire [7:0] addr,
input wire [31:0] in, output reg [width-1:0] out, output reg changed);
always @(posedge clk)
if(rst)
begin
out <= at_reset;
changed <= 1'b0;
end
else
if(strobe & (my_addr==addr))
begin
out <= in;
changed <= 1'b1;
end
else
changed <= 1'b0;
endmodule // setting_reg
简单说说:
1,寄存器地址可以参数配置。
2,复位后的数值可以参数配置。
3,写总线宽度是32位,但是寄存器位数可以配置。
4,这个代码还引出了changed来标识寄存器已经被更新,其实可以将这个信号作为写使能,给其他下游逻辑,或者用以控制其他下游的逻辑做相应的更新。
以下是实例化的使用代码:
// threshold to claim a power trigger.
setting_reg #(.my_addr(SR_POWER_THRES), .width(16), .at_reset(100)) sr_0 (
.clk(clock), .rst(reset), .strobe(set_stb), .addr(set_addr), .in(set_data),
.out(power_thres), .changed());
这个模块很适合分散实例化寄存器。
另外我们看到这是寄存器只写不读。