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

📄 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 - corrected way the module ends  **************************************************************************//*************************************************************************** *                                                                         * *   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"#include "spc.h"#define ANTENNA 0#define DBG_LVL 1swr_sdb_id stfa,mafi, macro_synch, sch, encode, rand_u8;struct chain_t *ch_ldpc, *ch_bch, *ch_sink;struct slot_bch bch_data;int slots_per_frame, blocks_per_slot, code_id;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  synch_rcv, send_data, mid, mod;  // 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, 10, 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", 12000 );  // And setup a simple RACH-chain...  ch_ldpc = swr_chain_create(              //NEW_SPC_VAR( "rndstr", randstr ),              NEW_SPC_VAR( "random", rand_u8 ),              NEW_SPC_VAR( "test_data_send", send_data ),              NEW_SPC_VAR( "ldpc_encode", encode ),              NEW_SPC_VAR( "mapper", mod ),              NEW_SPC_VAR( "midamble", mid ),              NEW_SPC( "rrc" ),              OLD_SPC_IN( stfa, 1 ),              CHAIN_END );  ch_sink = swr_chain_create( OLD_SPC_OUT( send_data, 1 ),                              NEW_SPC( "sink" ),                              CHAIN_END );  swr_stfa_notice_sdb( stfa, 1, mod );  swr_sdb_set_config_int( rand_u8, "seed", 0x1234 );  swr_sdb_set_config_int( rand_u8, "mode", 1 );  call_module( rand_u8 );  // swr_sdb_set_config_int( mod, "amplitude",3000/1.4);  //   swr_sdb_set_config_int( mid, "amplitude",3000);  PR( "Ready to go\n" );  return 0;}void do_ldpc( void ) {  // Make the same seed as for the receive module  // swr_sdb_set_config_int( rand_u8, "seed", 0x1234 );  if ( swr_sdb_get_stats_int( sch, "valid" ) ) {    if ( code_id != bch_data.ldpc_code_id ) {      code_id = bch_data.ldpc_code_id;      PR( "Ldpc-code-id: %i\n", code_id );      swr_sdb_set_config_int( encode, "ldpc_code_id", code_id );      call_module( rand_u8 );    }  } else {    PR( "SCh is wrong...\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" );  //  swr_sdb_set_config_int( stfa, "slot_send_offset", 10 );  count = 0;  state = synch_primary;  ch_ldpc = ch_bch = ch_sink = NULL;  code_id = 0;  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 ) && ( i < 10 ) ) {    //    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 );  PR( "Deleting sink, ldpc and bch\n" );  swr_chain_destroy( ch_sink );  swr_chain_destroy( ch_ldpc );  swr_chain_destroy( ch_bch );    PR( "Destroying macro and stfa\n" );  swr_sdb_destroy( macro_synch );  swr_sdb_destroy( stfa );  PR( "Finished deleting all\n" );  usleep( 1000000 );}module_init( um_module_init );module_exit( um_module_exit );

⌨️ 快捷键说明

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