| 1 |
3 |
sergeykhbr |
/**
|
| 2 |
|
|
* @file
|
| 3 |
|
|
* @copyright Copyright 2016 GNSS Sensor Ltd. All right reserved.
|
| 4 |
|
|
* @author Sergey Khabarov - sergeykhbr@gmail.com
|
| 5 |
|
|
* @brief Memory Cache Top level.
|
| 6 |
|
|
*/
|
| 7 |
|
|
|
| 8 |
|
|
#ifndef __DEBUGGER_RIVERLIB_CACHE_TOP_H__
|
| 9 |
|
|
#define __DEBUGGER_RIVERLIB_CACHE_TOP_H__
|
| 10 |
|
|
|
| 11 |
|
|
#include <systemc.h>
|
| 12 |
|
|
#include "../river_cfg.h"
|
| 13 |
|
|
#include "icache.h"
|
| 14 |
|
|
#include "dcache.h"
|
| 15 |
|
|
|
| 16 |
|
|
namespace debugger {
|
| 17 |
|
|
|
| 18 |
|
|
SC_MODULE(CacheTop) {
|
| 19 |
|
|
sc_in<bool> i_clk; // CPU clock
|
| 20 |
|
|
sc_in<bool> i_nrst; // Reset active LOW
|
| 21 |
|
|
// Control path:
|
| 22 |
|
|
sc_in<bool> i_req_ctrl_valid; // Control request from CPU Core is valid
|
| 23 |
|
|
sc_in<sc_uint<BUS_ADDR_WIDTH>> i_req_ctrl_addr; // Control request address
|
| 24 |
|
|
sc_out<bool> o_req_ctrl_ready; // Control request from CPU Core is accepted
|
| 25 |
|
|
sc_out<bool> o_resp_ctrl_valid; // ICache response is valid and can be accepted
|
| 26 |
|
|
sc_out<sc_uint<BUS_ADDR_WIDTH>> o_resp_ctrl_addr; // ICache response address
|
| 27 |
|
|
sc_out<sc_uint<32>> o_resp_ctrl_data; // ICache read data
|
| 28 |
|
|
sc_in<bool> i_resp_ctrl_ready; // CPU Core is ready to accept ICache response
|
| 29 |
|
|
// Data path:
|
| 30 |
|
|
sc_in<bool> i_req_data_valid; // Data path request from CPU Core is valid
|
| 31 |
|
|
sc_in<bool> i_req_data_write; // Data write memopy operation flag
|
| 32 |
|
|
sc_in<sc_uint<2>> i_req_data_size; // Memory operation size: 0=1B; 1=2B; 2=4B; 3=8B
|
| 33 |
|
|
sc_in<sc_uint<BUS_ADDR_WIDTH>> i_req_data_addr; // Memory operation address
|
| 34 |
|
|
sc_in<sc_uint<RISCV_ARCH>> i_req_data_data; // Memory operation write value
|
| 35 |
|
|
sc_out<bool> o_req_data_ready; // Memory operation request accepted by DCache
|
| 36 |
|
|
sc_out<bool> o_resp_data_valid; // DCache response is ready
|
| 37 |
|
|
sc_out<sc_uint<BUS_ADDR_WIDTH>> o_resp_data_addr; // DCache response address
|
| 38 |
|
|
sc_out<sc_uint<RISCV_ARCH>> o_resp_data_data; // DCache response read data
|
| 39 |
|
|
sc_in<bool> i_resp_data_ready; // CPU Core is ready to accept DCache repsonse
|
| 40 |
|
|
// Memory interface:
|
| 41 |
|
|
sc_in<bool> i_req_mem_ready; // System Bus (AXI) is available
|
| 42 |
|
|
sc_out<bool> o_req_mem_valid; // Memory operation to system bus is valid
|
| 43 |
|
|
sc_out<bool> o_req_mem_write; // Memory operation write flag
|
| 44 |
|
|
sc_out<sc_uint<BUS_ADDR_WIDTH>> o_req_mem_addr; // Requesting address
|
| 45 |
|
|
sc_out<sc_uint<BUS_DATA_BYTES>> o_req_mem_strob; // Writing strob 1 bit per 1 byte (AXI compliance)
|
| 46 |
|
|
sc_out<sc_uint<BUS_DATA_WIDTH>> o_req_mem_data; // Writing value
|
| 47 |
|
|
sc_in<bool> i_resp_mem_data_valid; // Memory operation from system bus is completed
|
| 48 |
|
|
sc_in<sc_uint<BUS_DATA_WIDTH>> i_resp_mem_data; // Read value
|
| 49 |
|
|
// Debug signals:
|
| 50 |
|
|
sc_out<sc_uint<2>> o_istate; // ICache state machine value
|
| 51 |
|
|
sc_out<sc_uint<2>> o_dstate; // DCache state machine value
|
| 52 |
|
|
sc_out<sc_uint<2>> o_cstate; // cachetop state machine value
|
| 53 |
|
|
|
| 54 |
|
|
void comb();
|
| 55 |
|
|
void registers();
|
| 56 |
|
|
|
| 57 |
|
|
SC_HAS_PROCESS(CacheTop);
|
| 58 |
|
|
|
| 59 |
|
|
CacheTop(sc_module_name name_);
|
| 60 |
|
|
virtual ~CacheTop();
|
| 61 |
|
|
|
| 62 |
|
|
void generateVCD(sc_trace_file *i_vcd, sc_trace_file *o_vcd);
|
| 63 |
|
|
|
| 64 |
|
|
private:
|
| 65 |
|
|
static const uint8_t State_Idle = 0;
|
| 66 |
|
|
static const uint8_t State_IMem = 1;
|
| 67 |
|
|
static const uint8_t State_DMem = 2;
|
| 68 |
|
|
|
| 69 |
|
|
struct CacheOutputType {
|
| 70 |
|
|
sc_signal<bool> req_mem_valid;
|
| 71 |
|
|
sc_signal<bool> req_mem_write;
|
| 72 |
|
|
sc_signal<sc_uint<BUS_ADDR_WIDTH>> req_mem_addr;
|
| 73 |
|
|
sc_signal<sc_uint<BUS_DATA_BYTES>> req_mem_strob;
|
| 74 |
|
|
sc_signal<sc_uint<BUS_DATA_WIDTH>> req_mem_wdata;
|
| 75 |
|
|
};
|
| 76 |
|
|
|
| 77 |
|
|
struct RegistersType {
|
| 78 |
|
|
sc_signal<sc_uint<2>> state;
|
| 79 |
|
|
} v, r;
|
| 80 |
|
|
|
| 81 |
|
|
CacheOutputType i, d;
|
| 82 |
|
|
|
| 83 |
|
|
// Memory Control interface:
|
| 84 |
|
|
sc_signal<bool> w_ctrl_resp_mem_data_valid;
|
| 85 |
|
|
sc_signal<sc_uint<BUS_DATA_WIDTH>> wb_ctrl_resp_mem_data;
|
| 86 |
|
|
sc_signal<bool> w_ctrl_req_ready;
|
| 87 |
|
|
// Memory Data interface:
|
| 88 |
|
|
sc_signal<bool> w_data_resp_mem_data_valid;
|
| 89 |
|
|
sc_signal<sc_uint<BUS_DATA_WIDTH>> wb_data_resp_mem_data;
|
| 90 |
|
|
sc_signal<bool> w_data_req_ready;
|
| 91 |
|
|
|
| 92 |
|
|
ICache *i0;
|
| 93 |
|
|
DCache *d0;
|
| 94 |
|
|
#ifdef DBG_ICACHE_TB
|
| 95 |
|
|
ICache_tb *i0_tb;
|
| 96 |
|
|
#endif
|
| 97 |
|
|
};
|
| 98 |
|
|
|
| 99 |
|
|
|
| 100 |
|
|
} // namespace debugger
|
| 101 |
|
|
|
| 102 |
|
|
#endif // __DEBUGGER_RIVERLIB_CACHE_TOP_H__
|