| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A modular RTL implementation of a Direct-Mapped Cache Controller designed using Verilog HDL. The cache implements a write-back and write-allocate policy and uses a finite state machine (FSM) to manage cache hits, misses, dirty block eviction, and memory refill operations.
The design follows a modular architecture by separating the cache controller, cache storage, and main memory model, making the project easier to verify, debug, and extend.
| Parameter | Value |
|---|---|
| Address Width | 32 bits |
| Data Width | 32 bits |
| Cache Size | 64 Bytes |
| Number of Cache Blocks | 16 |
| Block Size | 4 Bytes |
| Words per Block | 1 |
| Mapping | Direct Mapped |
| Write Policy | Write Back |
| Write Miss Policy | Write Allocate |
| Tag Width | 26 bits |
| Index Width | 4 bits |
| Byte Offset Width | 2 bits |
The 32-bit CPU address is divided into three fields:
The cache line index is determined using: Cache Index = (Memory Block Number) % (Number of Cache Lines)
Each cache line contains:
| Field | Width |
|---|---|
| Valid Bit | 1 bit |
| Dirty Bit | 1 bit |
| Tag | 26 bits |
| Data | 32 bits |
The cache data capacity is 64 bytes, while tag and status metadata are stored separately.
The project consists of the following modules:
Top-level cache module responsible for integrating the cache controller and cache memory.
Implements the cache control logic and FSM. It handles:
Implements the cache storage using separate arrays for:
A parameterized main memory model used for simulation. It includes configurable memory latency and a request/ready handshake interface.
Self-checking Verilog testbench used to verify cache functionality.
The cache controller uses five states:
The requested data is directly returned from the cache.
The cache data is updated and the dirty bit is set.
If the victim cache line is clean, the requested data is fetched from main memory and allocated in the cache.
If the victim cache line is dirty, it is first written back to main memory before the requested data is fetched.
The cache implements a write-allocate policy. The requested word is first fetched from main memory, allocated in the cache, updated with the CPU write data, and marked dirty.
The self-checking testbench verifies:
The testbench automatically reports PASS or FAIL for each read operation.
Compile using Icarus Verilog:
iverilog -g2012 -o cache_sim cache_memory.v cache_controller.v direct_mapped_cache.v main_memory.v tb_direct_mapped_cache.v
Run the simulation:
vvp cache_sim
View the generated waveform using GTKWave:
gtkwave cache.vcd
| Back | FazBrowse Home | New Git URL |