simulavr  1.1.0
vpi.cpp File Reference
#include "config.h"
#include <vpi_user.h>
#include "avrdevice.h"
#include "avrfactory.h"
#include "rwmem.h"
#include "pin.h"
#include "avrerror.h"
#include "cmd/dumpargs.h"
#include "systemclock.h"

Go to the source code of this file.

Macros

#define VPI_UNPACKS(name)
 
#define VPI_UNPACKI(name)
 
#define VPI_UNPACKT(name)
 
#define VPI_RETURN_INT(val)
 
#define AVR_HCHECK()
 
#define VPI_BEGIN()
 
#define VPI_END()   vpi_free_object(argv);
 
#define VPI_REGISTER_TASK(name)
 
#define VPI_REGISTER_FUNC(name)
 

Functions

static bool checkHandle (int h)
 
static PLI_INT32 avr_create_tf (char *xx)
 
static PLI_INT32 avr_reset_tf (char *xx)
 
static PLI_INT32 avr_destroy_tf (char *xx)
 
static PLI_INT32 avr_tick_tf (char *xx)
 
static PLI_INT32 avr_set_time_tf (char *xx)
 
static PLI_INT32 avr_get_pin_tf (char *xx)
 
static PLI_INT32 avr_set_pin_tf (char *xx)
 
static PLI_INT32 avr_get_pc_tf (char *xx)
 
static PLI_INT32 avr_get_rw_tf (char *xx)
 
static PLI_INT32 avr_set_rw_tf (char *xx)
 
static PLI_INT32 avr_trace_tf (char *xx)
 
static PLI_INT32 avr_dump_arg_tf (char *xx)
 
static PLI_INT32 avr_dump_start_tf (char *xx)
 
static PLI_INT32 avr_dump_stop_tf (char *xx)
 
static void register_tasks ()
 

Variables

static std::vector< AvrDevice * > devices
 
void(* vlog_startup_routines [])()
 

Macro Definition Documentation

◆ AVR_HCHECK

#define AVR_HCHECK ( )
Value:
if (!checkHandle(handle)) { \
vpi_printf("%s: Invalid handle parameter.\n", xx); \
return 0; \
}
static bool checkHandle(int h)
Definition: vpi.cpp:43

Definition at line 103 of file vpi.cpp.

Referenced by avr_destroy_tf(), avr_dump_arg_tf(), avr_get_pc_tf(), avr_get_pin_tf(), avr_get_rw_tf(), avr_reset_tf(), avr_set_pin_tf(), avr_set_rw_tf(), and avr_tick_tf().

◆ VPI_BEGIN

#define VPI_BEGIN ( )
Value:
s_vpi_value value; \
vpiHandle ch = vpi_handle(vpiSysTfCall, 0); \
vpiHandle argv = vpi_iterate(vpiArgument, ch);

Definition at line 109 of file vpi.cpp.

Referenced by avr_create_tf(), avr_destroy_tf(), avr_dump_arg_tf(), avr_get_pc_tf(), avr_get_pin_tf(), avr_get_rw_tf(), avr_reset_tf(), avr_set_pin_tf(), avr_set_rw_tf(), avr_set_time_tf(), avr_tick_tf(), and avr_trace_tf().

◆ VPI_END

◆ VPI_REGISTER_FUNC

#define VPI_REGISTER_FUNC (   name)
Value:
{ \
s_vpi_systf_data tf_data; \
tf_data.type = vpiSysFunc; \
tf_data.tfname = "$" #name; \
tf_data.calltf = name ## _tf; \
tf_data.compiletf = 0; \
tf_data.sizetf = 0; \
tf_data.user_data = (PLI_BYTE8 *)"$" #name; \
vpi_register_systf(&tf_data); \
}

Definition at line 129 of file vpi.cpp.

Referenced by register_tasks().

◆ VPI_REGISTER_TASK

#define VPI_REGISTER_TASK (   name)
Value:
{ \
s_vpi_systf_data tf_data; \
tf_data.type = vpiSysTask; \
tf_data.tfname = "$" #name; \
tf_data.calltf = name ## _tf; \
tf_data.compiletf = 0; \
tf_data.sizetf = 0; \
tf_data.user_data = (PLI_BYTE8 *)"$" #name; \
vpi_register_systf(&tf_data); \
}

Definition at line 117 of file vpi.cpp.

Referenced by register_tasks().

◆ VPI_RETURN_INT

#define VPI_RETURN_INT (   val)
Value:
value.format = vpiIntVal; \
value.value.integer = (val); \
vpi_put_value(ch, &value, 0, vpiNoDelay); \
return 0;

Definition at line 97 of file vpi.cpp.

Referenced by avr_create_tf(), avr_get_pc_tf(), avr_get_pin_tf(), and avr_get_rw_tf().

◆ VPI_UNPACKI

#define VPI_UNPACKI (   name)
Value:
{ \
vpiHandle name = vpi_scan(argv); \
if (! name) { \
vpi_printf("%s: " #name " parameter missing.\n", xx);\
vpi_free_object(argv); \
return 0; \
} \
value.format = vpiIntVal; \
vpi_get_value(name, &value); \
} \
int name = value.value.integer;

Definition at line 71 of file vpi.cpp.

Referenced by avr_destroy_tf(), avr_dump_arg_tf(), avr_get_pc_tf(), avr_get_pin_tf(), avr_get_rw_tf(), avr_reset_tf(), avr_set_pin_tf(), avr_set_rw_tf(), and avr_tick_tf().

◆ VPI_UNPACKS

#define VPI_UNPACKS (   name)
Value:
{ \
vpiHandle name = vpi_scan(argv); \
if (! name) { \
vpi_printf("%s: " #name " parameter missing.\n", xx);\
vpi_free_object(argv); \
return 0; \
} \
value.format = vpiStringVal; \
vpi_get_value(name, &value); \
} \
std::string name = value.value.str;

Definition at line 58 of file vpi.cpp.

Referenced by avr_create_tf(), avr_dump_arg_tf(), avr_get_pin_tf(), avr_set_pin_tf(), and avr_trace_tf().

◆ VPI_UNPACKT

#define VPI_UNPACKT (   name)
Value:
{ \
vpiHandle name = vpi_scan(argv); \
if (! name) { \
vpi_printf("%s: " #name " parameter missing.\n", xx);\
vpi_free_object(argv); \
return 0; \
} \
value.format = vpiTimeVal; \
vpi_get_value(name, &value); \
} \
t_vpi_time *name = value.value.time;

Definition at line 84 of file vpi.cpp.

Referenced by avr_set_time_tf().

Function Documentation

◆ avr_create_tf()

static PLI_INT32 avr_create_tf ( char *  xx)
static

This function creates a new AVR core and `returns' a handle to it Usage from Verilog:

$avr_create(device, progname) -> handle

where handle is an integer handle by which the avr can be accessed in all other calls here device is the name of the AVR device to create progname is the path to the flash program elf binary

Definition at line 153 of file vpi.cpp.

References AvrFactory::instance(), AvrDevice::Load(), AvrFactory::makeDevice(), VPI_BEGIN, VPI_END, VPI_RETURN_INT, and VPI_UNPACKS.

◆ avr_destroy_tf()

static PLI_INT32 avr_destroy_tf ( char *  xx)
static

This function destroys an existing AVR core. Usage from Verilog:

$avr_destroy(handle)

Definition at line 189 of file vpi.cpp.

References AVR_HCHECK, VPI_BEGIN, VPI_END, and VPI_UNPACKI.

◆ avr_dump_arg_tf()

static PLI_INT32 avr_dump_arg_tf ( char *  xx)
static

This allows to enable dumping of internal variables in the simulavrxx core as a Value Change Dump file. The arguments given to this function are exactly the same as when calling simulavrxx from the command line.

Definition at line 369 of file vpi.cpp.

References AVR_HCHECK, SetDumpTraceArgs(), VPI_BEGIN, VPI_END, VPI_UNPACKI, and VPI_UNPACKS.

◆ avr_dump_start_tf()

static PLI_INT32 avr_dump_start_tf ( char *  xx)
static

Initialize all dumpers and start them. Has to be done before any clock ticks on any AVR devices, if dumping is used!

Definition at line 383 of file vpi.cpp.

References DumpManager::Instance(), and DumpManager::start().

◆ avr_dump_stop_tf()

static PLI_INT32 avr_dump_stop_tf ( char *  xx)
static

Finishes all dumping processes at the end of the application.

Definition at line 389 of file vpi.cpp.

References DumpManager::Instance(), and DumpManager::stopApplication().

◆ avr_get_pc_tf()

static PLI_INT32 avr_get_pc_tf ( char *  xx)
static

This function reads the value of the program counter in the AVR. Usage from verilog: $avr_get_pc(handle) -> pc_value

Definition at line 284 of file vpi.cpp.

References AVR_HCHECK, VPI_BEGIN, VPI_END, VPI_RETURN_INT, and VPI_UNPACKI.

◆ avr_get_pin_tf()

static PLI_INT32 avr_get_pin_tf ( char *  xx)
static

This function reads an AVR pin value. Usage from verilog: $avr_pin_get(handle, name) -> value

Definition at line 241 of file vpi.cpp.

References AVR_HCHECK, Pin::outState, VPI_BEGIN, VPI_END, VPI_RETURN_INT, VPI_UNPACKI, and VPI_UNPACKS.

◆ avr_get_rw_tf()

static PLI_INT32 avr_get_rw_tf ( char *  xx)
static

This function reads the value of a RAM-readable location in the AVR (0..31 are the regs, followed by the IO-space etc). Usage from verilog: $avr_get_rw(handle, adr) -> val where adr is the adress to read and val is the returned value at that address

Definition at line 303 of file vpi.cpp.

References AVR_HCHECK, VPI_BEGIN, VPI_END, VPI_RETURN_INT, and VPI_UNPACKI.

◆ avr_reset_tf()

static PLI_INT32 avr_reset_tf ( char *  xx)
static

This function resets an existing AVR core. Usage from Verilog:

$avr_reset(handle)

Definition at line 173 of file vpi.cpp.

References AVR_HCHECK, VPI_BEGIN, VPI_END, and VPI_UNPACKI.

◆ avr_set_pin_tf()

static PLI_INT32 avr_set_pin_tf ( char *  xx)
static

This function sets an AVR pin value. Usage from verilog: $avr_pin_set(handle, name, val)

Definition at line 260 of file vpi.cpp.

References AVR_HCHECK, Pin::SetInState(), VPI_BEGIN, VPI_END, VPI_UNPACKI, and VPI_UNPACKS.

◆ avr_set_rw_tf()

static PLI_INT32 avr_set_rw_tf ( char *  xx)
static

Counterpart to avr_get_rw_tf. It sets the value of a RAM-readable location in the AVR (0..31 are the regs, followed by the IO-space etc). Usage from verilog: $avr_set_rw(handle, adr, val) where adr is the adress to read and val is the value to set at that address

Definition at line 323 of file vpi.cpp.

References AVR_HCHECK, VPI_BEGIN, VPI_END, and VPI_UNPACKI.

◆ avr_set_time_tf()

static PLI_INT32 avr_set_time_tf ( char *  xx)
static

Set the time in the AVR system, in ns. Used for trace dumps etc. $avr_time(handle)

Definition at line 224 of file vpi.cpp.

References SystemClock::Instance(), SystemClock::SetCurrentTime(), VPI_BEGIN, VPI_END, and VPI_UNPACKT.

◆ avr_tick_tf()

static PLI_INT32 avr_tick_tf ( char *  xx)
static

This function ticks the clock of an AVR. Usage from Verilog:

$avr_tick(handle)

Definition at line 209 of file vpi.cpp.

References AVR_HCHECK, VPI_BEGIN, VPI_END, and VPI_UNPACKI.

◆ avr_trace_tf()

static PLI_INT32 avr_trace_tf ( char *  xx)
static

Enable or disable tracing for all AVR core. TODO: Implement tracing per core?

Usage from Verilog:

$avr_trace(tracename)

where tracename is the output file name for tracing. If it is the empty string, tracing will be disabled again and the file will be closed.

Definition at line 349 of file vpi.cpp.

References SystemConsoleHandler::SetTraceFile(), SystemConsoleHandler::StopTrace(), sysConHandler, VPI_BEGIN, VPI_END, and VPI_UNPACKS.

◆ checkHandle()

static bool checkHandle ( int  h)
static

Definition at line 43 of file vpi.cpp.

◆ register_tasks()

static void register_tasks ( )
static

Definition at line 394 of file vpi.cpp.

References VPI_REGISTER_FUNC, and VPI_REGISTER_TASK.

Variable Documentation

◆ devices

◆ vlog_startup_routines

void(* vlog_startup_routines[])()
Initial value:
= {
0
}
static void register_tasks()
Definition: vpi.cpp:394

Definition at line 413 of file vpi.cpp.