Overview
Adding a new module involves five main steps:- Create the SystemVerilog module file
- Create a dump file for waveform generation
- Write cocotb tests
- Update the Makefile
- Run tests and view waveforms
Step-by-step process
Create the module file
Create your new SystemVerilog module in the Implement your module following the existing code style and conventions in the codebase. Ensure your module:
src/ directory:- Has clear input/output port definitions
- Includes proper reset logic
- Uses the fixed-point format (Q8.8) where applicable
- Follows SystemVerilog 2012 syntax
Create the dump file
Create a dump file in the This file instructs iverilog to dump all signals from your module to a VCD file for visualization.
test/ directory to generate VCD waveforms:test/dump_<MODULE_NAME>.sv
Create the test file
Create a cocotb test file in the Write your tests using cocotb. Here’s a basic template:
test/ directory:test/test_<MODULE_NAME>.py
Update the Makefile
Add your module to the build system by editing the 2. Create a test target:
Makefile:1. Add to SOURCES variable:Makefile
Makefile
Make sure to use tabs (not spaces) for indentation in Makefile targets.
Run the test
Build and test your new module:The test will:
- Compile your module with iverilog
- Run the cocotb test
- Generate a VCD waveform file
- Check for test failures in
results.xml
View waveforms
After the test completes successfully, view the generated waveforms:Or use the Makefile shorthand:See the waveforms guide for tips on configuring GTKwave for fixed-point viewing.
Example modules
Here are some existing modules you can reference:src/pe.sv- Processing Element (simple module)src/systolic.sv- Systolic Array (complex module with multiple instances)src/vpu.sv- Vector Processing Unit (module with sub-components)src/unified_buffer.sv- Unified Buffer (memory module)
Best practices
Use fixed-point arithmetic
Use fixed-point arithmetic
All arithmetic in Tiny TPU uses Q8.8 fixed-point format (8 integer bits, 8 fractional bits). Use the helper functions in tests:
to_fixed(val)- Convert float to fixed-pointfrom_fixed(val)- Convert fixed-point to float
Include comprehensive tests
Include comprehensive tests
Write tests that cover:
- Normal operation
- Edge cases (zero, negative, maximum values)
- Reset behavior
- Pipeline stages and timing
Follow naming conventions
Follow naming conventions
- Module files:
<module_name>.sv - Test files:
test_<module_name>.py - Dump files:
dump_<module_name>.sv - Makefile targets:
test_<module_name>
Document your module
Document your module
Add comments in your SystemVerilog code explaining:
- Module purpose and function
- Port descriptions
- Pipeline stages
- Timing requirements
Next steps
Testing
Learn more about the testing framework
Waveforms
Configure GTKwave for better visualization