mirror of
https://github.com/supleed2/axiTest.git
synced 2024-12-22 13:45:48 +00:00
Initial Commit
This commit is contained in:
commit
2fddfc0281
40
Axi4LiteDriver.sv
Normal file
40
Axi4LiteDriver.sv
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
// Driver module for use with AXI4-Lite bus, with exported DPI-C functions
|
||||||
|
// SPDX-FileCopyrightText: © 2022 Aadi Desai <21363892+supleed2@users.noreply.github.com>
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
`default_nettype none
|
||||||
|
|
||||||
|
module Axi4LiteDriver
|
||||||
|
#(parameter int AWIDTH = 12 // Default: 4KB, [1:0] ignored = word aligned accesses
|
||||||
|
, parameter int DWIDTH = 32 // AXI4-Lite Data bus is 32/64 bit only
|
||||||
|
, parameter int SWIDTH = DWIDTH / 8 // Strobe width = data width / 8
|
||||||
|
)(input var logic i_aClk
|
||||||
|
, input var logic i_aResetn
|
||||||
|
// Read Address Channel (Master -> Slave)
|
||||||
|
, output var logic o_arValid
|
||||||
|
, input var logic i_arReady
|
||||||
|
, output var logic [AWIDTH-1:0] o_arAddr
|
||||||
|
, output var Protection o_arProt
|
||||||
|
// Read Data Channel (Slave -> Master)
|
||||||
|
, input var logic i_rValid
|
||||||
|
, output var logic o_rReady
|
||||||
|
, input var logic [DWIDTH-1:0] i_rData
|
||||||
|
, input var Response i_rResp
|
||||||
|
// Write Address Channel (Master -> Slave)
|
||||||
|
, output var logic o_awValid
|
||||||
|
, input var logic i_awReady
|
||||||
|
, output var logic [AWIDTH-1:0] o_awAddr
|
||||||
|
, output var Protection o_awProt
|
||||||
|
// Write Data Channel (Master -> Slave)
|
||||||
|
, output var logic o_wValid
|
||||||
|
, input var logic i_wReady
|
||||||
|
, output var logic [DWIDTH-1:0] o_wData
|
||||||
|
, output var logic [SWIDTH-1:0] o_wStrb
|
||||||
|
// Write Response Channel (Slave -> Master)
|
||||||
|
, input var logic i_bValid
|
||||||
|
, output var logic o_bReady
|
||||||
|
, input var Response i_bResp
|
||||||
|
);
|
||||||
|
endmodule
|
||||||
|
|
||||||
|
`resetall
|
148
Axi4LiteSlave.sv
Normal file
148
Axi4LiteSlave.sv
Normal file
|
@ -0,0 +1,148 @@
|
||||||
|
// AXI4-Lite compatible memory module, for testing driver module
|
||||||
|
// SPDX-FileCopyrightText: © 2022 Aadi Desai <21363892+supleed2@users.noreply.github.com>
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
`default_nettype none
|
||||||
|
|
||||||
|
typedef enum bit [1:0]
|
||||||
|
{ OKAY = 2'b00
|
||||||
|
, EXOKAY = 2'b01
|
||||||
|
, SLVERR = 2'b10
|
||||||
|
, DECERR = 2'b11
|
||||||
|
} Response;
|
||||||
|
|
||||||
|
typedef enum bit [2:0]
|
||||||
|
{ UNPRIV_SEC_DATA = 3'b000 // Unprivileged, secure, data access
|
||||||
|
, PRIV_SEC_DATA = 3'b001 // Privileged, secure, data access
|
||||||
|
, UNPRIV_NONSEC_DATA = 3'b010 // Unprivileged, non-secure, data access
|
||||||
|
, PRIV_NONSEC_DATA = 3'b011 // Privileged, non-secure, data access
|
||||||
|
, UNPRIV_SEC_INSTR = 3'b100 // Unprivileged, secure, instruction access
|
||||||
|
, PRIV_SEC_INSTR = 3'b101 // Privileged, secure, instruction access
|
||||||
|
, UNPRIV_NONSEC_INSTR = 3'b110 // Unprivileged, non-secure, instruction access
|
||||||
|
, PRIV_NONSEC_INSTR = 3'b111 // Privileged, non-secure, instruction access
|
||||||
|
} Protection;
|
||||||
|
|
||||||
|
module Axi4LiteSlave
|
||||||
|
#(parameter int AWIDTH = 12
|
||||||
|
, parameter int DWIDTH = 32
|
||||||
|
, parameter int SWIDTH = DWIDTH / 8
|
||||||
|
)(input var logic i_aClk
|
||||||
|
, input var logic i_aResetn
|
||||||
|
// Read Address Channel (Master -> Slave)
|
||||||
|
, input var logic i_arValid
|
||||||
|
, output var logic o_arReady
|
||||||
|
, input var logic [AWIDTH-1:0] i_arAddr
|
||||||
|
, input var Protection i_arProt
|
||||||
|
// Read Data Channel (Slave -> Master)
|
||||||
|
, output var logic o_rValid
|
||||||
|
, input var logic i_rReady
|
||||||
|
, output var logic [DWIDTH-1:0] o_rData
|
||||||
|
, output var Response o_rResp
|
||||||
|
// Write Address Channel (Master -> Slave)
|
||||||
|
, input var logic i_awValid
|
||||||
|
, output var logic o_awReady
|
||||||
|
, input var logic [AWIDTH-1:0] i_awAddr
|
||||||
|
, input var Protection i_awProt
|
||||||
|
// Write Data Channel (Master -> Slave)
|
||||||
|
, input var logic i_wValid
|
||||||
|
, output var logic o_wReady
|
||||||
|
, input var logic [DWIDTH-1:0] i_wData
|
||||||
|
, input var logic [SWIDTH-1:0] i_wStrb
|
||||||
|
// Write Response Channel (Slave -> Master)
|
||||||
|
, output var logic o_bValid
|
||||||
|
, input var logic i_bReady
|
||||||
|
, output var Response o_bResp
|
||||||
|
);
|
||||||
|
|
||||||
|
logic [DWIDTH-1:0] mem [4096];
|
||||||
|
logic [DWIDTH-1:0] wDataStrb;
|
||||||
|
for (genvar i = 0; i < SWIDTH; i++) begin : la_StrobedWriteData
|
||||||
|
assign wDataStrb[8*i+7:8*i] = i_wStrb[i] ? i_wData[8*i+7:8*i] : mem[i_awAddr][8*i+7:8*i];
|
||||||
|
end
|
||||||
|
|
||||||
|
enum bit [0:0]
|
||||||
|
{ IDLE
|
||||||
|
, READ
|
||||||
|
} rState;
|
||||||
|
|
||||||
|
enum bit [2:0]
|
||||||
|
{ IDLE
|
||||||
|
, WRITE
|
||||||
|
} wState;
|
||||||
|
|
||||||
|
always_ff @(posedge i_aClk)
|
||||||
|
if (!i_aResetn) begin
|
||||||
|
o_arReady <= '0;
|
||||||
|
o_rValid <= '0;
|
||||||
|
o_rData <= '0;
|
||||||
|
o_rResp <= '0;
|
||||||
|
end else
|
||||||
|
case (rState)
|
||||||
|
IDLE: begin
|
||||||
|
if (i_arValid) begin
|
||||||
|
o_arReady <= '1;
|
||||||
|
o_rValid <= '1;
|
||||||
|
o_rData <= mem[i_arAddr];
|
||||||
|
o_rResp <= Response'(OKAY);
|
||||||
|
rState <= READ;
|
||||||
|
end else
|
||||||
|
rState <= IDLE;
|
||||||
|
end
|
||||||
|
READ: begin
|
||||||
|
o_arReady <= '0;
|
||||||
|
if (i_rReady) begin
|
||||||
|
o_rValid <= '0;
|
||||||
|
o_rData <= '0;
|
||||||
|
o_rResp <= '0;
|
||||||
|
rState <= IDLE;
|
||||||
|
end else
|
||||||
|
rState <= READ;
|
||||||
|
end
|
||||||
|
default: begin
|
||||||
|
o_arReady <= '0;
|
||||||
|
o_rValid <= '0;
|
||||||
|
o_rData <= '0;
|
||||||
|
o_rResp <= '0;
|
||||||
|
end
|
||||||
|
endcase
|
||||||
|
|
||||||
|
always_ff @(posedge i_aClk)
|
||||||
|
if (!i_aResetn) begin
|
||||||
|
o_awReady <= '0;
|
||||||
|
o_wReady <= '0;
|
||||||
|
o_bValid <= '0;
|
||||||
|
o_bResp <= '0;
|
||||||
|
end else
|
||||||
|
case (wState)
|
||||||
|
IDLE: begin
|
||||||
|
if (i_awValid && i_wValid) begin
|
||||||
|
o_awReady <= '1;
|
||||||
|
mem[i_awAddr] <= wDataStrb;
|
||||||
|
o_wReady <= '1;
|
||||||
|
o_bValid <= '1;
|
||||||
|
o_bResp <= Response'(OKAY);
|
||||||
|
wState <= WRITE;
|
||||||
|
end else
|
||||||
|
wState <= IDLE;
|
||||||
|
end
|
||||||
|
WRITE: begin
|
||||||
|
o_awReady <= '0;
|
||||||
|
o_wReady <= '0;
|
||||||
|
if (i_bReady) begin
|
||||||
|
o_bValid <= '0;
|
||||||
|
o_bResp <= '0;
|
||||||
|
wState <= IDLE;
|
||||||
|
end else
|
||||||
|
wState <= WRITE;
|
||||||
|
end
|
||||||
|
default: begin
|
||||||
|
o_awReady <= '0;
|
||||||
|
o_wReady <= '0;
|
||||||
|
o_bValid <= '0;
|
||||||
|
o_bResp <= '0;
|
||||||
|
end
|
||||||
|
endcase
|
||||||
|
|
||||||
|
endmodule
|
||||||
|
|
||||||
|
`resetall
|
201
LICENSE
Normal file
201
LICENSE
Normal file
|
@ -0,0 +1,201 @@
|
||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
<http://www.apache.org/licenses/>
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright 2022 Aadi Desai
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use 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.
|
3
README.md
Normal file
3
README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# axiTest
|
||||||
|
|
||||||
|
AXI4-Lite compatible Driver module for use with Verilator and other DPI-C compatible simulators. WIP
|
136
VerilatorTbFst.h
Normal file
136
VerilatorTbFst.h
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
// Header file to be used in verilator C++ testbenches.
|
||||||
|
// SPDX-FileCopyrightText: © 2022 Aadi Desai <21363892+supleed2@users.noreply.github.com>
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
// Intended usage / order:
|
||||||
|
// - VerilatorTbFst<Vtest_DUT> *tb = new VerilatorTbFst<Vtest_DUT>();
|
||||||
|
// - tb->setClockPeriodPS(clock_period_in_picoseconds);
|
||||||
|
// - This value can be taken from within the SystemVerilog Testbench
|
||||||
|
// - tb->opentrace("output/test_DUT.verilator.fst");
|
||||||
|
// - tb->m_trace->dump(0);
|
||||||
|
// - Followed by arst/rst and signals matching the intended testbench flow.
|
||||||
|
|
||||||
|
#ifndef _VERILATORTBFST_H
|
||||||
|
#define _VERILATORTBFST_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <svdpi.h>
|
||||||
|
#include <verilated_fst_c.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ERROR,
|
||||||
|
WARN,
|
||||||
|
NOTE
|
||||||
|
} TbPrintLevel;
|
||||||
|
|
||||||
|
template <class VA>
|
||||||
|
class VerilatorTbFst {
|
||||||
|
public:
|
||||||
|
VA *m_dut;
|
||||||
|
VerilatedFstC *m_trace;
|
||||||
|
uint64_t m_tickcount;
|
||||||
|
uint64_t m_clockperiod;
|
||||||
|
bool m_dodump;
|
||||||
|
|
||||||
|
VerilatorTbFst(void) : m_trace(NULL), m_tickcount(0l) {
|
||||||
|
m_dut = new VA;
|
||||||
|
Verilated::traceEverOn(true);
|
||||||
|
m_dut->i_clk = 0;
|
||||||
|
m_dut->i_rst = 1;
|
||||||
|
m_dodump = true;
|
||||||
|
eval(); // Get our initial values set properly.
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~VerilatorTbFst(void) {
|
||||||
|
closetrace();
|
||||||
|
delete m_dut;
|
||||||
|
m_dut = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void setClockPeriodPS(const uint64_t ps) {
|
||||||
|
m_clockperiod = ps;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void opentrace(const char *fstname) {
|
||||||
|
opentrace(fstname, 99);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void opentrace(const char *fstname, int tracedepth) {
|
||||||
|
if (!m_trace) {
|
||||||
|
m_trace = new VerilatedFstC;
|
||||||
|
m_dut->trace(m_trace, tracedepth);
|
||||||
|
m_trace->open(fstname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void closetrace(void) {
|
||||||
|
if (m_trace) {
|
||||||
|
m_trace->close();
|
||||||
|
delete m_trace;
|
||||||
|
m_trace = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void eval(void) {
|
||||||
|
m_dut->eval();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call from loop {check, drive, tick}
|
||||||
|
virtual void tick(void) {
|
||||||
|
// check
|
||||||
|
// drive
|
||||||
|
// rise eval dump
|
||||||
|
// fall eval dump
|
||||||
|
|
||||||
|
m_dut->i_clk = 1;
|
||||||
|
eval();
|
||||||
|
if (m_dodump && m_trace) {
|
||||||
|
m_trace->dump((uint64_t)(m_clockperiod * m_tickcount));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_dut->i_clk = 0;
|
||||||
|
eval();
|
||||||
|
if (m_dodump && m_trace) {
|
||||||
|
m_trace->dump((uint64_t)(m_clockperiod * m_tickcount + (m_clockperiod / 2)));
|
||||||
|
m_trace->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_tickcount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void ticks(int numTicks) {
|
||||||
|
for (int i = 0; i < numTicks; i++)
|
||||||
|
tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void areset(void) {
|
||||||
|
m_dut->i_arst = 0;
|
||||||
|
tick();
|
||||||
|
m_dut->i_arst = 1;
|
||||||
|
ticks(4);
|
||||||
|
m_dut->i_arst = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void reset(void) {
|
||||||
|
m_dut->i_rst = 1;
|
||||||
|
ticks(5);
|
||||||
|
m_dut->i_rst = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long tickcount(void) {
|
||||||
|
return m_tickcount;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool done(void) {
|
||||||
|
return Verilated::gotFinish();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void setScope(const char *scopeName) {
|
||||||
|
char fullScopeName[1024];
|
||||||
|
svSetScope(svGetScopeFromName(strcat(strcpy(fullScopeName, "TOP."), scopeName)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _VERILATORTBFST_H
|
46
axiTest.cpp
Normal file
46
axiTest.cpp
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
// C++ Verilator testbench for checking AXI4-Lite Driver module
|
||||||
|
// SPDX-FileCopyrightText: © 2022 Aadi Desai <21363892+supleed2@users.noreply.github.com>
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
#include <VaxiTest.h>
|
||||||
|
#include <VaxiTest__Dpi.h>
|
||||||
|
#include <VerilatorTbFst.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string>
|
||||||
|
#include <svdpi.h>
|
||||||
|
#include <verilated.h>
|
||||||
|
|
||||||
|
#ifndef N_CYCLES
|
||||||
|
#define N_CYCLES 100
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int main(int argc, char **argv, char **env) {
|
||||||
|
Verilated::commandArgs(argc, argv);
|
||||||
|
VerilatorTbFst<VaxiTest> *tb = new VerilatorTbFst<VaxiTest>();
|
||||||
|
tb->setScope("axiTest");
|
||||||
|
|
||||||
|
// Get SystemVerilog Parameters
|
||||||
|
const uint64_t CLOCK_PERIOD_PS = 10;
|
||||||
|
|
||||||
|
tb->setClockPeriodPS(2 * (CLOCK_PERIOD_PS / 3));
|
||||||
|
tb->opentrace("output/VaxiTest.fst");
|
||||||
|
|
||||||
|
tb->m_trace->dump(0); // Initialize waveform at beginning of time.
|
||||||
|
printf("Starting!\n");
|
||||||
|
|
||||||
|
tb->m_dut->i_rst = 1;
|
||||||
|
tb->ticks(2);
|
||||||
|
tb->m_dut->i_rst = 0;
|
||||||
|
tb->ticks(2);
|
||||||
|
|
||||||
|
while (tb->tickcount() < N_CYCLES * 2) {
|
||||||
|
tb->ticks(2); // Run Tests
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Time: %ldns\n", tb->tickcount());
|
||||||
|
printf("Stopped.\n");
|
||||||
|
|
||||||
|
tb->closetrace();
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
91
axiTest.sv
Normal file
91
axiTest.sv
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
// SystemVerilog testbench to instantiate AXI4-Lite driver and memory modules
|
||||||
|
// SPDX-FileCopyrightText: © 2022 Aadi Desai <21363892+supleed2@users.noreply.github.com>
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
`default_nettype none
|
||||||
|
|
||||||
|
// Verilator Class support is limited but in active development. Verilator
|
||||||
|
// supports members, and methods. Verilator does not support class static
|
||||||
|
// members, class extend, or class parameters.
|
||||||
|
|
||||||
|
module axiTest
|
||||||
|
( input var logic i_clk
|
||||||
|
, input var logic i_rst
|
||||||
|
, input var logic i_arst
|
||||||
|
);
|
||||||
|
|
||||||
|
Axi4LiteSlave
|
||||||
|
#(.AWIDTH (12 )
|
||||||
|
, .DWIDTH (32 )
|
||||||
|
) u_axiSlave
|
||||||
|
( .i_aClk (aClk )
|
||||||
|
, .i_aResetn (aResetn)
|
||||||
|
// Read Address Channel (Master -> Slave)
|
||||||
|
, .i_arValid (arValid)
|
||||||
|
, .o_arReady (arReady)
|
||||||
|
, .i_arAddr (arAddr )
|
||||||
|
, .i_arProt (arProt )
|
||||||
|
// Read Data Channel (Slave -> Master)
|
||||||
|
, .o_rValid (rValid )
|
||||||
|
, .i_rReady (rReady )
|
||||||
|
, .o_rData (rData )
|
||||||
|
, .o_rResp (rResp )
|
||||||
|
// Write Address Channel (Master -> Slave)
|
||||||
|
, .i_awValid (awValid)
|
||||||
|
, .o_awReady (awReady)
|
||||||
|
, .i_awAddr (awAddr )
|
||||||
|
, .i_awProt (awProt )
|
||||||
|
// Write Data Channel (Master -> Slave)
|
||||||
|
, .i_wValid (wValid )
|
||||||
|
, .o_wReady (wReady )
|
||||||
|
, .i_wData (wData )
|
||||||
|
, .i_wStrb (wStrb )
|
||||||
|
// Write Response Channel (Slave -> Master)
|
||||||
|
, .o_bValid (bValid )
|
||||||
|
, .i_bReady (bReady )
|
||||||
|
, .o_bResp (bResp )
|
||||||
|
);
|
||||||
|
|
||||||
|
generateClock u_generateClock
|
||||||
|
( .o_clk (aClk ) // Generated clock for testbench
|
||||||
|
, .i_rootClk (i_clk) // V_erilator clock input
|
||||||
|
, .i_periodHi (0 ) // Number of rootClk cycles-1 to stay high
|
||||||
|
, .i_periodLo (0 ) // Number of rootClk cycles-1 to stay low
|
||||||
|
, .i_jitterControl (0 ) // Random jitter control (0: none --> higher number: more jitter)
|
||||||
|
);
|
||||||
|
|
||||||
|
Axi4LiteDriver
|
||||||
|
#(.AWIDTH (12 )
|
||||||
|
, .DWIDTH (32 )
|
||||||
|
) u_axiDriver
|
||||||
|
( .i_aClk (aClk )
|
||||||
|
, .i_aResetn (aResetn)
|
||||||
|
// Read Address Channel (Master -> Slave)
|
||||||
|
, .o_arValid (arValid)
|
||||||
|
, .i_arReady (arReady)
|
||||||
|
, .o_arAddr (arAddr )
|
||||||
|
, .o_arProt (arProt )
|
||||||
|
// Read Data Channel (Slave -> Master)
|
||||||
|
, .i_rValid (rValid )
|
||||||
|
, .o_rReady (rReady )
|
||||||
|
, .i_rData (rData )
|
||||||
|
, .i_rResp (rResp )
|
||||||
|
// Write Address Channel (Master -> Slave)
|
||||||
|
, .o_awValid (awValid)
|
||||||
|
, .i_awReady (awReady)
|
||||||
|
, .o_awAddr (awAddr )
|
||||||
|
, .o_awProt (awProt )
|
||||||
|
// Write Data Channel (Master -> Slave)
|
||||||
|
, .o_wValid (wValid )
|
||||||
|
, .i_wReady (wReady )
|
||||||
|
, .o_wData (wData )
|
||||||
|
, .o_wStrb (wStrb )
|
||||||
|
// Write Response Channel (Slave -> Master)
|
||||||
|
, .i_bValid (bValid )
|
||||||
|
, .o_bReady (bReady )
|
||||||
|
, .i_bResp (bResp )
|
||||||
|
);
|
||||||
|
|
||||||
|
endmodule
|
||||||
|
|
||||||
|
`resetall
|
58
generateClock.sv
Normal file
58
generateClock.sv
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
// V_erilator clock generation module, allows for the clock to be "stepped down" for use within the testbench
|
||||||
|
// SPDX-FileCopyrightText: © 2022 Aadi Desai <21363892+supleed2@users.noreply.github.com>
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
`default_nettype none
|
||||||
|
|
||||||
|
module generateClock
|
||||||
|
( output var logic o_clk // Generated clock for testbench
|
||||||
|
, input var logic i_rootClk // V_erilator clock input
|
||||||
|
, input var logic [63:0] i_periodHi // Number of rootClk cycles-1 to stay high
|
||||||
|
, input var logic [63:0] i_periodLo // Number of rootClk cycles-1 to stay low
|
||||||
|
, input var logic [ 7:0] i_jitterControl // Random jitter control (0: none --> higher number: more jitter)
|
||||||
|
);
|
||||||
|
|
||||||
|
logic intClk_d;
|
||||||
|
logic intClk_q;
|
||||||
|
logic [63:0] downCounter_d;
|
||||||
|
logic [63:0] downCounter_q;
|
||||||
|
|
||||||
|
/* svlint off legacy_always */
|
||||||
|
always @(posedge i_rootClk)
|
||||||
|
intClk_q <= intClk_d;
|
||||||
|
always @(posedge i_rootClk)
|
||||||
|
downCounter_q <= downCounter_d;
|
||||||
|
/* svlint on legacy_always */
|
||||||
|
|
||||||
|
|
||||||
|
logic [7:0] rndJitter;
|
||||||
|
always_ff @(posedge i_rootClk)
|
||||||
|
/* verilator lint_off WIDTH */
|
||||||
|
rndJitter <= $random;
|
||||||
|
/* verilator lint_on WIDTH */
|
||||||
|
|
||||||
|
logic jitterThisCycle;
|
||||||
|
assign jitterThisCycle = (rndJitter < i_jitterControl);
|
||||||
|
|
||||||
|
always_comb
|
||||||
|
if (downCounter_q == '0)
|
||||||
|
if (jitterThisCycle)
|
||||||
|
downCounter_d = downCounter_q;
|
||||||
|
else if (intClk_q)
|
||||||
|
downCounter_d = i_periodLo;
|
||||||
|
else
|
||||||
|
downCounter_d = i_periodHi;
|
||||||
|
else
|
||||||
|
downCounter_d = downCounter_q - 'd1;
|
||||||
|
|
||||||
|
always_comb
|
||||||
|
if ((downCounter_q == '0) && !jitterThisCycle)
|
||||||
|
intClk_d = ~intClk_q;
|
||||||
|
else
|
||||||
|
intClk_d = intClk_q;
|
||||||
|
|
||||||
|
assign o_clk = intClk_q;
|
||||||
|
|
||||||
|
endmodule
|
||||||
|
|
||||||
|
`resetall
|
7
run.sh
Normal file
7
run.sh
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
rm output/*
|
||||||
|
mkdir -p output
|
||||||
|
verilator --trace-fst -DUSE_FST -CFLAGS -DUSEFST --cc --exe --default-language 1800-2017 --trace-depth 5 -DN_CYCLES=25 -CFLAGS -DN_CYCLES=25 --Mdir output -Wall axiTest.cpp axiTest.sv
|
||||||
|
make -C output -f VaxiTest.mk VaxiTest
|
||||||
|
time output/VaxiTest > output/verilator.log
|
||||||
|
! grep -q ERROR output/verilator.log
|
Loading…
Reference in a new issue