With a TCM, a manager port, an interconnect and an SRAM, you have everything a program needs to compute and to move data over a bus. This article joins them. You write the CPU subsystem, the module that puts the core, the TCM and the manager port together with a few lines of logic between them, and the tests connect it to your interconnect and SRAM and run compiled C programs on the result. It is the first time your blocks work as a system, and the first time a mistake can come from the way two correct blocks meet. Exercise S08 is the system exercise of this chapter.
9 min read | Intermediate
What You'll Learn
- Write the logic that joins a core to its local memory and its bus port
- Decide, for every data access, whether it completes at once or waits for the bus
- Run C programs on your own blocks and read the result of a system test
- Explain the cycle cost of putting data in the SRAM instead of the TCM
Before You Start
This section needs Verilog: see the Verilog Tutorial. Pass these first: S02 (The TCM and the Local Decode), S03 and S04 (An AXI4-Lite Manager Port), S05 (An AXI4-Lite SRAM) and S06 and S07 (The Interconnect). Integrating the CPU Subsystem explains what a CPU subsystem is in a real SoC, and Running Programs on an SoC explains how the tests load and run a program.
The CPU Subsystem
The CPU subsystem is the core together with what it needs close by, delivered as one block with one bus port. That is how CPUs are bought and integrated in industry: the core vendor's subsystem has the core, its local memories and its bus interface inside, and the rest of the chip sees only an AXI port. In cvsoc, cvsoc_cpu_subsys has exactly that outside: a clock, a reset, and the AXI4-Lite manager port.
module cvsoc_cpu_subsys (
input logic clk,
input logic rst_n,
// AXI4-Lite manager port (to the interconnect)
output logic [31:0] m_awaddr,
output logic m_awvalid,
input logic m_awready,
output logic [31:0] m_wdata,
output logic [3:0] m_wstrb,
output logic m_wvalid,
input logic m_wready,
input logic [1:0] m_bresp,
input logic m_bvalid,
output logic m_bready,
output logic [31:0] m_araddr,
output logic m_arvalid,
input logic m_arready,
input logic [31:0] m_rdata,
input logic [1:0] m_rresp,
input logic m_rvalid,
output logic m_rready
);
Inside it are three instances, and their names are part of the specification, because the tests reach into them: they load the program into u_tcm.mem and watch the core's data port through u_core.
u_core, acvr32_core. The tests provide it; to use your own from S01, start the file with`define CVSOC_OWN_COREand paste your core and its blocks.u_tcm, yourcvsoc_tcmfrom S02.u_axi, yourcvsoc_axil_masterfrom S04, whosem_ports are the subsystem's.
The Logic That Joins Them
The core's instruction port goes straight to the TCM's instruction port. Instructions only ever come from the TCM, which answers in the same cycle, so the core's imem_ready is tied to 1.
The core's data port is where the decisions are. For every cycle, look at what the core is doing in W and at the TCM's hit:
| The core in W | Address | Goes to | dmem_ready | dmem_rdata |
|---|---|---|---|---|
| no load or store | any | nowhere | 1 | don't care |
| load or store | in the TCM (hit = 1) | the TCM only | 1, at once | the TCM's data |
| load or store | outside (hit = 0) | the manager port, as a request | the manager port's done | the manager port's rdata |
Three details make the table work. A request to the manager port is the core's store or load qualified with hit = 0, so that TCM accesses never reach the bus; the core's address, data and byte enables can go to the manager port unchanged. While the bus access is in flight the core holds, so the request stays the same until done, exactly as the manager port requires. And the core's own write enable also goes to the TCM, which ignores it when hit is 0, as S02 required.
Quick Check
Q: A CPU subsystem sets dmem_ready = done whenever hit is 0, without looking at whether the core is making an access. What happens to a program, and when?
Show Answer
Most instructions are not loads or stores, and their address on the data port is whatever the ALU computed, often outside the TCM. For those, hit is 0 and no request is made, so done never comes: dmem_ready stays 0 and the core holds forever at the first such instruction. The "no access" row of the table matters: no access means ready.
How the Tests Build the System
For S08 you submit one file with your S02 to S07 modules and your new cvsoc_cpu_subsys. The tests build a system around it: your interconnect with the cvsoc windows, your SRAM as subordinate 0, and as subordinate 1 a small model of the peripheral window written in the test. The model holds the EXIT register at 0x4000_F000, answers OKAY in the four used slots and SLVERR in empty ones. The real peripherals come in chapter 13.
Three programs from Running Programs on an SoC run on it:
copy_tcmfills a 4 KB buffer in the TCM, copies it to a second buffer in the TCM and checksums the copy. It uses the bus only for its final store to EXIT.copy_sramdoes the same with the second buffer in the SRAM: 1,024 writes over the bus, then 1,024 reads back.badaddrreads three addresses no block owns and checks that each returned 0.
Each must end with its expected result. One more check runs all the time: if a TCM address ever appears on the manager port, the test fails at once, naming the address. That catches a subsystem that sends TCM accesses to the bus too, which would still give the right results here, because the interconnect answers them with DECERR and the TCM writes them anyway, but would be wrong in any real chip.
What the Programs Cost
On the reference design, with the 3-stage core, the hidden tests report:
S08: PASS (copy_tcm, 24600 cycles) S08: PASS (copy_sram, 30744 cycles) S08: PASS (badaddr, 34 cycles)
The two copies run the same 21,522 instructions. The difference, 6,144 cycles, is the price of the SRAM: 2,048 accesses, each taking 4 cycles instead of 1, so 3 more each. Nothing else changes; the core is the same and the program is the same. This is the trade every SoC makes: the TCM is fast and small and private to one core, the SRAM is slower and can be shared with other managers. Latency and Bandwidth works through the same kind of arithmetic.
The visible test runs copy_sram too, but on a behavioral stand-in core, a short model that runs one instruction per cycle, because a visible test cannot contain the real core. It checks your system the same way and prints a different cycle count; use the hidden tests' numbers above for the real design.
Where Is This Used?
The first time a program runs on a new chip's subsystem, in simulation, is a milestone on every SoC project, often called "hello world" or "first boot". The tests are much like these: small programs whose answers are known, chosen so that each one exercises one path (local memory only, the bus, an error response). When one fails, the team looks for the first access that went wrong, which is why the S08 test checks the manager port in every cycle instead of only the final result.
Quick Check
Q: If the SRAM answered every access in 2 cycles instead of 4, how many cycles would copy_sram take?
Show Answer
Each of the 2,048 SRAM accesses would save 2 cycles, 4,096 in all: 30,744 - 4,096 = 26,648 cycles, still 2,048 more than copy_tcm, because each SRAM access would still take 1 cycle more than a TCM access.
Common Mistakes
Mistake #1: Sending TCM accesses to the bus too
Passing the core's dmem_we or dmem_re to the manager port without the hit condition sends TCM accesses out on the bus as well. The core does not wait for them, because the TCM answers at once, but the manager port starts a transaction for each, which the interconnect answers with DECERR, and a real bus access that follows can meet a port that is still busy. The test stops at the first TCM address it sees on the manager port.
Mistake #2: Reversing the read data choice
Taking the manager port's rdata for TCM addresses and the TCM's data for bus addresses gives garbage for both. The first load from the stack returns whatever the bus last delivered.
Mistake #3: Renaming the instances
The tests load the program into u_cpu.u_tcm.mem (in S08, u_cpu is the test's instance of your subsystem) and watch u_core. Any other instance name fails to compile against the test.
Your Turn in the Lab
Exercise S08: paste your S02 to S07 modules into one file and write cvsoc_cpu_subsys. Run the visible test, then submit. Save the subsystem in your lab project; the complete SoC in S16 uses it unchanged.
Summary
- The CPU subsystem holds the core, the TCM and the manager port, named
u_core,u_tcmandu_axi, and shows the rest of the chip one AXI4-Lite port. - Instructions come from the TCM with
imem_ready= 1; a data access in the TCM is ready at once, one outside goes to the manager port and is ready atdone, and no access at all is ready. - The tests connect your subsystem to your interconnect and SRAM and a model of the peripherals, run
copy_tcm,copy_sramandbadaddr, and fail at once if a TCM address reaches the bus. copy_tcmtakes 24,600 cycles andcopy_sram30,744 for the same 21,522 instructions: 2,048 SRAM accesses, 3 cycles more each.