forked from ucb-bar/midas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoint.h
51 lines (41 loc) · 1.35 KB
/
endpoint.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// See LICENSE for license details.
#ifndef __ENDPOINT_H
#define __ENDPOINT_H
#include "simif.h"
// Endpoints are widgets that are directly exposed to simulation timing (they
// produce and/or consume simulation tokens). They must be tick()-ed for the
// simulation to make forward progress.
class endpoint_t
{
public:
endpoint_t(simif_t* s): sim(s) { }
virtual ~endpoint_t() {};
// Initialize FPGA-hosted endpoint state -- this can't be done in the constructor
virtual void init() = 0;
// Does work that allows the endpoint to advance in simulation time (one or more cycles)
virtual void tick() = 0;
// Indicates the simulation should terminate.
// Tie off to false if the endpoint will never call for the simulation to teriminate.
virtual bool terminate() = 0;
// If the endpoint calls for termination, encode a cause here. 0 = PASS All other
// codes are endpoint-implementation defined
virtual int exit_code() = 0;
protected:
void write(size_t addr, data_t data) {
sim->write(addr, data);
}
data_t read(size_t addr) {
return sim->read(addr);
}
ssize_t pull(size_t addr, char *data, size_t size) {
return sim->pull(addr, data, size);
}
ssize_t push(size_t addr, char *data, size_t size) {
if (size == 0)
return 0;
return sim->push(addr, data, size);
}
private:
simif_t *sim;
};
#endif // __ENDPOINT_H