For the usage of the Rah, Use shared library i.e. librah. Call rah_write and rah_read function to send and receive data from the FPGA respectively.
int rah_write(const uint8_t appid, const char* message, const unsigned long len);
Field | Value |
---|---|
appid | The ID of running application on FPGA |
message | The message to send |
len | The length of the message |
Here is the quick demo of the rah_write,
#include <rah.h>
#define APP_ID 3
int main(void) {
rah_write(APP_ID, "Hello!", 6);
}
For more fined grained access over the memory pointer, below APIs can be used, follow the mentioned steps:
- void *rah_request_mem(const uint8_t appid, const unsigned long len);
Field | Value |
---|---|
appid | The ID of running application on FPGA |
len | The length of the message |
It will provide the memory location kinf of mmap, now it can be accessed by the applications to copy data into this provided location.
- void rah_write_mem(const uint8_t appid, void* ptr, const unsigned long len);
Field | Value |
---|---|
appid | The ID of running application on FPGA |
ptr | Allocated buffer from the request |
len | The length of the message |
Copy the data into ptr and then call this API, to send the message to FPGA.
- void rah_free_mem(void* ptr);
Field | Value |
---|---|
ptr | Allocated buffer from the request |
Call this once you send all of your data.
#include <string.h>
#include <rah.h>
#define APP_ID 3
int main(void) {
const char *message = "Hello World!";
char *ptr = rah_request_mem(APP_ID, strlen(message));
memcpy(ptr, message, strlen(message));
rah_write_mem(APP_ID, ptr, strlen(message));
rah_free_mem(ptr);
}
Note
It can send at max 100663278 bytes at once, if you want to send more then split the data into multiple packets and send the same.
int rah_read(const uint8_t appid, char* message, const unsigned long len);
Field | Value |
---|---|
appid | The ID of running application on FPGA |
message | Pointer of receiving message |
len | Number of bytes to get |
Here is the quick demo of the rah_read,
#include <rah.h>
#define APP_ID 3
int main(void) {
char message[6];
rah_read(APP_ID, message, 6);
}
int rah_clear_buffer(const uint8_t appid);
Field | Value |
---|---|
appid | The ID of running application on FPGA |
Clear file buffer for appid
. This is the file that receives incoming
data from the FPGA. You can inspect it at location /tmp/(<appid> + 3)
.
gcc filename.c -lrah
./a.out
For more details, please refer to the given example.
The Pyrah library provides a Python wrapper for the RAH protocol, simplifying communication with an FPGA. With Pyrah, you can easily interact with the FPGA using Python, making tasks such as writing and reading data to/from the FPGA more accessible.
To install the Pyrah library, follow these steps:
-
Clone the repository:
git clone https://github.com/vicharak-in/pyrah
-
Navigate into the
pyrah
directory:cd pyrah
-
Install the package:
sudo python3 setup.py install
Once installed, you can use the Pyrah library to communicate with the FPGA. Below is an example Python code demonstrating how to interact with the FPGA.
import pyrah
APPID = 3
# Write a message to the FPGA
pyrah.rah_write(APPID, b"Hello World!")
# Read data from the FPGA
data = pyrah.rah_read(APPID, 10) # Here 10 is the length of data we need
print(data)
-
rah_write(APPID, data)
Sends a message to the FPGA using the specifiedAPPID
. -
rah_read(APPID, length)
Reads the specified number of bytes from the FPGA. Thelength
parameter defines how many bytes of data should be read.
-
Pyrah
Access the source code and additional documentation. -
Rahcomm
A wrapper for Pyrah that enables seamless data communication with RAH.
This documentation outlines how to use the Pyrah library to facilitate CPU-FPGA communication in Python.