📄 rrc_rcv.c
字号:
/*************************************************************************** * rrc_rcv.c - Inverse pulse-shape filtering ***************************************************************************//*************************************************************************** * * * 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. * * * ***************************************************************************//** * Does the inverse of the rrc_send, that is, applies the rrc, and downsamples * by a factor of 2. */#include "spc.h"#include "rrc_rcv.h"#include "antenna.h"#define DBG_LVL 0typedef struct { // How many samples delayed int delay; // 0}config_t;typedef struct { // How many samples we missed int modulo;}stats_t;typedef struct { // ADD HERE anything you want! short rrc_real[ RRC_RCV_LENGTH ]; short rrc_imag[ RRC_RCV_LENGTH ]; int delay;}private_t;/* * The initialisation function, or constructor, * is called the first time this module is instantiated. */int rcv_init( swr_sdb_t *context ) { // Begin system-definitions { config_t *config; stats_t *stats; int i; 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 ); // } End of system-definitions for( i=0; i<RRC_RCV_LENGTH; i++ ) { private->rrc_real[i] = cr[i] >> 0; private->rrc_imag[i] = ci[i] >> 0; } config->delay = 0; // Begin system-definitions swr_sdb_free_stats_struct( context->id, (void**)&stats ); swr_sdb_free_config_struct( context->id, (void**)&config ); return 0; // End system-definitions}/* * To configure the inputs * this is called when the output-sizes change. */int rcv_configure_inputs( swr_sdb_t *context ) { // Definition of variables - don't touch config_t *config; swr_sdb_get_config_struct( context->id, (void**)&config ); port_in(0).size = port_out(0).size * DAQ_SAMPLES_PER_CHIP; // 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 */int rcv_configure_outputs( swr_sdb_t *context ) { // Definition of variables - don't touch config_t *config; swr_sdb_get_config_struct( context->id, (void**)&config ); port_out(0).size = port_in(0).size / DAQ_SAMPLES_PER_CHIP; // 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 rcv_reconfig( swr_sdb_t *context ) { // Definition of variables - don't touch config_t *config; swr_sdb_get_config_struct( context->id, (void**)&config ); // Put you code here // ADD HERE private->delay = config->delay; // Definition - don't touch swr_sdb_free_config_struct( context->id, (void**)&config ); return 0;}/* * This is the function that implements the `main method' of the class * Every class has got just ONE method/working-mode. */int rcv_pdata( swr_sdb_t *context ) { // Definition of variables - don't touch stats_t *stats; void *d; mmx_t *x; SYMBOL_COMPLEX *y; int n,l; // loop counter indices mmx_t *h1tmp,*h2tmp,*xtmp, tmp, *h1, *h2, inv_complex = {0xffffffff00000000ULL}; int downsample_factor = 4; int filter_len = RRC_RCV_LENGTH; d = buffer_in(0); d += private->delay * 2; x = d; x -= RRC_RCV_LENGTH / 8 + 1; y = buffer_out(0); h1 = (mmx_t*)private->rrc_real; h2 = (mmx_t*)private->rrc_imag; PR_DBG( 4, "Buffer_in: %p, Buffer_out: %p\n", x, y ); downsample_factor = downsample_factor>>2; // downsample in chips filter_len = filter_len>>2; for( n=0; n<size_out(0); n++ ) { pxor_r2r(mm6,mm6); // result R pxor_r2r(mm7,mm7); // result I pxor_r2r(mm3,mm3); // clear mm3 for(l=0;l<filter_len;l+=4) { xtmp = &x[l]; h1tmp = &h1[l]; h2tmp = &h2[l]; movq_m2r(xtmp[0],mm0); pmaddwd_r2r(mm3,mm4); movq_m2r(h2tmp[0],mm1); pmaddwd_r2r(mm3,mm5); movq_m2r(h1tmp[0],mm2); paddd_r2r(mm4,mm6); paddd_r2r(mm5,mm7); movq_m2r(xtmp[1],mm3); pmaddwd_r2r(mm0,mm1); movq_m2r(h2tmp[1],mm4); pmaddwd_r2r(mm0,mm2); movq_m2r(h1tmp[1],mm5); paddd_r2r(mm1,mm6); paddd_r2r(mm2,mm7); movq_m2r(xtmp[2],mm0); pmaddwd_r2r(mm3,mm4); movq_m2r(h2tmp[2],mm1); pmaddwd_r2r(mm3,mm5); movq_m2r(h1tmp[2],mm2); paddd_r2r(mm4,mm6); paddd_r2r(mm5,mm7); movq_m2r(xtmp[3],mm3); pmaddwd_r2r(mm0,mm1); movq_m2r(h2tmp[3],mm4); pmaddwd_r2r(mm0,mm2); movq_m2r(h1tmp[3],mm5); paddd_r2r(mm1,mm6); paddd_r2r(mm2,mm7); } pmaddwd_r2r(mm3,mm4); pmaddwd_r2r(mm3,mm5); paddd_r2r(mm4,mm6); paddd_r2r(mm5,mm7); // make a copy of mm7 movq_r2r(mm7,mm5); punpckhdq_r2r(mm6,mm7); punpckldq_r2r(mm6,mm5); // add t10 t11 to mm6 paddd_r2r(mm5,mm7); // Aww, ugly. Somewhere a negative sign sneeks in for the complex-part. // I think it's in the definition of the midamble. But... pxor_m2r( inv_complex, mm7 ); movq_r2m(mm7, tmp); y->real = tmp.d[0] >> 12; y->imag = tmp.d[1] >> 12; y++; x += downsample_factor; } PR_DBG( 4, "RRC Done" ); emms(); swr_sdb_get_stats_struct( context->id, (void**)&stats ); stats->modulo = ( (uint)x ) % 8; swr_sdb_free_stats_struct( context->id, (void**)&stats ); return(0);}/* * This is the `destructor'. */int rcv_finalize( swr_sdb_t *context ) { if ( sizeof( private_t ) > 0 ) swr_free( private ); 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 rcv_id;int rcv_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. You have to define * them in the same order as they appear in the structures. The names * can be freely chosen. * * UM_CONFIG_{INT,DOUBLE,STRING128,POINTER}( "name" ); * UM_STATS_{INT,DOUBLE,STRING128,POINTER,BLOCK}( "name" ); */ UM_CONFIG_INT( "delay" ); UM_STATS_INT( "modulo" ); /** * The in- and outputs have also to be defined in the right order. First * port first. The additional flag is not used yet, but it will... * * UM_INPUT( SIG_{U8,SYMBOL_{S16,COMPLEX,MMX},SAMPLE_S12,S32}, 0 ); * UM_OUTPUT( SIG_{U8,SYMBOL_{S16,COMPLEX,MMX},SAMPLE_S12,S32}, 0 ); */ UM_INPUT( SIG_SAMPLE_S12, 0 ); UM_OUTPUT( SIG_SYMBOL_COMPLEX, 0 ); // Initialise the callback-functions. Delete the ones you don't use desc->fn_init = rcv_init; desc->fn_reconfigure = rcv_reconfig; desc->fn_process_data = rcv_pdata; desc->fn_configure_inputs = rcv_configure_inputs; desc->fn_configure_outputs = rcv_configure_outputs; desc->fn_finalize = rcv_finalize; // And register the module in the SPM. Change the name! rcv_id = swr_cdb_register_spc( &desc, "rrc_rcv" ); if ( rcv_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\n" ); return 0;}/* * This is called upon rmmod */void rcv_module_exit( void ) { PR_DBG( 4, "Freeing id: %i\n", rcv_id ); if ( swr_cdb_unregister_spc( rcv_id ) < 0 ) { PR_DBG( 0, "Still in use somewhere\n" ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -