2020-10-01 17:18:29 +02:00
|
|
|
#include "raven_spn.h"
|
|
|
|
#include "spn_regs.h"
|
2020-12-14 08:43:11 +01:00
|
|
|
#include "init.h"
|
2020-10-01 17:18:29 +02:00
|
|
|
|
2020-12-14 08:43:11 +01:00
|
|
|
#include <cmath> // log
|
2020-10-01 17:18:29 +02:00
|
|
|
|
|
|
|
using spn =spn_regs<0x90000000>;
|
|
|
|
|
2020-12-08 17:07:21 +01:00
|
|
|
// huge arrays of XSPN input and referance data
|
|
|
|
extern std::array<uint8_t, 50000> input_data;
|
|
|
|
extern std::array<double, 10000> ref_data;
|
|
|
|
constexpr auto ln2 = std::log(2);
|
|
|
|
|
2020-12-07 12:55:10 +01:00
|
|
|
bool double_equals(double a, double b, double epsilon = 0.001)
|
|
|
|
{
|
|
|
|
return std::abs(a - b) < epsilon;
|
|
|
|
}
|
|
|
|
|
2020-12-14 12:52:05 +01:00
|
|
|
void run_xspn(int in_addr, int out_addr) {
|
2020-12-10 15:38:25 +01:00
|
|
|
spn::mode_reg() = 0;
|
2020-12-14 12:52:05 +01:00
|
|
|
spn::input_length_reg() = 500; // each sample consists of 5 uint8 values
|
|
|
|
spn::input_addr_reg() = in_addr;
|
|
|
|
spn::output_addr_reg() = out_addr;
|
|
|
|
spn::num_of_in_beats_reg() = 40; // Number of AXI4 burst beats needed to load all input data
|
|
|
|
spn::num_of_out_beats_reg() = 64; // Number of AXI4 burst beats needed to store all result data
|
2020-12-10 15:38:25 +01:00
|
|
|
spn::start_reg() = 1;
|
2020-12-14 12:52:05 +01:00
|
|
|
}
|
2020-12-14 08:43:11 +01:00
|
|
|
|
2020-12-14 12:52:05 +01:00
|
|
|
void load_input_data(int addr, const int k=0) {
|
|
|
|
int * mem_base = (int *) addr;
|
|
|
|
int offset = k * 5;
|
|
|
|
|
|
|
|
for (size_t i = 0, j = 0; j < 625; i += 4, j++) { // load 5000 samples
|
|
|
|
*(mem_base + j) = input_data.at(offset + i);
|
|
|
|
*(mem_base + j) |= (input_data.at(offset + i + 1) << 8) & 0x0000FF00;
|
|
|
|
*(mem_base + j) |= (input_data.at(offset + i + 2) << 16) & 0x00FF0000;
|
|
|
|
*(mem_base + j) |= (input_data.at(offset + i + 3) << 24) & 0xFF000000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool check_results(int addr, int k) {
|
|
|
|
bool result = 0;
|
|
|
|
int step = 500;
|
|
|
|
double *res_base = (double*) (addr);
|
2020-12-30 11:37:06 +01:00
|
|
|
int * error_exit = (int *)0xF0000000;
|
|
|
|
|
2020-12-14 12:52:05 +01:00
|
|
|
for (int i = 0; i < step; i++) {
|
|
|
|
if (!double_equals(res_base[i] * ln2, ref_data.at(k + i))) {
|
|
|
|
printf("XSPN ref %d comparison FAILED\n", k + i);
|
2020-12-30 11:37:06 +01:00
|
|
|
*error_exit = 0x1;
|
2020-12-14 12:52:05 +01:00
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("Compared samples %d - %d with the reference\n", k, k+step);
|
|
|
|
return result;
|
2020-12-10 15:38:25 +01:00
|
|
|
}
|
2020-12-07 12:55:10 +01:00
|
|
|
|
2020-10-01 17:18:29 +02:00
|
|
|
/*! \brief main function
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int main() {
|
|
|
|
platform_init();
|
2020-12-14 12:52:05 +01:00
|
|
|
int ret_val = 0;
|
|
|
|
|
2020-11-04 17:41:56 +01:00
|
|
|
spn::mode_reg() = 1;
|
|
|
|
spn::start_reg() = 1;
|
2020-12-14 08:43:11 +01:00
|
|
|
wait_for_interrupt();
|
2020-11-04 17:41:56 +01:00
|
|
|
spn::interrupt_reg() = 1;
|
2020-12-14 08:43:11 +01:00
|
|
|
printf("READOUT HW:0x%x\n", spn::readout_reg());
|
2020-11-04 17:41:56 +01:00
|
|
|
|
2020-12-14 12:52:05 +01:00
|
|
|
int in_addr = 0x800C0000;
|
|
|
|
int out_addr = 0x800A0000;
|
|
|
|
load_input_data(in_addr);
|
2020-11-04 17:41:56 +01:00
|
|
|
|
2020-12-14 12:52:05 +01:00
|
|
|
int step = 500; // number of samples to be process at once
|
|
|
|
for (int k = 0; k < 10000; k+=step) {
|
2020-10-02 12:10:43 +02:00
|
|
|
|
2020-12-14 12:52:05 +01:00
|
|
|
run_xspn(in_addr, out_addr);
|
|
|
|
printf("XSPN processes samples %d - %d\n", k, k+step);
|
2020-12-10 15:38:25 +01:00
|
|
|
|
2020-12-14 12:52:05 +01:00
|
|
|
// pre-load data for the next run while HW accelerator is running
|
|
|
|
if(k<(10000-step))
|
|
|
|
load_input_data(in_addr, k+step);
|
2020-12-10 15:38:25 +01:00
|
|
|
|
2020-12-14 12:52:05 +01:00
|
|
|
wait_for_interrupt();
|
|
|
|
spn::interrupt_reg() = 1;
|
2020-12-07 12:55:10 +01:00
|
|
|
|
2020-12-14 12:52:05 +01:00
|
|
|
ret_val = check_results(out_addr, k);
|
2020-12-08 17:07:21 +01:00
|
|
|
}
|
2020-10-01 17:18:29 +02:00
|
|
|
|
2020-12-14 12:52:05 +01:00
|
|
|
return ret_val;
|
2020-10-01 17:18:29 +02:00
|
|
|
}
|