EAST-9 Adding virtual processor (VProc) and memory model to verification sub-directory of fw_development_tools repository.

This commit is contained in:
Simon Southwell 2018-11-23 07:42:08 +00:00
commit 4e0f8dd118
17 changed files with 1919 additions and 0 deletions

View file

@ -0,0 +1,189 @@
`timescale 1ps/1ps
module mem_model (
clk,
rst_n,
avs_address,
avs_write,
avs_writedata,
avs_read,
avs_readdata,
avm_rx_waitrequest,
avm_rx_burstcount,
avm_rx_address,
avm_rx_read,
avm_rx_readdata,
avm_rx_readdatavalid,
avm_tx_waitrequest,
avm_tx_burstcount,
avm_tx_address,
avm_tx_write,
avm_tx_writedata,
// SRAM style write port
wr_port_valid,
wr_port_data,
wr_port_addr
);
input clk;
input rst_n;
input [31:0] avs_address;
input avs_write;
input [31:0] avs_writedata;
input avs_read;
output reg [31:0] avs_readdata;
output reg avm_rx_waitrequest;
input [11:0] avm_rx_burstcount;
input [31:0] avm_rx_address;
input avm_rx_read;
output reg [31:0] avm_rx_readdata;
output reg avm_rx_readdatavalid;
output reg avm_tx_waitrequest;
input [11:0] avm_tx_burstcount;
input [31:0] avm_tx_address;
input avm_tx_write;
input [31:0] avm_tx_writedata;
input wr_port_valid;
input [31:0] wr_port_data;
input [31:0] wr_port_addr;
reg [31:0] rx_count;
reg [31:0] rd_addr;
reg [31:0] tx_count;
reg [31:0] wr_addr;
reg [31:0] readdata;
reg avm_rx_readdatavalid_int;
reg [31:0] avm_rx_readdata_int;
always @(posedge clk or negedge rst_n)
begin
if (rst_n == 1'b0)
begin
rx_count <= 32'h00000000;
rd_addr <= 32'h00000000;
tx_count <= 32'h00000000;
wr_addr <= 32'h00000000;
avm_tx_waitrequest <= 1'b0;
avm_rx_waitrequest <= 1'b0;
avm_rx_readdatavalid <= 1'b0;
avm_rx_readdatavalid_int <= 1'b0;
avs_readdata <= 32'h00000000;
end
else
begin
// Default some of the outputs
avs_readdata = 32'h00000000;
// Update the output valid signal wit that calculated last cycle
avm_rx_readdatavalid = avm_rx_readdatavalid_int;
// read data is valid (internally) whenever the RX counter is non-zero
avm_rx_readdatavalid_int = rx_count != 32'h00000000;
// Update RX bus output with value calculated from last cycle
avm_rx_readdata = avm_rx_readdata_int;
// Internal read data is updated from that fetched from model last cycle.
avm_rx_readdata_int = readdata;
// If a slave read, return memory contents
if (avs_read == 1'b1)
begin
$memread({avs_address[29:0], 2'b00}, avs_readdata);
end
@(negedge clk);
// If a slave write, update memory
if (avs_write == 1'b1)
begin
$memwrite({avs_address[29:0], 2'b00}, avs_writedata);
end
if (tx_count == 32'h00000000 && rx_count == 32'h00000000)
begin
avm_rx_waitrequest = 1'b0;
end
else
begin
avm_rx_waitrequest = 1'b1;
end
if (rx_count == 32'h00000000 || tx_count != 32'h00000000)
begin
avm_tx_waitrequest = 1'b0;
end
else
begin
avm_tx_waitrequest = 1'b1;
end
// If a new master read request comes in (and not active), latch the rx_count and address values
if (avm_rx_read == 1'b1 && avm_rx_waitrequest == 1'b0)
begin
// Load RX count with burst + 1 as we are going to decrement it immediately
rx_count = avm_rx_burstcount + 1;
rd_addr = avm_rx_address;
end
// If a new master write request comes in (and not active), latch the tx_count and address values
if (avm_tx_write == 1'b1 && avm_tx_waitrequest == 1'b0 && tx_count == 0)
begin
tx_count = avm_tx_burstcount;
wr_addr = avm_tx_address;
end
// If an active read transfer in progress, transfer data
if (rx_count != 32'h00000000)
begin
$memread(rd_addr, readdata);
// Decrement the word count
rx_count = rx_count - 32'h00000001;
// Increment the read address
rd_addr = rd_addr + 32'h00000004;
// Set the outputs with a valid word
//avm_rx_readdatavalid_int = 1'b1;
end
// If an active write transfer in progress, transfer data
if (avm_tx_write == 1'b1 && avm_tx_waitrequest == 1'b0 && tx_count != 32'h00000000)
begin
$memwrite(wr_addr, avm_tx_writedata);
// Decrement the word count
tx_count = tx_count - 32'h00000001;
// Increment the write address
wr_addr = wr_addr + 32'h00000004;
end
// If a write port access valid, write data
if (wr_port_valid == 1'b1)
begin
$memwrite(wr_port_addr, wr_port_data);
end
end
end
endmodule

View file

@ -0,0 +1,401 @@
//=====================================================================
//
// mem.c Date: 2018/08/20
//
// Copyright (c) 2018 Global Inkjet Systems
//
//=====================================================================
// -------------------------------------------------------------------------
// INCLUDES
// -------------------------------------------------------------------------
#include "mem.h"
// -------------------------------------------------------------------------
// STATICS
// -------------------------------------------------------------------------
static pPrimaryTbl_t PrimaryTable[VP_MAX_NODES];
// -------------------------------------------------------------------------
// InitialiseMem()
//
// Intiliases memory table to a NULL state
//
// -------------------------------------------------------------------------
void InitialiseMem (int node)
{
PrimaryTable[node] = NULL;
}
// -------------------------------------------------------------------------
// InitialisePrimaryTable()
//
// Invalidates all entries in the memory primary table
//
// -------------------------------------------------------------------------
static void InitialisePrimaryTable (const pPrimaryTbl_t table)
{
int i;
for (i = 0; i < TABLESIZE; i++)
{
table[i].valid = false;
}
}
// -------------------------------------------------------------------------
// InitialiseTable()
//
// Initialise a secondary table
//
// -------------------------------------------------------------------------
static void InitialiseTable (char **table)
{
int i;
for (i = 0; i < TABLESIZE; i++)
{
table[i] = NULL;
}
}
// -------------------------------------------------------------------------
// bitrev()
//
// An efficient bit reverse, up to 32 bits.
//
// -------------------------------------------------------------------------
static uint32_t bitrev(const uint32_t Data, const int bits)
{
unsigned long result = Data;
int i;
// Compare each of the bottom bits with reflected top bits
for (i = 0; i < bits/2; i++)
{
// If top and bottom bits different, invert both bits
if (((result >> (bits-1-i*2)) ^ result) & (1 << i))
{
result ^= (1 << i) | (1 << (bits-1-i));
}
}
return result & ((1 << bits) - 1);
}
// -------------------------------------------------------------------------
// GenHash12()
//
// A cheap and cheerful hash
//
// -------------------------------------------------------------------------
static uint32_t GenHash12(const uint64_t addr)
{
uint64_t munge = 0;
munge ^= (addr >> 52) & 0xfffULL;
munge ^= (addr >> 40) & 0xfffULL;
munge ^= (addr >> 32) & 0xffULL;
munge ^= (addr >> 24) & 0xffULL;
return bitrev((uint32_t) (munge & 0xfffULL), 12);
}
// -------------------------------------------------------------------------
// WriteRamByteBlock()
//
// Write a block of data to memory
//
// -------------------------------------------------------------------------
void WriteRamByteBlock(const uint64_t addr, const PktData_t *data, const int fbe, int const lbe, const int length, const uint32_t node)
{
uint32_t pidx, sidx, offset;
int idx;
idx = pidx = GenHash12(addr);
sidx = (addr >> 12) & TABLEMASK;
offset = addr & TABLEMASK;
if ((addr & ~TABLEMASK) != ((addr + length - 1) & ~TABLEMASK))
{
VPrint("WriteRamByteBlock: ***Error --- block write crosses 4K boundary (addr=0x%llx len=0x%x\n", addr, length);
//VWrite(PVH_FATAL, 0, 0, node);
}
// No primary table, so allocate some space for one and initialise
if (PrimaryTable[node] == NULL)
{
if ((PrimaryTable[node] = malloc(TABLESIZE * sizeof(PrimaryTbl_t))) == NULL)
{
VPrint("WriteRamByteBlock: ***Error --- failed to allocate primary table memory\n");
//VWrite(PVH_FATAL, 0, 0, node);
}
InitialisePrimaryTable(PrimaryTable[node]);
}
// Whilst we have a collision, increment primary offset until an invalid entry, or we matched address
while (PrimaryTable[node][pidx].valid && PrimaryTable[node][pidx].addr != (addr & 0xffffffffff000000ULL))
{
pidx = (pidx+1) % TABLESIZE;
// If we have searched through the whole table....
if (pidx == idx)
{
VPrint("WriteRamByteBlock: ***Error --- ran out of primary table space\n");
//VWrite(PVH_FATAL, 0, 0, node);
}
}
// If first time we have written to this block, validate it
if (!PrimaryTable[node][pidx].valid)
{
PrimaryTable[node][pidx].valid = true;
PrimaryTable[node][pidx].addr = (addr & 0xffffffffff000000ULL);
PrimaryTable[node][pidx].p = NULL;
}
// No secondary table, so allocate some space for one and initialise
if (PrimaryTable[node][pidx].p == NULL)
{
if ((PrimaryTable[node][pidx].p = malloc(TABLESIZE * sizeof(uint32_t *))) == NULL)
{
VPrint("WriteRamByteBlock: ***Error --- failed to allocate secondary table memory\n");
//VWrite(PVH_FATAL, 0, 0, node);
}
InitialiseTable(PrimaryTable[node][pidx].p);
}
// No memory block allocated, so allocate some space
if ((PrimaryTable[node][pidx].p)[sidx] == NULL)
{
if (((PrimaryTable[node][pidx].p)[sidx] = malloc(TABLESIZE)) == NULL)
{
VPrint("WriteRamByteBlock: ***Error --- failed to allocate memory\n");
//VWrite(PVH_FATAL, 0, 0, node);
}
}
for (idx = 0; idx < length; idx++)
{
if ( (idx < 4 && ((1<<idx) & fbe)) ||
(idx >= (length-4) && ((1<<(4-(length-idx))) & lbe)) ||
(idx >= 4 && idx < (length-4)))
{
((char *)((PrimaryTable[node][pidx].p)[sidx]))[idx+offset] = data[idx];
}
}
}
// -------------------------------------------------------------------------
// ReadRamByteBlock()
//
// Read a block of data from memory.
//
// -------------------------------------------------------------------------
int ReadRamByteBlock(const uint64_t addr, PktData_t *data, const int length, const uint32_t node)
{
uint32_t pidx, sidx, offset;
int idx, len;
idx = pidx = GenHash12(addr);
sidx = (addr >> 12) & TABLEMASK;
offset = addr & TABLEMASK;
if ((addr & ~TABLEMASK) != ((addr + length-1) & ~TABLEMASK))
{
VPrint("ReadRamByteBlock: ***Error --- block read crosses 4K boundary\n");
//VWrite(PVH_FATAL, 0, 0, node);
}
if (PrimaryTable[node] == NULL)
{
DebugVPrint("ReadRamByteBlock: ***Error --- reading from uninitialised primary table\n");
return MEM_BAD_STATUS;
}
// Whilst we have detected a collision, increment primary offset until an invalid entry or we matched address
while (PrimaryTable[node][pidx].valid && PrimaryTable[node][pidx].addr != (addr & 0xffffffffff000000ULL))
{
pidx = (pidx+1) % TABLESIZE;
// If we searched the whole table...
if (pidx == idx)
{
VPrint("ReadRamByteBlock: ***Error --- address does not exist in primary table\n");
//VWrite(PVH_FATAL, 0, 0, node);
}
}
// No secondary table, so flag an error
if (PrimaryTable[node][pidx].p == NULL)
{
DebugVPrint("ReadRamByteBlock: ***Error --- reading from uninitialised secondary table\n");
return MEM_BAD_STATUS;
}
// No memory block allocated, so flag an error
if ((PrimaryTable[node][pidx].p)[sidx] == NULL)
{
DebugVPrint("ReadRamByteBlock: ***Error --- reading from uninitialised memory block\n");
return MEM_BAD_STATUS;
}
for (idx = 0; idx < length; idx++)
{
data[idx] = ((char *)(PrimaryTable[node][pidx].p)[sidx])[idx+offset] & 0xff;
}
return MEM_GOOD_STATUS;
}
// -------------------------------------------------------------------------
// WriteRamByte()
//
// Write a data byte to memory.
//
// -------------------------------------------------------------------------
void WriteRamByte(const uint64_t inaddr, const uint32_t data, const uint32_t node)
{
uint64_t addr;
int addr_lo, fbe;
PktData_t buf[4];
addr = inaddr & ~3ULL;
addr_lo = (int)(inaddr & 3ULL);
fbe = 0x1 << addr_lo;
buf[addr_lo] = data & 0xff;
WriteRamByteBlock (addr, buf, fbe, 0, 4, node);
}
// -------------------------------------------------------------------------
// WriteRamWord()
//
// Write a data word to memory.
//
// -------------------------------------------------------------------------
void WriteRamWord (const uint64_t addr, const uint32_t data, const int le, const uint32_t node)
{
//VPrint("WriteRamWord(): addr=0x%08x data=0x%08x\n", addr, data);
PktData_t buf[4];
int i;
for (i = 0; i < 4; i++)
{
buf[i] = (le ? (data >> (i*8)) : (data >> ((3-i)*8))) & 0xff;
}
WriteRamByteBlock (addr & ~3ULL, buf, 0xf, 0x0, 4, node);
}
// -------------------------------------------------------------------------
// WriteRamDWord()
//
// Write a double data word (64 bits) to memory.
//
// -------------------------------------------------------------------------
void WriteRamDWord (const uint64_t addr, const uint64_t data, const int le, const uint32_t node)
{
PktData_t buf[8];
int i;
for (i = 0; i < 8; i++)
{
buf[i] = (PktData_t) (le ? (data >> (i*8)) : (data >> ((7-i)*8))) & 0xffULL;
}
WriteRamByteBlock (addr & ~7ULL, buf, 0xf, 0xf, 8, node);
}
// -------------------------------------------------------------------------
// ReadRamByte()
//
// Read a byte from memory
//
// -------------------------------------------------------------------------
uint32_t ReadRamByte (const uint64_t addr, const uint32_t node)
{
PktData_t buf[4];
int i;
// If ReadRamByteBlock fails, return 0
if (ReadRamByteBlock (addr & ~3ULL, buf, 4, node))
{
return 0;
}
i = (int)(addr & 3ULL);
return buf[i];
}
// -------------------------------------------------------------------------
// ReadRamWord()
//
// Read a word from memory
//
// -------------------------------------------------------------------------
uint32_t ReadRamWord (const uint64_t addr, const int le, const uint32_t node)
{
PktData_t buf[4];
uint32_t data = 0;
int i;
// If ReadRamByteBlock fails, return 0
if (ReadRamByteBlock (addr & ~3ULL & 0xffffffffULL, buf, 4, node))
{
return 0;
}
for (i = 0; i < 4; i++)
{
data |= (buf[i] & 0xff) << (le ? (i*8) : ((3-i)*8));
}
//VPrint("ReadRamWord(): addr=0x%08x data=0x%08x\n", addr, data);
return data;
}
// -------------------------------------------------------------------------
// ReadRamDWord()
//
// Read a double word (64 bits) from memory
//
// -------------------------------------------------------------------------
uint64_t ReadRamDWord (const uint64_t addr, const int le, const uint32_t node)
{
PktData_t buf[8];
uint64_t data = 0;
int i;
// If ReadRamByteBlock fails, return 0
if (ReadRamByteBlock (addr & ~7ULL, buf, 8, node))
{
return 0ULL;
}
for (i = 0; i < 8; i++)
{
data |= ((uint64_t)(buf[i] & 0xff)) << (le ? (i*8) : ((7-i)*8));
}
return data;
}

View file

@ -0,0 +1,59 @@
//=====================================================================
//
// mem.h Date: 2018/08/20
//
// Copyright (c) 2018 Global Inkjet Systems
//
//=====================================================================
#ifndef _MEM_H_
#define _MEM_H_
// -------------------------------------------------------------------------
// INCLUDES
// -------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include "VUser.h"
// -------------------------------------------------------------------------
// DEFINES
// -------------------------------------------------------------------------
#define TABLESIZE (4096UL)
#define TABLEMASK (TABLESIZE-1)
#define MEM_BAD_STATUS 1
#define MEM_GOOD_STATUS 0
// -------------------------------------------------------------------------
// TYPEDEFS
// -------------------------------------------------------------------------
typedef struct {
char** p;
uint64_t addr;
bool valid;
} PrimaryTbl_t, *pPrimaryTbl_t;
typedef uint16_t PktData_t;
typedef uint16_t* pPktData_t;
// -------------------------------------------------------------------------
// PROTOTYPES
// -------------------------------------------------------------------------
extern void InitialiseMem (int node);
extern void WriteRamByteBlock (const uint64_t addr, const PktData_t* const data, const int fbe, const int lbe, const int length, const uint32_t node);
extern int ReadRamByteBlock (const uint64_t addr, PktData_t* const data, const int length, const uint32_t node);
extern void WriteRamByte (const uint64_t addr, const uint32_t data, const uint32_t node);
extern void WriteRamWord (const uint64_t addr, const uint32_t data, const int little_endian, const uint32_t node);
extern void WriteRamDWord (const uint64_t addr, const uint64_t data, const int little_endian, const uint32_t node);
extern uint32_t ReadRamByte (const uint64_t addr, const uint32_t node);
extern uint32_t ReadRamWord (const uint64_t addr, const int little_endian, const uint32_t node);
extern uint64_t ReadRamDWord (const uint64_t addr, const int little_endian, const uint32_t node);
#endif

View file

@ -0,0 +1,48 @@
//=====================================================================
//
// mem_model.c Date: 2018/08/20
//
// Copyright (c) 2018 Global Inkjet Systems
//
//=====================================================================
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include "mem_model.h"
// PLI access function for $memread.
// Argument 1 is word address
// Argument 2 is 32 bit return data
int MemRead (void)
{
// Get address from $memread argument list and scale to byte address
uint32_t address = tf_getp(MEM_MODEL_ADDR_ARG);
// Get data word from memory model
uint32_t data = ReadRamWord(address, MEM_MODEL_DEFAULT_ENDIAN, MEM_MODEL_DEFAULT_NODE);
// Update data argument of $memread with returned read data
tf_putp (MEM_MODEL_DATA_ARG, data);
return 0;
}
// PLI access function for $memwrite.
// Argument 1 is word address
// Argument 2 is 32 bit data
int MemWrite (void)
{
// Get address from $memwrite argument list and scale to byte address
uint32_t address = tf_getp(MEM_MODEL_ADDR_ARG);
// Get write data from $memwrite argument list
uint32_t data = tf_getp(MEM_MODEL_DATA_ARG);
// Update data word in memory model
WriteRamWord(address, data, MEM_MODEL_DEFAULT_ENDIAN, MEM_MODEL_DEFAULT_NODE);
return 0;
}

View file

@ -0,0 +1,29 @@
//=====================================================================
//
// mem_model.h Date: 2018/08/20
//
// Copyright (c) 2018 Global Inkjet Systems
//
//=====================================================================
#include "string.h"
#include "veriuser.h"
#include "vpi_user.h"
#include "mem.h"
#define MEM_MODEL_TF_TBL \
{usertask, 0, NULL, 0, MemRead, NULL, "$memread", 1}, \
{usertask, 0, NULL, 0, MemWrite, NULL, "$memwrite", 1}
#define MEM_MODEL_TF_TBL_SIZE 2
#define MEM_MODEL_ADDR_ARG 1
#define MEM_MODEL_DATA_ARG 2
#define MEM_MODEL_DEFAULT_NODE 0
#define MEM_MODEL_DEFAULT_ENDIAN 0
extern int MemRead (void);
extern int MemWrite (void);

View file

@ -0,0 +1,136 @@
-- Virtual processor with Avalon memory mapped master BFM, based on VProc co-simulation element.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity avsvproc is
generic (
NODE_NUM : integer := 0;
SEQ_PAGE : std_logic_vector(3 downto 0) := 4x"4";
AUTO_VALID_CSR : boolean := false
);
port (
clk : in std_logic;
rst_n : in std_logic;
-- Avalon memory mapped master interface
avs_csr_address : out std_logic_vector(31 downto 0);
avs_csr_write : out std_logic;
avs_csr_writedata : out std_logic_vector(31 downto 0);
avs_csr_read : out std_logic;
avs_csr_readdata : in std_logic_vector(31 downto 0) := (others => '0');
avs_csr_readdatavalid : in std_logic := '0';
-- Avalon memory mapped master interface
avs_seq_address : out std_logic_vector(31 downto 0);
avs_seq_write : out std_logic;
avs_seq_writedata : out std_logic_vector(31 downto 0);
avs_seq_read : out std_logic;
avs_seq_readdata : in std_logic_vector(31 downto 0) := (others => '0');
avs_seq_readdatavalid : in std_logic := '0';
-- Interrupt
irq : in std_logic := '0'
);
end entity;
architecture behavioural of avsvproc is
-- Signals for VProc
signal update : std_logic;
signal RD : std_logic;
signal RDLast : std_logic;
signal Addr : std_logic_vector(31 downto 0);
signal WE : std_logic;
signal DataOut : std_logic_vector(31 downto 0);
signal DataIn : std_logic_vector(31 downto 0);
signal RDAck : std_logic;
-- Avalon bus protocol signals
signal sel_seq_bus : std_logic;
signal avs_read : std_logic;
signal avs_csr_readdatavalid_int : std_logic;
begin
-- If auto-generation of read valid for CSR bus is selected, generate in cycle after avs_csr_read
GEN_AUTO_VALID_CSR : if AUTO_VALID_CSR generate
-- Generate a read data valid for the CSR bus, as the UUT does not do so
PROC_CSR_RDVALID : process(clk, rst_n)
begin
if rst_n = '0' then
avs_csr_readdatavalid_int <= '0';
elsif clk'event and clk = '1' then
avs_csr_readdatavalid_int <= '0';
if avs_csr_read = '1' then
avs_csr_readdatavalid_int <= '1';
end if;
end if;
end process;
end generate;
-- If auto-generation of read valid for CSR bus is not selected, connect up the input port
GEN_NOT_AUTO_VALID_CSR : if not AUTO_VALID_CSR generate
avs_csr_readdatavalid_int <= avs_csr_readdatavalid;
end generate;
-- Flag if the VProc address selects the sequencer buffers page
sel_seq_bus <= '1' when Addr(19 downto 16) = SEQ_PAGE else '0';
-- Mux the busses based on the sequencer buff page flag.
-- Note. VProc produces byte addresses, but bus is 32 bit word addresses
avs_csr_read <= avs_read and not sel_seq_bus;
avs_csr_write <= WE and not sel_seq_bus;
avs_csr_writedata <= DataOut when sel_seq_bus = '0' else (others => '0');
avs_csr_address <= "00" & Addr(31 downto 2) when sel_seq_bus = '0' else (others => '0');
avs_seq_read <= avs_read and sel_seq_bus;
avs_seq_write <= WE and sel_seq_bus;
avs_seq_writedata <= DataOut when sel_seq_bus = '1' else (others => '0');
avs_seq_address <= "00" & Addr(31 downto 2) when sel_seq_bus = '1' else (others => '0');
DataIn <= avs_csr_readdata when sel_seq_bus = '0' else avs_seq_readdata;
RDAck <= avs_csr_readdatavalid_int when sel_seq_bus = '0' else avs_seq_readdatavalid;
-----------------------------------------
-- VProc instantiation
-----------------------------------------
vproc_inst : entity work.VProc
port map (
Clk => clk,
Addr => Addr,
WE => WE,
RD => RD,
DataOut => DataOut,
DataIn => DataIn,
WRAck => WE,
RDAck => RDAck,
Interrupt => "00" & irq,
Update => update,
UpdateResponse => update,
Node => std_logic_vector(to_unsigned(NODE_NUM, 4))
);
-----------------------------------------
-- Generate a delayed version of the RD
-- output of VProc
-----------------------------------------
process(clk, rst_n)
begin
if rst_n = '0' then
RDLast <= '0';
elsif clk'event and clk = '1' then
RDLast <= RD;
end if;
end process;
-- Pulse the AVS read signal only for the first cycles of RD, which won't be
-- deasserted until the RDAck/avs_readdatavalid is returned.
avs_read <= RD and not RDLast;
end behavioural;

View file

@ -0,0 +1,124 @@
//=====================================================================
//
// VProc.h Date: 2004/12/13
//
// Copyright (c) 2004-2010 Simon Southwell.
//
// This file is part of VProc.
//
// $Id$
// $Source$
//
//=====================================================================
//
// Internal header for VProc definitions and data types
//
//=====================================================================
#ifndef _VPROC_H_
#define _VPROC_H_
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#define __USE_GNU
#include <dlfcn.h>
#undef __USE_GNU
#include <pthread.h>
#include <sched.h>
#include <semaphore.h>
// For file IO
#include <fcntl.h>
// For inode manipulation
#include <unistd.h>
#ifndef VP_MAX_NODES
#define VP_MAX_NODES 64
#endif
#define M_TICK 0x100
#define M_IO 0x200
#define M_STOP 0x300
#define M_PRINT 0x400
#define V_IDLE 0
#define V_WRITE 1
#define V_READ 2
#define V_HALT 4
#define V_SWAP 8
#define VP_EXIT_OK 0
#define VP_QUEUE_ERR 1
#define VP_KEY_ERR 2
#define VP_USER_ERR 3
#define VP_SYSCALL_ERR 4
#define UNDEF -1
#define VPNODENUM_ARG 1
#define VPINTERRUPT_ARG 2
#define VPINDEX_ARG 2
#define VPDATAIN_ARG 3
#define VPDATAOUT_ARG 4
#define VPADDR_ARG 5
#define VPRW_ARG 6
#define VPTICKS_ARG 7
#define VPRESTORE_ARG 8
#define DEFAULT_STR_BUF_SIZE 32
#define MIN_INTERRUPT_LEVEL 1
#define MAX_INTERRUPT_LEVEL 7
#define MONITOR_SEG_SIZE 4096
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
typedef struct {
unsigned int addr;
unsigned int data_out;
unsigned int rw;
void *data_p;
int ticks;
} send_buf_t, *psend_buf_t;
typedef struct {
unsigned int data_in;
unsigned int interrupt;
} rcv_buf_t, *prcv_buf_t;
typedef struct {
int VPDataIn;
int VPDataOut;
int VPAddr;
int VPTicks;
short VPRw;
short Interrupt;
} monitor_t, *pmonitor_t;
// Shared object handle type
typedef void * handle_t;
// Interrupt function pointer type
typedef int (*pVUserInt_t) (void);
typedef int (*pVUserCB_t) (int);
typedef struct {
sem_t snd;
sem_t rcv;
send_buf_t send_buf;
rcv_buf_t rcv_buf;
pVUserInt_t VInt_table[MAX_INTERRUPT_LEVEL+1];
pVUserCB_t VUserCB;
} SchedState_t, *pSchedState_t;
extern pSchedState_t ns[VP_MAX_NODES];
#endif

View file

@ -0,0 +1,178 @@
//=====================================================================
//
// VSched.c Date: 2004/12/13
//
// Copyright (c) 2004-2010 Simon Southwell.
//
// This file is part of VProc.
//
// $Id$
// $Source$
//
//=====================================================================
//
// Simulator VProc C interface routines for scheduling
// access to user processes
//
// Only uses first generation PLI task/function (TF) routines
//
//=====================================================================
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include "VProc.h"
#include "VUser.h"
#include "VSched_pli.h"
// Pointers to state for each node (up to VP_MAX_NODES)
pSchedState_t ns[VP_MAX_NODES];
/////////////////////////////////////////////////////////////
// Main routine called whenever $vinit task invoked from
// initial block of VProc module.
//
int VInit ()
{
int node;
pid_t pid;
int fd;
debug_io_printf("VInit()\n");
// Get single argument value of $vinit call
node = tf_getp(VPNODENUM_ARG);
// Range check node number
if (node < 0 || node >= VP_MAX_NODES) {
io_printf("***Error: VInit() got out of range node number (%d)\n", node);
exit(VP_USER_ERR);
}
debug_io_printf("VInit(): node = %d\n", node);
// Allocate some space for the node state and update pointer
ns[node] = (pSchedState_t) malloc(sizeof(SchedState_t));
// Set up semaphores for this node
debug_io_printf("VInit(): initialising semaphores for node %d\n", node);
if (sem_init(&(ns[node]->snd), 0, 0) == -1) {
io_printf("***Error: VInit() failed to initialise semaphore\n");
exit(1);
}
if (sem_init(&(ns[node]->rcv), 0, 0) == -1) {
io_printf("***Error: VInit() failed to initialise semaphore\n");
exit(1);
}
debug_io_printf("VInit(): initialising semaphores for node %d---Done\n", node);
// Issue a new thread to run the user code
VUser(node);
return 0;
}
/////////////////////////////////////////////////////////////
// Called for a 'reason'. Holding procedure to catch 'finish'
// in case of any tidying up required.
//
int VHalt (int data, int reason)
{
debug_io_printf("VHalt(): data = %d reason = %d\n", data, reason);
if (reason == reason_endofcompile) {
} else if (reason == reason_finish) {
} else if (reason == reason_startofsave) {
} else if (reason == reason_save) {
} else if (reason == reason_restart) {
debug_io_printf("VHalt(): restart\n");
} else if (reason != reason_finish) {
debug_io_printf("VHalt(): not called for a halt reason (%d)\n", reason);
return 0;
}
}
/////////////////////////////////////////////////////////////
// Main routine called whenever $vsched task invoked, on
// clock edge of scheduled cycle.
//
int VSched ()
{
int node, Interrupt, VPDataIn;
int VPDataOut, VPAddr, VPRw, VPTicks;
// Get the input argumant values of $vsched
node = tf_getp (VPNODENUM_ARG);
Interrupt = tf_getp (VPINTERRUPT_ARG);
VPDataIn = tf_getp (VPDATAIN_ARG);
// Sample inputs and update node state
ns[node]->rcv_buf.data_in = VPDataIn;
ns[node]->rcv_buf.interrupt = Interrupt;
// Send message to VUser with VPDataIn value
debug_io_printf("VSched(): setting rcv[%d] semaphore\n", node);
sem_post(&(ns[node]->rcv));
// Wait for a message from VUser process with output data
debug_io_printf("VSched(): waiting for snd[%d] semaphore\n", node);
sem_wait(&(ns[node]->snd));
// Update outputs of $vsched task
if (ns[node]->send_buf.ticks >= DELTA_CYCLE) {
VPDataOut = ns[node]->send_buf.data_out;
VPAddr = ns[node]->send_buf.addr;
VPRw = ns[node]->send_buf.rw;
VPTicks = ns[node]->send_buf.ticks;
debug_io_printf("VSched(): VPTicks=%08x\n", VPTicks);
}
debug_io_printf("VSched(): Interrupt=%d VPDataIn=%08x VPDataOut=%08x VPAddr=%08x VPRw=%d VPTicks=%d\n", Interrupt, VPDataIn, VPDataOut, VPAddr, VPRw, VPTicks);
debug_io_printf("VSched(): returning to simulation from node %d\n\n", node);
// Update verilog PLI task ($vsched) output values with returned update data
tf_putp (VPDATAOUT_ARG, VPDataOut);
tf_putp (VPADDR_ARG, VPAddr);
tf_putp (VPRW_ARG, VPRw);
tf_putp (VPTICKS_ARG, VPTicks);
return 0;
}
/////////////////////////////////////////////////////////////
// Calls a user registered function (if available) when
// $vprocuser(node) called in verilog
//
int VProcUser()
{
int node, value;
node = tf_getp (VPNODENUM_ARG);
value = tf_getp (VPINTERRUPT_ARG);
if (ns[node]->VUserCB != NULL)
(*(ns[node]->VUserCB))(value);
return 0;
}
/////////////////////////////////////////////////////////////
// Called on $vaccess PLI task. Exchanges block data between
// C and verilog domain
//
int VAccess()
{
int node, idx;
node = tf_getp (VPNODENUM_ARG);
idx = tf_getp (VPINDEX_ARG);
tf_putp (VPDATAOUT_ARG, ((int *) ns[node]->send_buf.data_p)[idx]);
((int *) ns[node]->send_buf.data_p)[idx] = tf_getp (VPDATAIN_ARG);
return 0;
}

View file

@ -0,0 +1,41 @@
//=====================================================================
//
// VSched_pli.h Date: 2004/12/13
//
// Copyright (c) 2004-2010 Simon Southwell.
//
// This file is part of VProc.
//
// $Id$
// $Source$
//
//=====================================================================
//
// VSched function's export prototypes
//
//=====================================================================
#include "string.h"
#include "veriuser.h"
#include "vpi_user.h"
#ifdef DEBUG
#define debug_io_printf io_printf
#else
#define debug_io_printf //
#endif
#define VPROC_TF_TBL \
{usertask, 0, NULL, 0, VInit, VHalt, "$vinit", 1}, \
{usertask, 0, NULL, 0, VSched, NULL, "$vsched", 1}, \
{usertask, 0, NULL, 0, VAccess, NULL, "$vaccess", 1}, \
{usertask, 0, NULL, 0, VProcUser, NULL, "$vprocuser", 1}
#define VPROC_TF_TBL_SIZE 4
extern int VInit (void);
extern int VSched (void);
extern int VPrinter (void);
extern int VHalt (int, int);
extern int VProcUser (void);
extern int VAccess (void);

View file

@ -0,0 +1,259 @@
//=====================================================================
//
// VUser.c Date: 2004/12/13
//
// Copyright (c) 2004-2010 Simon Southwell.
//
// This file is part of VProc.
//
// $Id$
// $Source$
//
//=====================================================================
//
// Top level VP user thread routines. Sets up connection to
// queue and calls relevant user function for node number.
//
//=====================================================================
#include <errno.h>
#include "VProc.h"
#include "VUser.h"
static void VUserInit (int node);
/////////////////////////////////////////////////////////////
// Entry point for new user process. Creates a new thread
// calling VUserInit().
//
int VUser (int node)
{
pthread_t thread;
pthread_attr_t tattr;
int status;
int idx, jdx;
debug_io_printf("VUser(): node %d\n", node);
// Interrupt table initialisation
for (jdx = 0; jdx < 8; jdx++)
ns[node]->VInt_table[jdx] = NULL;
ns[node]->VUserCB = NULL;
debug_io_printf("VUser(): initialised interrupt table node %d\n", node);
pthread_attr_init(&tattr);
pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM);
// Set off the user code thread
if (status = pthread_create(&thread, &tattr, (pThreadFunc_t)VUserInit, (void *)node)) {
debug_io_printf("VUser(): pthread_create returned %d\n", status);
return 1;
}
debug_io_printf("VUser(): spawned user thread for node %d\n", node);
// Detach the thread (we won't wait for it)
//pthread_detach(thread);
//debug_io_printf("VUser(): detached user thread for node %d\n", node);
return 0;
}
/////////////////////////////////////////////////////////////
// New thread initialisation procedure. Synchronises with
// simulation before calling user procedure.
//
static void VUserInit (int node)
{
handle_t hdl;
pVUserMain_t VUserMain_func;
char funcname[DEFAULT_STR_BUF_SIZE];
int status;
debug_io_printf("VUserInit(%d)\n", node);
// Get function pointer of user entry routine
sprintf(funcname, "%s%d", "VUserMain", node);
if ((VUserMain_func = (pVUserMain_t) dlsym(RTLD_DEFAULT, funcname)) == NULL) {
io_printf("***Error: failed to find user code symbol %s (VUserInit)\n", funcname);
exit(1);
}
debug_io_printf("VUserInit(): got user function (%s) for node %d (%x)\n", funcname, node, VUserMain_func);
// Wait for first message from simulator
debug_io_printf("VUserInit(): waiting for first message semaphore rcv[%d]\n", node);
if ((status = sem_wait(&(ns[node]->rcv))) == -1) {
io_printf("***Error: bad sem_post status (%d) on node %d (VUserInit)\n", status, node);
exit(1);
}
debug_io_printf("VUserInit(): calling user code for node %d\n", node);
// Call user program
debug_io_printf("VUserInit(): calling VUserMain%d\n", node);
VUserMain_func();
}
/////////////////////////////////////////////////////////////
// Message exchange routine. Handles all messages to and from
// simulation process (apart from initialisation. Each sent
// message has a reply. Interrupt messages require that
// the original IO message reply is waited for again.
//
static void VExch (psend_buf_t psbuf, prcv_buf_t prbuf, uint32 node)
{
int status;
// Send message to simulator
ns[node]->send_buf = *psbuf;
debug_io_printf("VExch(): setting snd[%d] semaphore\n", node);
if ((status = sem_post(&(ns[node]->snd))) == -1) {
io_printf("***Error: bad sem_post status (%d) on node %d (VExch)\n", status, node);
exit(1);
}
do {
// Wait for response message from simulator
debug_io_printf("VExch(): waiting for rcv[%d] semaphore\n", node);
sem_wait(&(ns[node]->rcv));
*prbuf = ns[node]->rcv_buf;
// Check if this is an interrupt
if (prbuf->interrupt > 0) {
debug_io_printf("VExch(): node %d processing interrupt (%d)\n", node, prbuf->interrupt);
if (prbuf->interrupt >= 8) {
io_printf("***Error: invalid interrupt level %d (VExch)\n", prbuf->interrupt);
exit(1);
}
if (ns[node]->VInt_table[prbuf->interrupt] == NULL) {
io_printf("***Error: interrupt to unregistered level %d on node %d (VExch)\n", prbuf->interrupt, node);
exit(1);
}
// Call user registered interrupt function
psbuf->ticks = (*(ns[node]->VInt_table[prbuf->interrupt]))();
ns[node]->send_buf = *psbuf;
debug_io_printf("VExch(): interrupt send_buf[node].ticks = %d\n", ns[node]->send_buf.ticks);
// Send new message to simulation
debug_io_printf("VExch(): setting snd[%d] semaphore (interrupt)\n", node);
if ((status = sem_post(&(ns[node]->snd))) == -1) {
io_printf("***Error: bad sem_post status (%d) on node %d (VExch)\n", status, node);
exit(1);
}
}
// If the response was an interrupt, go back and wait for IO message response.
// (This could be in the same cycle as the interrupt)
} while (prbuf->interrupt > 0);
debug_io_printf("VExch(): returning to user code from node %d\n", node);
}
/////////////////////////////////////////////////////////////
// Invokes a write message exchange
//
int VWrite (unsigned int Addr, unsigned int Data, int Delta, uint32 node)
{
rcv_buf_t rbuf;
send_buf_t sbuf;
sbuf.addr = Addr;
sbuf.data_out = Data;
sbuf.rw = V_WRITE;
sbuf.ticks = Delta ? DELTA_CYCLE : 0;
VExch(&sbuf, &rbuf, node);
return rbuf.data_in ;
}
/////////////////////////////////////////////////////////////
// Invokes a read message exchange
//
int VRead (unsigned int Addr, unsigned int *rdata, int Delta, uint32 node)
{
rcv_buf_t rbuf;
send_buf_t sbuf;
sbuf.addr = Addr;
sbuf.data_out = 0;
sbuf.rw = V_READ;
sbuf.ticks = Delta ? DELTA_CYCLE : 0;;
VExch(&sbuf, &rbuf, node);
*rdata = rbuf.data_in;
return 0;
}
/////////////////////////////////////////////////////////////
// Invokes a array message exchange
//
int VSwap (unsigned int Addr, void *data, int Delta, uint32 node)
{
rcv_buf_t rbuf;
send_buf_t sbuf;
sbuf.addr = Addr;
sbuf.data_out = 0;
sbuf.data_p = data;
sbuf.rw = V_SWAP;
sbuf.ticks = Delta ? DELTA_CYCLE : 0;;
VExch(&sbuf, &rbuf, node);
return 0;
}
/////////////////////////////////////////////////////////////
// Invokes a tick message exchange
//
int VTick (unsigned int ticks, uint32 node)
{
rcv_buf_t rbuf;
send_buf_t sbuf;
sbuf.addr = 0;
sbuf.data_out = 0;
sbuf.rw = V_IDLE;
sbuf.ticks = ticks;
VExch(&sbuf, &rbuf, node);
return 0;
}
/////////////////////////////////////////////////////////////
// Registers a user function as an interrupt callback
//
void VRegInterrupt (int level, pVUserInt_t func, uint32 node)
{
debug_io_printf("VRegInterrupt(): at node %d, registering interrupt level %d\n", node, level);
if (level < MIN_INTERRUPT_LEVEL || level >= MAX_INTERRUPT_LEVEL) {
io_printf("***Error: attempt to register an out of range interrupt level (VRegInterrupt)\n");
exit(1);
}
ns[node]->VInt_table[level] = func;
}
/////////////////////////////////////////////////////////////
// Registers a user function as a callback against
// $vprocuser
//
void VRegUser (pVUserCB_t func, uint32 node)
{
debug_io_printf("VRegFinish(): at node %d, registering finish callback function\n", node);
ns[node]->VUserCB = func;
}

View file

@ -0,0 +1,50 @@
//=====================================================================
//
// VUser.h Date: 2005/01/10
//
// Copyright (c) 2005-2010 Simon Southwell.
//
// This file is part of VProc.
//
// $Id$
// $Source$
//
//=====================================================================
#ifndef _VUSER_H_
#define _VUSER_H_
#include "VProc.h"
#include "VSched_pli.h"
#define DELTA_CYCLE -1
#define GO_TO_SLEEP 0x7fffffff
#define MAX_INT_LEVEL 7
#define MIN_INT_LEVEL 1
// Pointer to pthread_create compatible function
typedef void *(*pThreadFunc_t)(void *);
// VUser function prototypes
extern int VUser (int node);
extern int VWrite (unsigned int addr, unsigned int data, int delta, unsigned int node);
extern int VRead (unsigned int addr, unsigned int *data, int delta, unsigned int node);
extern int VSwap (unsigned int addr, void *data, int delta, unsigned int node);
extern int VTick (unsigned int ticks, unsigned int node);
extern void VRegInterrupt (int level, pVUserInt_t func, unsigned int node);
extern void VRegUser (pVUserCB_t func, uint32 node);
//#define VPrint io_printf
#define VPrint vpi_printf
#ifdef DEBUG
#define DebugVPrint VPrint
#else
#define DebugVPrint //
#endif
// Pointer to VUserMain function type definition
typedef void (*pVUserMain_t)(void);
#endif

View file

@ -0,0 +1,67 @@
//=====================================================================
// VUserMain.c Date:
//
//=====================================================================
// Template for user program
//=====================================================================
#include <stdio.h>
#include <stdlib.h>
#include "VUser.h"
static int node;
static int VInterrupt_1(void)
{
return 0;
}
static int VInterrupt_2(void)
{
return 0;
}
static int VInterrupt_3(void)
{
return 0;
}
static int VInterrupt_4(void)
{
return 0;
}
static int VInterrupt_5(void)
{
return 0;
}
static int VInterrupt_6(void)
{
return 0;
}
static int VInterrupt_7(void)
{
return 0;
}
static int VUserCB (int value)
{
return 0;
}
// Alter ?? for this node's number (between 0 and 63)
void VUserMain??(void)
{
// Set node number to match this node
node = ??;
// Register interrupt functions (delete unused interrupts)
VRegInterrupt (1, VInterrupt_1, node);
VRegInterrupt (2, VInterrupt_2, node);
VRegInterrupt (3, VInterrupt_3, node);
VRegInterrupt (4, VInterrupt_4, node);
VRegInterrupt (5, VInterrupt_5, node);
VRegInterrupt (6, VInterrupt_6, node);
VRegInterrupt (7, VInterrupt_7, node);
VRegUser (VUserCB, node);
// --- Put user specific code here ---
// -------------- end ----------------
}

View file

@ -0,0 +1,45 @@
//=====================================================================
//
// veriuser.c Date: 2002/07/10
//
// Copyright (c) 2002-2010 Simon Southwell.
//
// This file is part of VProc.
//
// $Id$
// $Source$
//
//=====================================================================
//
// PLI task/function registration table for plitask
//
//=====================================================================
#if !defined(MODELSIM)
#include "vxl_veriuser.h"
#endif
#include "VSched_pli.h"
#include "mem_model.h"
char *veriuser_version_str = "Virtual Processor PLI V0.1 Copyright (c) 2005 Simon Southwell.";
s_tfcell veriusertfs[VPROC_TF_TBL_SIZE+MEM_MODEL_TF_TBL_SIZE+1] =
{
VPROC_TF_TBL,
MEM_MODEL_TF_TBL,
{0}
};
p_tfcell bootstrap ()
{
return veriusertfs;
}
#ifdef ICARUS
static void veriusertfs_register(void)
{
veriusertfs_register_table(veriusertfs);
}
void (*vlog_startup_routines[])() = { &veriusertfs_register, 0 };
#endif

Binary file not shown.

View file

@ -0,0 +1,15 @@
/*
* User defined Extra definitions for verilog compilation
*
* Copyright (c) 2004-2010 Simon Southwell.
*
* This file is part of VProc.
*
* $Id$
* $Source$
*/
`define VProcTimeScale `timescale 1 ps / 1 ps
`ifndef RegDel
`define RegDel 200
`endif

137
verification/vproc/makefile Normal file
View file

@ -0,0 +1,137 @@
###################################################################
# Makefile for VProc code in Modelsim on Windows with MinGW32 gcc/g++
#
# Copyright (c) 2018 Global Inkjet Systems
#
###################################################################
# The following variable can be overridden on the make command line
# for specific environment. VUsermain C++ code is expected to be
# located in USRCDIR. An additional include location under USRCDIR
# can be set in EXTINCLDIR. MODELSIMDIR should point to the simul-
# ator's root directory.
TESTDIR = ..
USRCDIR = ${TESTDIR}/src
EXTINCLDIR = ${USRCDIR}/hal
MEMMODELDIR = ../mem_model/src
MODELSIMDIR = c:\altera_17_1\ver\modelsim_ase
# -----------------------------------------------------------------
# Destination folder for object code
VOBJDIR = ${TESTDIR}\obj
# Define the maximum number of supported VProcs in the compile pli library
MAX_NUM_VPROC = 16
# VProc C source code
SRCDIR = code
# VPROC C source code
VPROC_C = VSched.c \
VUser.c
# Memory model C code
MEM_C = mem.c mem_model.c
# Test user code default (override on command line if additional files
USER_C = VUserMain0.cpp
USER_INCL =
VOBJS = ${addprefix ${VOBJDIR}/, ${USER_C:%.cpp=%.o} ${VPROC_C:%.c=%.o} ${MEM_C:%.c=%.o}}
# Generated PLI C library
VPROC_PLI = ${TESTDIR}/VProc.so
VLIB = ${TESTDIR}/libvproc.a
VPROC_TOP = test
CC = gcc
C++ = g++
CFLAGS = -fPIC \
-I${SRCDIR} \
-I${USRCDIR} \
-I${EXTINCLDIR} \
-I${MODELSIMDIR}/include \
-I${MEMMODELDIR} \
-DVP_MAX_NODES=${MAX_NUM_VPROC} \
-DMODELSIM \
-DHDL_SIM \
-D_REENTRANT
CFLAGS_SO = -shared -Wl,-export-all-symbols
# Common flags for vsim
VSIMFLAGS = -pli ${VPROC_PLI} ${VPROC_TOP}
#------------------------------------------------------
# BUILD RULES
#------------------------------------------------------
all: ${VPROC_PLI}
${VOBJDIR}/%.o: ${SRCDIR}/%.c
@${CC} -c ${CFLAGS} $< -o $@
${VOBJDIR}/%.o: ${USRCDIR}/%.cpp ${USRCDIR}/*.h ${EXTINCLDIR}/*.h
@${C++} -Wno-write-strings -c ${CFLAGS} $< -o $@
${VOBJDIR}/%.o: ${MEMMODELDIR}/%.c ${MEMMODELDIR}/*.h
@${CC} -c ${CFLAGS} $< -o $@
${VLIB} : ${VOBJS} ${VOBJDIR}
@ar cr ${VLIB} ${VOBJS}
${VOBJS}: | ${VOBJDIR}
${VOBJDIR}:
@mkdir ${VOBJDIR}
@mkdir ${VOBJDIR}\hal
${VPROC_PLI}: ${VLIB} ${VOBJDIR}/veriuser.o
@${C++} \
${CFLAGS_SO} \
${CFLAGS} \
-Wl,-whole-archive \
${VOBJDIR}/veriuser.o \
-lpthread \
-L${MODELSIMDIR}/win32aloem \
-lmtipli \
-L${TESTDIR} -lvproc \
-Wl,-no-whole-archive \
-o $@
# Let modelsim decide what's changed in the verilog
.PHONY: verilog
verilog: ${VPROC_PLI}
@vlib work
@vlog -f test.vc
#------------------------------------------------------
# EXECUTION RULES
#------------------------------------------------------
run: verilog
@vsim -c ${VSIMFLAGS}
rungui: verilog
@vsim -gui -do wave.do ${VSIMFLAGS}
gui: rungui
#------------------------------------------------------
# CLEANING RULES
#------------------------------------------------------
clean:
@rm -rf "${VPROC_PLI}"
@rm -rf "${VLIB}"
@rm -rf "${VOBJDIR}"
@rm -rf "${VOBJDIR}\hal"
@rm -rf "wlf*"
@rm -rf "work"

141
verification/vproc/vproc.v Normal file
View file

@ -0,0 +1,141 @@
/*
* Verilog side Virtual Processor, for running host
* programs as control in simulation.
*
* Copyright (c) 2004-2016 Simon Southwell.
*
* This file is part of VProc.
*
* $Id$
* $Source
*/
`VProcTimeScale
`define WEbit 0
`define RDbit 1
`define DeltaCycle -1
module VProc (Clk, Addr, WE, RD, DataOut, DataIn, WRAck, RDAck, Interrupt, Update, UpdateResponse, Node);
input Clk;
input RDAck;
input WRAck;
input UpdateResponse;
input [3:0] Node;
input [2:0] Interrupt;
input [31:0] DataIn;
output [31:0] Addr, DataOut;
output WE;
output RD;
output Update;
integer VPDataOut;
integer VPAddr;
integer VPRW;
integer VPTicks;
integer TickVal;
reg [31:0] DataOut;
reg [31:0] DataInSamp;
reg [31:0] Addr;
reg [2:0] IntSamp;
reg WE;
reg RD;
reg RdAckSamp;
reg WRAckSamp;
reg Initialised;
reg Update;
initial
begin
TickVal = 1;
Initialised = 0;
WE = 0;
RD = 0;
Update = 0;
// Don't remove delay! Needed to allow Node to be assigned
#1
$vinit(Node);
Initialised = 1;
end
always @(posedge Clk)
begin
// Cleanly sample the inputs
DataInSamp = DataIn;
RdAckSamp = RDAck;
WRAckSamp = WRAck;
IntSamp = Interrupt;
if (Initialised == 1'b1)
begin
if (IntSamp > 0)
begin
$vsched({28'h0000000, Node}, {29'h00000000, IntSamp}, DataInSamp, VPDataOut, VPAddr, VPRW, VPTicks);
// If interrupt routine returns non-zero tick, then override
// current tick value. Otherwise, leave at present value.
if (VPTicks > 0)
begin
TickVal = VPTicks;
end
end
// If tick, write or a read has completed...
if ((RD === 1'b0 && WE === 1'b0 && TickVal === 0) ||
(RD === 1'b1 && RdAckSamp === 1'b1) ||
(WE === 1'b1 && WRAckSamp === 1'b1))
begin
// Host process message scheduler called
$vsched({28'h0000000, Node}, 32'h0, DataInSamp, VPDataOut, VPAddr, VPRW, VPTicks);
#`RegDel
WE = VPRW[`WEbit];
RD = VPRW[`RDbit];
DataOut = VPDataOut;
Addr = VPAddr;
Update = ~Update;
@(UpdateResponse);
// Update current tick value with returned number (if not zero)
if (VPTicks > 0)
begin
TickVal = VPTicks;
end
else if ( VPTicks < 0)
begin
while (VPTicks == `DeltaCycle)
begin
// Resample delta input data
DataInSamp = DataIn;
$vsched({28'h0000000, Node}, 32'h0, DataInSamp, VPDataOut, VPAddr, VPRW, VPTicks);
WE = VPRW[`WEbit];
RD = VPRW[`RDbit];
DataOut = VPDataOut;
Addr = VPAddr;
Update = ~Update;
if (VPTicks >= 0)
begin
TickVal = VPTicks;
end
@(UpdateResponse);
end
end
end
else
begin
// Count down to zero and stop
TickVal = (TickVal > 0) ? TickVal - 1 : 0;
end
end
end
endmodule