diff --git a/BF_companion b/BF_companion index d146586..4112af0 100755 Binary files a/BF_companion and b/BF_companion differ diff --git a/build/main.o b/build/main.o index 1e384a7..644d7f0 100644 Binary files a/build/main.o and b/build/main.o differ diff --git a/main.c b/main.c index 108189f..6d4e18f 100644 --- a/main.c +++ b/main.c @@ -702,20 +702,8 @@ int main(int argc, char** argv) { int32_t err = X502_ERR_OK; uint32_t ver; t_x502_hnd hnd = NULL; -#ifndef _WIN32 - struct sigaction sa; - memset(&sa, 0, sizeof(sa)); - // В ОС Linux устанавливаем свой обработчик на сигнал закрытия, - // чтобы завершить сбор корректно // - sa.sa_handler = f_abort_handler; - sigaction(SIGTERM, &sa, NULL); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGABRT, &sa, NULL); -#endif -#ifdef _WIN32 - // для вывода русских букв в консоль для ОС Windows в CP1251 без перевода в OEM // - setlocale(LC_CTYPE, ""); -#endif + + // читаем имя командного файла из аргументов CLI const char* cmd_filename = "default.cmd"; if (argc > 1 && argv[1] != NULL && argv[1][0] != '\0') { @@ -842,87 +830,110 @@ int main(int argc, char** argv) { // освобождаем описатель X502_Free(hnd); return 0; - } - } + + }else if (state.run_mode == RUN_MODE_INF){ + state.run_I = 0; + char tmp_data_filename[] = " "; + struct timespec ts; + uint32_t max_total_words = 0; + uint32_t *inp_buff = malloc(1024*100*1024*2*4); + while (1){ //should be infinite. because it is RUN_MODE_INF + //while(state.run_I < state.runs_N){ + max_total_words = 10000000; + timespec_get(&ts, TIME_UTC); + // sprintf(&tmp_data_filename, "tmp/received_data_%ld.%ld.csv", ts.tv_sec, ts.tv_nsec); + // sprintf(&logfilename, "tmp/received_data_%ld.%ld.csv", ts.tv_sec, ts.tv_nsec); + //sprintf(&logfilename, "data/received_data_%ld.csv", seconds); + snprintf(tmp_data_filename, sizeof(tmp_data_filename), "tmp/received_data_%ld.%ld.csv", ts.tv_sec, ts.tv_nsec); + printf("%u dumping to file: %s\n", (unsigned)state.run_I, tmp_data_filename); + receive_to_file(hnd, tmp_data_filename, inp_buff, max_total_words, state.run_length); + state.run_I++; + } + free(inp_buff); + X502_Close(hnd); + // освобождаем описатель + X502_Free(hnd); + return 0; + }else{ //TEST mode as default - time_t seconds; - time(&seconds); - char logfilename[] = " "; - sprintf(&logfilename, "data/received_data_%ld.csv", seconds); - //logfile_ptr = fopen(logfilename, "w"); - FILE *logfile_ptr; - logfile_ptr = fopen(logfilename, "a"); - fprintf(logfile_ptr, "sync_frec_source: %d \nsync_start_source: %d \n", SYNC_FREC_SOURCE, SYNC_START_SOURCE); + time_t seconds; + time(&seconds); + char logfilename[] = " "; + sprintf(&logfilename, "data/received_data_%ld.csv", seconds); + //logfile_ptr = fopen(logfilename, "w"); + FILE *logfile_ptr; + logfile_ptr = fopen(logfilename, "a"); - for (int chan_I = 0; chan_I < ADC_LCH_CNT; chan_I++){ - fprintf(logfile_ptr, "chan: %d, mode: %d, range: %d \n", chan_I, f_ch_modes[chan_I], f_ch_ranges[chan_I]); - } - fclose(logfile_ptr); + fprintf(logfile_ptr, "sync_frec_source: %d \nsync_start_source: %d \n", SYNC_FREC_SOURCE, SYNC_START_SOURCE); + for (int chan_I = 0; chan_I < ADC_LCH_CNT; chan_I++){ + fprintf(logfile_ptr, "chan: %d, mode: %d, range: %d \n", chan_I, f_ch_modes[chan_I], f_ch_ranges[chan_I]); + } + fclose(logfile_ptr); -// printf("dumping to file: %s\n", logfilename); - printf("\n"); - //printf("start streams sampling\n"); - //BF_exec_cmd_with_arr(hnd, 0x8004U, 0, NULL, 0, 1); //setup and start streams + // printf("dumping to file: %s\n", logfilename); + printf("\n"); + //printf("start streams sampling\n"); + //BF_exec_cmd_with_arr(hnd, 0x8004U, 0, NULL, 0, 1); //setup and start streams - uint32_t waiting_cnt = 1; - waiting_cnt = 100000; - printf("\nwaiting %d ...", waiting_cnt); - while(--waiting_cnt){;} - //for(uint32_t timeout = 100000000; timeout; --timeout){;} - printf("done\n"); - 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); + uint32_t waiting_cnt = 1; + waiting_cnt = 100000; + printf("\nwaiting %d ...", waiting_cnt); + while(--waiting_cnt){;} + //for(uint32_t timeout = 100000000; timeout; --timeout){;} + printf("done\n"); + 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\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, 3); + // 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, 3); - uint32_t *inp_buff = malloc(1024*100*1024*2*4); - double *adc_data = malloc(1024*1024*sizeof(double)); - //uint32_t inp_buff[1024*2048] = {0,}; - /* Removed unused counters */ + uint32_t *inp_buff = malloc(1024*100*1024*2*4); + double *adc_data = malloc(1024*1024*sizeof(double)); + //uint32_t inp_buff[1024*2048] = {0,}; + /* Removed unused counters */ - insert_marker_to_file(logfilename, "start transparent"); - printf("\nStart transparent mode\n"); - BF_exec_cmd_simple(hnd, 0x8007, 10, 1); //start transparent + insert_marker_to_file(logfilename, "start transparent"); - printf("\nFlushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd)); + printf("\nStart transparent mode\n"); + BF_exec_cmd_simple(hnd, 0x8007, 10, 1); //start transparent - printf("receiving data...\n"); + printf("\nFlushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd)); + printf("receiving data...\n"); - /* Removed unused readiness checks */ - uint32_t max_total_words = 100000; - /* Removed unused data_receive_trys_counter */ -// printf("\nflush TX buff. \n Number of free TX descriptors before flushing:"); -// BF_exec_cmd_simple(hnd, 0x8010, 10, 1); + /* Removed unused readiness checks */ + uint32_t max_total_words = 100000; + /* Removed unused data_receive_trys_counter */ + // printf("\nflush TX buff. \n Number of free TX descriptors before flushing:"); + // BF_exec_cmd_simple(hnd, 0x8010, 10, 1); -// receive_to_file(hnd, logfilename, inp_buff, max_total_words, 10000); + // receive_to_file(hnd, logfilename, inp_buff, max_total_words, 10000); - 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\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); -//* + //* @@ -935,51 +946,51 @@ int main(int argc, char** argv) { - insert_marker_to_file(logfilename, "start AVG"); - printf("\nStart AVG mode\n"); - BF_exec_cmd_simple(hnd, 0x8008, 2, 1); //start averaging + insert_marker_to_file(logfilename, "start AVG"); + printf("\nStart AVG mode\n"); + BF_exec_cmd_simple(hnd, 0x8008, 2, 1); //start averaging -// printf("\nflush TX buff. \n Number of free TX descriptors before flushing:"); -// BF_exec_cmd_simple(hnd, 0x8010, 10, 1); - X502_StreamsStop(hnd); - X502_StreamsStart(hnd); + // printf("\nflush TX buff. \n Number of free TX descriptors before flushing:"); + // BF_exec_cmd_simple(hnd, 0x8010, 10, 1); + X502_StreamsStop(hnd); + X502_StreamsStart(hnd); -// for(uint32_t wait_i = 1e6; wait_i; --wait_i){;} - printf("\nFlushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd)); + // for(uint32_t wait_i = 1e6; wait_i; --wait_i){;} + printf("\nFlushed 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"); -// BF_exec_cmd_with_arr(hnd, 0x8005U, 100, NULL, 0, 1); + // 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); - //fprintf(logfile_ptr, "value number; time, sec; adc_value, V\n"); + //fprintf(logfile_ptr, "value number; time, sec; adc_value, V\n"); - max_total_words = 100000; - //printf("\n dbg value: "); - //BF_exec_cmd_simple(hnd, 0x800A, 10, 1); + max_total_words = 100000; - struct timespec time_receive_started, time_receive_ended; + //printf("\n dbg value: "); + //BF_exec_cmd_simple(hnd, 0x800A, 10, 1); - clock_gettime(CLOCK_MONOTONIC, &time_receive_started); - receive_to_file(hnd, logfilename, inp_buff, max_total_words, 10000); - clock_gettime(CLOCK_MONOTONIC, &time_receive_ended); + struct timespec time_receive_started, time_receive_ended; + clock_gettime(CLOCK_MONOTONIC, &time_receive_started); + receive_to_file(hnd, logfilename, inp_buff, max_total_words, 10000); + clock_gettime(CLOCK_MONOTONIC, &time_receive_ended); - double receive_time = (time_receive_ended.tv_sec - time_receive_started.tv_sec); - receive_time += time_receive_ended.tv_nsec*1e-9; - receive_time += time_receive_started.tv_nsec*1e-9; + double receive_time = (time_receive_ended.tv_sec - time_receive_started.tv_sec); + receive_time += time_receive_ended.tv_nsec*1e-9; + receive_time += time_receive_started.tv_nsec*1e-9; - printf("\n Receive time: %g, %g sec/value \n", receive_time, receive_time/max_total_words); + printf("\n Receive time: %g, %g sec/value \n", receive_time, receive_time/max_total_words); @@ -990,43 +1001,45 @@ int main(int argc, char** argv) { - insert_marker_to_file(logfilename, "start transparent"); - printf("\nStart transparent mode\n"); - BF_exec_cmd_simple(hnd, 0x8007, 2, 1); //start transparent - X502_StreamsStop(hnd); - X502_StreamsStart(hnd); + insert_marker_to_file(logfilename, "start transparent"); - printf("\nflush TX buff. \n Number of free TX descriptors before flushing:"); - BF_exec_cmd_simple(hnd, 0x8010, 10, 1); + printf("\nStart transparent mode\n"); + BF_exec_cmd_simple(hnd, 0x8007, 2, 1); //start transparent + X502_StreamsStop(hnd); + X502_StreamsStart(hnd); - printf("\nFlushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd)); + printf("\nflush TX buff. \n Number of free TX descriptors before flushing:"); + BF_exec_cmd_simple(hnd, 0x8010, 10, 1); + printf("\nFlushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd)); -// printf("\n dbg value: "); -// BF_exec_cmd_simple(hnd, 0x800A, 10, 1); - receive_to_file(hnd, logfilename, inp_buff, max_total_words, 10000); - printf("\n dbg value: "); - BF_exec_cmd_simple(hnd, 0x800A, 10, 1); -//*/ + // printf("\n dbg value: "); + // BF_exec_cmd_simple(hnd, 0x800A, 10, 1); + receive_to_file(hnd, logfilename, inp_buff, max_total_words, 10000); + printf("\n dbg value: "); + BF_exec_cmd_simple(hnd, 0x800A, 10, 1); + //*/ - printf("\n\nreceive done. Exiting...\n\n\n"); - //logfile_ptr = fopen(logfilename, "w"); - printf("dumped to file: %s\n", logfilename); - fprintf(stderr, "%s\n", logfilename); - X502_Close(hnd); - // освобождаем описатель - X502_Free(hnd); - return 0; + printf("\n\nreceive done. Exiting...\n\n\n"); + //logfile_ptr = fopen(logfilename, "w"); + printf("dumped to file: %s\n", logfilename); + fprintf(stderr, "%s\n", logfilename); + X502_Close(hnd); + // освобождаем описатель + X502_Free(hnd); + return 0; + } - + } + return -1; }