2023-06-15 12:24:35 -04:00
|
|
|
/* Copyright 2023 (C) Peter McGoron
|
|
|
|
* This file is a part of Upsilon, a free and open source software project.
|
|
|
|
* For license terms, refer to the files in `doc/copying` in the Upsilon
|
|
|
|
* source distribution.
|
|
|
|
*/
|
2022-12-16 19:46:04 -05:00
|
|
|
#include <memory>
|
2022-12-18 01:06:44 -05:00
|
|
|
#include <cassert>
|
2022-12-16 19:46:04 -05:00
|
|
|
#include <limits>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
|
|
|
#include <random>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <verilated.h>
|
2022-12-17 13:39:58 -05:00
|
|
|
#include "Vram_fifo.h"
|
2022-12-16 19:46:04 -05:00
|
|
|
using ModType = Vram_fifo;
|
|
|
|
ModType *mod;
|
|
|
|
|
|
|
|
uint32_t main_time = 0;
|
|
|
|
|
2022-12-18 01:06:44 -05:00
|
|
|
double sc_time_stamp() {
|
|
|
|
return main_time;
|
|
|
|
}
|
|
|
|
|
2022-12-16 19:46:04 -05:00
|
|
|
static void run_clock() {
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
mod->clk = !mod->clk;
|
|
|
|
mod->eval();
|
|
|
|
main_time++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cleanup_exit() {
|
|
|
|
mod->final();
|
|
|
|
delete mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init(int argc, char **argv) {
|
|
|
|
Verilated::commandArgs(argc, argv);
|
|
|
|
Verilated::traceEverOn(true);
|
|
|
|
mod = new ModType;
|
|
|
|
mod->clk = 0;
|
|
|
|
atexit(cleanup_exit);
|
|
|
|
}
|
|
|
|
|
2022-12-17 13:39:58 -05:00
|
|
|
static void init_values() {
|
|
|
|
mod->rst = 0;
|
|
|
|
mod->read_enable = 0;
|
|
|
|
mod->write_enable = 0;
|
|
|
|
mod->write_dat = 0;
|
|
|
|
}
|
|
|
|
|
2022-12-18 01:06:44 -05:00
|
|
|
#define MAX_VALS 1500
|
2022-12-17 13:39:58 -05:00
|
|
|
uint32_t vals[MAX_VALS];
|
|
|
|
|
2022-12-16 19:46:04 -05:00
|
|
|
static void push(uint32_t v) {
|
2022-12-18 01:06:44 -05:00
|
|
|
assert(!mod->full);
|
2022-12-17 13:39:58 -05:00
|
|
|
mod->write_dat = v;
|
2022-12-16 19:46:04 -05:00
|
|
|
mod->write_enable = 1;
|
2022-12-17 13:39:58 -05:00
|
|
|
run_clock();
|
2022-12-16 19:46:04 -05:00
|
|
|
mod->write_enable = 0;
|
|
|
|
run_clock();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pop(int i) {
|
2022-12-18 01:06:44 -05:00
|
|
|
assert(!mod->empty);
|
2022-12-16 19:46:04 -05:00
|
|
|
mod->read_enable = 1;
|
2022-12-17 13:39:58 -05:00
|
|
|
run_clock();
|
2022-12-16 19:46:04 -05:00
|
|
|
mod->read_enable = 0;
|
|
|
|
run_clock();
|
|
|
|
}
|
|
|
|
|
2022-12-18 01:06:44 -05:00
|
|
|
static void push_random(int start, int end) {
|
|
|
|
for (int i = start; i < end; i++) {
|
2022-12-16 19:46:04 -05:00
|
|
|
vals[i] = rand() & 0xFFFFFFFFFFFF;
|
2022-12-18 01:06:44 -05:00
|
|
|
printf("%d\n", i);
|
2022-12-17 13:39:58 -05:00
|
|
|
push(vals[i]);
|
2022-12-16 19:46:04 -05:00
|
|
|
}
|
2022-12-18 01:06:44 -05:00
|
|
|
}
|
2022-12-16 19:46:04 -05:00
|
|
|
|
2022-12-18 01:06:44 -05:00
|
|
|
static void pop_random(int start, int end) {
|
|
|
|
for (int i = start; i < end; i++) {
|
2022-12-16 19:46:04 -05:00
|
|
|
pop(i);
|
2022-12-17 13:39:58 -05:00
|
|
|
if (mod->read_dat != vals[i]) {
|
|
|
|
fprintf(stderr, "expect %u, %u\n", vals[i], mod->read_dat);
|
2022-12-18 01:06:44 -05:00
|
|
|
exit(1);
|
2022-12-16 19:46:04 -05:00
|
|
|
}
|
|
|
|
}
|
2022-12-18 01:06:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
init(argc, argv);
|
|
|
|
init_values();
|
|
|
|
run_clock();
|
|
|
|
assert(mod->empty);
|
|
|
|
|
|
|
|
push_random(0, MAX_VALS);
|
|
|
|
assert(mod->full);
|
|
|
|
|
|
|
|
pop_random(0, MAX_VALS);
|
|
|
|
assert(mod->empty);
|
|
|
|
|
|
|
|
push_random(0, 50);
|
|
|
|
pop_random(0, 20);
|
|
|
|
push_random(50, 100);
|
|
|
|
pop_random(20, 100);
|
2022-12-16 19:46:04 -05:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|