📄 subsystem.c
字号:
swr_port_t *this_port; for ( port=0; port<context->cdb_desc->outputs.nbr_ports; port++ ) { this_port = &context->port_out[port]; if ( ( this_port->sdb_id >= 0 ) && this_port->data && ( this_port->flags & SWR_PORT_DATA ) ) { // Prepare a data-block send PR_DBG( 3, "send_data to %i:%i\n", this_port->sdb_id, port ); this_port->flags &= ~SWR_PORT_DATA; // Set the flag of the receiving port swr_sdb_get_struct( this_port->sdb_id )->port_in[this_port->port].flags |= SWR_PORT_DATA; swr_sdb_send_msg( this_port->sdb_id, SUBS_MSG_DATA, NULL, context->id ); } }}void user_msg(swr_sdb_t *context, swr_sdb_id sender, swr_usr_msg_t *data ) { if ( data ) { PR_DBG( 3, "Received user-message %s\n", data->id ); } else { PR_DBG( 3, "Received empty user-message\n" ); } funcarg( context->cdb_desc->fn_custom_msg )( context, data, sender ); if ( data ) { if ( swr_free( data ) ) { PR_DBG( 0, "Error in freeing data\n" ); } }}int subsys_init( swr_sdb_t *context ) { int i; char name[SWR_CDB_MAX_NAME_LENGTH]; swr_cdb_get_name( context->cdb_desc->id, name ); PR_DBG( 1, "Initialising subsys-id %i (%s)\n", context->id, name ); for ( i=0; i<context->cdb_desc->inputs.nbr_ports; i++ ) { context->port_in[i].sdb_id = -1; context->port_in[i].size = 0; context->port_in[i].data = NULL; context->port_in[i].flags = context->cdb_desc->inputs.ports[i].flags; context->port_in[i].type = swr_spc_get_input_signal_type( context->cdb_desc, i ); } for ( i=0; i<context->cdb_desc->outputs.nbr_ports; i++ ) { context->port_out[i].sdb_id = -1; context->port_out[i].data = NULL; context->port_out[i].size = 0; context->port_out[i].flags = context->cdb_desc->outputs.ports[i].flags; context->port_out[i].type = swr_spc_get_output_signal_type( context->cdb_desc, i ); } for ( i=0; i<=profiling_total; i++ ) { context->profiling.calls[i] = 0; context->profiling.time[i] = 0; } PR_DBG( 3, "initialising\n" ); func( context->cdb_desc->fn_init ); PR_DBG( 3, "Reconfiguration\n" ); reconfig( context ); PR_DBG( 3, "finished\n" ); return 0;}/** * stores the sizes and data-pointers in a table. ATTENTION: cmp_params is supposed * to clean up the table! */void get_params( swr_sdb_t *context, swr_signal_dir_t dir, swr_port_t **pparams ) { int p, num_ports; swr_port_t *ports; if ( dir == INPUT ) { num_ports = context->cdb_desc->inputs.nbr_ports; ports = context->port_in; } else { num_ports = context->cdb_desc->outputs.nbr_ports; ports = context->port_out; } // We allocate at least one byte, just to say "we've been here"... *pparams = swr_malloc( sizeof( swr_port_t ) * num_ports + 1 ); if ( num_ports ) { for ( p=0; p<num_ports; p++ ) { (*pparams)[p].size = ports[p].size; (*pparams)[p].data = ports[p].data; (*pparams)[p].flags = 0; } }}/** * compares the sizes and data-pointers and sends resize-messages if necessary. * also cleans up the table 'pparams' */void cmp_params( swr_sdb_t *context, swr_signal_dir_t dir, swr_port_t *pparams ) { int num_ports; swr_port_t *ports; int p; swr_spc_configure_ports_t *conf_first, *conf_second; if ( !pparams ) { return; } if ( dir == INPUT ) { num_ports = context->cdb_desc->inputs.nbr_ports; ports = context->port_in; conf_first = context->cdb_desc->fn_configure_outputs; conf_second = context->cdb_desc->fn_configure_inputs; } else { num_ports = context->cdb_desc->outputs.nbr_ports; ports = context->port_out; conf_first = context->cdb_desc->fn_configure_inputs; conf_second = context->cdb_desc->fn_configure_outputs; } for ( p=0; p<num_ports; p++ ) { if ( ( pparams[p].size != ports[p].size ) || ( pparams[p].data != ports[p].data ) ) { PR_DBG( 3, "Detected change: pparams[%i].flags = %i\n", p, pparams[p].flags ); PR_DBG( 3, " Size: %i->%i, Data: %p->%p\n", pparams[p].size, ports[p].size, pparams[p].data, ports[p].data ); if ( !( pparams[p].flags & SWR_PORT_GOT_RESIZE ) ) { evtl_malloc( context, NULL, &ports[p], ports[p].port ); // func( conf_first ); // func( conf_second ); } if ( !( pparams[p].flags & SWR_PORT_GOT_RESIZE ) || ( ports[p].flags & SWR_PORT_OWN_MALLOC ) ) { if ( ports[p].sdb_id >= 0 ) { PR_DBG( 3, "Changed size or data of port %i, sending to %i\n", p, ports[p].sdb_id ); send_resize( ports[p].sdb_id, context->id, &ports[p], !dir ); } } } } if ( swr_free( pparams ) > 0 ) { PR_DBG( 0, "Error in freeing pparams\n" ); }}/** * When no port is initialised yet, searches for a newly * initialised port */void cmp_params_new( swr_sdb_t *context ) { int num_ports; swr_port_t *ports; int p, dir; swr_spc_configure_ports_t *conf; // Search for both input and output for ( dir = 0; dir < 2; dir++ ) { if ( !dir ) { num_ports = context->cdb_desc->inputs.nbr_ports; ports = context->port_in; conf = context->cdb_desc->fn_configure_outputs; } else { num_ports = context->cdb_desc->outputs.nbr_ports; ports = context->port_out; conf = context->cdb_desc->fn_configure_inputs; } for ( p=0; p<num_ports; p++ ) { if ( ports[p].size ) { PR_DBG( 3, "Detected new port[%i]-size, dir(%i): Size: %i\n", p, dir, ports[p].size ); if ( dir ){ SET_STATUS( RESIZE_DOWN ); } else { SET_STATUS( RESIZE_UP ); } evtl_malloc( context, NULL, &ports[p], ports[p].port ); if ( ports[p].sdb_id >= 0 ) { PR_DBG( 3, "Changed size or data of port %i, sending to %i\n", p, ports[p].sdb_id ); send_resize( ports[p].sdb_id, context->id, &ports[p], !dir ); } } } if ( IS_STATUS( RESIZE_BOTH ) ) { // if we found one side of the ports having changed, we won't // look at the other sides. This is to avoid loops return; } }}/** * Asks the module to resize and handles the request further up */void resize(swr_sdb_t *context, swr_sdb_id sender, swr_propagation_t *prop_msg, swr_port_t **params_out, swr_port_t **params_in ) { swr_port_t *port_rm = NULL; swr_spc_configure_ports_t *config_ports = NULL; if ( IS_STATUS( RESIZE_NONE ) ) { PR_DBG( 0, "Module %i got a resize while it's RESIZE_NONE!\n", context->id ); swr_free( prop_msg ); return; } // if the message is coming from an input to our output if ( prop_msg->port < context->cdb_desc->outputs.nbr_ports && ( prop_msg->dir_to == OUTPUT ) ) { PR_DBG( 3, "resizing output %i to size %i\n", prop_msg->port, prop_msg->size ); port_rm = &context->port_out[prop_msg->port]; if ( *params_out ) { (*params_out)[prop_msg->port].flags |= SWR_PORT_GOT_RESIZE; } else if ( !*params_in ) { PR_DBG( 3, "Initialising to RESIZE_UP (%i), configuring inputs\n", context->status ); get_params( context, INPUT, params_in ); } config_ports = context->cdb_desc->fn_configure_inputs; if ( IS_STATUS( RESIZE_DOWN ) ) { if ( !IS_STATUS( RESIZE_BOTH ) ) { // This means that the first time this module has been configured // it's been from input to output, and now the contrary is asked. // This is NOT VALID PR_DBG( 0, "Resize-conflict: trying to go up after being down\n" ); return; } } else { SET_STATUS( RESIZE_UP ); PR_DBG( 4, "Set Up-status: %i\n", context->status ); } } // if the message is coming from an output to our input if ( prop_msg->port < context->cdb_desc->inputs.nbr_ports && ( prop_msg->dir_to == INPUT ) ) { PR_DBG( 3, "resizing input %i to size %i\n", prop_msg->port, prop_msg->size ); port_rm = &context->port_in[prop_msg->port]; if ( *params_in ) { (*params_in)[prop_msg->port].flags |= SWR_PORT_GOT_RESIZE; } else if ( !*params_out ) { PR_DBG( 3, "Initialised to RESIZE_DOWN, configuring outputs\n" ); get_params( context, OUTPUT, params_out ); } config_ports = context->cdb_desc->fn_configure_outputs; if ( IS_STATUS( RESIZE_UP ) ) { if ( !IS_STATUS( RESIZE_BOTH ) ) { // This means that the first time this module has been configured // it's been from output to input, and now the contrary is asked. // This is NOT VALID PR_DBG( 0, "Resize-conflict: trying to go down after being up\n" ); return; } } else { SET_STATUS( RESIZE_DOWN ); PR_DBG( 4, "Set Down-status: %i\n", context->status ); } } // If we found a valid resize-msg if ( port_rm ) { // It may still be a bounce-back message with no info if ( ( port_rm->size == prop_msg->size ) && ( port_rm->data == prop_msg->data ) ) { PR_DBG( 1, "This is a useless but IT DOESN'T WORK message...\n" ); PR_DBG( 1, "Sender: %i, Rcv: %i\n", sender, context->id ); } else { PR_DBG( 4, "Changing size of %i\n", context->id ); // Allocate this port's input port_rm->size = prop_msg->size; evtl_malloc( context, prop_msg->data, port_rm, prop_msg->port ); func( config_ports ); } } else { // Something went wrong PR_DBG(0, "resize: not a valid port (%i) or invalid size (%i). Dir was %i\n", prop_msg->port, prop_msg->size, prop_msg->dir_to ); } // Free the messages if ( swr_free(prop_msg) ) { PR_DBG( 0, "Error in freeing prop_msg\n" ); }}// Write the appropriate things into the trackvoid update_track( swr_sdb_t *context ) { struct swr_stats_track_t *st; int i, j, k, c[2]; long int t[2]; int *d_int; double *d_double; SYMBOL_COMPLEX *d_complex; for ( i = 0; i < MAX_TRACKS; i++ ) { st = swr_stats_track[ i ]; if ( st[0].counter == -1 ) { continue; } for ( j=0; j<2; j++ ) { if ( context->id == st[j].m ) { PR_DBG( 2, "Entry %i is ours: %i,%i and type %i at index %i and time %li\n", j, st[j].m, st[j].pi, st[j].pt, st[j].counter, context->time_prepare / 1000 ); if ( st[j].counter >= TRACK_LENGTH ) { PR_DBG( 1, "OOPS, track #%i has reached it's full length\n", j ); st[j].counter = TRACK_LENGTH - 1; } for ( k=0; k<2; k++ ){ c[k] = st[k].counter; if ( st[k].time_d ){ t[k] = st[k].time_d[ c[k] ]; } else { t[k] = -1; } } // Make sure we're writing at the right place. The basic idea is to // have at most one element more than the other counter, but to make // sure that the new element is not 'more near' in time than the old // element. So, if we track A and B, and they hold a value from time // 10 and 2, respectively, and B has a new value at time-instant 11, // it will overwrite it's own value from time "2". // We suppose that this function is called with monotonely increasing // context->time_prepare // With the upcoming of 1D-lists, we have to rule this out, too if ( st[1-j].m >= 0 ){ if ( !c[j] || c[j] < c[1-j] ){ PR_DBG( 4, "First entry or catching up\n" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -