📄 radio_ms.c
字号:
/*************************************************************************** radio_ms.c - SRadio controller module ------------------- begin : 02/10/30 authors : Linus Gasser emails : linus.gasser@epfl.ch ***************************************************************************//*************************************************************************** Changes ------- date - name - description02/10/30 - ineiti - begin03/01/09 - ineiti - clean up **************************************************************************//*************************************************************************** * * * 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 */#define DBG_LVL 2#include "system.h"#include "sdb.h"#include "stfa.h"#include "antenna.h"#include "std.h"#include "debugging.h"#include "chain.h"#include "../sradio.h"#include "../common.h"#define ANTENNA 0swr_sdb_id stfa, cch[ MAX_SLOTS ], sch,mafi[ MAX_SLOTS ], macro_synch,mod[ MAX_SLOTS ], mid[ MAX_SLOTS ];struct chain_t *ch_rach, *ch_sch, dch[ MAX_SLOTS ], *uplink[ MAX_TR_SLOTS ], *downlink[ MAX_TR_SLOTS ];struct rach_data rach_data;struct ms_data mobile;char *slot_str[ MAX_SLOTS ];int slots_per_frame,blocks_per_slot;enum st{ synch_primary, send_rach, transmit, stop_stfa, done } state;int count, loops, mobile_index;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 sch 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; // 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 sch ch_sch = swr_chain_create( OLD_SPC( synch_rcv ), NEW_SPC_VAR( "matched_filter", mafi[0] ), 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[0], "gain_control", 9000 ); return 0;}void do_send_rach( void ) { int i, up, ups, down, downs; if ( !count ) { if ( swr_sdb_get_stats_int( sch, "valid" ) == 0 ) { // A SCH has been received succesfully rach_data.id = swr_sdb_get_stats_int( sch, "free_id" ); rach_data.class = 0; PR_DBG( 1, "RACh-id is: %i\n", rach_data.id ); swr_sdb_set_config_int( sch, "id", rach_data.id ); // Setup a RACH-chain... ch_rach = swr_chain_create( NEW_SPC_VAR( "cch_send", cch[ SLOT_RACH ] ), NEW_SPC( "mapper" ), NEW_SPC( "spread" ), NEW_SPC( "midamble" ), NEW_SPC( "rrc" ), OLD_SPC_IN( stfa, SLOT_RACH ), CHAIN_END ); swr_stfa_notice_sdb( stfa, SLOT_RACH, cch[ SLOT_RACH ] ); swr_sdb_set_config_pointer( cch[ SLOT_RACH ], "data", &rach_data ); swr_sdb_set_config_int( cch[ SLOT_RACH ], "length", sizeof( rach_data ) ); count++; } else { PR_DBG( 3, "Sch not received\n" ); // state = stop_stfa; } } else if ( count == 1 ) { // switch off rach swr_chain_destroy( ch_rach ); swr_stfa_notice_sdb( stfa, SLOT_RACH, -1 ); count++; } else if ( count <= 3 ) { // Depending on how things are unsynched, we have to wait for one // or two frames to get an answer... if ( swr_sdb_get_stats_int( sch, "valid" ) == 1 ) { PR_DBG( 4, "Received SCh and connected\n" ); PR_DBG( 1, "Mobile connected as id %i\n", rach_data.id ); // Setup Up- and Downlink slots ups = swr_sdb_get_stats_int( sch, "uplinks" ); downs = swr_sdb_get_stats_int( sch, "downlinks" ); up = down = 0; for ( i=0; i<slots_per_frame; i++ ) { if ( ups & ( 1 << i ) ) { PR_DBG( 2, "Setting uplink[ %i ] to slot %i\n", up, i ); uplink[ up++ ] = setup_send( i, cch, mod, stfa, slot_str ); } if ( downs & ( 1 << i ) ) { PR_DBG( 2, "Setting downlink[ %i ] to slot %i\n", up, i ); downlink[ down++ ] = setup_rcv( i, stfa, mafi, cch, slot_str ); } } state++; count = 0; } else { PR_DBG( 4, "Couldnt' receive Sch\n" ); // state = stop_stfa; } } else { // Didn't get an answer for two frames -> retry count = 0; }}void do_transmit( void ) { int valid; valid = swr_sdb_get_stats_int( sch, "valid" ); count++; if ( valid < 0 ) { PR_DBG( 3, "Didn't receive SCh\n" ); return; } else if ( !valid ) { PR_DBG( 0, "Got thrown out...\n" ); state = send_rach; count = 0; return; }}int callback( int msg, void *data, swr_sdb_id ret_id ) { switch( state ) { case synch_primary: // This should never be called... break; case send_rach: do_send_rach(); break; case transmit: do_transmit(); break; case stop_stfa: swr_stfa_stop( stfa ); state++; break; case done: // WARNING: this is never reached... PR_DBG( 0, "Done...\n" ); break; } return 0;}void *start_it( void *arg ) { int i; 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" ); if ( slots_per_frame < 0 ) { PR( "Couldn't get spf...\n" ); return 0; } if ( slots_per_frame > MAX_SLOTS ) { PR( "Too many slots...\n" ); return 0; } count = 0; loops = 0; state = synch_primary; ch_rach = ch_sch = NULL; swr_ant_set_gains( ANTENNA, 0, 0 ); // This sets up the synchronisation-macro 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_DBG( 0, "Starting stfa\n" ); swr_stfa_go( stfa ); i = 0; while ( ( state != done ) && ( i < 300 ) ) { usleep( 1000000 ); i++; } 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) { 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 ) { int i; state = stop_stfa; PR_DBG( 0, "deleting everything\n" ); swr_thread_free( &start, NULL ); swr_chain_destroy( ch_rach ); swr_chain_destroy( ch_sch ); for ( i=0; i<slots_per_frame; i++ ) { swr_chain_destroy( uplink[ i ] ); swr_chain_destroy( downlink[ i ] ); } swr_sdb_destroy( stfa );}module_init( um_module_init );module_exit( um_module_exit );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -