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

📄 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 04/04/20 - ineiti - exit was not correct  **************************************************************************//*************************************************************************** *                                                                         * *   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 * - send RACh */#include "system.h"#include "sdb.h"#include "stfa.h"#include "antenna.h"#include "std.h"#include "debugging.h"#include "../simple_radio.h"#include "chain.h"#include "../common.h"#define ANTENNA 0#define DBG_LVL 0swr_sdb_id stfa,mafi, macro_synch, sch, encode;struct chain_t *ch_ldpc, *ch_bch;struct slot_bch bch_data;int slots_per_frame, blocks_per_slot;enum st{ synch_primary, send_ldpc, stop_stfa, done } state;int count, loops;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 randstr, synch_rcv;  // Clean the synchronisation  swr_sdb_set_config_int( macro_synch, "synch", 0 );  // Initialise some values  count = 0;  synch_rcv = swr_sdb_get_stats_int( macro_synch, "synch_rcv" );  swr_stfa_notice_func( stfa, 0, callback );  state++;  count = 0;  // Listen to the bch  ch_bch = swr_chain_create( OLD_SPC( synch_rcv ),                             NEW_SPC_VAR( "matched_filter", mafi ),                             NEW_SPC( "despread" ),                             NEW_SPC( "slicer" ),                             NEW_SPC_VAR( "sch_rcv", sch ),			     CHAIN_END );  swr_sdb_set_config_pointer( sch, "data_usr", &bch_data );  swr_sdb_set_config_int( sch, "len_usr", sizeof( struct slot_bch ) );  swr_sdb_set_config_int( sch, "antenna", 0 );  swr_sdb_set_config_int( sch, "id", 0x1234 );  swr_sdb_set_config_int( mafi, "gain_control", 9000 );  // And setup a simple RACH-chain...  ch_ldpc = swr_chain_create( NEW_SPC_VAR( "rndstr", randstr ),                              NEW_SPC_VAR( "ldpc_encode", encode ),                              NEW_SPC( "mapper" ),                              NEW_SPC( "midamble" ),                              NEW_SPC( "rrc" ),                              OLD_SPC_IN( stfa, 1 ),			      CHAIN_END );  swr_stfa_notice_sdb( stfa, 1, randstr );  PR( "Ready to go\n" );  return 0;}void do_ldpc( void ) {  if ( swr_sdb_get_stats_int( sch, "valid" ) && bch_data.ldpc_code_id ) {    PR_DBG( 2, "Ldpc-code-id: %i\n", bch_data.ldpc_code_id );    swr_sdb_set_config_int( encode, "ldpc_code_id", bch_data.ldpc_code_id );  } else {    PR_DBG( 1, "Not yet recognized by BS\n" );  }}int callback( int msg, void *data, swr_sdb_id ret_id ) {  switch( state ) {  case synch_primary:    // Will never be called...    break;  case send_ldpc:    do_ldpc();    break;  case stop_stfa:    swr_stfa_stop( stfa );    state++;    break;  case done:    // WARNING: this is never reached...    PR( "Done...\n" );    break;  }  return 0;}void *start_it( void *arg ) {  int i;  usleep( 1000000 );  PR( "getting sdbs\n" );  stfa = swr_sdb_instantiate_name( "stfa" );  slots_per_frame = swr_sdb_get_stats_int( stfa, "slots_per_frame" );  blocks_per_slot = swr_sdb_get_stats_int( stfa, "blocks_per_slot" );  count = 0;  state = synch_primary;  ch_ldpc = ch_bch = NULL;  PR( "Setting up synchronisation\n" );  macro_synch = swr_sdb_instantiate_name( "macro_synch" );  swr_sdb_set_config_int( macro_synch, "stfa_id", stfa );  swr_sdb_set_config_int( macro_synch, "synch", 1 );  swr_sdb_set_config_pointer( macro_synch, "call_synched", synchronised );  PR( "Starting stfa\n" );  swr_stfa_go( stfa );  i = 0;  while ( state != done ) {    //    PR( "%2i seconds past\n", i );    usleep( 1000000 );    i++;  }  PR( "stfa stopped\n" );  swr_sdb_set_config_int( macro_synch, "synch", 0 );  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) {  MOD_INC_USE_COUNT;  if ( swr_thread_init( &start, start_it, NULL ) ) {    goto rrc_no_thread;  }  MOD_DEC_USE_COUNT;  return 0;rrc_no_thread:  PR( "Couldn't init thread\n" );  MOD_DEC_USE_COUNT;  return -1;}void um_module_exit( void ) {  state = stop_stfa;  PR( "deleting everything\n" );  swr_thread_free( &start, NULL );  swr_sdb_destroy( macro_synch );  swr_chain_destroy( ch_ldpc );  swr_chain_destroy( ch_bch );  swr_sdb_destroy( stfa );}module_init( um_module_init );module_exit( um_module_exit );

⌨️ 快捷键说明

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