📄 synch_send.c
字号:
/*************************************************************************** * send.c - Software Radio to generate primary synch * ------------------- * begin : 02/10/22 * authors : Linus Gasser * emails : Linus.Gasser@epfl.ch ***************************************************************************//*************************************************************************** * Changes * ------- * date - name - description * 02/10/22 - ineiti - init * 03/08/20 - ineiti - put synch in the middle * 04/02/13 - ineiti - put synch back at the beginning * 04/03/08 - ineiti - adjusted 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. * * * ***************************************************************************//** * It produces a simple-to retrieve synch-signal on one slot. Contrary to * the 3GPP definition, which has the synchronisation-signal simply added * to the rest of the signal, we explicitly take some place at the beginning * of a slot to put the signal in there. */#include "spc.h"#include "mmx.h"#include "synch.h"#define DBG_LVL 0typedef struct { // The amplitude of the signal int amplitude; // 32767}config_t;typedef struct { // How many slots have been sent already int slots_sent;}stats_t;typedef struct { unsigned int sequence[8]; mmx_t mapping[4]; mmx_t synch_amp;}private_t;/* * The initialisation function, or constructor, * is called the first time this module is instantiated. */int send_init( swr_sdb_t *context ) { // Definition of variables - don't touch if you're not an expert config_t *config; stats_t *stats; int i; unsigned int seq[8] = { (BB <<16) + BB, (BBI<<16) + BB, (BB <<16) + BBI, (BBI<<16) + BBI, (BB <<16) + BB, (BBI<<16) + BB, (BBI<<16) + BB, (BB <<16) + BB }; MOD_INC_USE_COUNT; if ( sizeof( private_t ) > 0 ) { context->private_data = swr_malloc( sizeof( private_t ) ); } swr_sdb_get_config_struct( context->id, (void**)&config ); swr_sdb_get_stats_struct( context->id, (void**)&stats ); config->amplitude = 32767; stats->slots_sent = 0; for ( i=0; i < 8; i++ ) { private->sequence[i] = seq[i]; } // maps in BPSK, is used for synch mapping in 3GPP private->mapping[0].w[0] = 1; private->mapping[0].w[1] = 0; private->mapping[0].w[2] = 1; private->mapping[0].w[3] = 0; private->mapping[1].w[0] = -1; private->mapping[1].w[1] = 0; private->mapping[1].w[2] = 1; private->mapping[1].w[3] = 0; private->mapping[2].w[0] = 1; private->mapping[2].w[1] = 0; private->mapping[2].w[2] = -1; private->mapping[2].w[3] = 0; private->mapping[3].w[0] = -1; private->mapping[3].w[1] = 0; private->mapping[3].w[2] = -1; private->mapping[3].w[3] = 0; private->synch_amp.w[0] = config->amplitude; private->synch_amp.w[1] = 0; private->synch_amp.w[2] = config->amplitude; private->synch_amp.w[3] = 0; // Definition - don't touch swr_sdb_free_config_struct( context->id, (void**)&config ); swr_sdb_free_stats_struct( context->id, (void**)&stats ); return 0;}/* * To configure the inputs * this is called when the output-sizes change. */int send_configure_inputs( swr_sdb_t *context ) { // Definition of variables - don't touch config_t *config; swr_sdb_get_config_struct( context->id, (void**)&config ); if ( port_out(0).size < 2 * SYNCH_PRIM_LENGTH_SYMBOLS ) { PR_DBG( 0, "Synching too big!\n" ); return 0; } // We add the synchronisation-signal in the middle size_in(0) = size_out(0) - SYNCH_PRIM_LENGTH_SYMBOLS; // Definition - don't touch swr_sdb_free_config_struct( context->id, (void**)&config ); return 0;}/* * To configure the outputs * this is called when the input-sizes change. Only changes on port_in(0) * do have an effect. */int send_configure_outputs( swr_sdb_t *context ) { // Definition of variables - don't touch config_t *config; swr_sdb_get_config_struct( context->id, (void**)&config ); // Configure the output-port size_out(0) = size_in(0) + SYNCH_PRIM_LENGTH_SAMPLES; // Definition - don't touch swr_sdb_free_config_struct( context->id, (void**)&config ); return(0);}/* * Every time modules from the outside change the value of a configuration parameter, * this function is called. */int send_reconfig( swr_sdb_t *context ) { // Definition of variables - don't touch config_t *config; swr_sdb_get_config_struct( context->id, (void**)&config ); private->synch_amp.w[0] = config->amplitude; private->synch_amp.w[1] = 0; private->synch_amp.w[2] = config->amplitude; private->synch_amp.w[3] = 0; // Definition - don't touch swr_sdb_free_config_struct( context->id, (void**)&config ); return(0);}/* * This is function that impements the `main method' of the class * Every calss has got just ONE method/working-mode. */int send_pdata( swr_sdb_t *context ) { // Definition of variables - don't touch stats_t *stats; register short bit01; register int bits,bmask=3; int i, j;//, half_length_chips; SYMBOL_COMPLEX *in, *out; in = buffer_in( 0 ); out = buffer_out( 0 ); movq_m2r( private->synch_amp, mm0 ); // half_length_chips = size_in( 0 ) / 2; memcpy( out + SYNCH_PRIM_LENGTH_SYMBOLS, in, size_in(0) * 4 ); // Put the synchronisation in place for (i=0; i < SYNCH_PRIM_LENGTH_32; i++) { /* Read in 32 new bits */ bits = private->sequence[i]; for ( j=0; j < 16; j++ ) { bit01 = bits & bmask; bits = bits >> 2; movq_m2r(private->mapping[bit01],mm3); pmullw_r2r(mm0,mm3); movq_r2m(mm3,out[32 * i + 2 * j]); } } emms(); swr_sdb_get_stats_struct( context->id, (void**)&stats ); stats->slots_sent++; swr_sdb_free_stats_struct( context->id, (void**)&stats ); return(0);}/* * This is the `destructor'. */int send_finalize( swr_sdb_t *context ) { swr_free( context->private_data ); MOD_DEC_USE_COUNT; return(0);}/* * This function is called upon "insmod" and is used to register the * different parts of the module to the SPM. */swr_spc_id_t send_id;int send_module_init(void) { swr_spc_desc_t *desc; // Get a description-part from SPM // Give the following parameters: // Input-ports, output-ports, config-params, stat-params desc = swr_spc_get_new_desc( 1, 1, 1, 1 ); if ( !desc ) { PR_DBG( 0, "Can't initialise the module. This is BAD!\n" ); return -1; } // Define the different parts of config and stats UM_CONFIG_INT( "amplitude" ); UM_STATS_INT( "slots_sent" ); UM_INPUT( SIG_SYMBOL_COMPLEX, 0 ); UM_OUTPUT( SIG_SYMBOL_COMPLEX, 0 ); // Initialise the callback-functions. NULL for not-used functions desc->fn_init = send_init; desc->fn_reconfigure = send_reconfig; desc->fn_process_data = send_pdata; desc->fn_configure_inputs = send_configure_inputs; desc->fn_configure_outputs = send_configure_outputs; desc->fn_finalize = send_finalize; // And register the module in the SPM send_id = swr_cdb_register_spc( &desc, "synch_send" ); if ( send_id == SWR_SPM_INVALID_ID ) { swr_spc_free_desc( desc ); PR_DBG( 0, "Couldn't register the module!\n" ); return 1; } PR_DBG( 4, "Ready to synch\n" ); return 0;}/* * This is called upon rmmod */void send_module_exit( void ) { PR_DBG( 4, "Freeing id: %i\n", send_id ); if ( swr_cdb_unregister_spc( send_id ) < 0 ) { PR_DBG( 0, "Still in use somewhere\n" ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -