forked from IObundle/iob-soc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip(verilator): Add verilator testbench utility functions.
- Update mkregs.py to generate verilator testbench code - Add iob_tasks equivalent for verilator - Update iob-soc verilator testbench to use new functions and drive ethernet [WIP]
- Loading branch information
Showing
6 changed files
with
254 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "iob_tasks.h" | ||
|
||
// Keep track of simulation time | ||
vluint64_t main_time = 0; | ||
|
||
// Store timer related settings (clk and eval) | ||
timer_settings_t task_timer_settings; | ||
|
||
// | ||
// Verilator functions to drive the IOb Native protocol | ||
// | ||
|
||
// Write data to IOb Native slave | ||
// 1-cycle write | ||
void iob_write(unsigned int cpu_address, unsigned int cpu_data, | ||
unsigned int nbytes, iob_native_t *native_if) { | ||
char wstrb_int = 0; | ||
switch (nbytes) { | ||
case 1: | ||
wstrb_int = 0b01; | ||
break; | ||
case 2: | ||
wstrb_int = 0b011; | ||
break; | ||
default: | ||
wstrb_int = 0b01111; | ||
break; | ||
} | ||
*(native_if->iob_addr) = cpu_address; | ||
*(native_if->iob_valid) = 1; | ||
*(native_if->iob_wstrb) = wstrb_int << (cpu_address & 0b011); | ||
*(native_if->iob_wdata) = cpu_data | ||
<< ((cpu_address & 0b011) * 8); // align data to 32 bits | ||
Timer(CLK_PERIOD); | ||
*(native_if->iob_wstrb) = 0; | ||
*(native_if->iob_valid) = 0; | ||
} | ||
|
||
// Read data from IOb Native slave | ||
// 2-cycle read | ||
char iob_read(unsigned int cpu_address, iob_native_t *native_if) { | ||
char read_reg = 0; | ||
*(native_if->iob_addr) = cpu_address; | ||
*(native_if->iob_valid) = 1; | ||
Timer(CLK_PERIOD); | ||
read_reg = | ||
*(native_if->iob_rdata) >> ((cpu_address & 0b011) * 8); // align to 32 bits | ||
*(native_if->iob_valid) = 0; | ||
return read_reg; | ||
} | ||
|
||
// Delay | ||
void Timer(unsigned int ns) { | ||
for (int i = 0; i < ns; i++) { | ||
if (!(main_time % (CLK_PERIOD / 2))) { | ||
*(task_timer_settings.clk) = !*(task_timer_settings.clk); | ||
(*task_timer_settings.eval)(); | ||
} | ||
// To add a new clk follow the example | ||
// if(!(main_time%(EXAMPLE_CLK_PERIOD/2))){ | ||
// *(task_timer_settings.example_clk) = !*(task_timer_settings.example_clk); | ||
//} | ||
main_time += 1; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef H_IOB_TASKS_H | ||
#define H_IOB_TASKS_H | ||
|
||
#include "bsp.h" | ||
#include <verilated.h> | ||
|
||
#ifndef CLK_PERIOD | ||
#define CLK_PERIOD 1000000000 / FREQ // 1/100MHz*10^9 = 10 ns | ||
#endif | ||
|
||
// Struct defining iob-native interface | ||
typedef struct { | ||
unsigned char *iob_valid; | ||
short unsigned int *iob_addr; | ||
unsigned int *iob_wdata; | ||
unsigned char *iob_wstrb; | ||
unsigned int *iob_rdata; | ||
unsigned char *iob_rvalid; | ||
unsigned char *iob_ready; | ||
} iob_native_t; | ||
|
||
typedef struct { | ||
unsigned char *clk; | ||
void (*eval)(void); | ||
} timer_settings_t; | ||
|
||
void Timer(unsigned int ns); | ||
void iob_write(unsigned int cpu_address, unsigned int cpu_data, unsigned int nbytes, iob_native_t *native_if); | ||
char iob_read(unsigned int cpu_address, iob_native_t *native_if); | ||
|
||
#endif // H_IOB_TASKS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.