aboutsummaryrefslogtreecommitdiff
path: root/riscv/htif.h
blob: 01066957245ba7141cdfdb8bb6f6a635b6bde3b3 (plain)
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
#ifndef _HTIF_H
#define _HTIF_H

#include <stdint.h>

class sim_t;
struct packet;

// this class implements the host-target interface for program loading, etc.
class htif_t
{
public:
  htif_t(int _tohost_fd, int _fromhost_fd);
  ~htif_t();
  void init(sim_t* _sim);

  // wait for host to send start command
  void wait_for_start();

  // we block on the host if the target machine reads the fromhost register,
  // which provides determinism in tohost/fromhost communication.
  void wait_for_fromhost_write();

private:
  sim_t* sim;
  int tohost_fd;
  int fromhost_fd;
  uint16_t seqno;

  void nack(uint16_t seqno);
  void send_packet(packet* p);
  int wait_for_packet();
};

#endif