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

📄 radio_ms.c

📁 软件无线电的平台
💻 C
字号:
/***************************************************************************               radio_ms.c  -  SRadio controller module                            -------------------    begin                :  02/10/30    authors              :  Linus Gasser    emails               :  linus.gasser@epfl.ch ***************************************************************************//***************************************************************************                                 Changes                                 ------- date - name - description 02/10/30 - ineiti - begin 03/01/09 - ineiti - clean up 03/02/27 - ineiti - simplified to only two slots 03/03/06 - ineiti - added synchronisation-macro 03/03/19 - ineiti - added SCH and gain-control 03/11/11 - selvan - added MIMO-capability 03/11/24 - ineiti - prepared for Nicous LDPC 04/04/08 - ineiti - changed from stfa_complex to stfa_ics  **************************************************************************//*************************************************************************** *                                                                         * *   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 MS that connects to the BS. * * Function: * - listen to Synch * - find synch * - set up a channel for sending */#include "system.h"#include "sdb.h"#include "stfa.h"#include "antenna.h"#include "std.h"#include "debugging.h"#include "../mimo_radio.h"#include "chain.h"#define ANTENNA 0#define DBG_LVL 4swr_sdb_id stfa[2], mafi, macro_synch, split, sch, rrc_rcv, chest_send[2];struct chain_t *ch_up_1, *ch_up_2, *ch_bch;enum st{ user_mode, synching, send_up, stop_stfa, done } state;int count;struct bch_struct bch_data;int callback( int msg, void *data, swr_sdb_id ret_id );/** * This function is called once to clean up the synchronisation-macro, * set up the bch and up-channel, and to set the callback-function * as default. */int synchronised( int msg, void *data, swr_sdb_id ret_id ) {  swr_sdb_id rand_u8, spread[2];  // Initialise some values  count = 0;  state = send_up;  rrc_rcv = swr_sdb_get_stats_int( macro_synch, "rrc_rcv" );  swr_stfa_notice_func( stfa[0], 0, callback );  // Listen to the bch    PR( "Setting downlink in slot 0\n" );  ch_bch = swr_chain_create(             OLD_SPC( rrc_rcv ),             NEW_SPC_VAR( "chest_rcv", mafi ),             NEW_SPC( "despread" ),             NEW_SPC( "slicer" ),             NEW_SPC_VAR( "sch_rcv", sch ),             CHAIN_END );  // swr_sdb_set_config_int( sch, "antenna", 0 );  swr_sdb_set_config_int( mafi, "calc_taps", 4 );  swr_sdb_set_config_int( mafi, "align", 1 );  swr_sdb_set_config_int( sch, "id", 0x1234 );  PR( "Setting uplink in slot 1\n" );  // And setup a simple UP-chain...  ch_up_1 = swr_chain_create(			     NEW_SPC_VAR( "random", rand_u8 ),			     NEW_SPC( "mapper" ),			     NEW_SPC_VAR( "split", split ),			     NEW_SPC_VAR( "spread", spread[0] ),			     NEW_SPC_VAR( "chest_send", chest_send[0] ),			     NEW_SPC( "rrc_complex_send" ),			     OLD_SPC_IN( stfa[0], 1 ),			     CHAIN_END );    ch_up_2 = swr_chain_create(OLD_SPC_OUT( split, 1 ),			     NEW_SPC_VAR( "spread", spread[1] ),			     NEW_SPC_VAR( "chest_send", chest_send[1] ),			     NEW_SPC( "rrc_complex_send" ),			     OLD_SPC_IN( stfa[1], 1 ),			     CHAIN_END );  swr_sdb_set_config_int( chest_send[1], "index", 1 );   // Chose two orthogonally sequences  swr_sdb_set_config_int( spread[0], "sequence", 0x0f );  swr_sdb_set_config_int( spread[1], "sequence", 0xff );  swr_stfa_notice_sdb( stfa[0], 1, rand_u8 );  PR( "Ready to go" );  return 0;}/** * Once a frame this function is called. Do here whatever seems accurate... */void do_send_up( void ) {}/** * The first time this */int callback( int msg, void *data, swr_sdb_id ret_id ) {  count++;  switch( state ) {  case send_up:    do_send_up();    break;  case stop_stfa:    swr_stfa_stop( stfa[0] );    state++;    break;  case done:    // WARNING: this is never reached...    PR_DBG( 0, "Done...\n" );    break;  default:    break;  }  return 0;}void *start_it( void *arg ) {  int i;  PR( "getting sdbs\n" );  stfa[0] = swr_sdb_instantiate_name( "stfa_ics" );  stfa[1] = swr_sdb_instantiate_name( "stfa_ics" );    // Initialise the STFA  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 );  swr_sdb_set_config_int( stfa[0], "stfa_id", stfa[1] );   PR( "Slots: %i, Length: %i\n", SLOTS, SLOT_LEN );  // Initialise our local vars  ch_up_1 = ch_bch = NULL;  ch_up_2 = NULL;  // This sets up the synchronisation-macro  PR( "Setting up synchronisation\n" );  macro_synch = swr_sdb_instantiate_name( "macro_synch_ics" );  swr_sdb_set_config_int( macro_synch, "stfa_id", stfa[0] );  swr_sdb_set_config_int( macro_synch, "synch", 1 );  swr_sdb_set_config_pointer( macro_synch, "call_synched", synchronised );  swr_sdb_send_msg( macro_synch, SUBS_MSG_RECONFIG, 0, -1 );  PR( "Starting stfa\n" );  swr_stfa_go( stfa[0] );  i = 0;  while ( state != done ) {    usleep( 1000000 );  }  swr_stfa_stop( stfa[0] );  PR_DBG( 0, "stfa stopped\n" );  return NULL;}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) {  state = synching;  if ( swr_thread_init( &start, start_it, NULL ) ) {    goto rrc_no_thread;  }  return 0;rrc_no_thread:  PR_DBG( 0, "Couldn't init thread\n" );  return -1;}void um_module_exit( void ) {  state = done;  PR_DBG( 0, "Waiting for thread to finish\n" );  swr_thread_free( &start, NULL );  PR_DBG( 2, "Destroying uplink\n" );  swr_chain_destroy( ch_up_2 );  PR_DBG( 2, "Destroying uplink\n" );  swr_chain_destroy( ch_up_1 );  PR_DBG( 2, "Destroying bch\n" );  swr_chain_destroy( ch_bch );  PR_DBG( 2, "Destroying macro_synch\n" );  swr_sdb_destroy( macro_synch );  PR_DBG( 2, "Destroying stfa\n" );  swr_sdb_destroy( stfa[0] );  PR_DBG( 2, "Destroying stfa[1]\n" );  swr_sdb_destroy( stfa[1] );}module_init( um_module_init );module_exit( um_module_exit );

⌨️ 快捷键说明

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