-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRAM.h
More file actions
68 lines (56 loc) · 1.97 KB
/
Copy pathRAM.h
File metadata and controls
68 lines (56 loc) · 1.97 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once
#include <map>
#include <systemc>
#include <unordered_map>
#include <cstdint>
SC_MODULE(RAM) {
public:
// ====================================== External Ports ======================================
// Global Clock
sc_core::sc_in<bool> SC_NAMED(clock);
// -> RAM
sc_core::sc_in<std::uint32_t> SC_NAMED(dataInBus);
sc_core::sc_in<std::uint32_t> SC_NAMED(addressBus);
sc_core::sc_in<bool> SC_NAMED(weBus);
sc_core::sc_in<bool> SC_NAMED(validRequestBus);
// RAM ->
sc_core::sc_out<sc_dt::sc_bv<128>> SC_NAMED(dataOutBus);
sc_core::sc_out<bool> SC_NAMED(readyBus);
private:
std::uint32_t memoryLatency;
std::uint32_t wordsPerRead;
#ifdef RAM_DEBUG
public:
#endif
std::unordered_map<std::uint32_t, std::uint8_t> dataMemory{};
public:
RAM(sc_core::sc_module_name name, std::uint32_t memoryLatency, std::uint32_t wordsPerRead);
private:
SC_CTOR(RAM) {}
// ======================================= Main Handling =======================================
/**
* Sleeps until it receives a valid requests and than based on the requests either reads from the data memory
* or writes to it.
*/
void provideData() noexcept;
/**
* Reads byte at the given address from the data memory
* @param address to read
* @return data to to corresponding address
*/
std::uint8_t readByteFromMem(std::uint32_t addr) noexcept;
/**
* Splits up input int into 4 bytes and then writes it to data memory to the given address
*/
void doWrite() noexcept;
/**
* Reads word into a 128 bit buffer byte by byte at the received address a with a offset of (128/8) * word
* @param word offset * 16 to received address
*/
void readWord(std::uint32_t word) noexcept;
// ====================================== Waiting Helpers ======================================
/**
* Sleeps for memoryLatency cycles
*/
void waitOutMemoryLatency() noexcept;
};