📄 rrc_complex_ics_rcv.c
字号:
/*************************************************************************** * rrc_complex_ics_rcv.c - Receives a s32 signal and downsamples by two ***************************************************************************//*************************************************************************** * * * 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. * * * ***************************************************************************//*************************************************************************** * Changelog * --------- * 04/03/08 - ineiti - adjusted descriptions * **************************************************************************//** * Downsamples by a factor of 2. One can chose to apply a filter before, or * not. This is for the output of the ICS-card, which is probably thought * to support complex I/Q-data. But we get direct I/Q-data on each input * channel, so the format has to be adopted. * An important parameter is 'channel', which says whether it's an even or * odd channel. This is due to the ICS-hardware... */#include "spc.h"#include "rrcs.h"#define DBG_LVL 1#define SIDE_BUFFER 1024// ADD_HERE, int, double, char[128], void*// BEFORE each declaration, write a short description.// ON THE SAME LINE as the declaration, write the default value// Example:// {// // size of the input in bytes// int size; // 2560// }typedef struct { // Apply the conv_rrc // 0 - no filtering // 1 - filtering int conv_rrc; // 0 // Shift the input by this many samples int shift; // 0 // Which channel to decode int channel; // 0 // How many bits to shift left int shift_left; // 12 // Which of the rrcs to use int rrc_index; // 0}config_t;// ADD_HERE, int, double, char[128], void*// for the rest, the same definition as the confit_t is valid.typedef struct {}stats_t;// ADD HERE anything you want!typedef struct { int rrc_len; double *rrc; int output_length; SYMBOL_COMPLEX *output;}private_t;/* * The initialisation function, or constructor, * is called the first time this module is instantiated. */int ics_rcv_init( swr_sdb_t *context ) { // Begin system-definitions { config_t *config; stats_t *stats; 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 config->conv_rrc = 0; config->shift = 0; config->channel = 0; config->shift_left = 12; config->rrc_index = 0; private->output = NULL; private->output_length = 0; port_out(0).flags |= SWR_PORT_OWN_MALLOC; // 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}int ics_rcv_reconfig( swr_sdb_t *context ) { config_t *config; swr_sdb_get_config_struct( context->id, (void**)&config ); if ( ( config->rrc_index < NUM_OF_RRCS ) && ( config->rrc_index >= 0 ) ){ private->rrc_len = *rrcs[ config->rrc_index ]; private->rrc = rrcs[ config->rrc_index ] + 1; } swr_sdb_free_config_struct( context->id, (void**)&config ); return 0;}/* * This is called when the output-sizes change. * It configures the inputs */int ics_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 ); size_in(0) = size_out(0) * 2; // Definition - don't touch swr_sdb_free_config_struct( context->id, (void**)&config ); return 0;}/* * This is called when the input-sizes change * It configures the outputs */int ics_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 ); size_out(0) = size_in(0) / 2; // Prepare the output-buffer, so that we can write some more information // in it ( for convolutions etc. ) if ( size_out(0) != private->output_length ){ if ( private->output_length ){ swr_free( private->output ); } private->output_length = size_out(0); private->output = swr_malloc( sizeof( SYMBOL_COMPLEX ) * ( size_out(0) + 2 * SIDE_BUFFER ) ); port_out(0).data = private->output + SIDE_BUFFER; } // Definition - don't touch swr_sdb_free_config_struct( context->id, (void**)&config ); return 0;}void do_rrc_ics_inv( swr_sdb_t *context, complex double *in, SYMBOL_COMPLEX *out, int len, double a ){ int i, j; in -= private->rrc_len / 2; for ( i=0; i < 2*len + 2*private->rrc_len; i+=2 ){ complex double res = 0; for ( j=0; j<private->rrc_len; j++ ){ res += in[ i + j ] * private->rrc[ j ]; } res *= a; out[i/2] = (SYMBOL_COMPLEX){ creal( res ), cimag( res ) }; }}#define RX_INDEX(ch,i) ( (ch) % 2 ) * 4 + (i) + ( ( (i) / 4 ) * 4 )/* * This is the function that implements the `main method' of the class * Every class has got just ONE method/working-mode. */int ics_rcv_pdata( swr_sdb_t *context ) { // Definition of variables - don't touch stats_t *stats; config_t *config; SYMBOL_COMPLEX_S32 *in; complex double *buf; double a; unsigned int p; SYMBOL_COMPLEX *out; int i, channel, sl, shift, conv_rrc, buflen; in = buffer_in(0); out = buffer_out(0); if ( !out ){ PR_DBG( 1, "Output of id %i not yet defined\n", context->id ); return -1; } swr_sdb_get_config_struct( context->id, (void**)&config ); // Take care about the nasty set-up of the 554-cards p = (unsigned int)in; shift = ( p & 0x3f ) / 0x10; in = (SYMBOL_COMPLEX_S32*)(p & ~0x3f); shift += config->shift; conv_rrc = config->conv_rrc; channel = config->channel % 2; sl = config->shift_left; sl = min( 32, sl ); sl = max( 1, sl ); swr_sdb_free_config_struct( context->id, (void**)&config ); // Allocate a buffer to write the things in linear order buflen = sizeof( complex double ) * ( size_in(0) + 2 * private->rrc_len + 4 * SIDE_BUFFER ); buf = swr_malloc( buflen ); memset( buf, 0, buflen ); in -= 4 * SIDE_BUFFER; for ( i=0; i<size_in(0) + 4*SIDE_BUFFER; i++ ){ buf[i] = in[ RX_INDEX( channel, i + shift ) ].real + in[ RX_INDEX( channel, i + shift ) ].imag * I; } a = pow( 2, -sl ); // Either we do the rrc or not if ( conv_rrc ){ do_rrc_ics_inv( context, buf, private->output, size_out(0) + 2 * SIDE_BUFFER, a ); } else { out -= SIDE_BUFFER; for ( i=0; i<size_out(0) + 2*SIDE_BUFFER; i++ ){ out[i].real = creal( buf[ 2 * i ] ) * a; out[i].imag = cimag( buf[ 2 * i ] ) * a; } } swr_free( buf ); swr_sdb_get_stats_struct( context->id, (void**)&stats ); // Put your code here // ADD HERE swr_sdb_free_stats_struct( context->id, (void**)&stats ); return(0);}/* * This is the `destructor'. */int ics_rcv_finalize( swr_sdb_t *context ) { if ( private->output_length ){ swr_free( private->output ); } 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 ics_rcv_id;int ics_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, 5, 0 ); 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,DOUBLE_COMPLEX,STRING128,POINTER}( "name" ); * UM_STATS_{INT,DOUBLE,DOUBLE_COMPLEX,STRING128,POINTER,BLOCK,IMAGE}( "name" ); */ UM_CONFIG_INT( "conv_rrc" ); UM_CONFIG_INT( "shift" ); UM_CONFIG_INT( "channel" ); UM_CONFIG_INT( "shift_left" ); UM_CONFIG_INT( "rrc_index" ); /** * 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,DOUBLE_{,COMPLEX}}, 0 ); * UM_OUTPUT( SIG_{U8,SYMBOL_{S16,COMPLEX,MMX},SAMPLE_S12,S32,DOUBLE_{,COMPLEX}}, 0 ); */ UM_INPUT( SIG_SYMBOL_COMPLEX_S32, 0 ); UM_OUTPUT( SIG_SYMBOL_COMPLEX, 0 ); // Initialise the callback-functions. Delete the ones you don't use desc->fn_init = ics_rcv_init; desc->fn_process_data = ics_rcv_pdata; desc->fn_reconfigure = ics_rcv_reconfig; desc->fn_configure_inputs = ics_rcv_configure_inputs; desc->fn_configure_outputs = ics_rcv_configure_outputs; desc->fn_finalize = ics_rcv_finalize; // And register the module in the SPM. Change the name! ics_rcv_id = swr_cdb_register_spc( &desc, "rrc_complex_ics_rcv" ); if ( ics_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 ics_rcv_module_exit( void ) { PR_DBG( 4, "Freeing id: %i\n", ics_rcv_id ); if ( swr_cdb_unregister_spc( ics_rcv_id ) < 0 ) { PR_DBG( 0, "Still in use somewhere\n" ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -