⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ics_test.c

📁 软件无线电的平台
💻 C
字号:
/***************************************************************************             ics_test.c  -  ICS-5x4 tester                            -------------------    begin                :  2003    authors              :  Linus Gasser    emails               :  linus.gasser@epfl.ch***************************************************************************//***************************************************************************                                 Changes                                 ------- date - name - description 03-12-01 - ineiti - create **************************************************************************//*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************/#define DBG_LVL 4#include <math.h>#include "system.h"#include "debugging.h"#include "memory.h"#include "sdb.h"#include "antenna.h"#include "ics_dev.h"#include "ics_helper.h"#include "ics_554.h"#include "ics_564.h"#include "antenna.h"int test_loop; #define CHANNELS 4#define RX_INDEX(ch,i) ( (ch) % 2 ) * CHANNELS * 2 + \                        (i) * 2 + ( ( (i) / CHANNELS ) * CHANNELS * 2 )/** * Initialises the channels, allocates memory for the dma-blocks and * prepares for sending */int init_channels( int nbr_ch, int bpf, swr_ant_param_t *params,		    s32 *data_rx[], s32 *data_tx[], int init_tx ){  int ch;  board_tx.blocks_per_frame = bpf;  board_rx.blocks_per_frame = bpf;  // Initialise all channels  for ( ch=0; ch<nbr_ch; ch++ ){    // Do we get the channels in a strange order?    if ( swr_ant_ch_init( params + ch ) != ch ){      PR_DBG( 0, "Couldn't get antenna in order!\n" );      return -1;    }    if ( ch % 2 == 0 ){      // Only initialise one data_rx for two channels      data_rx[ ch / 2 ] = swr_malloc( board_rx.block_size * bpf *				      sizeof( u64 ) );    }    // For the TX, we initialise one data_tx per channel    data_tx[ ch ] = swr_malloc( board_tx.block_size * bpf *				sizeof( u32 ) );    // We could be out of memory    if ( !data_rx[ ch / 2 ] || !data_tx[ ch ] ){      PR_DBG( 0, "Couldn't get %ikB of memory.\n",	      board_rx.block_size * bpf * sizeof( u64 ) / 1024 );      for ( ; ch>= 0; ch-- ){	if ( ch % 2 == 0 ){	  swr_free( data_rx[ ch / 2 ] );	}	swr_free( data_tx[ ch ] );      }      return -1;    }    params[ ch ].addr_rx = data_rx[ ch / 2 ];    params[ ch ].addr_tx = data_tx[ ch ];    params[ ch ].frame_blocks = bpf;        swr_ant_ch_reconfig( ch );    init_dma_s32_buffer( &board_tx, ch, init_tx );  }  return 0;}void *ics_test_2x2( void *v ){  int i, ch, t, nbr_ch = 2,    bpf = 3;  int dft_len=9;  swr_ant_param_t params[ nbr_ch ];  s32 *data_rx[ nbr_ch / 2 ];  s32 *data_tx[ nbr_ch ];  board_tx.flags |= ICS564_STARTED;  board_tx.blocks_per_frame = bpf;  board_rx.flags |= ICS554_STARTED | ICS554_TEST;  if ( init_channels( nbr_ch, bpf, params, data_rx, data_tx, 0 ) < 0 ){    PR_DBG( 0, "Error while initialising channels\n" );    return NULL;  }  // OK, let's start  swr_ant_ch_start( );  t = 0;  pthread_make_periodic_np( pthread_self(), gethrtime(), 1000*1000*500 );  while ( test_loop ){    pthread_wait_np();    PR_DBG( 0, "Still looping: %6i blocks and %i seconds\n",	    board_rx.block_count, t++ );#if 1    for ( ch=0; ch<nbr_ch; ch++ ){      PR_DBG( 0, "------------- Channel %i:\n", ch );#if 0      for ( i=0; i<16; i++ ){	int index = RX_INDEX( ch, count );	//( ch % 2 ) * 8 +	//i * 2 + ( ( i / 4 ) * 8 );	PR_DBG( 0, "Data_Rx[%x] = %5i + i*%5i\n", i,		data_rx[ch/2][ index ] >> 8, 		data_rx[ch/2][ index ] >> 8 );	rtl_udelay( 50 );      }      rtl_udelay( 1000 );#endif#if 1      {	int count;	int d[dft_len * 2];	for( count = 0; count < dft_len; count++){	  int index = RX_INDEX( ch, count );	  d[2*count] = data_rx[ch/2][ index ];	  d[2*count+1] = data_rx[ch/2][ index + 1 ];	}	show_dft( d, dft_len, 0 );      }#endif    }#endif  }  PR_DBG( 1, "Stopping the antennas\n" );  swr_ant_ch_stop();  PR_DBG( 1, "Freeing the memory\n" );  for ( i=0; i<nbr_ch; i++ ){    if ( i % 2 == 0 ){      swr_free( data_rx[ i / 2 ] );    }    swr_free( data_tx[ i ] );  }  return NULL;}void *ics_test_2x2_count( void *v ){  int i, t, nbr_ch = 2,    bpf = 1;  swr_ant_param_t params[ nbr_ch ];  s32 *data_rx[ nbr_ch / 2 ];  s32 *data_tx[ nbr_ch ];  board_tx.flags |= ICS564_STARTED;  board_tx.blocks_per_frame = bpf;  board_rx.flags |= ICS554_STARTED | ICS554_TEST;  if ( init_channels( nbr_ch, bpf, params, data_rx, data_tx, 0 ) < 0 ){    PR_DBG( 0, "Error while initialising channels\n" );    return NULL;  }  // OK, let's start  swr_ant_ch_start( );  t = 0;  pthread_make_periodic_np( pthread_self(), gethrtime(), 1000*1000*1000 );  while ( test_loop ){    u64 rx = board_rx.block_count,      tx = board_tx.block_count,      w, f;    pthread_wait_np();    tx = max( 1ULL, tx );    w = rx / tx;    f = ( rx * 1000000ULL / tx ) % 1000000ULL;    PR_DBG( 0, "%8llirx / %8llitx = %6lli.%-6lli, diff=%6lli\n",	    rx, tx, w, f, tx / 2 - rx );  }  PR_DBG( 1, "Stopping the antennas\n" );  swr_ant_ch_stop();  PR_DBG( 1, "Freeing the memory\n" );  for ( i=0; i<nbr_ch; i++ ){    if ( i % 2 == 0 ){      swr_free( data_rx[ i / 2 ] );    }    swr_free( data_tx[ i ] );  }  return NULL;}void *ics_test_synch( void *v ){  int i, t, nbr_ch = 4,    ch, bpf = 5;  swr_ant_param_t params[ nbr_ch ];  s32 *data_rx[ nbr_ch / 2 ];  s32 *data_tx[ nbr_ch ];  board_tx.flags |= ICS564_STARTED;  board_rx.flags |= ICS554_STARTED | ICS554_TEST;  if ( init_channels( nbr_ch, bpf, params, data_rx, data_tx, 6 ) < 0 ){    PR_DBG( 0, "Error while initialising channels\n" );    return NULL;  }  // OK, let's start  swr_ant_ch_start( );/*   usleep( 1000000 ); */  /*   swr_ant_ch_stop(); *//*   return NULL; */  t = 0;  pthread_make_periodic_np( pthread_self(), gethrtime(), 1000*1000*1000 );  while ( test_loop ){    pthread_wait_np();    PR_DBG( 0, "Still looping: %6i blocks and %i seconds\n",	    board_rx.block_count, t++ );    // Search for the peak-position in each block    for ( ch=0; ch<nbr_ch; ch++ ){      int peak_amp = 0, peak_pos = 0, surr = 10;      for ( i=0; i<board_rx.block_size / 2; i++ ){	s32 *d = data_rx[ch/2] + RX_INDEX( ch, i );	int re = d[0] >> 8, im = d[1] >> 8, v = abs(re) + abs(im);	if ( v > peak_amp ){	  peak_amp = v;	  peak_pos = i;	}      }      PR_DBG( 0, "Channel %i: Peak position @ %i with amplitude %i\n",	      ch, peak_pos, peak_amp );#if 1      if ( peak_pos > surr ){	int c;	peak_pos -= 2;	for ( c = peak_pos - surr; c <= peak_pos + surr; c++ ){	  s32 *d = data_rx[ch/2] + RX_INDEX( ch, c );	  s32 re = d[0] >> 8, im = d[1] >> 8, v = hypot( re, im );	  PR_DBG( 0, "    Data[%6i] = %8i + %8ii = | %8i |\n",		  c, re, im, v );	  rtl_udelay( 50 );	}      }#endif	        rtl_udelay( 1000 );    }  }  PR_DBG( 1, "Stopping the antennas\n" );  swr_ant_ch_stop();  PR_DBG( 1, "Freeing the memory\n" );  for ( i=0; i<nbr_ch; i++ ){    if ( i % 2 == 0 ){      swr_free( data_rx[ i / 2 ] );    }    swr_free( data_tx[ i ] );  }  return NULL;}struct thread test;void ics_test_start( void ){  test_loop = 1;  switch( 1 ){  case 0:    swr_thread_init( &test, ics_test_2x2, NULL );    break;  case 1:    swr_thread_init( &test, ics_test_2x2_count, NULL );    break;  case 2:    swr_thread_init( &test, ics_test_synch, NULL );    break;  }}void ics_test_stop( void ){  test_loop = 0;  swr_thread_free( &test, NULL );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -