// Created with Corsair v{{ corsair_ver }}
//
// APB to Local Bus bridge
//

module {{ module_name }} #(
    parameter ADDR_W = {{ addr_width }},
    parameter DATA_W = {{ data_width }},
    parameter STRB_W = DATA_W / 8
)(
    // APB
    input               psel,
    input  [ADDR_W-1:0] paddr,
    input               penable,
    input               pwrite,
    input  [DATA_W-1:0] pwdata,
    input  [STRB_W-1:0] pstrb,
    output [DATA_W-1:0] prdata,
    output              pready,
    output              pslverr,
    // Local Bus
    input               wready,
    output [ADDR_W-1:0] waddr,
    output [DATA_W-1:0] wdata,
    output              wen,
    output [STRB_W-1:0] wstrb,
    input  [DATA_W-1:0] rdata,
    input               rvalid,
    output [ADDR_W-1:0] raddr,
    output              ren
);

// APB interface
assign prdata  = rdata;
assign pslverr = 1'b0; // always OKAY
assign pready  = wen             ? wready :
                 (ren & penable) ? rvalid : 1'b1;

// Local Bus interface
assign waddr = paddr;
assign wdata = pwdata;
assign wstrb = pstrb;
assign wen   = psel & penable & pwrite;

assign raddr = paddr;
assign ren   = psel & (~pwrite);

endmodule
