📄 radio_ics_ms.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 03/03/06 - ineiti - added synchronisation-macro 03/03/19 - ineiti - added SCH and gain-control 04/04/08 - ineiti - made an uplink instead of a downlink **************************************************************************//*************************************************************************** * * * 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 * - set up a channel for sending */#include "system.h"#include "sdb.h"#include "stfa.h"#include "antenna.h"#include "std.h"#include "debugging.h"#include "../radio_ics.h"#include "chain.h"#include "spc.h"#define DBG_LVL 4swr_sdb_id stfa[NO_RX], mafi, macro_synch, sch, rrc_rcv_synch, slicer[NO_RX], slcr, rrc_rcv[NO_RX], chest_rcv[NO_RX], decoder, rcd, rand_rcv;struct chain_t *ch_up[NO_RX], *ch_bch, *ch_test;enum st{ user_mode, synching, send_up, stop_stfa, done } state;int count, offset;struct bch_struct bch_data;int a;int callback( int msg, void *data, swr_sdb_id ret_id );/* * uplink-chain */void setup_uplink( void ){ int a, spread[NO_TX]; swr_sdb_id rand_u8, rrc_send[NO_TX], mapper, chest_send[NO_TX], split; PR( "Setting up an uplink\n" ); ch_up[0] = swr_chain_create( NEW_SPC_VAR( "random", rand_u8 ), NEW_SPC_VAR( "mapper", mapper ), NEW_SPC_VAR( "split", split ), NEW_SPC_VAR( "spread", spread[0] ), NEW_SPC_VAR( "chest_send", chest_send[0] ), NEW_SPC_VAR( "rrc_complex_send", rrc_send[0] ), OLD_SPC_IN( stfa[0], 2 ), CHAIN_END ); swr_sdb_set_config_int( rand_u8, "mode", 1 ); swr_sdb_set_config_int( rand_u8, "seed", 0x1234 ); for ( a=0; a<NO_TX; a++ ){ if ( a ){ ch_up[a] = swr_chain_create( OLD_SPC_OUT( split, a ), NEW_SPC_VAR( "spread", spread[a] ), NEW_SPC_VAR( "chest_send", chest_send[a] ), NEW_SPC_VAR( "rrc_complex_send", rrc_send[a] ), OLD_SPC_IN( stfa[a], 2 ), CHAIN_END ); } swr_sdb_set_config_int( chest_send[a], "index", a ); swr_sdb_set_config_int( rrc_send[a], "rrc_index", 2 ); swr_sdb_set_config_int( spread[a], "sequence", spread_ortho_8[a] ); } swr_stfa_notice_sdb( stfa[0], 2, rand_u8 );}/** * 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 ) { // Initialise some values count = 0; state = send_up; offset = swr_sdb_get_stats_int( macro_synch, "offset" ); rrc_rcv_synch = swr_sdb_get_stats_int( macro_synch, "rrc_rcv" ); swr_stfa_notice_func( stfa[0], 0, callback ); // Listen to the bch ch_bch = swr_chain_create( OLD_SPC( rrc_rcv_synch ), NEW_SPC_VAR( "chest_rcv", mafi ), NEW_SPC( "despread" ), NEW_SPC_VAR( "slicer", slcr ), NEW_SPC_VAR( "sch_rcv", sch ), CHAIN_END ); swr_sdb_set_config_int( sch, "antenna", 0 ); swr_sdb_set_config_int( sch, "id", 0x1234 ); swr_sdb_set_config_int( mafi, "calc_taps", 8 ); swr_sdb_set_config_int( mafi, "align", 1 ); //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(slcr, "mafi_id", mafi); setup_uplink(); PR( "Ready to go" ); return 0;}/** * Once a frame this function is called. Do here whatever seems accurate... */void do_send_up( void ) {}/** * The first time this */int callback( int msg, void *data, swr_sdb_id ret_id ) { count++; switch( state ) { case send_up: do_send_up(); break; case stop_stfa: swr_stfa_stop( stfa[0] ); state++; break; case done: // WARNING: this is never reached... PR( "Done...\n" ); break; default: break; } return 0;}void *start_it( void *arg ) { int i; PR( "getting sdbs\n" ); stfa[0] = swr_sdb_instantiate_name( "stfa_ics" ); for ( i=1; i<NO_RX; i++ ){ stfa[i] = swr_sdb_instantiate_name( "stfa_ics" ); swr_sdb_set_config_int( stfa[i-1], "stfa_id", stfa[i] ); } // Initialise the STFA swr_sdb_set_config_int( stfa[0], "slots_per_frame", SLOTS ); swr_sdb_set_config_int( stfa[0], "blocks_per_slot", SLOT_LEN ); swr_sdb_set_config_int( stfa[0], "slot_send_offset", SLOT_OFFSET ); // swr_sdb_set_config_int( stfa[0], "freq", 2380 ); PR( "Slots: %i, Length: %i\n", SLOTS, SLOT_LEN ); // Initialise our local vars ch_bch = NULL; for ( i = 0; i< NO_RX; i++) { ch_up[i]=NULL; } // This sets up the synchronisation-macro PR( "Setting up synchronisation\n" ); macro_synch = swr_sdb_instantiate_name( "macro_synch_ics" ); swr_sdb_set_config_int( macro_synch, "stfa_id", stfa[0] ); swr_sdb_set_config_pointer( macro_synch, "call_synched", synchronised ); swr_sdb_set_config_int( macro_synch, "synch", 1 ); PR( "Starting stfa\n" ); swr_stfa_go( stfa[0] ); i = 0; while ( state != done ) { usleep( 1000000 ); } swr_stfa_stop( stfa[0] ); PR( "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) { state = synching; if ( swr_thread_init( &start, start_it, NULL ) ) { goto rrc_no_thread; } return 0;rrc_no_thread: PR( "Couldn't init thread\n" ); return -1;}void um_module_exit( void ) { int i; state = done; PR( "Waiting for thread to finish\n" ); swr_thread_free( &start, NULL ); PR( "Destroying test\n" ); swr_chain_destroy( ch_test ); PR( "Destroying bch\n" ); swr_chain_destroy( ch_bch ); PR( "Destroying macro_synch\n" ); swr_sdb_destroy( macro_synch ); for ( i=0; i<NO_RX; i++ ){ PR( "Destroying transmitting chains[%i]\n", i ); swr_chain_destroy( ch_up[i] ); } for ( i=0; i<NO_RX; i++ ){ PR( "Destroying stfa[%i]\n", i ); swr_sdb_destroy( stfa[i] ); }}module_init( um_module_init );module_exit( um_module_exit );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -