implemented simple and robust function for receiving data and dumping it to the file: receive_to_file. Old function was somehow broken.
This commit is contained in:
BIN
BF_companion
BIN
BF_companion
Binary file not shown.
103
main.c
103
main.c
@ -174,7 +174,7 @@ static uint32_t f_ch_ranges[ADC_LCH_CNT] = {X502_ADC_RANGE_5, X502_ADC_RANGE_5,X
|
||||
|
||||
|
||||
|
||||
#define SYNC_FREC_SOURCE X502_SYNC_DI_SYN1_FALL
|
||||
#define SYNC_FREC_SOURCE X502_SYNC_DI_SYN1_RISE
|
||||
#define SYNC_START_SOURCE X502_SYNC_DI_SYN2_RISE
|
||||
|
||||
|
||||
@ -851,6 +851,23 @@ uint32_t X502_FlushRcv_buff(t_x502_hnd hnd){
|
||||
return ready;
|
||||
}
|
||||
|
||||
|
||||
void receive_to_file(t_x502_hnd hnd, char* logfilename, uint32_t* inp_buff, uint32_t max_total_words){
|
||||
FILE* logfile_ptr = fopen(logfilename, "a");
|
||||
uint32_t recv_Err_code = X502_Recv(hnd, inp_buff, max_total_words, 1000);
|
||||
if (recv_Err_code > 0){
|
||||
uint32_t received_words = recv_Err_code;
|
||||
for (uint32_t word_I = 0; word_I < received_words; word_I ++){
|
||||
//printf("%06d 0x%08X\n", word_I, inp_buff[word_I]);
|
||||
fprintf(logfile_ptr, "0x%08X \n", inp_buff[word_I]);
|
||||
}
|
||||
printf("received %ld words\n", received_words);
|
||||
}else{
|
||||
printf("receive error: %d\n======================\n", recv_Err_code);
|
||||
}
|
||||
fclose(logfile_ptr);
|
||||
}
|
||||
|
||||
void receive_data(t_x502_hnd hnd, char* logfilename, uint32_t* inp_buff, int data_receive_trys_counter, uint32_t max_total_words, uint8_t mode){
|
||||
//int data_receive_trys_counter = 100;
|
||||
//uint32_t max_total_words = 10000;
|
||||
@ -865,10 +882,10 @@ void receive_data(t_x502_hnd hnd, char* logfilename, uint32_t* inp_buff, int dat
|
||||
|
||||
logfile_ptr = fopen(logfilename, "a");
|
||||
|
||||
while((--data_receive_trys_counter)&& (max_total_words)){
|
||||
//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);
|
||||
//ready_cnt_Err = X502_GetRecvReadyCount(hnd, &ready_cnt);
|
||||
recv_Err_code = X502_Recv(hnd, inp_buff, max_total_words, data_receive_trys_counter);
|
||||
//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");
|
||||
@ -918,7 +935,7 @@ void receive_data(t_x502_hnd hnd, char* logfilename, uint32_t* inp_buff, int dat
|
||||
;
|
||||
}
|
||||
//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);
|
||||
}
|
||||
|
||||
@ -1058,11 +1075,16 @@ int main(int argc, char** argv) {
|
||||
|
||||
char* BF_firmware_filename = "l502-BFfirmware0.ldr";
|
||||
|
||||
printf("loading Blackfin firmware file: %s\n", BF_firmware_filename);
|
||||
if (1){
|
||||
|
||||
uint32_t bf_firmware_load_state = X502_BfLoadFirmware(hnd, BF_firmware_filename); //load firmware from l502-BFfirmware0.ldr file to BlackFin
|
||||
printf("load state: %d \n", bf_firmware_load_state);
|
||||
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
|
||||
printf("load state: %d \n", bf_firmware_load_state);
|
||||
|
||||
}else{
|
||||
printf("No BF firmware loaded\n");
|
||||
}
|
||||
printf("setup module again");
|
||||
if (err == X502_ERR_OK) {
|
||||
// настраиваем параметры модуля //
|
||||
@ -1186,22 +1208,22 @@ int main(int argc, char** argv) {
|
||||
uint32_t recv_Err_code = 0;
|
||||
|
||||
|
||||
//printf("\nStart transparent mode\n");
|
||||
//BF_exec_cmd_simple(hnd, 0x8007, 10, 1); //start transparent
|
||||
printf("\nStart transparent mode\n");
|
||||
BF_exec_cmd_simple(hnd, 0x8007, 10, 1); //start transparent
|
||||
|
||||
printf("\nFlushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd));
|
||||
|
||||
printf("receiving data...\n");
|
||||
|
||||
|
||||
ready_cnt_Err = X502_GetRecvReadyCount(hnd, &ready_cnt_copy);
|
||||
recv_Err_code = X502_Recv(hnd, inp_buff, 1024, 10);
|
||||
//ready_cnt_Err = X502_GetRecvReadyCount(hnd, &ready_cnt_copy);
|
||||
//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("Recv Err code (<0 -- err, >= 0 -- number of received words(32bit)): %d\n", recv_Err_code);
|
||||
// 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);
|
||||
|
||||
if (recv_Err_code > 0){
|
||||
ready_cnt = recv_Err_code;
|
||||
@ -1212,11 +1234,13 @@ int main(int argc, char** argv) {
|
||||
|
||||
int data_receive_trys_counter = 100;
|
||||
uint32_t max_total_words = 100000;
|
||||
printf("\nflush TX buff. \n Number of free TX descriptors before flushing:");
|
||||
BF_exec_cmd_simple(hnd, 0x8010, 10, 1);
|
||||
// printf("\nflush TX buff. \n Number of free TX descriptors before flushing:");
|
||||
// BF_exec_cmd_simple(hnd, 0x8010, 10, 1);
|
||||
|
||||
|
||||
receive_data(hnd, logfilename, inp_buff, data_receive_trys_counter, max_total_words, DUMP_TO_FILE);
|
||||
receive_to_file(hnd, logfilename, inp_buff, max_total_words);
|
||||
|
||||
//receive_data(hnd, logfilename, inp_buff, data_receive_trys_counter, max_total_words, DUMP_TO_FILE);
|
||||
/*
|
||||
data_receive_trys_counter = 100;
|
||||
max_total_words = 10000;
|
||||
@ -1224,24 +1248,26 @@ int main(int argc, char** argv) {
|
||||
receive_data(hnd, logfilename, inp_buff, data_receive_trys_counter, max_total_words, DUMP_TO_FILE);
|
||||
*/
|
||||
|
||||
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("\nStart averaging mode\n");
|
||||
|
||||
printf("\nflush TX buff. \n Number of free TX descriptors before flushing:");
|
||||
BF_exec_cmd_simple(hnd, 0x8010, 10, 1);
|
||||
// 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);
|
||||
//BF_exec_cmd_simple(hnd, 0x8008, 2, 1); //start averaging
|
||||
BF_exec_cmd_simple(hnd, 0x8008, 2, 1); //start averaging
|
||||
//BF_exec_cmd_simple(hnd, 0x8007, 2, 1); //start transparent
|
||||
BF_exec_cmd_simple(hnd, 0x800B, 2, 1); //start HDMA flood for speedtest
|
||||
//BF_exec_cmd_simple(hnd, 0x800B, 2, 1); //start HDMA flood for speedtest
|
||||
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");
|
||||
@ -1258,8 +1284,9 @@ int main(int argc, char** argv) {
|
||||
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);
|
||||
// receive_data(hnd, logfilename, inp_buff, data_receive_trys_counter, max_total_words, FLUSH);
|
||||
receive_data(hnd, logfilename, inp_buff, data_receive_trys_counter, max_total_words, DUMP_TO_FILE);
|
||||
//receive_data(hnd, logfilename, inp_buff, data_receive_trys_counter, max_total_words, DUMP_TO_FILE);
|
||||
clock_gettime(CLOCK_MONOTONIC, &time_receive_ended);
|
||||
|
||||
|
||||
@ -1271,38 +1298,40 @@ int main(int argc, char** argv) {
|
||||
printf("\n Receive time: %g, %g sec/value \n", receive_time, receive_time/max_total_words);
|
||||
|
||||
|
||||
printf("\n dbg value: ");
|
||||
BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
|
||||
// printf("\n dbg value: ");
|
||||
// BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
|
||||
|
||||
|
||||
|
||||
printf("\nStart transparent mode\n");
|
||||
BF_exec_cmd_simple(hnd, 0x8007, 10, 1); //start transparent
|
||||
|
||||
printf("\nflush TX buff. \n Number of free TX descriptors before flushing:");
|
||||
BF_exec_cmd_simple(hnd, 0x8010, 10, 1);
|
||||
|
||||
BF_exec_cmd_simple(hnd, 0x8007, 10, 1); //start averaging
|
||||
|
||||
printf("\nFlushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd));
|
||||
|
||||
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_data(hnd, logfilename, inp_buff, data_receive_trys_counter, max_total_words, DUMP_TO_FILE);
|
||||
printf("\n dbg value: ");
|
||||
BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
|
||||
// printf("\n dbg value: ");
|
||||
// BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
|
||||
|
||||
|
||||
printf("\nStart averaging 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);
|
||||
|
||||
BF_exec_cmd_simple(hnd, 0x8008, 2, 1); //start averaging
|
||||
printf("\nFlushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd));
|
||||
printf("\nFlushed from receiving buff: %d\n", X502_FlushRcv_buff(hnd));
|
||||
|
||||
|
||||
printf("\n dbg value: ");
|
||||
BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
|
||||
|
||||
receive_data(hnd, logfilename, inp_buff, data_receive_trys_counter, max_total_words, DUMP_TO_FILE);
|
||||
// printf("\n dbg value: ");
|
||||
// BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
|
||||
receive_to_file(hnd, logfilename, inp_buff, max_total_words);
|
||||
//receive_data(hnd, logfilename, inp_buff, data_receive_trys_counter, max_total_words, DUMP_TO_FILE);
|
||||
printf("\n dbg value: ");
|
||||
BF_exec_cmd_simple(hnd, 0x800A, 10, 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user