|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
这段代码是将自己写的RAM挂在AHB-Lite总线上的
localparam ram_log2 = 18;
reg [31:0] ram [02**ram_log2)-1]; // Storage for AHB memory model
assign HREADY = 1'b1; // All devices are zero-wait-state
assign HRESP = 1'b0; // No device in this system generates errors
// Record transaction information from last accepted address phase
reg [ 1:0] htrans_last;
reg hwrite_last;
reg [31:0] haddr_last;
reg [ 2:0] hsize_last;
always @(posedge HCLK)
if (HREADY) begin
htrans_last <= HTRANS;
hwrite_last <= HWRITE;
haddr_last <= HADDR;
hsize_last <= HSIZE;
end
// Select RAM only if between address zero and top of RAM
wire hsel_ram = ~|haddr_last[31:ram_log2];
assign HRDATA[31:0] = hsel_ram ? ram[haddr_last[ram_log2+1:2]] : 32'd0;
这里是CPU读,表示从从RAM地址0处读32位数据到CPU?为什么不判断相关控制信号?
reg [31:0] ram_tmp;
always @(posedge HCLK)
if(HREADY & hwrite_last & hsel_ram & htrans_last[1]) begin
// Extract RAM entry into temporary buffer
ram_tmp = ram[haddr_last[ram_log2+1:2]];
这个always应该是CPU写数据到RAM,为什么把入口处的数据给ram_tmp?
// Insert appropriate bytes from AHB-Lite transaction
case({hsize_last[1:0], haddr_last[1:0]})
// Byte writes are valid to any address
4'b00_00 : ram_tmp[ 7: 0] = HWDATA[ 7: 0];
4'b00_01 : ram_tmp[15: 8] = HWDATA[15: 8];
4'b00_10 : ram_tmp[23:16] = HWDATA[23:16];
4'b00_11 : ram_tmp[31:24] = HWDATA[31:24];
// Halfword writes are only valid to even addresses
4'b01_00 : ram_tmp[15: 0] = HWDATA[15: 0];
4'b01_10 : ram_tmp[31:16] = HWDATA[31:16];
// Word writes are only valid to word aligned addresses
4'b10_00 : ram_tmp[31: 0] = HWDATA[31: 0];
default : begin
$display("%t: Illegal AHB transaction, stopping simulation\n", $time);
$finish(2);
end
endcase
// Commit write to RAM model
ram[haddr_last[ram_log2+1:2]] <= ram_tmp;
end |
|