📄 radio_bs.c
字号:
/*************************************************************************** radio_bs.c - SRadio simple bs for convolutional coding ------------------- begin : 03/12/10 authors : Roman Hofer emails : roman.hofer@epfl.ch ***************************************************************************//*************************************************************************** Changes ------- date - name - description **************************************************************************//*************************************************************************** * * * 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 BS and receive the convolutional encoded * random data, which is compared to its should-be-values * * Function: * - emit sync * - listen to RACh */#include "system.h"#include "sdb.h"#include "spc.h"#include "stfa.h"#include "antenna.h"#include "std.h"#include "debugging.h"#include "../convolution_radio.h"#include "chain.h"#define SNR_SWEEP_MIN -10#ifdef USER_SPACE#define SNR_SWEEP_STEP .5#else#define SNR_SWEEP_STEP .005#endif#define SNR_SWEEP_MAX 10#define ANTENNA 0#define DBG_LVL 0#define TARGET_MOBILE_HERE 1000*1000swr_sdb_id stfa, sch, mafi, slicer;struct chain_t *ch_bch, *ch_rach, *ch_rnd;struct bch_struct bch_data;int looping, delay;double target_snr;/** * Once a frame this function is called. Here we do some gain-adjustements, * so that we get interesting BER/SNR curves. */int do_send_down( int msg, void *data, swr_sdb_id ret_id ) { // Do a 'sweep' on the snr target_snr += SNR_SWEEP_STEP; if ( target_snr > SNR_SWEEP_MAX ) { target_snr = SNR_SWEEP_MIN; } PR_DBG( 4, "target_snr: %s%i.%i\n", swr_ftosii( target_snr ) ); swr_sdb_set_config_double( sch, "target_snr0", target_snr ); return 0;}void *start_it( void *arg ) { swr_sdb_id mod, conv_rcv, test_data_rcv, rand_u8; looping = 1; target_snr = SNR_SWEEP_MIN; usleep( 100000 ); PR( "Init STFA\n" ); stfa = swr_sdb_instantiate_name( "stfa" ); PR( "Initialized STFA\n" ); swr_sdb_set_config_int( stfa, "slots_per_frame", SLOTS ); swr_sdb_set_config_int( stfa, "blocks_per_slot", SLOT_LEN ); swr_sdb_set_config_int( stfa, "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( "midamble" ), NEW_SPC( "synch_send" ), NEW_SPC( "rrc" ), OLD_SPC_IN( stfa, 0 ), CHAIN_END ); swr_stfa_notice_sdb( stfa, 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, 1 ), NEW_SPC_VAR( "matched_filter", mafi ), NEW_SPC_VAR( "slicer", slicer ), NEW_SPC_VAR( "convolution_rcv",conv_rcv ), NEW_SPC_VAR( "test_data_rcv",test_data_rcv ), CHAIN_END ); swr_sdb_set_config_int( sch, "mafi0", mafi ); //Mode1=reset counter for each slot (so not add up errors) swr_sdb_set_config_int( test_data_rcv, "mode", 1 ); // wait for both inputs (0=both,1=input0,2=input2) swr_sdb_set_config_int( test_data_rcv, "wait", 1 ); //Put a random source to 2nd input of test_data_rcv, which is in mode 1 and has same //seed like MS's random source ch_rnd=swr_chain_create( NEW_SPC_VAR( "random", rand_u8 ), OLD_SPC_IN( test_data_rcv, 1 ), 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);#if 0 //number of output bits swr_sdb_set_config_int( conv_rcv, "cfg_n", 7 ); //per number of input bits swr_sdb_set_config_int( conv_rcv, "cfg_k", 5 ); //number of memory registers swr_sdb_set_config_int( conv_rcv, "cfg_m", 8 ); //max trellis lenght swr_sdb_set_config_int( conv_rcv, "cfg_trunclength", 32 ); //truncation iteration size swr_sdb_set_config_int( conv_rcv, "cfg_truncblock", 10 ); //polynomes swr_sdb_set_config_pointer( conv_rcv, "cfg_polys", polys );#endif swr_sdb_set_config_int( rand_u8, "seed", 0x1234 ); swr_sdb_set_config_int( rand_u8, "mode", 1 ); // And produce random-data for the test_data_rcv //activate the random-source (we wait for some slot, to active it (could be any slot)) call_module(rand_u8); //swr_stfa_notice_sdb( stfa, 1, rand_u8 ); swr_stfa_notice_func( stfa, 2, do_send_down ); swr_stfa_go( stfa ); while ( looping ) { usleep( 1000000 ); } swr_stfa_stop( stfa ); 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( "Couldn't init thread\n" ); MOD_DEC_USE_COUNT; return -1;}void um_module_exit( void ) { looping = 0; swr_thread_free( &start, NULL ); PR( "deleting everything\n" ); swr_chain_destroy( ch_bch ); swr_chain_destroy( ch_rach ); swr_chain_destroy( ch_rnd ); swr_sdb_destroy( stfa );}module_init( um_module_init );module_exit( um_module_exit );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -