AHB APB 简单通讯架构 代码 APB_Slave

从机,实现数据读写

module APB_Slave(
input wire PRESETn,
input wire PCLK,

input wire PSELx,
input wire PENABLE,

input wire PWRITE,
input wire [31:0] PADDR,
input wire [31:0] PWDATA,
output reg [31:0] PRDATA
);

reg [31:0] Slave_Data [31:0];

/*
S0:  0x0000_0000 ~ 0x0000_00ff;
S1:  0x0000_0100 ~ 0x0000_01ff;
S2:  0x0000_0200 ~ 0x0000_02ff;
S3:  0x0000_0300 ~ 0x0000_03ff;
*/

wire [5:0] num = PADDR[7:2];
always @(posedge PCLK or negedge PRESETn)
begin
  if(!PRESETn)  PRDATA <= 32'h00000000;
  else
  begin
    if(PSELx && PENABLE)
    begin
        if(PWRITE)  Slave_Data[num] <= PWDATA;
        else        PRDATA          <= Slave_Data[num];
          
        if(PWRITE)  $display("%m    Write Addr:%x, Reg:%d, Data:%x", PADDR, num, PWDATA);
        else        $display("%m    Read  Addr:%x, Reg:%d, Data:%x", PADDR, num, Slave_Data[num]);
    end
  end   
end // PCLK


endmodule

相关文章:

  • 2021-08-07
  • 2021-07-31
  • 2021-04-15
  • 2021-09-07
  • 2021-09-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-04-15
  • 2021-08-25
  • 2021-06-30
  • 2021-08-20
  • 2021-12-16
  • 2021-05-30
  • 2022-12-23
相关资源
相似解决方案