summaryrefslogtreecommitdiff
path: root/inc/dram.h
blob: 7774040e68112fe0786f4912665bedb790469256 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef DRAM_H
#define DRAM_H
#include "definitions.h"
#include "storage.h"
#include <ostream>

class Dram : public Storage
{
  public:
	/**
	 * Constructor.
	 * @param The number of `lines` contained in memory. The total number of
	 * words is this number multiplied by LINE_SIZE.
	 * @param The number of clock cycles each access takes.
	 * @return A new memory object.
	 */
	Dram(int lines, int delay);
	~Dram();

	Response write(Accessor accessor, signed int data, int address) override;
	Response read(
		Accessor accessor,
		int address,
		std::array<signed int, LINE_SIZE> &data_line) override;
	Response write_line(Accessor accessor, std::array<signed int, LINE_SIZE> data_line, int address) override;
	Response read_word(Accessor accessor, int address, signed int &data) override;

	private:
	/**
	 * Helper for `write` a word
	 */
	void do_write(signed int, int);
	/**
	 * Helper for writing a line.
	 */
	void do_write_line(std::array<signed int, LINE_SIZE> data_line, int address);
	/**
	 * Helper for `read` a line
	 */
	void do_read(std::array<signed int, LINE_SIZE> &data_line, int address);
	/**
	 * Helper for reading a word.
	 */
	void do_read_word(signed int &data, int address);
};

std::ostream &operator<<(std::ostream &os, const Dram &d);

#endif /* DRAM_H_INCLUDED */