
The C++ driver API, build instructions and hardware models for "Preinception" can be found in the PRESM repository.
All commands are sent via the C++ driver.
+------------------------------------------------+
| driver (C++ API) |
+------------------------------------------------+
| (Host) ^
| |
--------|------[ 48-bit packet ]----|-------------
| |
Y (Device) |
+------------------------------------------------+
| UARTPacket |
| +-------------+ +-------------+ |
| | UARTRx | | UARTTx | |
| +-------------+ +-------------+ |
| |
+------------------------------------------------+
| ^
| |
Y |
+------------------------------------------------+
| Command |
| Processor |
| (CP) |
+------------------------------------------------+
+-----------------------------------------------+-------------------+
| 16-bit header | 32-bit body |
++----------------------------------------------+-------------------+
|| 4-bit | 4-bit | 4-bit | 4-bit || 32-bits data ||
|| Unique ID | Type | Command | Sub-command || ||
++--------------------------------------------------+---------------+
<b>Prerequisits</b>
<b>Notes</b>
Clone PRESM and navigate to the cloned directory.
Build the Tiny Tapeout config for Preinception:
python scripts/build.py --config hw_configs/preinception/serial_tapeout_tt_ihp26b.json
Next, we need to connect the chip to the PC.
The chip can be connected in two ways:
As of now, not sure which one will work, so give both a go when chips become available.
You may need to run the following command to activate the FTDI drivers:
sudo modprobe ftdi_sio
This is straightforward. Testing is done by running verification apps:
python scripts/verify.py --config hw_configs/preinception/serial_tapeout_tt_ihp26b.json
You should see an output like so:
++ Copying files from /home/aakashkt/presm/build/verification/ to verify_runs/00491
++ Copying file /home/aakashkt/presm/build/driver/matrix/libmatrix_serial.so to verify_runs/00491
++ Copying file hw_configs/preinception/serial_fpga_tangnano20k.json to verify_runs/00491/hw_config.json
++ ======================
++ PRESM Execution Begin
++ ======================
++ Changing working directory to: /home/aakashkt/presm/verify_runs/00491
++ Executing: ./verification sanity device
++ Environment:
{'LD_PRELOAD': 'libmatrix_serial.so'}
++ Changing working directory to: /home/aakashkt/presm
++ ======================
++ PRESM Execution End
++ ======================
++ Changing working directory to: /home/aakashkt/presm/verify_runs/00491
++ Executing: ./verification sanity host
++ Changing working directory to: /home/aakashkt/presm
++ Verification of "sanity" succeeded.
++ ======================
++ PRESM Execution Begin
++ ======================
++ Changing working directory to: /home/aakashkt/presm/verify_runs/00491
++ Executing: ./verification addition device
++ Environment:
{'LD_PRELOAD': 'libmatrix_serial.so'}
++ Changing working directory to: /home/aakashkt/presm
++ ======================
++ PRESM Execution End
++ ======================
++ Changing working directory to: /home/aakashkt/presm/verify_runs/00491
++ Executing: ./verification addition host
++ Changing working directory to: /home/aakashkt/presm
++ Verification of "addition" succeeded.
.....
.....
On the demo board:
uo[6] (PIN_HI in datasheet) to input pin 0 ui[0] (SEL_RX_TX in datasheet).
ui[7] (RX_secondary in datasheet)uo[7] (TX_secondary in datasheet)Now we can run the verification apps like above.
Make sure you have built Preinception with the tapeout configuration.
python scripts/build.py --config hw_configs/preinception/serial_tapeout_tt_ihp26b.json
The build creates a package of the driver in packages/, which looks like:
├── packages/
│ ├── matrix/
│ | ├── include/
| | | ├── matrix.h # Driver API header
| | ├── lib/
| | | ├── libmatrix_serial.so # Driver library
Lets compile a simple C++ code that uses the driver to add two numbers on preinception.
#include "include/matrix.h"
#include <iostream>
int main()
{
mInit(); // Initialize the driver
// Allocate memory for device, and initialize it
MIntDeviceMemory a(-64);
MIntDeviceMemory b(-80);
MIntDeviceMemory c(10);
mAdd(a, b, c); // Call add on 'a' and 'b', store in 'c'
mSync(); // Wait for device to finish
std::cout << a.getValue() << " + " << b.getValue() << " = " << c.getValue() << std::endl;
mFree(); // Free driver resources
}
Compilation needs to link with the driver library:
g++ main.cpp -L./lib/ -lmatrix_serial -o main -Wl,-rpath,./lib
Running the program:
$ ./main
-64 + -80 = -144
/dev/ttyUSB0 --> /dev/ttyUSB4
Possibly requires an external UART-USB module.
| # | Input | Output | Bidirectional |
|---|---|---|---|
| 0 | SEL_RX_TX | ||
| 1 | |||
| 2 | |||
| 3 | RX_primary | ||
| 4 | TX_primary | ||
| 5 | |||
| 6 | PIN_HI | ||
| 7 | RX_secondary | TX_secondary |