Hi all, i have the following code just as a playground to the Pynq and Vivado environment.
foo.cpp
#include "complex.h"
complex_t complex_add(const complex_t a, const complex_t b)
{
return complex_init(a.real + b.real, a.imaj + b.imaj);
}
complex_t complex_substract(const complex_t a, const complex_t b) {
return complex_init(a.real - b.real, a.imaj - b.imaj);
}
complex_t complex_multiply(const complex_t a, const complex_t b) {
return complex_init(a.real * b.real - a.imaj * b.imaj, a.real * b.imaj + a.imaj * b.real);
}
void foo(double re1[50], double im1[50],const double re,const double im, double& I, double& Q){
#pragma HLS INTERFACE ap_ctrl_none port=return
#pragma HLS INTERFACE s_axilite port=re1
#pragma HLS INTERFACE s_axilite port=im1
#pragma HLS INTERFACE s_axilite port=re
#pragma HLS INTERFACE s_axilite port=im
#pragma HLS INTERFACE s_axilite port=I
#pragma HLS INTERFACE s_axilite port=Q
complex_t tmp = complex_init(0, 0);
for (int i = 0; i < 50; i++) {
tmp = complex_add(tmp, complex_init(re1[i], im1[i]));
}
complex_t out = complex_multiply(tmp, complex_init(re, im));
I = out.real;
Q = out.imaj;
}
complex.h
#pragma once
#if !defined(M_PI)
# define M_PI 3.14159265358979323846
#endif
struct complex {
double real;
double imaj;
};
typedef struct complex complex_t;
complex_t complex_init(const double real, const double imaj) {
complex_t temp;
temp.real = real;
temp.imaj = imaj;
return temp;
}
I want to learn how to give an array to an IP and get some values back but so far i have had no success. This is my Python code,
import numpy as np
foo.write(0x010, 1) # Write to 're'
foo.write(0x01c, 1) # Write to 'im'
print(foo.read(0x010)) # Prints 1
print(foo.read(0x01c)) # Prints 1
from struct import pack, unpack
print(foo.read(0x200)) # Prints 0
print(foo.read(0x204)) # Prints 0
# First pack value in bytes as double
aux = np.ones((50,1))
aux_double = np.array([pack('d', x) for x in aux])
aux_double
foo.write(0x200, aux_double.tobytes())
foo.write(0x400, aux_double.tobytes())
When i read the memory address where I and Q are stored i always get 0 no matter which way i use to input variables into the two re1 and im1 arrays (see c++ code)
What am i missing?
I’m new to Pynq so this might have an answer in another post i simply don’t know how it’s called (i called it interfacing). In this post he does not uses arrays but a pointer. Is that the way to approach it?
My final goal is to be able to use the cv::Mat object from Vitis Vision library but i’m stuck in this simpler example. Any help, advice or even tutorial will be appreciated.