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-10 15:38:25 +01:00
|
|
|
void run_xspn() {
|
|
|
|
spn::mode_reg() = 0;
|
|
|
|
spn::input_length_reg() = 100; // each sample consists of 5 uint8 values
|
2020-12-11 17:01:35 +01:00
|
|
|
spn::input_addr_reg() = 0x800C0000;
|
2020-12-14 08:43:11 +01:00
|
|
|
spn::output_addr_reg() = 0x800A0000;
|
2020-12-10 15:38:25 +01:00
|
|
|
spn::num_of_in_beats_reg() = 8; // Number of AXI4 burst beats needed to load all input data
|
|
|
|
spn::num_of_out_beats_reg() = 13; // Number of AXI4 burst beats needed to store all result data
|
|
|
|
spn::start_reg() = 1;
|
2020-12-14 08:43:11 +01:00
|
|
|
|
|
|
|
wait_for_interrupt();
|
2020-12-10 15:38:25 +01:00
|
|
|
spn::interrupt_reg() = 1;
|
|
|
|
}
|
2020-12-07 12:55:10 +01:00
|
|
|
|
2020-10-01 17:18:29 +02:00
|
|
|
/*! \brief main function
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int main() {
|
|
|
|
platform_init();
|
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-11 17:01:35 +01:00
|
|
|
for (int k = 0; k < 10000; k+=100) {
|
2020-12-10 15:38:25 +01:00
|
|
|
// write input samples into the memory
|
2020-12-11 17:01:35 +01:00
|
|
|
int * mem_base = (int *) 0x800C0000;
|
2020-12-10 15:38:25 +01:00
|
|
|
int offset = k * 5;
|
2020-11-04 17:41:56 +01:00
|
|
|
|
2020-12-10 15:38:25 +01:00
|
|
|
for(size_t i = 0, j = 0; j < 125; i += 4, j++) {
|
|
|
|
*(mem_base+j) = input_data.at(offset+i);
|
2020-12-11 17:01:35 +01:00
|
|
|
*(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;
|
2020-12-10 15:38:25 +01:00
|
|
|
}
|
2020-10-02 12:10:43 +02:00
|
|
|
|
2020-12-11 17:01:35 +01:00
|
|
|
printf("XSPN process samples %d - %d\n", k, k+100);
|
2020-12-10 15:38:25 +01:00
|
|
|
run_xspn();
|
|
|
|
|
|
|
|
// read calculation results from the memory
|
2020-12-14 08:43:11 +01:00
|
|
|
double * res_base = (double*) 0x800A0000;
|
2020-12-10 15:38:25 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < 100; i++) {
|
2020-12-11 17:01:35 +01:00
|
|
|
if (!double_equals(res_base[i] * ln2, ref_data.at(k+i))) {
|
2020-12-10 15:38:25 +01:00
|
|
|
printf("XSPN ref %d comparison FAILED\n", k+i);
|
|
|
|
}
|
|
|
|
}
|
2020-12-07 12:55:10 +01:00
|
|
|
|
2020-12-08 17:07:21 +01:00
|
|
|
}
|
2020-10-01 17:18:29 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|