added flushing (function X502_FlushRcv_buff) of receing buffer on PC between changing BlackFin settings via commands.
This commit is contained in:
BIN
BF_companion
BIN
BF_companion
Binary file not shown.
212
main.c
212
main.c
@ -67,6 +67,9 @@
|
|||||||
#include "l502_BF_enums.h"
|
#include "l502_BF_enums.h"
|
||||||
#include "l502_fpga_regs.h"
|
#include "l502_fpga_regs.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
unknown = 0x00,
|
unknown = 0x00,
|
||||||
ADC_data =0x01,
|
ADC_data =0x01,
|
||||||
@ -170,6 +173,18 @@ typedef struct {
|
|||||||
char const *devname;
|
char const *devname;
|
||||||
} ip_dev_list_t;
|
} ip_dev_list_t;
|
||||||
|
|
||||||
|
|
||||||
|
volatile sig_atomic_t abort_crtl_C = 0;
|
||||||
|
|
||||||
|
void handle_sigint(int signal_stop){
|
||||||
|
(void)signal_stop;
|
||||||
|
abort_crtl_C = 1;
|
||||||
|
for (int i = 100; i ; --i){
|
||||||
|
printf("abort");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Функция находит все подключенные модули по интерфейсам PCI-Express и USB и
|
/* Функция находит все подключенные модули по интерфейсам PCI-Express и USB и
|
||||||
* сохраняет записи о этих устройствах в выделенный массив.
|
* сохраняет записи о этих устройствах в выделенный массив.
|
||||||
* Также создаются записи по переданным IP-адресам модулей и добавляются в конец
|
* Также создаются записи по переданным IP-адресам модулей и добавляются в конец
|
||||||
@ -768,9 +783,83 @@ long int X502_Raw_User_Data_Parser(uint32_t *inp_buff, uint32_t inp_values_N,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t X502_FlushRcv_buff(t_x502_hnd hnd){
|
||||||
|
uint32_t ready;
|
||||||
|
X502_GetRecvReadyCount(hnd, &ready);
|
||||||
|
if (ready > 0) {
|
||||||
|
uint32_t *tmp = malloc(ready * sizeof(uint32_t));
|
||||||
|
X502_Recv(hnd, tmp, ready, 0); // вычитываем и отбрасываем
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
return ready;
|
||||||
|
}
|
||||||
|
|
||||||
|
void receive_data(t_x502_hnd hnd, char* logfilename, uint32_t* inp_buff, int data_receive_trys_counter, uint32_t max_total_words){
|
||||||
|
//int data_receive_trys_counter = 100;
|
||||||
|
//uint32_t max_total_words = 10000;
|
||||||
|
uint32_t ready_cnt_Err = 0;
|
||||||
|
uint32_t recv_Err_code = 0;
|
||||||
|
|
||||||
|
int ready_cnt = 0;
|
||||||
|
int ready_cnt_copy = 0;
|
||||||
|
int values_in_line = 0;
|
||||||
|
|
||||||
|
FILE *logfile_ptr;
|
||||||
|
|
||||||
|
logfile_ptr = fopen(logfilename, "a");
|
||||||
|
|
||||||
|
while((--data_receive_trys_counter)&& (max_total_words)){
|
||||||
|
|
||||||
|
ready_cnt_Err = X502_GetRecvReadyCount(hnd, &ready_cnt);
|
||||||
|
recv_Err_code = X502_Recv(hnd, inp_buff, ready_cnt, 10);
|
||||||
|
printf("\n\nget counters of calls of SPORT_RX, SPORT_TX, HDMA_RX, HDMA_TX\n");
|
||||||
|
BF_exec_cmd_with_arr(hnd, 0x8005U, 100, NULL, 0, 1);
|
||||||
|
printf("\n\request TX_buff_I_shadow value (last size of TX_buff transferred to pc )\n");
|
||||||
|
BF_exec_cmd_simple(hnd, 0x8009, 10, 1);
|
||||||
|
if (ready_cnt){
|
||||||
|
printf("Ready count: %d, Err: %d \n", ready_cnt, ready_cnt_Err);
|
||||||
|
for (int i = 0; i < ready_cnt; ++i){
|
||||||
|
//printf("\nabort value: %d\n", abort_crtl_C);
|
||||||
|
if (abort_crtl_C){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
--max_total_words;
|
||||||
|
if (max_total_words == 0){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
char bin_str_val[9] = {0,};
|
||||||
|
uin32_t_to_bin(inp_buff[i], bin_str_val);
|
||||||
|
printf(" 0x%08X,", inp_buff[i]);
|
||||||
|
fprintf(logfile_ptr, "0x%08X \n", inp_buff[i]);
|
||||||
|
//printf(" 0b%s,", bin_str_val);
|
||||||
|
++values_in_line;
|
||||||
|
if (values_in_line == 10){
|
||||||
|
printf("\n");
|
||||||
|
values_in_line = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
uint32_t process_data_Err = 0;
|
||||||
|
uint32_t adc_data_size = ready_cnt;
|
||||||
|
X502_Raw_User_Data_Parser(inp_buff, inp_values_N,
|
||||||
|
adc_data, adc_chans_N, adc_readouts_N,
|
||||||
|
&LFSM_res_tmp, &LFSM_res,
|
||||||
|
&FFT_res_tmp, &FFT_res);
|
||||||
|
//process_data_Err = X502_ProcessData(hnd, inp_buff, ready_cnt, X502_PROC_FLAGS_VOLT, adc_data, &adc_data_size, NULL, NULL);
|
||||||
|
uint64_t data_sum = 0;
|
||||||
|
for (int i = 0; i < ready_cnt; ++i){
|
||||||
|
data_sum += inp_buff[i];
|
||||||
|
if (i % 1000 == 1){
|
||||||
|
//printf(" %e\n", adc_data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
//printf("try: %04d, words ready: %06d, receive_error_code: %05d, data_sum: %d \n", data_receive_trys_counter, ready_cnt, recv_Err_code, data_sum);
|
||||||
|
}
|
||||||
|
fclose(logfile_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -779,6 +868,7 @@ long int X502_Raw_User_Data_Parser(uint32_t *inp_buff, uint32_t inp_values_N,
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
signal(SIGINT, handle_sigint);
|
||||||
int32_t err = X502_ERR_OK;
|
int32_t err = X502_ERR_OK;
|
||||||
uint32_t ver;
|
uint32_t ver;
|
||||||
t_x502_hnd hnd = NULL;
|
t_x502_hnd hnd = NULL;
|
||||||
@ -910,7 +1000,7 @@ int main(int argc, char** argv) {
|
|||||||
printf("loading Blackfin firmware file: %s\n", BF_firmware_filename);
|
printf("loading Blackfin firmware file: %s\n", BF_firmware_filename);
|
||||||
|
|
||||||
uint32_t bf_firmware_load_state = X502_BfLoadFirmware(hnd, BF_firmware_filename); //load firmware from l502-BFfirmware0.ldr file to BlackFin
|
uint32_t bf_firmware_load_state = X502_BfLoadFirmware(hnd, BF_firmware_filename); //load firmware from l502-BFfirmware0.ldr file to BlackFin
|
||||||
printf("load state: %u \n", bf_firmware_load_state);
|
printf("load state: %d \n", bf_firmware_load_state);
|
||||||
|
|
||||||
printf("setup module again");
|
printf("setup module again");
|
||||||
if (err == X502_ERR_OK) {
|
if (err == X502_ERR_OK) {
|
||||||
@ -985,6 +1075,14 @@ int main(int argc, char** argv) {
|
|||||||
streams_start_Err = X502_StreamsStart(hnd);
|
streams_start_Err = X502_StreamsStart(hnd);
|
||||||
printf("Streams start err: %d \n", streams_start_Err);
|
printf("Streams start err: %d \n", streams_start_Err);
|
||||||
|
|
||||||
|
|
||||||
|
time_t seconds;
|
||||||
|
time(&seconds);
|
||||||
|
char logfilename[] = " ";
|
||||||
|
sprintf(&logfilename, "received_data_%ld.csv", seconds);
|
||||||
|
//logfile_ptr = fopen(logfilename, "w");
|
||||||
|
printf("dumping to file: %s\n", logfilename);
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
//printf("start streams sampling\n");
|
//printf("start streams sampling\n");
|
||||||
//BF_exec_cmd_with_arr(hnd, 0x8004U, 0, NULL, 0, 1); //setup and start streams
|
//BF_exec_cmd_with_arr(hnd, 0x8004U, 0, NULL, 0, 1); //setup and start streams
|
||||||
@ -1002,57 +1100,63 @@ int main(int argc, char** argv) {
|
|||||||
BF_exec_cmd_with_arr(hnd, 0x8005U, 100, NULL, 0, 1);
|
BF_exec_cmd_with_arr(hnd, 0x8005U, 100, NULL, 0, 1);
|
||||||
|
|
||||||
|
|
||||||
printf("\n\nget a some data made by sport isr handler\n");
|
// printf("\n\nget a some data made by sport isr handler\n");
|
||||||
BF_exec_cmd_with_arr(hnd, 0x8006U, 100, NULL, 0, 1);
|
// BF_exec_cmd_with_arr(hnd, 0x8006U, 100, NULL, 0, 1);
|
||||||
//BF_exec_cmd_with_arr(hnd, 0x8006U, 100, NULL, 0, 3);
|
//BF_exec_cmd_with_arr(hnd, 0x8006U, 100, NULL, 0, 3);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
printf("\nStart transparent mode\n");
|
||||||
|
BF_exec_cmd_simple(hnd, 0x8007, 10, 1); //start transparent
|
||||||
|
|
||||||
|
printf("\Flushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd));
|
||||||
|
|
||||||
printf("receiving data...\n");
|
printf("receiving data...\n");
|
||||||
|
|
||||||
uint32_t *inp_buff = malloc(1024*100*1024*2*4);
|
uint32_t *inp_buff = malloc(1024*100*1024*2*4);
|
||||||
double *adc_data = malloc(1024*1024*sizeof(double));
|
double *adc_data = malloc(1024*1024*sizeof(double));
|
||||||
//uint32_t inp_buff[1024*2048] = {0,};
|
//uint32_t inp_buff[1024*2048] = {0,};
|
||||||
uint32_t ready_cnt = 0;
|
int ready_cnt = 0;
|
||||||
|
int ready_cnt_copy = 0;
|
||||||
|
|
||||||
|
|
||||||
uint32_t ready_cnt_Err = 0;
|
uint32_t ready_cnt_Err = 0;
|
||||||
uint32_t recv_Err_code = 0;
|
uint32_t recv_Err_code = 0;
|
||||||
|
|
||||||
|
|
||||||
ready_cnt_Err = X502_GetRecvReadyCount(hnd, &ready_cnt);
|
ready_cnt_Err = X502_GetRecvReadyCount(hnd, &ready_cnt_copy);
|
||||||
recv_Err_code = X502_Recv(hnd, inp_buff, 1024, 10);
|
recv_Err_code = X502_Recv(hnd, inp_buff, 1024, 10);
|
||||||
|
|
||||||
|
|
||||||
|
ready_cnt = ready_cnt_copy;
|
||||||
|
|
||||||
printf("Ready count: %d, Err: %d \n", ready_cnt, ready_cnt_Err);
|
printf("Ready count: %d, Err: %d \n", ready_cnt, ready_cnt_Err);
|
||||||
printf("Recv Err code (<0 -- err, >= 0 -- number of received words(32bit)): %d\n", recv_Err_code);
|
printf("Recv Err code (<0 -- err, >= 0 -- number of received words(32bit)): %d\n", recv_Err_code);
|
||||||
|
|
||||||
if (recv_Err_code > 0){
|
if (recv_Err_code > 0){
|
||||||
ready_cnt = recv_Err_code;
|
ready_cnt = recv_Err_code;
|
||||||
}
|
}
|
||||||
|
if (ready_cnt < 0){
|
||||||
FILE *logfile_ptr;
|
ready_cnt = 0;
|
||||||
time_t seconds;
|
|
||||||
time(&seconds);
|
|
||||||
char logfilename[] = " ";
|
|
||||||
sprintf(&logfilename, "received_data_%ld.csv", seconds);
|
|
||||||
logfile_ptr = fopen(logfilename, "w");
|
|
||||||
printf("dumping to file: %c\n", logfilename);
|
|
||||||
|
|
||||||
printf("\n\nreceived data:\n");
|
|
||||||
int values_in_line = 0;
|
|
||||||
//for (int i = 0; i < 1024; ++i){
|
|
||||||
for (int i = 0; i < ready_cnt; ++i){
|
|
||||||
char bin_str_val[9] = {0,};
|
|
||||||
uin32_t_to_bin(inp_buff[i], bin_str_val);
|
|
||||||
printf(" 0x%08X,", inp_buff[i]);
|
|
||||||
fprintf(logfile_ptr, "0x%08X \n", inp_buff[i]);
|
|
||||||
//printf(" 0b%s,", bin_str_val);
|
|
||||||
++values_in_line;
|
|
||||||
if (values_in_line == 10){
|
|
||||||
printf("\n");
|
|
||||||
values_in_line = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
printf("\n");
|
|
||||||
|
int data_receive_trys_counter = 100;
|
||||||
|
uint32_t max_total_words = 10000;
|
||||||
|
|
||||||
|
receive_data(hnd, logfilename, inp_buff, data_receive_trys_counter, max_total_words);
|
||||||
|
/*
|
||||||
|
data_receive_trys_counter = 100;
|
||||||
|
max_total_words = 10000;
|
||||||
|
|
||||||
|
receive_data(hnd, logfilename, inp_buff, data_receive_trys_counter, max_total_words);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
printf("\nStart averaging mode\n");
|
||||||
|
BF_exec_cmd_simple(hnd, 0x8008, 2, 1); //start averaging
|
||||||
|
printf("\Flushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
printf("\n\nget counters of calls of SPORT_RX, SPORT_TX, HDMA_RX, HDMA_TX\n");
|
printf("\n\nget counters of calls of SPORT_RX, SPORT_TX, HDMA_RX, HDMA_TX\n");
|
||||||
@ -1062,8 +1166,34 @@ int main(int argc, char** argv) {
|
|||||||
//fprintf(logfile_ptr, "value number; time, sec; adc_value, V\n");
|
//fprintf(logfile_ptr, "value number; time, sec; adc_value, V\n");
|
||||||
|
|
||||||
|
|
||||||
int data_receive_trys_counter = 1000;
|
data_receive_trys_counter = 100;
|
||||||
while(--data_receive_trys_counter){
|
max_total_words = 10000;
|
||||||
|
|
||||||
|
// void receive_data(t_x502_hnd hnd, FILE* logfile_ptr, uint32_t* inp_buff, int data_receive_trys_counter, uint32_t max_total_words)
|
||||||
|
|
||||||
|
|
||||||
|
receive_data(hnd, logfilename, inp_buff, data_receive_trys_counter, max_total_words);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
printf("\nStart transparent mode\n");
|
||||||
|
BF_exec_cmd_simple(hnd, 0x8007, 10, 1); //start averaging
|
||||||
|
printf("\Flushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd));
|
||||||
|
|
||||||
|
receive_data(hnd, logfilename, inp_buff, data_receive_trys_counter, max_total_words);
|
||||||
|
|
||||||
|
printf("\nStart averaging mode\n");
|
||||||
|
BF_exec_cmd_simple(hnd, 0x8008, 2, 1); //start averaging
|
||||||
|
printf("\Flushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd));
|
||||||
|
|
||||||
|
receive_data(hnd, logfilename, inp_buff, data_receive_trys_counter, max_total_words);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
while((--data_receive_trys_counter)&& (max_total_words)){
|
||||||
|
|
||||||
ready_cnt_Err = X502_GetRecvReadyCount(hnd, &ready_cnt);
|
ready_cnt_Err = X502_GetRecvReadyCount(hnd, &ready_cnt);
|
||||||
recv_Err_code = X502_Recv(hnd, inp_buff, ready_cnt, 10);
|
recv_Err_code = X502_Recv(hnd, inp_buff, ready_cnt, 10);
|
||||||
printf("\n\nget counters of calls of SPORT_RX, SPORT_TX, HDMA_RX, HDMA_TX\n");
|
printf("\n\nget counters of calls of SPORT_RX, SPORT_TX, HDMA_RX, HDMA_TX\n");
|
||||||
@ -1071,6 +1201,14 @@ int main(int argc, char** argv) {
|
|||||||
if (ready_cnt){
|
if (ready_cnt){
|
||||||
printf("Ready count: %d, Err: %d \n", ready_cnt, ready_cnt_Err);
|
printf("Ready count: %d, Err: %d \n", ready_cnt, ready_cnt_Err);
|
||||||
for (int i = 0; i < ready_cnt; ++i){
|
for (int i = 0; i < ready_cnt; ++i){
|
||||||
|
//printf("\nabort value: %d\n", abort_crtl_C);
|
||||||
|
if (abort_crtl_C){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
--max_total_words;
|
||||||
|
if (max_total_words == 0){
|
||||||
|
break;
|
||||||
|
}
|
||||||
char bin_str_val[9] = {0,};
|
char bin_str_val[9] = {0,};
|
||||||
uin32_t_to_bin(inp_buff[i], bin_str_val);
|
uin32_t_to_bin(inp_buff[i], bin_str_val);
|
||||||
printf(" 0x%08X,", inp_buff[i]);
|
printf(" 0x%08X,", inp_buff[i]);
|
||||||
@ -1083,7 +1221,6 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
uint32_t process_data_Err = 0;
|
uint32_t process_data_Err = 0;
|
||||||
uint32_t adc_data_size = ready_cnt;
|
uint32_t adc_data_size = ready_cnt;
|
||||||
X502_Raw_User_Data_Parser(inp_buff, inp_values_N,
|
X502_Raw_User_Data_Parser(inp_buff, inp_values_N,
|
||||||
@ -1098,15 +1235,22 @@ int main(int argc, char** argv) {
|
|||||||
//printf(" %e\n", adc_data[i]);
|
//printf(" %e\n", adc_data[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
//printf("try: %04d, words ready: %06d, receive_error_code: %05d, data_sum: %d \n", data_receive_trys_counter, ready_cnt, recv_Err_code, data_sum);
|
//printf("try: %04d, words ready: %06d, receive_error_code: %05d, data_sum: %d \n", data_receive_trys_counter, ready_cnt, recv_Err_code, data_sum);
|
||||||
}
|
}
|
||||||
fclose(logfile_ptr);
|
|
||||||
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
//fclose(logfile_ptr);
|
||||||
|
|
||||||
|
|
||||||
|
printf("\n\nreceive done. Exiting...\n\n\n");
|
||||||
|
//logfile_ptr = fopen(logfilename, "w");
|
||||||
|
printf("dumped to file: %s\n", logfilename);
|
||||||
|
|
||||||
X502_Close(hnd);
|
X502_Close(hnd);
|
||||||
// освобождаем описатель
|
// освобождаем описатель
|
||||||
X502_Free(hnd);
|
X502_Free(hnd);
|
||||||
|
|||||||
12
plotter.py
12
plotter.py
@ -18,7 +18,7 @@ if __name__ == "__main__":
|
|||||||
data = {}
|
data = {}
|
||||||
values_N = 0
|
values_N = 0
|
||||||
for line in f:
|
for line in f:
|
||||||
print(line)
|
#print(line)
|
||||||
#print(line, len(line))
|
#print(line, len(line))
|
||||||
len_line = len(line)
|
len_line = len(line)
|
||||||
try:
|
try:
|
||||||
@ -28,6 +28,8 @@ if __name__ == "__main__":
|
|||||||
header = line[2:4]
|
header = line[2:4]
|
||||||
value = line[4:10]
|
value = line[4:10]
|
||||||
if not(header in data):
|
if not(header in data):
|
||||||
|
print("New msg type!")
|
||||||
|
print(line)
|
||||||
data[header] = []
|
data[header] = []
|
||||||
data[header + "_N"] = []
|
data[header + "_N"] = []
|
||||||
data[header + "_hex"] = []
|
data[header + "_hex"] = []
|
||||||
@ -38,11 +40,17 @@ if __name__ == "__main__":
|
|||||||
pass
|
pass
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
|
if (values_N > 10000):
|
||||||
|
# break
|
||||||
|
pass
|
||||||
f.close()
|
f.close()
|
||||||
# print("data samples:",len(data["X"]))
|
print("data samples:", values_N)
|
||||||
chart = go.Figure()
|
chart = go.Figure()
|
||||||
for key, val in data.items():
|
for key, val in data.items():
|
||||||
if (key.count("_N") + key.count("_hex")) == 0:
|
if (key.count("_N") + key.count("_hex")) == 0:
|
||||||
|
#print(key+"_hex :", data[key+"_hex"])
|
||||||
|
#chart.add_trace(go.Scatter(x=data[key+"_N"], y=data[key], name=key, mode="lines", text=data[key+"_hex"]))
|
||||||
chart.add_trace(go.Scatter(x=data[key+"_N"], y=data[key], name=key, mode="lines+markers", text=data[key+"_hex"]))
|
chart.add_trace(go.Scatter(x=data[key+"_N"], y=data[key], name=key, mode="lines+markers", text=data[key+"_hex"]))
|
||||||
|
chart.update_layout(title=argv[1])
|
||||||
chart.show()
|
chart.show()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user