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"
|
2021-03-04 11:19:35 +01:00
|
|
|
#include <math.h>
|
2020-10-01 17:18:29 +02:00
|
|
|
|
2021-03-04 11:19:35 +01:00
|
|
|
using spn = spn_regs<0x90000000>;
|
2020-10-01 17:18:29 +02:00
|
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-03-04 11:19:35 +01:00
|
|
|
void run_xspn(int in_addr, int out_addr, int num_samples, int in_beats, int out_beats) {
|
|
|
|
spn::mode_reg() = 0;
|
|
|
|
spn::input_length_reg() = num_samples; // 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() = in_beats; // Number of AXI4 burst beats needed to load all input data
|
|
|
|
spn::num_of_out_beats_reg() = out_beats; // Number of AXI4 burst beats needed to store all result data
|
|
|
|
printf("Starting XSPN\n");
|
|
|
|
spn::start_reg() = 1;
|
2020-12-14 12:52:05 +01:00
|
|
|
}
|
2020-12-14 08:43:11 +01:00
|
|
|
|
2021-03-04 11:19:35 +01:00
|
|
|
void check_results(int addr, int k, int step) {
|
2021-03-19 11:56:13 +01:00
|
|
|
int k0 = 0;
|
2021-03-04 11:19:35 +01:00
|
|
|
bool result = 0;
|
|
|
|
double *res_base = (double*) (addr);
|
|
|
|
int * error_exit = (int *)0xF0000000;
|
2020-12-30 11:37:06 +01:00
|
|
|
|
2021-03-04 11:19:35 +01:00
|
|
|
for (int i = 0; i < step; i++) {
|
|
|
|
|
2021-03-19 11:56:13 +01:00
|
|
|
if (!double_equals(res_base[i], ref_data.at(k0 + i))) {
|
|
|
|
printf("XSPN ref %d comparison FAILED\n", k0 + i);
|
2021-03-04 11:19:35 +01:00
|
|
|
result = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (result == 1) *error_exit = 0x1;
|
2020-12-14 12:52:05 +01:00
|
|
|
printf("Compared samples %d - %d with the reference\n", k, k+step);
|
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() {
|
2021-03-04 11:19:35 +01:00
|
|
|
|
|
|
|
|
2020-10-01 17:18:29 +02:00
|
|
|
platform_init();
|
2020-12-14 12:52:05 +01:00
|
|
|
|
2020-11-04 17:41:56 +01:00
|
|
|
spn::mode_reg() = 1;
|
|
|
|
spn::start_reg() = 1;
|
2021-01-08 09:30:47 +01:00
|
|
|
wait_for_interrupt();
|
2020-11-04 17:41:56 +01:00
|
|
|
spn::interrupt_reg() = 1;
|
2021-03-04 11:19:35 +01:00
|
|
|
uint32_t readout = spn::readout_reg();
|
|
|
|
printf("READOUT HW:0x%x\n", readout);
|
2020-11-04 17:41:56 +01:00
|
|
|
|
2021-03-04 11:19:35 +01:00
|
|
|
uint32_t axi_bytes = readout;
|
|
|
|
axi_bytes = axi_bytes & 0xff;
|
|
|
|
axi_bytes = 1 << axi_bytes;
|
2020-11-04 17:41:56 +01:00
|
|
|
|
2021-03-04 11:19:35 +01:00
|
|
|
printf("AXI Bytes: %d\n", axi_bytes);
|
2021-01-08 09:30:47 +01:00
|
|
|
|
2021-03-04 11:19:35 +01:00
|
|
|
uint32_t sample_bytes = readout;
|
|
|
|
sample_bytes = sample_bytes >> 16;
|
|
|
|
sample_bytes = sample_bytes / 8;
|
2020-12-10 15:38:25 +01:00
|
|
|
|
2021-03-04 11:19:35 +01:00
|
|
|
printf("Sample Bytes: %d\n", sample_bytes);
|
|
|
|
|
|
|
|
uint32_t result_bytes = 8;
|
|
|
|
|
|
|
|
printf("Result Bytes: %d\n", result_bytes);
|
|
|
|
|
|
|
|
uint32_t step = 500;
|
2021-03-19 11:56:13 +01:00
|
|
|
<<<<<<< Updated upstream
|
2021-03-10 12:05:23 +01:00
|
|
|
uint32_t iterations = 20;
|
2021-03-19 11:56:13 +01:00
|
|
|
=======
|
|
|
|
uint32_t iterations = 5;
|
|
|
|
>>>>>>> Stashed changes
|
2021-03-04 11:19:35 +01:00
|
|
|
|
|
|
|
uint32_t in_beats = (step * sample_bytes) / axi_bytes;
|
|
|
|
if (in_beats * axi_bytes < step * sample_bytes) in_beats++;
|
|
|
|
uint32_t out_beats = (step * result_bytes) / axi_bytes;
|
|
|
|
if (out_beats * axi_bytes < step * result_bytes) out_beats++;
|
|
|
|
|
|
|
|
int in_addr = (int)input_data.data();
|
|
|
|
int out_addr = 0x800B0000;
|
|
|
|
|
|
|
|
for (int k = 0; k < iterations*step; k+=step) {
|
|
|
|
printf("XSPN processes samples %d - %d\n", k, k+step);
|
|
|
|
run_xspn(in_addr, out_addr, step, in_beats, out_beats);
|
2020-12-14 12:52:05 +01:00
|
|
|
wait_for_interrupt();
|
2021-03-04 11:19:35 +01:00
|
|
|
printf("XSPN finished\n");
|
|
|
|
spn::interrupt_reg() = 1;
|
2021-03-10 12:05:23 +01:00
|
|
|
check_results(out_addr, k, step);
|
2020-12-07 12:55:10 +01:00
|
|
|
|
2021-03-10 12:05:23 +01:00
|
|
|
in_addr += step * sample_bytes; // 5 bytes in each sample
|
2021-03-04 11:19:35 +01:00
|
|
|
}
|
2020-10-01 17:18:29 +02:00
|
|
|
|
2021-03-04 11:19:35 +01:00
|
|
|
return 0;
|
2020-10-01 17:18:29 +02:00
|
|
|
}
|