main_pcie40_timediff.cpp 2.29 KiB
#include <iostream>
#include <ctime>
#include <string>
#include <stdlib.h>
#include <unistd.h>
#include <memory.h>
#include <stdexcept>
#include <string.h>
#include <cstdio>
#include "pcie40_b2slc.h"
#include "pcie40_ecs.h"
/*
std::string exec(const char* cmd) {
char buffer[128];
std::string result = "";
FILE* pipe = popen(cmd, "r");
if (!pipe) throw std::runtime_error("popen() failed!");
try {
while (fgets(buffer, sizeof buffer, pipe) != NULL) {
result += buffer;
}
} catch (...) {
pclose(pipe);
throw;
}
pclose(pipe);
return result;
}
*/
int main(int argc, char **argv) {
int ch = -1;
int addr = 0;
int data = 0;
int loops = 0;
bool WRITE_FLAG = false;
bool READ_FLAG = false;
bool HSLB_FLAG = false;
for(int i=1; i<argc; i++){
std::string ss = argv[i];
if(ss=="--ch"){
ch = atoi(argv[++i]);
}
if(ss=="-w" || ss=="--write"){
WRITE_FLAG = true;
addr = strtoul(argv[++i], 0, 16);
data = strtoul(argv[++i], 0, 16);
}
if(ss=="-r" || ss=="--read"){
READ_FLAG = true;
addr = strtoul(argv[++i], 0, 16);
}
if(ss=="-l" || ss=="--loop"){
loops = atoi(argv[++i]);
}
if(ss=="--hslb"){
HSLB_FLAG = true;
}
}
struct timespec ts;
struct timespec ts1;
// Success: Returns 0
// // Failure: Returns -1
// // First arg: CLOCK_REALTIME, CLOCL_MONOTONIC, etc.
int ret = clock_gettime(CLOCK_REALTIME, &ts);
int result;
ecs_open( 0 , 2 );
for(int i=0; i<loops; i++){
if(HSLB_FLAG){
//int result = system("./reghsx -c fee32 0x12");
//int result = readfee32(0, ch, addr, &valp);
//std::cout << valp << std::endl;
}else{
if(WRITE_FLAG){
result = pcie40_writefee32( 0 , ch , addr, data) ;
}else if (READ_FLAG){
result = pcie40_readfee32( 0 , ch , addr) ;
}
}
//usleep(1000);
}
ecs_close( 0 , 2 ) ;
//usleep(1e6);
int ret1 = clock_gettime(CLOCK_REALTIME, &ts1);
if(ret == 0 && ret1 == 0){
std::cout << "Processing time in Seconds : " << ts1.tv_sec - ts.tv_sec << std::endl
<< "Processing time in Nano seconds : " << ts1.tv_nsec - ts.tv_nsec << std::endl;
}else{
std::cout << "Failed clock_gettime()" << std::endl;
}
return 0;
}