📄 radio_bs.c
字号:
/*************************************************************************** radio_bs.c - LDPC BS ------------------- 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/04/04 - ineiti - uses synch-macro 03/04/28 - ineiti - use mode-config of test_data_rcv rather than clear 03/04/28 - ineiti - use mafi-config of decode so it can calculate it's own SNR 03/05/09 - ineiti - uses done-stats of decode to know when it's safe to start another round of decoding 04/03/20 - ineiti - used make_thread instead of send_msg 04/04/20 - ineiti - cleaned up finishing of the module **************************************************************************//*************************************************************************** * * * 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 * * Function: * - emit sync * - listen to RACh */#include "system.h"#include "sdb.h"#include "stfa.h"#include "antenna.h"#include "std.h"#include "debugging.h"#include "spc.h"#include "../simple_radio.h"#include "chain.h"#include "../common.h"#define DBG_LVL 0#define SNR_SWEEP_MIN -10#ifdef USER_SPACE#define SNR_SWEEP_STEP .1#else#define SNR_SWEEP_STEP .005#endif#define SNR_SWEEP_MAX 10#define ANTENNA 0#define MIN_AMP 3#define TIME_TO_LINUX 50#ifdef USER_SPACE#define gethrtime() ( count * TIME_TO_LINUX * 1000000 )#endifswr_sdb_idstfa,energy,sch,decode,sink,mafi,received_data,rand_u8;struct chain_t *ch_bch, *ch_rach, *ch_rnd;struct slot_bch bch_data;int slots_per_frame, looping, count;double target_snr;int callback( 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 ) { looping = 1; usleep( 100000 ); stfa = swr_sdb_instantiate_name( "stfa" ); PR( "Setting up BCh on slot 0\n" ); ch_bch = swr_chain_create( NEW_SPC_VAR( "sch_send", sch ), NEW_SPC( "mapper" ), 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 ); swr_sdb_set_config_pointer( sch, "data_usr", &bch_data ); swr_sdb_set_config_int( sch, "len_usr", sizeof( struct slot_bch ) ); target_snr = SNR_SWEEP_MIN; // 1 -> 0.25 // 2 -> 0.5 // 3 -> 0.75 bch_data.ldpc_code_id = 2; PR( "Setting up LDPC slot 1\n" ); ch_rach = swr_chain_create( OLD_SPC_OUT( stfa, 1 ), NEW_SPC_VAR( "energy", energy ), NEW_SPC_VAR( "matched_filter", mafi ), NEW_SPC_VAR( "ldpc_decode", decode ), NEW_SPC_VAR( "test_data_rcv", received_data ), CHAIN_END ); make_thread( energy ); swr_sdb_set_config_int( sch, "mafi0", mafi ); swr_sdb_set_config_int( decode, "mafi", mafi ); // Reset counters to zero after each run swr_sdb_set_config_int( received_data, "mode", 1 ); // Only wait for input 0 swr_sdb_set_config_int( received_data, "wait", 1 ); ch_rnd = swr_chain_create( NEW_SPC_VAR( "random", rand_u8 ), OLD_SPC_IN( received_data, 1 ), CHAIN_END ); swr_sdb_set_config_int( rand_u8, "seed", 0x1234 ); swr_sdb_set_config_int( rand_u8, "mode", 1 ); // set up the ldpc-decoder swr_sdb_set_config_int( decode, "ldpc_code_id", bch_data.ldpc_code_id ); swr_sdb_set_config_int( decode, "iterations", 30 ); swr_sdb_set_config_int( decode, "channel_type", 2 ); count = 0; // And produce random-data for the test_data_rcv call_module( rand_u8 ); swr_stfa_notice_func( stfa, 10, callback ); // Start the transmission swr_stfa_go( stfa ); while ( looping++ ) { usleep( 1000000 ); if ( looping > 30 ) { // looping = 0; } } swr_stfa_stop( stfa ); usleep( 100000 ); 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 = 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 ) { looping = 0; swr_thread_free( &start, NULL ); PR_DBG( 0, "deleting everything\n" ); swr_chain_destroy( ch_rnd ); swr_chain_destroy( ch_bch ); swr_chain_destroy( ch_rach ); swr_sdb_destroy( stfa );}module_init( um_module_init );module_exit( um_module_exit );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -