CIRCT  20.0.0git
Functions | Variables
DpiEntryPoints.cpp File Reference
#include "dpi.h"
#include "esi/Ports.h"
#include "esi/backends/RpcServer.h"
#include <algorithm>
#include <cassert>
#include <cstdlib>
Include dependency graph for DpiEntryPoints.cpp:

Go to the source code of this file.

Functions

static void log (char *epId, bool toClient, const MessageData &msg)
 Emit the contents of 'msg' to the log file in hex. More...
 
static int findPort ()
 Get the TCP port on which to listen. More...
 
static int validateSvOpenArray (const svOpenArrayHandle data, int expectedElemSize)
 Check that an array is an array of bytes and has some size. More...
 
DPI int sv2cCosimserverEpRegister (char *endpointId, char *fromHostTypeIdC, int fromHostTypeSize, char *toHostTypeIdC, int toHostTypeSize)
 Register an endpoint. More...
 
DPI int sv2cCosimserverEpTryGet (char *endpointId, const svOpenArrayHandle data, unsigned int *dataSize)
 Try to get a message from a client. More...
 
DPI int sv2cCosimserverEpTryPut (char *endpointId, const svOpenArrayHandle data, int dataSize)
 Send a message to a client. More...
 
DPI void sv2cCosimserverFinish ()
 Shutdown the RPC server. More...
 
DPI int sv2cCosimserverInit ()
 Start the server. More...
 
DPI void sv2cCosimserverSetManifest (int esiVersion, const svOpenArrayHandle compressedManifest)
 Set the system zlib-compressed manifest. More...
 
DPI int sv2cCosimserverMMIORegister ()
 Register an MMIO module. Just checks that there is only one instantiated. More...
 
DPI int sv2cCosimserverMMIOReadTryGet (uint32_t *address)
 Read MMIO function pair. More...
 
DPI void sv2cCosimserverMMIOReadRespond (uint32_t data, char error)
 
DPI void sv2cCosimserverMMIOWriteRespond (char error)
 
DPI int sv2cCosimserverMMIOWriteTryGet (uint32_t *address, uint32_t *data)
 Write MMIO function pair. More...
 

Variables

static FILE * logFile
 If non-null, log to this file. Protected by 'serverMutex`. More...
 
static std::unique_ptr< RpcServerserver = nullptr
 
static std::mutex serverMutex
 
std::map< std::string, ReadChannelPort & > readPorts
 
std::map< ReadChannelPort *, std::future< MessageData > > readFutures
 
std::map< std::string, WriteChannelPort & > writePorts
 
static bool mmioRegistered = false
 

Function Documentation

◆ findPort()

static int findPort ( )
static

Get the TCP port on which to listen.

If the port isn't specified via an environment variable, return 0 to allow automatic selection.

Definition at line 62 of file DpiEntryPoints.cpp.

Referenced by sv2cCosimserverInit().

◆ log()

static void log ( char *  epId,
bool  toClient,
const MessageData msg 
)
static

Emit the contents of 'msg' to the log file in hex.

Definition at line 38 of file DpiEntryPoints.cpp.

References esi::MessageData::getBytes(), esi::MessageData::getSize(), logFile, and serverMutex.

Referenced by sv2cCosimserverEpTryGet(), and sv2cCosimserverEpTryPut().

◆ sv2cCosimserverEpRegister()

DPI int sv2cCosimserverEpRegister ( char *  endpointId,
char *  fromHostTypeIdC,
int  fromHostTypeSize,
char *  toHostTypeIdC,
int  toHostTypeSize 
)

Register an endpoint.

Definition at line 116 of file DpiEntryPoints.cpp.

References esi::ReadChannelPort::readAsync(), readFutures, readPorts, server, sv2cCosimserverInit(), and writePorts.

◆ sv2cCosimserverEpTryGet()

DPI int sv2cCosimserverEpTryGet ( char *  endpointId,
const svOpenArrayHandle  data,
unsigned int *  dataSize 
)

◆ sv2cCosimserverEpTryPut()

DPI int sv2cCosimserverEpTryPut ( char *  endpointId,
const svOpenArrayHandle  data,
int  dataSize 
)

Send a message to a client.

Definition at line 220 of file DpiEntryPoints.cpp.

References log(), server, svGetArrElemPtr1(), svSizeOfArray(), validateSvOpenArray(), esi::WriteChannelPort::write(), and writePorts.

◆ sv2cCosimserverFinish()

DPI void sv2cCosimserverFinish ( )

Shutdown the RPC server.

Definition at line 262 of file DpiEntryPoints.cpp.

References logFile, server, and serverMutex.

◆ sv2cCosimserverInit()

DPI int sv2cCosimserverInit ( )

Start the server.

Not required as the first endpoint registration will do this. Provided if one wants to start the server early.

Definition at line 276 of file DpiEntryPoints.cpp.

References findPort(), logFile, server, and serverMutex.

Referenced by sv2cCosimserverEpRegister(), sv2cCosimserverMMIORegister(), and sv2cCosimserverSetManifest().

◆ sv2cCosimserverMMIOReadRespond()

DPI void sv2cCosimserverMMIOReadRespond ( uint32_t  data,
char  error 
)

Definition at line 347 of file DpiEntryPoints.cpp.

References assert().

◆ sv2cCosimserverMMIOReadTryGet()

DPI int sv2cCosimserverMMIOReadTryGet ( uint32_t *  address)

Read MMIO function pair.

Assumes that reads come back in the order in which they were requested.

Definition at line 336 of file DpiEntryPoints.cpp.

◆ sv2cCosimserverMMIORegister()

DPI int sv2cCosimserverMMIORegister ( )

Register an MMIO module. Just checks that there is only one instantiated.

Definition at line 326 of file DpiEntryPoints.cpp.

References mmioRegistered, and sv2cCosimserverInit().

◆ sv2cCosimserverMMIOWriteRespond()

DPI void sv2cCosimserverMMIOWriteRespond ( char  error)

Definition at line 359 of file DpiEntryPoints.cpp.

References assert().

◆ sv2cCosimserverMMIOWriteTryGet()

DPI int sv2cCosimserverMMIOWriteTryGet ( uint32_t *  address,
uint32_t *  data 
)

Write MMIO function pair.

Assumes that write errors come back in the order in which the writes were issued.

Definition at line 373 of file DpiEntryPoints.cpp.

◆ sv2cCosimserverSetManifest()

DPI void sv2cCosimserverSetManifest ( int  esiVersion,
const svOpenArrayHandle  compressedManifest 
)

Set the system zlib-compressed manifest.

Definition at line 297 of file DpiEntryPoints.cpp.

References server, sv2cCosimserverInit(), svGetArrElemPtr1(), svSizeOfArray(), and validateSvOpenArray().

◆ validateSvOpenArray()

static int validateSvOpenArray ( const svOpenArrayHandle  data,
int  expectedElemSize 
)
static

Check that an array is an array of bytes and has some size.

Definition at line 75 of file DpiEntryPoints.cpp.

References svDimensions(), svGetArrayPtr(), svSize(), and svSizeOfArray().

Referenced by sv2cCosimserverEpTryGet(), sv2cCosimserverEpTryPut(), and sv2cCosimserverSetManifest().

Variable Documentation

◆ logFile

FILE* logFile
static

If non-null, log to this file. Protected by 'serverMutex`.

Definition at line 31 of file DpiEntryPoints.cpp.

Referenced by log(), sv2cCosimserverFinish(), and sv2cCosimserverInit().

◆ mmioRegistered

bool mmioRegistered = false
static

Definition at line 325 of file DpiEntryPoints.cpp.

Referenced by sv2cCosimserverMMIORegister().

◆ readFutures

std::map<ReadChannelPort *, std::future<MessageData> > readFutures

Definition at line 109 of file DpiEntryPoints.cpp.

Referenced by sv2cCosimserverEpRegister(), and sv2cCosimserverEpTryGet().

◆ readPorts

std::map<std::string, ReadChannelPort &> readPorts

Definition at line 108 of file DpiEntryPoints.cpp.

Referenced by sv2cCosimserverEpRegister(), and sv2cCosimserverEpTryGet().

◆ server

std::unique_ptr<RpcServer> server = nullptr
static

◆ serverMutex

std::mutex serverMutex
static

Definition at line 33 of file DpiEntryPoints.cpp.

Referenced by log(), sv2cCosimserverFinish(), and sv2cCosimserverInit().

◆ writePorts

std::map<std::string, WriteChannelPort &> writePorts