radio_ics_local.c

来自「This a framework to test new ideas in tr」· C语言 代码 · 共 279 行

C
279
字号
/***************************************************************************                     radio_ics_local.c - for a local-loop                            -------------------    begin                :  02/10/30    authors              :  Linus Gasser    emails               :  linus.gasser@epfl.ch ***************************************************************************//***************************************************************************                                 Changes                                 ------- date - name - description 02/10/30 - ineiti - begin 02/11/04 - ineiti - no msgqs... 03/02/27 - ineiti - simplified to only two slots: BCH and RACH 03/03/19 - ineiti - added SCH and gain-control 04/03/01 - ineiti - adjusted calc_taps and align from mafi  **************************************************************************//*************************************************************************** *                                                                         * *   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.                                   * *                                                                         * ***************************************************************************//** * Make a simple local-loop * * On each antenna, one slot is transmitted. */#include "system.h"#include "sdb.h"#include "stfa.h"#include "antenna.h"#include "std.h"#include "debugging.h"#include "radio_ics_local.h"#include "chain.h"#define DBG_LVL 4#define TARGET_MOBILE_HERE 1000*1000#define DATA_LEN 4096    SYMBOL_COMPLEX d[DATA_LEN] = {      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {16000, 0},      {0, 16000},      {-16000, 0},      {0, -16000},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {16000, 0},      {0, 16000},      {-16000, 0},      {0, -16000},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {32000, 0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0, 32000},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {-32000, 0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},      {0, -32000},    };swr_sdb_id stfa[ANTENNAS], sch, mafi, slicer;struct chain_t *ch_bch, *ch_rach, *ch_supp[ANTENNAS], *ch_down[ANTENNAS];struct bch_struct bch_data;double gain;int looping, delay;/** * Once a frame this function is called. Do here whatever seems accurate... */int do_send_down( int msg, void *data, swr_sdb_id ret_id ) {#ifdef USER_SPACE  // Have some fun - move the BS. This is done 'automatically' in real-mode  //  swr_sdb_set_config_int( stfa, "offset_chips_rcv", delay++ );#endif/*   PR( "Offset:  TX=%i   RX=%i\n", *//*       swr_sdb_get_stats_int( stfa, "buffer_off_tx" ), *//*       swr_sdb_get_stats_int( stfa, "buffer_off_rx" ) ); */  return 0;}void *start_it( void *arg ) {  swr_sdb_id mod, despread;  int i;  looping = 1;  gain = 0.;  usleep( 100000 );  PR( "Init STFA\n" );  stfa[0] = swr_sdb_instantiate_name( "stfa_ics" );  for ( i=1; i<ANTENNAS; i++ ){    stfa[i] = swr_sdb_instantiate_name( "stfa_ics" );    swr_sdb_set_config_int( stfa[i-1], "stfa_id", stfa[i] );  }  PR( "Initialized STFA\n" );  swr_sdb_set_config_int( stfa[0], "slots_per_frame", SLOTS );  swr_sdb_set_config_int( stfa[0], "blocks_per_slot", SLOT_LEN );  swr_sdb_set_config_int( stfa[0], "slot_send_offset", SLOT_OFFSET );  PR( "Setting up BCh on slot 0\n" );  ch_bch = swr_chain_create(             NEW_SPC_VAR( "sch_send", sch ),             NEW_SPC_VAR( "mapper", mod ),             NEW_SPC( "spread" ),             NEW_SPC( "chest_send" ),             NEW_SPC( "synch_send" ),             NEW_SPC( "rrc_complex_send" ),             OLD_SPC_IN( stfa[0], 0 ),             CHAIN_END );  swr_stfa_notice_sdb( stfa[0], 0, sch );  swr_sdb_set_config_int( sch, "id0", 0x1234 );  swr_sdb_set_config_int( sch, "uplinks0", 2 );  ch_rach = swr_chain_create(              OLD_SPC_OUT( stfa[0], 0 ),	      NEW_SPC( "rrc_complex_ics_rcv" ),	      NEW_SPC( "synch_complex_rcv" ),              NEW_SPC_VAR( "chest_rcv", mafi ),              NEW_SPC_VAR( "despread", despread ),              NEW_SPC_VAR( "slicer", slicer ),              NEW_SPC( "sink" ),              CHAIN_END );  // Give the mafi_id to the slicer, so it can get the   // max signal amplitude from the matched filter  // if set to -1, the slicer evaluate the ampl itself  swr_sdb_set_config_int( slicer, "mafi_id", mafi );  swr_sdb_set_config_int( sch, "mafi0", mafi );  swr_sdb_set_config_int( mafi, "calc_taps", 5 );  swr_sdb_set_config_int( mafi, "align", 1 );  swr_stfa_notice_func( stfa[0], 2, do_send_down );#if 1  for ( i=1; i<ANTENNAS; i++ ){    swr_sdb_id rand_u8, slicer, rrc_rcv;    PR( "Setting up some random stuff on slot 0 of stfa %i\n", i );    ch_supp[i] = swr_chain_create(				  //NEW_SPC_VAR_OUT( "source", source, 1 ),				  NEW_SPC_VAR( "random", rand_u8 ),				  NEW_SPC( "mapper" ),				  NEW_SPC( "spread" ),				  NEW_SPC( "chest_send" ),				  //NEW_SPC( "synch_send" ),				  NEW_SPC( "rrc_complex_send" ),				  OLD_SPC_IN( stfa[i], 0 ),				  CHAIN_END );    swr_stfa_notice_sdb( stfa[i], 0, rand_u8 );    //swr_stfa_notice_sdb( stfa[i], 0, source );    //swr_sdb_set_config_int( source, "complex_type", 1 );    //swr_sdb_set_config_pointer( source, "data", d );    //swr_sdb_set_config_int( source, "len", DATA_LEN );        ch_down[i] = swr_chain_create(              OLD_SPC_OUT( stfa[i], 0 ),	      NEW_SPC_VAR( "rrc_complex_ics_rcv", rrc_rcv ),	      //NEW_SPC( "synch_complex_rcv" ),	      NEW_SPC_VAR( "chest_rcv", mafi ),              NEW_SPC( "despread" ),              NEW_SPC_VAR( "slicer", slicer ),              NEW_SPC( "sink" ),              CHAIN_END );    //    swr_sdb_set_config_int( slicer, "mafi_id", mafi );    swr_sdb_set_config_int( mafi, "calc_taps", 5 );    swr_sdb_set_config_int( mafi, "align", 1 );    swr_sdb_set_config_int( rrc_rcv, "channel", i );  }#endif  swr_stfa_go( stfa[0] );  while ( looping ) {    usleep( 1000000 );  }  swr_stfa_stop( stfa[0] );  usleep( 1000000 );  return 0;}struct thread start;/** * This function is called upon "insmod" and is used to register the * different parts of the module to the SPM. */int um_module_init(void) {  MOD_INC_USE_COUNT;  looping = 1;  delay = 0;  ch_bch = NULL;  ch_rach = NULL;  if ( swr_thread_init( &start, start_it, NULL ) ) {    goto rrc_no_thread;  }  MOD_DEC_USE_COUNT;  return 0;rrc_no_thread:  PR_DBG( 0, "Couldn't init thread\n" );  MOD_DEC_USE_COUNT;  return -1;}void um_module_exit( void ) {  int i;  looping = 0;  swr_thread_free( &start, NULL );  PR_DBG( 0, "deleting everything\n" );  swr_chain_destroy( ch_bch );  swr_chain_destroy( ch_rach );  PR( "Destroying stfas\n" );  for ( i=0; i<ANTENNAS; i++ ){    if ( i > 0 ){      swr_chain_destroy( ch_supp[ i ] );      swr_chain_destroy( ch_down[ i ] );    }    swr_sdb_destroy( stfa[i] );  }}module_init( um_module_init );module_exit( um_module_exit );

⌨️ 快捷键说明

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