820 lines
		
	
	
		
			21 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			820 lines
		
	
	
		
			21 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
| #include "hw_reg_api.h"
 | |
| #include "chip_reg_base.h"
 | |
| #include "ada_reg.h"
 | |
| #include "phy_ana.h"
 | |
| #include "phy_tools.h"
 | |
| #include "ada_main.h"
 | |
| #include "iot_config.h"
 | |
| #include "math.h"
 | |
| #include "fft.h"
 | |
| #include "phy_reg.h"
 | |
| #include "hw_phy_init.h"
 | |
| #include "mac_reset.h"
 | |
| #include "phy_bb.h"
 | |
| #include "hw_desc.h"
 | |
| #include "iot_bitops.h"
 | |
| #include "hw_tonemask.h"
 | |
| #include "phy_dfe_reg.h"
 | |
| #include "phy_rx_fd_reg.h"
 | |
| #include "phy_rxtd_reg.h"
 | |
| #include "ahb_rf.h"
 | |
| #include "phy_cal.h"
 | |
| #include "plc_protocol.h"
 | |
| #include "granite_reg.h"
 | |
| #include "mac_sys_reg.h"
 | |
| #include "mac_reset.h"
 | |
| #include "phy_ana_glb.h"
 | |
| #include "flash.h"
 | |
| #include "gpio_mtx.h"
 | |
| #include "apb.h"
 | |
| #include "os_mem.h"
 | |
| #include "mac_rx_reg.h"
 | |
| #include "hw_ada.h"
 | |
| #include "hw_phy_api.h"
 | |
| #include "phy_chn.h"
 | |
| #if HW_PLATFORM > HW_PLATFORM_SIMU
 | |
| #include "dbg_io.h"
 | |
| #endif
 | |
| #include "iot_io.h"
 | |
| 
 | |
| uint16_t cur_tone_id = 0;
 | |
| extern void fft(int N,complex f[]);
 | |
| 
 | |
| AdaCasePara_t ada_cases_tb[] =
 | |
| {
 | |
|     {ADA_TEST_DUMP, "\n[Dtest][ADA][DUMP] Dump ADC data::::::::::::::::::::::::::::::\n"},
 | |
|     {ADA_TEST_VPP,  "\n[Dtest][ADA][VPP]  Print Tone VPP voltage:::::::::::::::::::::\n"},
 | |
|     {ADA_TEST_SNR,  "\n[Dtest][ADA][SNR]  Print SIGNAL-NOISE RATIO:::::::::::::::::::\n"},
 | |
|     {ADA_TEST_FA,   "\n[Dtest][ADA][FA]   Print Freq vs Amp feature::::::::::::::::::\n"},
 | |
|     {ADA_TEST_TONE, "\n[Dtest][ADA][TONE] Gen tone:::::::::::::::::::::::::::::::::::\n"},
 | |
|     {ADA_TEST_FLASH,"\n[Dtest][ADA][FLASH] DUMP write FLASH and print back:::::::::::\n"},
 | |
|     {ADA_FFT_FLASH, "\n[Dtest][ADA][FLASH] FFT write FLASH and print back::::::::::::\n"},
 | |
| };
 | |
| 
 | |
| /* info:
 | |
|  *  this API reinit mtx, gpio config may miss.
 | |
|  */
 | |
| void phy_led_set(uint32_t gpio, bool_t on)
 | |
| {
 | |
|     gpio_mtx_enable();
 | |
|     apb_enable(APB_GPIO);
 | |
|     gpio_pin_select(gpio, 3);
 | |
|     if (on) {
 | |
|         gpio_pin_wpu(gpio, 1);
 | |
|         gpio_pin_wpd(gpio, 0);
 | |
|     } else {
 | |
|         gpio_pin_wpu(gpio, 0);
 | |
|         gpio_pin_wpd(gpio, 1);
 | |
|     }
 | |
| }
 | |
| 
 | |
| void adc_cal_vpp(uint8_t *mem_buf, int32_t st_offset)
 | |
| {
 | |
|     int16_t i = 0;
 | |
|     int16_t *p_addr = NULL;
 | |
|     int16_t top_peak_ave = 0, bottom_peak_ave = 0;
 | |
| 
 | |
|     p_addr = (int16_t *)(mem_buf + (st_offset << 2));
 | |
| 
 | |
|     /* print the pre-trig buf to the end */
 | |
|     while (i < (ADA_TONE_CYCLE_NUM >> 2))
 | |
|     {
 | |
|         if (*p_addr > top_peak_ave) {
 | |
|             top_peak_ave = *p_addr;
 | |
|         }
 | |
| 
 | |
|         if (*p_addr < bottom_peak_ave) {
 | |
|             bottom_peak_ave = *p_addr;
 | |
|         }
 | |
| 
 | |
|         /* iot_printf("%06d\r\n",*p_addr); */
 | |
|         p_addr++;
 | |
|         i++;
 | |
|     }
 | |
| 
 | |
| #if ADA_DEBUG_LEVEL >= ADA_PRINT_DEBUG
 | |
|     i = 0;
 | |
|     p_addr = (int16_t *)(mem_buf + (st_offset << 2));
 | |
|     while (i < ADA_TONE_CYCLE_NUM)
 | |
|     {
 | |
| #if DATA_INV_EN
 | |
|         iot_printf("%06d\n", *(p_addr+1));
 | |
|         iot_printf("%06d\n", *p_addr);
 | |
| #else
 | |
|         iot_printf("%06d\n", *p_addr);
 | |
|         iot_printf("%06d\n", *(p_addr+1));
 | |
| #endif
 | |
|         i += 2;
 | |
|         p_addr += 2;
 | |
|     }
 | |
| #endif
 | |
| 
 | |
|     iot_printf("[*vpp*] tone id=%d, "\
 | |
|         "peak-peak=%06d from %06d, vpp= %06d (***%d mV***)\n", \
 | |
|         cur_tone_id, top_peak_ave, bottom_peak_ave, \
 | |
|         top_peak_ave - bottom_peak_ave, \
 | |
|         ((top_peak_ave-bottom_peak_ave) * VPP_CNT_VOL_A - VPP_CNT_VOL_B)/10);
 | |
| }
 | |
| 
 | |
| #if ADA_DTEST_SNR_SUPPORT
 | |
| /*
 | |
|     sigPower = sum(abs(X).^2)/length(X)
 | |
|     noisePower=sum(abs(Y-X).^2)/length(Y-X)
 | |
| */
 | |
| void adc_cal_snr(uint8_t *mem_buf, int32_t st_offset)
 | |
| {
 | |
|     int16_t i = 0;
 | |
|     int16_t *p_addr = NULL;
 | |
|     static complex sample_data[ADA_TONE_CYCLE_NUM] = {0};
 | |
|     static float f_amp[ADA_TONE_CYCLE_NUM]={0};
 | |
|     uint32_t ind_lowband=0,ind_highband=0;
 | |
|     float max_amp = 0, min_amp = 0, sig_power = 0, noise_pwr = 0;
 | |
|     uint32_t max_idx = 0, offset_num = 0;
 | |
| 
 | |
|     p_addr = (int16_t *)(mem_buf + st_offset << 2);
 | |
| 
 | |
|     /* print the pre-trig buf to the end */
 | |
|     while (i < ADA_TONE_CYCLE_NUM)
 | |
|     {
 | |
|         sample_data[i].real = *p_addr;
 | |
|         sample_data[i].imag = 0;
 | |
| 
 | |
|         p_addr++;
 | |
|         i++;
 | |
|     }
 | |
| 
 | |
|     fft(ADA_TONE_CYCLE_NUM, sample_data);
 | |
| 
 | |
|     i = 0;
 | |
|     while (i < ADA_TONE_CYCLE_NUM)
 | |
|     {
 | |
|         f_amp[i] = iot_sqrt( \
 | |
|             iot_pow((int32_t)sample_data[i].real, 2) + \
 | |
|             (iot_pow((int32_t)sample_data[i].imag, 2) ) << 1) / \
 | |
|             ADA_TONE_CYCLE_NUM;
 | |
|         /*not support float*/
 | |
|         i++;
 | |
|     }
 | |
| 
 | |
|     /* find max freq */
 | |
|     i = 0;
 | |
|     while (i < (ADA_TONE_CYCLE_NUM >> 1))
 | |
|     {
 | |
|         if (f_amp[i] > max_amp) {
 | |
|             max_amp = f_amp[i];
 | |
|             max_idx = i;
 | |
|         }
 | |
|         i++;
 | |
|     }
 | |
|     /* find min freq */
 | |
|     min_amp = f_amp[0];
 | |
|     i = 1;
 | |
|     while (i < (ADA_TONE_CYCLE_NUM >> 1))
 | |
|     {
 | |
|         if (f_amp[i] < min_amp) {
 | |
|             min_amp = f_amp[i];
 | |
|         }
 | |
|         i++;
 | |
|     }
 | |
| 
 | |
|     /* find signal,6dB = 1/2 AMP */
 | |
|     i = 1;
 | |
|     while ((f_amp[max_idx-i] << 1) > f_amp[max_idx])
 | |
|     {
 | |
|         if ((max_idx-i) < 0) {
 | |
|             break;
 | |
|         }
 | |
| 
 | |
|         offset_num++;
 | |
|         i++;
 | |
|     }
 | |
| 
 | |
|     ind_lowband = \
 | |
|         BW_LOW/ADA_SAMP_FREQ * ADA_TONE_CYCLE_NUM + 1;
 | |
|     ind_highband = \
 | |
|         (uint32_t)((float)BW_HIGH/ADA_SAMP_FREQ * ADA_TONE_CYCLE_NUM) + 1;
 | |
| #if ADA_DEBUG_LEVEL >= ADA_PRINT_DEBUG
 | |
|     iot_printf("band:%d-%d Point, offset:%d, ", \
 | |
|         ind_lowband,ind_highband,offset_num);
 | |
| #endif
 | |
| 
 | |
|     /* cal power */
 | |
|     i = ind_lowband;
 | |
|     while (i < ind_highband)
 | |
|     {
 | |
|         if (iot_pow(max_idx-i, 2) < iot_pow(offset_num+SNR_FREQ_NUM, 2)) {
 | |
|             sig_power = f_amp[i] * f_amp[i] + sig_power;
 | |
|         } else {
 | |
|             if (noise_pwr == 0) {
 | |
|                 noise_pwr = iot_pow(f_amp[i], 2);
 | |
|             } else {
 | |
|                 noise_pwr=(iot_pow(f_amp[i], 2) + noise_pwr) >> 1;
 | |
|             }
 | |
|         }
 | |
|         i++;
 | |
|     }
 | |
| 
 | |
|     /* noise power avg, first find the posedge */
 | |
|     #if 0
 | |
|     i = max_idx;
 | |
|     while (i < (ADA_TONE_CYCLE_NUM >> 1))
 | |
|     {
 | |
|         if (f_amp[i] < f_amp[i+1]) {
 | |
|             noise_pwr = pow(f_amp[i++], 2);
 | |
|             int num = (((ADA_TONE_CYCLE_NUM >> 1) - i) >> 1) + i;
 | |
|             while(i < num)
 | |
|             {
 | |
|                 noise_pwr=(pow(f_amp[i++], 2) + noise_pwr) >> 1;
 | |
|             }
 | |
|             break;
 | |
|         }
 | |
|         i++;
 | |
|     }
 | |
|     #endif
 | |
| 
 | |
|     /* SNR */
 | |
|     iot_printf("sig power=%d,noise power=%d,", \
 | |
|         (uint32_t)sig_power, (uint32_t)noise_pwr);
 | |
|     iot_printf("SNR=%d\r\n", \
 | |
|         (uint32_t)(10 * Log10(max_amp * max_amp/noise_pwr)));
 | |
| }
 | |
| #endif
 | |
| 
 | |
| void mac_rx_dump_init()
 | |
| {
 | |
|     uint32_t tmp = 0;
 | |
| 
 | |
|     /* fc ok only if long pkt */
 | |
|     tmp = RGF_RX_READ_REG(CFG_RX_TIMEOUT_1_ADDR);
 | |
|     REG_FIELD_SET(CFG_RX_PB_TIMEOUT, tmp, 2000000);
 | |
|     RGF_RX_WRITE_REG(CFG_RX_TIMEOUT_1_ADDR, tmp);
 | |
| }
 | |
| 
 | |
| /* ADA adc data dump */
 | |
| int ada_auto_dump_test(uint32_t b_size, uint32_t s_size)
 | |
| {
 | |
|     uint32_t ret = ERR_FAIL;
 | |
|     uint32_t trig_offset = 0;
 | |
| #if ADC_DUMP_FROM_DDR_EN
 | |
|     uint8_t *adc_buf = (uint8_t *)ADC_DUMP_DDR_ADDR;
 | |
| #else
 | |
|     uint8_t *adc_buf = (uint8_t *)ADC_DUMP_RAM_ADDR;
 | |
| #endif
 | |
| 
 | |
| #if IOT_DTEST_ONLY_SUPPORT == 1
 | |
|     /* reset mac */
 | |
|     mac_reset(MAC_RST_REASON_COLD);
 | |
|     /* reset phy */
 | |
|     phy_reset(PHY_RST_REASON_COLD);
 | |
|     /* reset mac */
 | |
|     mac_reset(MAC_RST_REASON_COLD);
 | |
| 
 | |
|     /* basic data struct init for bit ops */
 | |
|     iot_bitops_init();
 | |
| 
 | |
|     /* init gain table */
 | |
|     phy_init(PLC_PROTO_TYPE_SG, \
 | |
|         IOT_PLC_PHY_BAND_DFT, TONE_MASK_ID_NULL, true);
 | |
| 
 | |
|     /* special config */
 | |
|     mac_rx_dump_init();
 | |
| #endif
 | |
| 
 | |
|     /* only for loopback dump */
 | |
| #if ADA_DUMP_WITH_TX_TONE_EN == 1
 | |
|     cur_tone_id = ADA_TONE_ID;
 | |
| #else
 | |
|     cur_tone_id = 0;
 | |
| #endif
 | |
| 
 | |
|     /* fix gain and disable agc */
 | |
|     phy_agc_gain_lvl_set(1, 0, -24, 0);
 | |
|     ret = phy_dump_from_ada(b_size, \
 | |
|         s_size, \
 | |
|         cur_tone_id, \
 | |
|         ADC_DUMP_MODE_SUPPORT, \
 | |
|         PHY_PHASE_OVR_A, \
 | |
|         &trig_offset, \
 | |
|         adc_buf, \
 | |
|         ADC_DUMP_SPEED_SUPPORT, \
 | |
|         NULL);
 | |
| 
 | |
|     if (ret == ERR_OK) {
 | |
| #if ADC_DUMP_MEM_FROM_MTX == 1
 | |
|         if (b_size == s_size) {
 | |
|             /* force dump from 0xfd0000 within 48K word */
 | |
|             dumpMem(adc_buf, trig_offset, b_size);
 | |
|         } else {
 | |
| #if ADA_DUMP_FULL_IRAM_SUPPORT == 1
 | |
|             /* dump all from fc8000 */
 | |
|             dumpMem(adc_buf - 0x8000, 0, b_size);
 | |
| #else
 | |
|             /* dump from 0xfd0000 with 32K */
 | |
|             dumpMem(adc_buf, 0, b_size);
 | |
| #endif
 | |
|         }
 | |
| #else
 | |
|         int32_t start_offset = trig_offset - (b_size - s_size);
 | |
|         if ( start_offset >= 0) {
 | |
|             /* do nothing */
 | |
|         } else {
 | |
|             start_offset = trig_offset + s_size;
 | |
|             start_offset += 1; /* add some of offset */
 | |
|         }
 | |
| 
 | |
|         dumpMem(adc_buf, start_offset, b_size);
 | |
| #endif
 | |
|     }
 | |
| 
 | |
|     return ret;
 | |
| }
 | |
| 
 | |
| /* ADA tone VPP cal */
 | |
| int ada_auto_vpp_test(int argc, char **argv)
 | |
| {
 | |
|     uint32_t trig_offset;
 | |
|     uint8_t *adc_buf = (uint8_t *)ADC_DUMP_DST_ADDR;
 | |
|     uint32_t buf_size = 0, sample_size = 0;
 | |
| 
 | |
|     iot_printf("%s",ada_cases_tb[ADA_TEST_VPP].name);
 | |
| 
 | |
|     cur_tone_id = TONE_ID_CAL(15);
 | |
| 
 | |
|     /* get dump size */
 | |
|     phy_dump_size_cal(&buf_size, &sample_size);
 | |
| 
 | |
|     ada_common_init(cur_tone_id, buf_size, sample_size);
 | |
|     phy_adc_en_cfg(true);
 | |
| 
 | |
|     /* adc trigger */
 | |
|     phy_adc_trig_en_cfg(true);
 | |
| 
 | |
|     while(1) {
 | |
|         /* sample done */
 | |
|         if (phy_adc_is_sample_done()) {
 | |
|             trig_offset = phy_adc_trig_addr_get();
 | |
|             break;
 | |
|         }
 | |
|     }
 | |
|     phy_adc_en_cfg(false);
 | |
| 
 | |
| #if ADA_DEBUG_LEVEL >= ADA_PRINT_DEBUG
 | |
|     /* dump adc buffer */
 | |
|     iot_printf("trigger address:%d\n", trig_offset);
 | |
| #endif
 | |
| 
 | |
|     adc_cal_vpp(adc_buf, trig_offset);
 | |
| 
 | |
|     iot_printf("%s\r\n", TEST_END_SPLIT_STR);
 | |
| 
 | |
|     return 0;
 | |
| }
 | |
| 
 | |
| /* ADC SNR/SNDR */
 | |
| int ada_auto_snr_test(int argc, char **argv)
 | |
| {
 | |
|     uint32_t trig_offset;
 | |
|     uint32_t buf_size = 0, sample_size = 0;
 | |
| 
 | |
|     iot_printf("%s",ada_cases_tb[ADA_TEST_SNR].name);
 | |
| 
 | |
|     cur_tone_id = ADA_TONE_ID;
 | |
| 
 | |
|     /* get dump size */
 | |
|     phy_dump_size_cal(&buf_size, &sample_size);
 | |
| 
 | |
|     ada_common_init(cur_tone_id, buf_size, sample_size);
 | |
|     phy_adc_en_cfg(true);
 | |
| 
 | |
|     /* adc trigger */
 | |
|     phy_adc_trig_en_cfg(true);
 | |
| 
 | |
|     while(1) {
 | |
|         /* sample done */
 | |
|         if(phy_adc_is_sample_done()) {
 | |
|             trig_offset = phy_adc_trig_addr_get();
 | |
|             break;
 | |
|         }
 | |
|     }
 | |
|     phy_adc_en_cfg(false);
 | |
| 
 | |
| #if ADA_DEBUG_LEVEL >= ADA_PRINT_DEBUG
 | |
|     /* dump adc buffer */
 | |
|     iot_printf("trigger address:%d\n", trig_offset);
 | |
| #endif
 | |
| 
 | |
| #if ADA_DTEST_SNR_SUPPORT
 | |
|     uint8_t *adc_buf = (uint8_t *)ADC_DUMP_DST_ADDR;
 | |
|     adc_cal_snr(adc_buf, trig_offset);
 | |
| #endif
 | |
|     (void)trig_offset;
 | |
| 
 | |
|     iot_printf("%s\r\n", TEST_END_SPLIT_STR);
 | |
| 
 | |
|     return 0;
 | |
| }
 | |
| 
 | |
| int ada_auto_fa_test(int argc, char **argv)
 | |
| {
 | |
|     uint32_t i = 0, tmp = 0;
 | |
|     uint32_t tone_num = 0, trig_offset = 0;
 | |
|     uint8_t *adc_buf = (uint8_t *)ADC_DUMP_DST_ADDR;
 | |
|     uint32_t buf_size = 0, sample_size = 0;
 | |
| 
 | |
|     iot_printf("%s",ada_cases_tb[ADA_TEST_FA].name);
 | |
| 
 | |
|     /* get dump size */
 | |
|     phy_dump_size_cal(&buf_size, &sample_size);
 | |
| 
 | |
|     ada_common_init(cur_tone_id, buf_size, sample_size);
 | |
|     phy_adc_mode_cfg(ADC_MODE_FORCE);
 | |
| 
 | |
|     iot_printf("[ada][1~30 MHz]:\n");
 | |
|     for (i = 1; i < 31; i++)
 | |
|     {
 | |
|         tone_num = TONE_ID_CAL(i);
 | |
|         cur_tone_id = tone_num;
 | |
| 
 | |
|         tmp = PHY_DFE_READ_REG(CFG_BB_TX_TONE_0_CFG_ADDR);
 | |
|         REG_FIELD_SET(SW_TONE_CFG_EN,tmp,1);
 | |
|         REG_FIELD_SET(SW_TONE_0_CFG_NUM,tmp,tone_num);
 | |
|         PHY_DFE_WRITE_REG(CFG_BB_TX_TONE_0_CFG_ADDR,tmp);
 | |
| 
 | |
|         /* wait dly */
 | |
|         phy_busy_wait(0x20000);
 | |
| 
 | |
|         /* adc trigger */
 | |
|         phy_adc_trig_en_cfg(true);
 | |
|         phy_adc_en_cfg(true);
 | |
|         while (1) {
 | |
|             /* sample done */
 | |
|             if (phy_adc_is_sample_done()) {
 | |
|                 trig_offset = phy_adc_trig_addr_get();
 | |
|                 break;
 | |
|             }
 | |
|         }
 | |
|         phy_adc_en_cfg(false);
 | |
|         phy_adc_trig_en_cfg(false);
 | |
| 
 | |
|         adc_cal_vpp(adc_buf,trig_offset);
 | |
| #if ADA_DTEST_SNR_SUPPORT
 | |
|         adc_cal_snr(adc_buf,trig_offset);
 | |
| #endif
 | |
| 
 | |
|         if (i == -1) {
 | |
|             int16_t *p_addr = (int16_t *)(adc_buf + (trig_offset << 2));
 | |
|             uint32_t j = 0;
 | |
|             while (j < ADA_TONE_CYCLE_NUM)
 | |
|             {
 | |
| #if DATA_INV_EN
 | |
|                 iot_printf("%06d\n", *(p_addr + 1));
 | |
|                 iot_printf("%06d\n", *p_addr);
 | |
| #else
 | |
|                 iot_printf("%06d\n", *p_addr);
 | |
|                 iot_printf("%06d\n", *(p_addr + 1));
 | |
| #endif
 | |
|                 j += 2;
 | |
|                 p_addr += 2;
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     iot_printf("%s\r\n", TEST_END_SPLIT_STR);
 | |
| 
 | |
|     return 0;
 | |
| }
 | |
| 
 | |
| /*
 | |
|  *  Must config PLL out 180M and use GREE High band
 | |
|  *      for generating 30M tone.
 | |
| */
 | |
| void ada_tone_gen()
 | |
| {
 | |
|     uint32_t tmp = 0;
 | |
| 
 | |
|     /* reset mac */
 | |
|     mac_reset(MAC_RST_REASON_COLD);
 | |
|     /* reset phy */
 | |
|     phy_reset(PHY_RST_REASON_COLD);
 | |
|     /* reset mac */
 | |
|     mac_reset(MAC_RST_REASON_COLD);
 | |
| 
 | |
|     /* basic data struct init for bit ops */
 | |
|     iot_bitops_init();
 | |
| 
 | |
|     /* init gain table */
 | |
|     phy_init(PLC_PROTO_TYPE_SG, \
 | |
|         IOT_PLC_PHY_BAND_DFT, TONE_MASK_ID_NULL, true);
 | |
| 
 | |
|     /* force A phase */
 | |
|     tmp = RGF_MAC_READ_REG(CFG_PHY_FORCE_1_ADDR);
 | |
|     REG_FIELD_SET(CFG_PHY_TX_ENABLE, tmp, 1);
 | |
|     REG_FIELD_SET(CFG_PHY_TX_ENABLE_FORCE_EN, tmp, 1);
 | |
|     RGF_MAC_WRITE_REG(CFG_PHY_FORCE_1_ADDR, tmp);
 | |
| 
 | |
|     tmp = RGF_MAC_READ_REG(CFG_PHY_FORCE_2_ADDR);
 | |
|     REG_FIELD_SET(CFG_PHY_TX_PHASE_SEL, tmp, 1);
 | |
|     REG_FIELD_SET(CFG_PHY_TX_PHASE_SEL_FORCE_EN, tmp, 1);
 | |
|     RGF_MAC_WRITE_REG(CFG_PHY_FORCE_2_ADDR, tmp);
 | |
| 
 | |
|     /* en analog tx */
 | |
|     uint8_t reg_id = ANA_GRANITE_TOP_REG;
 | |
|     uint32_t wdata = TOP_EN_TX_MASK | TOP_EN_DAC_MASK | \
 | |
|             (2 << TOP_ENLIC_OFFSET);
 | |
|     uint32_t wmask = TOP_EN_TX_MASK | TOP_EN_DAC_MASK | \
 | |
|             TOP_ENLIC_MASK;
 | |
|     phy_ana_i2c_write(reg_id, wdata, wmask);
 | |
| 
 | |
|     /* att */
 | |
|     phy_dfe_tone_att_cfg(0, 0, 0);
 | |
| 
 | |
|     /* 40M tone */
 | |
|     phy_dfe_tone_cfg(1, 450, 0);
 | |
| 
 | |
|     while(1);
 | |
| }
 | |
| 
 | |
| /* ADA adc flash dump */
 | |
| int ada_flash_dump_test(uint32_t b_size, uint32_t s_size)
 | |
| {
 | |
|     int16_t gain = 0;
 | |
|     uint32_t trig_offset = 0;
 | |
|     uint64_t time_span = 0;
 | |
|     uint32_t start_time = 0, end_time = 0;
 | |
|     uint8_t dump_rty_cnt = 0;
 | |
| #if ADC_DUMP_FROM_DDR_EN
 | |
|     uint8_t *adc_buf = (uint8_t *)ADC_DUMP_DDR_ADDR;
 | |
| #else
 | |
|     uint8_t *adc_buf = (uint8_t *)ADC_DUMP_RAM_ADDR;
 | |
| #endif
 | |
|     uint32_t g_flash_pos = 0;
 | |
|     uint32_t ret = ERR_FAIL;
 | |
|     static bool_t flash_first_flag = true;
 | |
| 
 | |
|     /* check param */
 | |
|     IOT_ASSERT(b_size == s_size);
 | |
| 
 | |
|     /* flash init*/
 | |
|     flash_init(1);
 | |
| 
 | |
|     /* set buf size */
 | |
|     b_size = 32*K;
 | |
|     s_size = b_size;
 | |
| 
 | |
|     /* read flash and print*/
 | |
|     flash_read(adc_buf, ADC_DUMP_FLASH_START + g_flash_pos, 0x10,  0);
 | |
|     if (*adc_buf == ADC_DUMP_FLASH_MG0 && \
 | |
|         *(adc_buf + 1) == ADC_DUMP_FLASH_MG1 && \
 | |
|         *(adc_buf + 2) == ADC_DUMP_FLASH_MG2 && \
 | |
|         *(adc_buf + 3) == ADC_DUMP_FLASH_MG3) {
 | |
|         for(uint32_t buf_cnt = 0; \
 | |
|             buf_cnt < (ADC_DUMP_FLASH_END - ADC_DUMP_FLASH_START)/(b_size << 2); \
 | |
|             buf_cnt++)
 | |
|         {
 | |
|             flash_read(adc_buf, ADC_DUMP_FLASH_START + g_flash_pos, b_size << 2,  0);
 | |
|             g_flash_pos += b_size << 2;
 | |
|             dumpMem(adc_buf, 0, b_size);
 | |
|         }
 | |
| 
 | |
|         /* led on */
 | |
|         phy_led_set(32, false);
 | |
|         phy_led_set(33, false);
 | |
|         return 0;
 | |
|     }
 | |
| 
 | |
| #if IOT_DTEST_ONLY_SUPPORT == 1
 | |
|     /* reset mac */
 | |
|     mac_reset(MAC_RST_REASON_COLD);
 | |
|     /* reset phy */
 | |
|     phy_reset(PHY_RST_REASON_COLD);
 | |
|     /* reset mac */
 | |
|     mac_reset(MAC_RST_REASON_COLD);
 | |
| 
 | |
|     /* basic data struct init for bit ops */
 | |
|     iot_bitops_init();
 | |
| 
 | |
|     /* init gain table */
 | |
|     phy_init(PLC_PROTO_TYPE_SG, IOT_PLC_PHY_BAND_DFT, TONE_MASK_ID_NULL, true);
 | |
| #endif
 | |
| 
 | |
| #if ADA_DUMP_NF_WITH_CSI_BUF_DUMP == 1
 | |
|     /* tone id 0 for trig fft */
 | |
|     cur_tone_id = 0;
 | |
| #else
 | |
|     cur_tone_id = ADA_TONE_ID;
 | |
| #endif
 | |
| 
 | |
| #if 1
 | |
|     /* get current gain */
 | |
|     gain = phy_gain_get_from_agc();
 | |
| #else
 | |
|     gain = 50;
 | |
| #endif
 | |
|     /* fix gain and disable agc */
 | |
|     phy_agc_gain_lvl_set(1, gain, -24, 0);
 | |
|     iot_printf("current gain: %u\n", gain);
 | |
| 
 | |
|     /* prepare flash param */
 | |
|     flash_write_param_t param = {0};
 | |
|     param.read_mode = MOD_SFC_READ_QUAD_IO_FAST;
 | |
|     param.write_mode = MOD_SFC_PROG_QUAD;
 | |
|     param.is_erase = 1;
 | |
| 
 | |
|     start_time = RGF_MAC_READ_REG(CFG_RD_NTB_ADDR);
 | |
|     dump_rty_cnt = (ADC_DUMP_FLASH_END - ADC_DUMP_FLASH_START)/(b_size << 2);
 | |
|     while (dump_rty_cnt--)
 | |
|     {
 | |
|         do {
 | |
|             end_time = RGF_MAC_READ_REG(CFG_RD_NTB_ADDR);
 | |
|             time_span = end_time - start_time;
 | |
|             if (time_span < 0) { // wrap around
 | |
|                 time_span = (0x100000000LL) - start_time + end_time;
 | |
|             }
 | |
|             if ((uint64_t)time_span > 10000*TICKS_MS) {
 | |
|                 break;
 | |
|             }
 | |
|         } while(1);
 | |
|         start_time = end_time;
 | |
| 
 | |
|         ret = phy_dump_from_ada(b_size, \
 | |
|             s_size, \
 | |
|             cur_tone_id, \
 | |
|             ADC_DUMP_MODE_FORCE, \
 | |
|             PHY_PHASE_OVR_A, \
 | |
|             &trig_offset, \
 | |
|             adc_buf, \
 | |
|             ADC_DUMP_SPEED_SUPPORT, \
 | |
|             NULL);
 | |
| 
 | |
|         if (ret == ERR_OK) {
 | |
|             if (flash_first_flag) {
 | |
|                 /* done flag */
 | |
|                 *adc_buf = ADC_DUMP_FLASH_MG0;
 | |
|                 *(adc_buf + 1) = ADC_DUMP_FLASH_MG1;
 | |
|                 *(adc_buf + 2) = ADC_DUMP_FLASH_MG2;
 | |
|                 *(adc_buf + 3) = ADC_DUMP_FLASH_MG3;
 | |
|                 /* clear first flag */
 | |
|                 flash_first_flag = 0;
 | |
|             }
 | |
|             /* current gain */
 | |
|             *(adc_buf + 4) = gain;
 | |
|         }
 | |
| 
 | |
|         /* write flash */
 | |
|         flash_write(adc_buf, ADC_DUMP_FLASH_START + g_flash_pos, b_size << 2, ¶m);
 | |
|         g_flash_pos += b_size << 2;
 | |
|         iot_printf("size %u write flash done!\n", b_size << 2);
 | |
|     }
 | |
| 
 | |
|     /* led on */
 | |
|     phy_led_set(32, false);
 | |
|     phy_led_set(33, false);
 | |
|     return 0;
 | |
| }
 | |
| 
 | |
| void fft_dump_flash_test()
 | |
| {
 | |
|     uint8_t dump_rty_cnt = 0;
 | |
|     uint64_t time_span = 0;
 | |
|     uint32_t start_time = 0, end_time = 0;
 | |
|     uint32_t *csi_buf = NULL;
 | |
|     uint16_t tone_idx = 0;
 | |
|     int16_t csi_i = 0, csi_q = 0;
 | |
|     static bool_t fft_first_flag = true;
 | |
|     uint8_t *fft_buf = (uint8_t *)ADC_DUMP_DST_ADDR;
 | |
|     uint32_t g_flash_pos = 0;
 | |
| 
 | |
|     /* flash init*/
 | |
|     flash_init(1);
 | |
| 
 | |
|     /* read flash and print*/
 | |
|     flash_read(fft_buf, ADC_DUMP_FLASH_START + g_flash_pos, 0x10,  0);
 | |
|     if (*fft_buf == ADC_DUMP_FLASH_MG0 && \
 | |
|         *(fft_buf + 1) == ADC_DUMP_FLASH_MG1 && \
 | |
|         *(fft_buf + 2) == ADC_DUMP_FLASH_MG2 && \
 | |
|         *(fft_buf + 3) == ADC_DUMP_FLASH_MG3) {
 | |
|         for (uint32_t buf_cnt = 0; \
 | |
|             buf_cnt < (ADC_DUMP_FLASH_END - ADC_DUMP_FLASH_START)/(6 * K); buf_cnt++)
 | |
|         {
 | |
|             flash_read(fft_buf, ADC_DUMP_FLASH_START + g_flash_pos, 6 * K,  0);
 | |
|             g_flash_pos += 6 * K;
 | |
|             csi_buf = (uint32_t *)fft_buf;
 | |
|             for (tone_idx = 0; tone_idx < TOTAL_TONE_MASK_NUM; tone_idx++ )
 | |
|             {
 | |
|                 csi_i = (int16_t)(*(csi_buf + tone_idx) & 0xFFFF);
 | |
|                 csi_q = (int16_t)(*(csi_buf + tone_idx) >> 16);
 | |
|                 iot_printf("%u %d %d\n", tone_idx, csi_i, csi_q);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         /* led on */
 | |
|         phy_led_set(32, false);
 | |
|         phy_led_set(33, false);
 | |
|         return;
 | |
|     }
 | |
| 
 | |
| #if IOT_DTEST_ONLY_SUPPORT == 1
 | |
|     /* reset mac */
 | |
|     mac_reset(MAC_RST_REASON_COLD);
 | |
|     /* reset phy */
 | |
|     phy_reset(PHY_RST_REASON_COLD);
 | |
|     /* reset mac */
 | |
|     mac_reset(MAC_RST_REASON_COLD);
 | |
| 
 | |
|     /* basic data struct init for bit ops */
 | |
|     iot_bitops_init();
 | |
| 
 | |
|     /* init gain table */
 | |
|     phy_init(PLC_PROTO_TYPE_SG, IOT_PLC_PHY_BAND_DFT, TONE_MASK_ID_NULL, true);
 | |
| #endif
 | |
| 
 | |
| #if ADA_DUMP_NF_WITH_CSI_BUF_DUMP == 1
 | |
|     /* tone id 0 for trig fft */
 | |
|     cur_tone_id = 0;
 | |
| #else
 | |
|     cur_tone_id = ADA_TONE_ID;
 | |
| #endif
 | |
| 
 | |
|     /* delay 10s */
 | |
|     start_time = RGF_MAC_READ_REG(CFG_RD_NTB_ADDR);
 | |
|     do {
 | |
|         end_time = RGF_MAC_READ_REG(CFG_RD_NTB_ADDR);
 | |
|         time_span = end_time - start_time;
 | |
|         if (time_span < 0) { // wrap around
 | |
|             time_span = (0x100000000LL) - start_time + end_time;
 | |
|         }
 | |
|         if ((uint64_t)time_span > 10000*TICKS_MS) {
 | |
|             break;
 | |
|         }
 | |
|     } while(1);
 | |
| 
 | |
|     /* prepare para */
 | |
|     flash_write_param_t param = {0};
 | |
|     param.read_mode = MOD_SFC_READ_QUAD_IO_FAST;
 | |
|     param.write_mode = MOD_SFC_PROG_QUAD;
 | |
|     param.is_erase = 1;
 | |
|     param.sw_mode = MOD_SW_MODE_DIS;
 | |
|     dump_rty_cnt = (ADC_DUMP_FLASH_END - ADC_DUMP_FLASH_START)/(6 * K);
 | |
|     while (dump_rty_cnt--)
 | |
|     {
 | |
|         csi_buf = (uint32_t *)fft_buf;
 | |
|         phy_fft_flash_dump(csi_buf);
 | |
|         if (fft_first_flag) {
 | |
|             /* done flag */
 | |
|             *fft_buf = ADC_DUMP_FLASH_MG0;
 | |
|             *(fft_buf + 1) = ADC_DUMP_FLASH_MG1;
 | |
|             *(fft_buf + 2) = ADC_DUMP_FLASH_MG2;
 | |
|             *(fft_buf + 3) = ADC_DUMP_FLASH_MG3;
 | |
|             /* clear first flag */
 | |
|             fft_first_flag = 0;
 | |
|         }
 | |
| 
 | |
|         flash_write(fft_buf, ADC_DUMP_FLASH_START + g_flash_pos, 6 * K, ¶m);
 | |
|         g_flash_pos += 6 * K;
 | |
| #if PHY_DBG_EN
 | |
|         for (tone_idx = 0; tone_idx < TOTAL_TONE_MASK_NUM; tone_idx++ )
 | |
|         {
 | |
|             csi_i = (int16_t)(*(csi_buf + tone_idx) & 0xFFFF);
 | |
|             csi_q = (int16_t)(*(csi_buf + tone_idx) >> 16);
 | |
|             iot_printf("tone_id:%u, csi_i:%d, csi_q:%d\n", tone_idx, csi_i, csi_q);
 | |
|         }
 | |
| #endif
 | |
|     }
 | |
| 
 | |
|     /* led on */
 | |
|     phy_led_set(32, false);
 | |
|     phy_led_set(33, false);
 | |
| }
 | |
| 
 | |
| #ifdef __GNUC__
 | |
| #if !MODULE_EN
 | |
| int main(int argc, char **argv)
 | |
| {
 | |
|     /* hw platform parameters init */
 | |
|     dtest_platform_ada_pre_init();
 | |
| 
 | |
| #if HW_PLATFORM > HW_PLATFORM_SIMU
 | |
| #if EDA_SIMU_SUPPORT != 1
 | |
|     iot_print_config(true);
 | |
|     dbg_uart_init();
 | |
| #endif
 | |
| #endif
 | |
| 
 | |
|     /* ada soft reset */
 | |
|     warm_rst_ada();
 | |
| 
 | |
|     /* get dump size */
 | |
|     uint32_t buf_size = 0, sample_size = 0;
 | |
|     phy_dump_size_cal(&buf_size, &sample_size);
 | |
| 
 | |
|     /* trig dump from phy */
 | |
|     ada_auto_dump_test(buf_size,sample_size);
 | |
| 
 | |
|     while(1);//run away
 | |
| 
 | |
|     return 0;
 | |
| }
 | |
| #endif
 | |
| #endif // __GCC__
 | |
| 
 |