implemented more accurate display of received arrays. Also implemented printing arrays as binary data. Working receive (by command) last piece of SPORT0 data
This commit is contained in:
BIN
BF_companion
BIN
BF_companion
Binary file not shown.
255
main.c
255
main.c
@ -64,6 +64,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "l502_BF_enums.h"
|
||||
#include "l502_fpga_regs.h"
|
||||
|
||||
// количество используемых логических каналов //
|
||||
#define ADC_LCH_CNT 1
|
||||
|
||||
@ -330,6 +333,174 @@ int32_t f_setup_params(t_x502_hnd hnd) {
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
void uin32_t_to_bin(uint32_t val, char* string){
|
||||
for (int i = 0; i < 8; ++i){
|
||||
if (val & (0b1 << i)){
|
||||
string[i] = '1';
|
||||
}else{
|
||||
string[i] = '0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t BF_exec_cmd_simple(t_x502_hnd hnd, uint16_t cmd_code, uint32_t cmd_par, uint8_t verbosity_lvl){
|
||||
|
||||
uint32_t BF_cmd_receive_code = 0;
|
||||
//uint16_t cmd_code = 0x8001; //read ADC data
|
||||
//uint32_t cmd_par = 87;
|
||||
const uint32_t snd_data[1] = {0,};
|
||||
uint32_t snd_size = 0;
|
||||
uint32_t rcv_data[100] = {0,};
|
||||
uint32_t rcv_size = 100;
|
||||
uint32_t tout = 1;
|
||||
uint32_t recvd_size = 0;
|
||||
//*/
|
||||
if (verbosity_lvl == 2){
|
||||
printf("\n\n");
|
||||
|
||||
printf("TX cmd_code: 0x%X\n", cmd_code);
|
||||
printf("TX tout: %u\n", tout);
|
||||
printf("TX par: %u\n", cmd_par);
|
||||
printf("TX snd_data size: %u\n", snd_size);
|
||||
for (int i = 0; i < snd_size; ++i){
|
||||
printf(" 0x%0X,", snd_data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
printf("TX rcv_size: %u\n", rcv_size);
|
||||
}
|
||||
|
||||
BF_cmd_receive_code = X502_BfExecCmd (hnd,
|
||||
cmd_code,
|
||||
cmd_par,
|
||||
snd_data,
|
||||
snd_size,
|
||||
rcv_data,
|
||||
rcv_size,
|
||||
tout,
|
||||
&recvd_size);
|
||||
|
||||
if (verbosity_lvl == 2){
|
||||
|
||||
printf("\n======================\n\n");
|
||||
printf("RX received code dec: %u hex: 0x%3X, %d\n", BF_cmd_receive_code, BF_cmd_receive_code,BF_cmd_receive_code);
|
||||
printf("RX recvd_size: %u\n", recvd_size);
|
||||
printf("RX received_data:\n" );
|
||||
for (int i = 0; i < recvd_size; ++i){
|
||||
printf(" 0x%0X,", rcv_data[i]);
|
||||
}
|
||||
printf("\n\n\n\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (verbosity_lvl == 1){
|
||||
printf("\ncmd: 0x%0X, par: %d, rcv_code: %d, result[0]: %d (0x%0X) , result_L: %d\n", cmd_code, cmd_par, BF_cmd_receive_code, rcv_data[0],rcv_data[0], recvd_size);
|
||||
}
|
||||
return BF_cmd_receive_code;
|
||||
}
|
||||
|
||||
uint32_t BF_exec_cmd_with_arr(t_x502_hnd hnd, uint16_t cmd_code, uint32_t cmd_par, uint32_t* snd_data, uint32_t snd_data_size, uint8_t verbosity_lvl){
|
||||
|
||||
uint32_t BF_cmd_receive_code = 0;
|
||||
//uint16_t cmd_code = 0x8001; //read ADC data
|
||||
//uint32_t cmd_par = 87;
|
||||
//const uint32_t snd_data[1] = {0,};
|
||||
//uint32_t snd_data_size = 0;
|
||||
uint32_t rcv_data[100] = {0,};
|
||||
uint32_t rcv_size = 100;
|
||||
uint32_t tout = 1;
|
||||
uint32_t recvd_size = 0;
|
||||
//*/
|
||||
if (verbosity_lvl == 2){
|
||||
printf("\n\n");
|
||||
printf("TX cmd_code: 0x%X\n", cmd_code);
|
||||
printf("TX tout: %u\n", tout);
|
||||
printf("TX par: %u\n", cmd_par);
|
||||
printf("TX snd_data size: %u\n", snd_data_size);
|
||||
for (int i = 0; i < snd_data_size; ++i){
|
||||
printf(" 0x%0X,", snd_data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
printf("TX rcv_size: %u\n", rcv_size);
|
||||
}
|
||||
|
||||
BF_cmd_receive_code = X502_BfExecCmd (hnd,
|
||||
cmd_code,
|
||||
cmd_par,
|
||||
snd_data,
|
||||
snd_data_size,
|
||||
rcv_data,
|
||||
rcv_size,
|
||||
tout,
|
||||
&recvd_size);
|
||||
|
||||
if (verbosity_lvl == 2){
|
||||
|
||||
printf("\n======================\n\n");
|
||||
printf("RX received code dec: %u hex: 0x%3X, %d\n", BF_cmd_receive_code, BF_cmd_receive_code,BF_cmd_receive_code);
|
||||
printf("RX recvd_size: %u\n", recvd_size);
|
||||
printf("RX received_data:\n" );
|
||||
for (int i = 0; i < recvd_size; ++i){
|
||||
printf(" 0x%0X,", rcv_data[i]);
|
||||
}
|
||||
printf("\n\n\n\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (verbosity_lvl == 1){
|
||||
printf("\n");
|
||||
printf("cmd: 0x%0X, par: %d, rcv_code: %d, result[0]: %d (0x%0X) , result_L: %d\n", cmd_code, cmd_par, BF_cmd_receive_code, rcv_data[0],rcv_data[0], recvd_size);
|
||||
printf(" TX arr: ");
|
||||
for (int i = 0; i < snd_data_size; ++i){
|
||||
printf(" 0x%0X,", snd_data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
printf(" RX arr: ");
|
||||
int values_in_line = 0;
|
||||
|
||||
for (int i = 0; i < recvd_size; ++i){
|
||||
printf(" 0x%08X,", rcv_data[i]);
|
||||
++values_in_line;
|
||||
if (values_in_line == 10){
|
||||
printf("\n");
|
||||
values_in_line = 0;
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
if (verbosity_lvl == 3){
|
||||
printf("\n");
|
||||
printf("cmd: 0x%0X, par: %d, rcv_code: %d, result[0]: %d (0x%0X) , result_L: %d\n", cmd_code, cmd_par, BF_cmd_receive_code, rcv_data[0],rcv_data[0], recvd_size);
|
||||
printf(" TX arr: ");
|
||||
for (int i = 0; i < snd_data_size; ++i){
|
||||
printf(" 0x%0X,", snd_data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
printf(" RX arr: ");
|
||||
int values_in_line = 0;
|
||||
for (int i = 0; i < recvd_size; ++i){
|
||||
char bin_str_val[9] = {0,};
|
||||
uin32_t_to_bin(rcv_data[i], bin_str_val);
|
||||
//printf(" 0x%0X,", rcv_data[i]);
|
||||
printf(" 0b%s,", bin_str_val);
|
||||
++values_in_line;
|
||||
if (values_in_line == 10){
|
||||
printf("\n");
|
||||
values_in_line = 0;
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return BF_cmd_receive_code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int32_t err = X502_ERR_OK;
|
||||
uint32_t ver;
|
||||
@ -416,17 +587,83 @@ int main(int argc, char** argv) {
|
||||
*/
|
||||
printf("\n\n\n");
|
||||
|
||||
//*
|
||||
//setup ADC:
|
||||
|
||||
//t_x502_hnd hnd, uint16_t cmd_code, uint32_t cmd_arg, uint8_t verbosity_lvl
|
||||
//BF_exec_cmd_simple(hnd, L502_BF_CMD_CODE_GET_PARAM, 87, 2);
|
||||
//BF_exec_cmd_simple(hnd, L502_BF_CMD_CODE_GET_PARAM, 87, 1);
|
||||
//BF_exec_cmd_simple(hnd, L502_BF_CMD_CODE_GET_PARAM, 87, 0);
|
||||
|
||||
|
||||
//BF_exec_cmd_simple(hnd, L502_BF_USR_CMD_CODE_ECHO, 87, 1);
|
||||
//BF_exec_cmd_simple(hnd, L502_BF_USR_CMD_CODE_DATA_ECHO, 87, 1);
|
||||
|
||||
//BF_exec_cmd_with_arr(t_x502_hnd hnd, uint16_t cmd_code, uint32_t cmd_par, uint32_t* snd_data, uint32_t snd_data_size, uint8_t verbosity_lvl);
|
||||
|
||||
//uint32_t tx_data[] = {0,1,2,3,4,53,4,2,2,1,0};
|
||||
//uint32_t tx_data_size = 11;
|
||||
|
||||
//BF_exec_cmd_with_arr(hnd, L502_BF_USR_CMD_CODE_DATA_ECHO, 328, tx_data, tx_data_size, 2);
|
||||
//BF_exec_cmd_with_arr(hnd, L502_BF_USR_CMD_CODE_DATA_ECHO, 328, tx_data, tx_data_size, 1);
|
||||
|
||||
//setup ADC:
|
||||
uint32_t tx_data[] = {0,1,2,3,4,53,4,2,2,1,0};
|
||||
|
||||
//set ADC Установка значения опорной частоты
|
||||
uint32_t tx_data_size = 1;
|
||||
tx_data[0] = 2000000; //valid values: 2000000, 1500000 Hz
|
||||
//printf("\n");
|
||||
|
||||
//BF_exec_cmd_with_arr(hnd, L502_BF_CMD_CODE_SET_PARAM, L502_BF_PARAM_REF_FREQ_SRC, tx_data, tx_data_size, 2);
|
||||
|
||||
//printf("run tests\n");
|
||||
//BF_exec_cmd_simple(hnd, 0x8010, 17, 1); //test SPORT0
|
||||
|
||||
|
||||
//BF_exec_cmd_simple(hnd, 0x8003U, 0, 1);
|
||||
printf("setup ADC\n");
|
||||
BF_exec_cmd_with_arr(hnd, 0x8003U, 0, NULL, 0, 1); //setup ADC. Values in array are configuring functions return codes
|
||||
|
||||
//some delay to allow ADC to acquire some data
|
||||
|
||||
//printf("L502_REGS_IOHARD_OUTSWAP_BFCTL reg:");
|
||||
//BF_exec_cmd_simple(hnd, 0x8006, L502_REGS_IOHARD_OUTSWAP_BFCTL, 1); //reaf fpga reg
|
||||
|
||||
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 = 1000;
|
||||
printf("\nwaiting %d ...", waiting_cnt);
|
||||
while(--waiting_cnt){;}
|
||||
//for(uint32_t timeout = 100000000; timeout; --timeout){;}
|
||||
printf("done\n");
|
||||
|
||||
printf("get 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("get 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);
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
//uint16_t cmd_code = 0x80001U;
|
||||
uint16_t cmd_code = 0x8001;
|
||||
uint16_t cmd_code = 0x8001; //read ADC data
|
||||
uint32_t par = 87;
|
||||
const uint32_t snd_data[] = {1,1,2,2,3,4,5,56,67,23,1};
|
||||
uint32_t snd_size = 11;
|
||||
uint32_t rcv_data[13] = {0,};
|
||||
uint32_t rcv_size = 13;
|
||||
uint32_t snd_size = 0;
|
||||
uint32_t rcv_data[100] = {0,};
|
||||
uint32_t rcv_size = 100;
|
||||
uint32_t tout = 1;
|
||||
uint32_t recvd_size = 0;
|
||||
//*/
|
||||
|
||||
|
||||
|
||||
printf("TX cmd_code: 0x%X\n", cmd_code);
|
||||
@ -456,7 +693,7 @@ int main(int argc, char** argv) {
|
||||
printf("RX recvd_size: %u\n", recvd_size);
|
||||
printf("RX received_data:\n" );
|
||||
for (int i = 0; i < recvd_size; ++i){
|
||||
printf(" %u,", rcv_data[i]);
|
||||
printf(" %0X,", rcv_data[i]);
|
||||
}
|
||||
printf("\n\n\n\n");
|
||||
|
||||
@ -472,7 +709,7 @@ int main(int argc, char** argv) {
|
||||
rcv_size = 13;
|
||||
tout = 1;
|
||||
recvd_size = 0;
|
||||
//*/
|
||||
|
||||
|
||||
|
||||
printf("TX cmd_code: 0x%X\n", cmd_code);
|
||||
@ -506,7 +743,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user