//////////////////////////////////////////////////////////////////////////////// // // Filename: apbslave.v // {{{ // Project: WB2AXIPSP: bus bridges and other odds and ends // // Purpose: Just a simple demonstration APB slave // // Creator: Dan Gisselquist, Ph.D. // Gisselquist Technology, LLC // //////////////////////////////////////////////////////////////////////////////// // }}} // Copyright (C) 2020-2024, Gisselquist Technology, LLC // {{{ // This file is part of the WB2AXIP project. // // The WB2AXIP project contains free software and gateware, licensed under the // Apache License, Version 2.0 (the "License"). You may not use this project, // or this file, except in compliance with the License. You may obtain a copy // of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations // under the License. // //////////////////////////////////////////////////////////////////////////////// // // }}} `default_nettype none // module apbslave #( // {{{ parameter C_APB_ADDR_WIDTH = 12, parameter C_APB_DATA_WIDTH = 32, localparam AW = C_APB_ADDR_WIDTH, localparam DW = C_APB_DATA_WIDTH, localparam APBLSB = $clog2(C_APB_DATA_WIDTH)-3 // }}} ) ( // {{{ input wire PCLK, PRESETn, input wire PSEL, input wire PENABLE, output reg PREADY, input wire [AW-1:0] PADDR, input wire PWRITE, input wire [DW-1:0] PWDATA, input wire [DW/8-1:0] PWSTRB, input wire [2:0] PPROT, output reg [DW-1:0] PRDATA, output wire PSLVERR // }}} ); // Register declarations // {{{ // Just our demonstration "memory" here reg [DW-1:0] mem [0:(1<<(AW-APBLSB))-1]; integer ik; // }}} // PREADY // {{{ initial PREADY = 1'b0; always @(posedge PCLK) if (!PRESETn) PREADY <= 1'b0; else if (PSEL && !PENABLE) PREADY <= 1'b1; else PREADY <= 1'b0; // }}} // mem writes // {{{ always @(posedge PCLK) if (PRESETn && PSEL && !PENABLE && PWRITE) begin for(ik=0; ik