Exemplo n.º 1
0
Arquivo: source.c Projeto: alring/aloe
int work(void **inp, void **out) {
	int block_length, type;
	int i,j;
	int snd_samples;

	period_cnt++;
	if (period_cnt>=period) {
		period_cnt=0;
	}
	if (period_cnt) {
		return 0;
	}

	block_length = 0;
	if (param_get_int(blen_id,&block_length) != 1) {
		moderror("Getting integer parameter block_length\n");
		return -1;
	}
	type = 0;
	if (param_get_int(gen_id,&type) != 1) {
		moderror("Getting integer parameter type\n");
		return -1;
	}

	for(i=0;i<NOF_GENERATORS;i++) {
		if (generators[i].key == type) {
			break;
		}
	}
	if (i == NOF_GENERATORS) {
		moderror_msg("Generator type %d not implemented\n", type);
		return -1;
	}
	if (type != last_type) {
		moddebug("Select generator: %s\n",generators[i].desc);
		last_type = type;
	}

	if (block_length > OUTPUT_MAX_SAMPLES/generators[i].samp_sz) {
		moderror_msg("block_length %d too large. Maximum is %d for this generator\n",block_length,
				OUTPUT_MAX_SAMPLES/generators[i].samp_sz);
		return -1;
	}

#ifdef _COMPILE_ALOE
	if (block_length != last_block_length) {
		moddebug("Select block_length: block_length=%d at tslot=%d\n",block_length,oesr_tstamp(ctx));
		last_block_length = block_length;
	}
#endif

	snd_samples = generators[i].work(out[0],block_length);

#ifdef _COMPILE_ALOE
	moddebug("Sent %d samples at ts=%d\n",snd_samples,oesr_tstamp(ctx));
#endif
	return snd_samples;
}
Exemplo n.º 2
0
/**
 * @ingroup Lte Rate Matching of convolutionally encoded information
 * Applied for PDCCH
 *
 * Main DSP function
 *
 *
 * \param inp Input interface buffers. The value inp[i] points to the buffer received
 * from the i-th interface. The function get_input_samples(i) returns the number of received
 * samples (the sample size is by default sizeof(input_t))
 *
 * \param out Output interface buffers. The value out[i] points to the buffer where the samples
 * to be sent through the i-th interfaces must be stored.
 *
 * \param E Number of output bits of rate matching in transmitter mode
 * \param S Number of output bits of rate matching in receiver mode
 *
 * @return On success, returns a non-negative number indicating the output
 * samples that should be transmitted through all output interface. To specify a different length
 * for certain interface, use the function set_output_samples(int idx, int len)
 * On error returns -1.
 */
int work(void **inp, void **out) {
	int S, E;
	int rcv_samples, snd_samples;
	char *input_b;
	char *output_b;
	float *input_f;
	float *output_f;

	rcv_samples = get_input_samples(0);
	if (!rcv_samples || !out[0] || rcv_samples > 3*6114) {
		return 0;
	}

	input_f = inp[0];
	input_b = inp[0];
	output_f = out[0];
	output_b = out[0];

	if (!direction) {
		/* @Transmitter */
		if (param_get_int(E_id, &E) != 1) {
			moderror("Error getting parameter 'E', indiciating the "
			  "number of rate matching output samples in Tx mode.\n");
			return -1;
		}
		if (E > OUTPUT_MAX_SAMPLES) {
			moderror("Too may output samples (E).\n");
			return -1;
		}
		rate_matching(input_b, output_b, rcv_samples, E);
		snd_samples = E;

	} else {
		/* @Receiver */
		if (param_get_int(S_id, &S) != 1) {
			moderror("Error getting parameter 'S', indiciating the "
			  "number of rate matching output samples in Rx mode\n");
			return -1;
		}
		if (S > OUTPUT_MAX_SAMPLES) {
			moderror("Too may output samples (S).\n");
			return -1;
		}
		if (S%3 > 0) {
			moderror("Number of output samples S not integer divisible by 3.\n");
			return -1;
		}
		snd_samples = rate_unmatching(input_f, output_f, rcv_samples, S);
	}

	return snd_samples;
}
Exemplo n.º 3
0
/**
 * @ingroup lte_ratematching
 *
 * Main DSP function
 *
 */
int work(void **inp, void **out) {
	int i, in_pkt_len, out_pkt_len, j;
	int rcv_samples;

	char *input, *output;

	param_get_int(pre_padding_id, &pre_padding);
	param_get_int(post_padding_id, &post_padding);
	param_get_int(nof_packets_id, &nof_packets);

	for (i=0;i<NOF_INPUT_ITF;i++) {
		input = inp[i];
		output = out[i];
		rcv_samples = get_input_samples(i);
		moddebug("%d samples received on input interface %d.\n",rcv_samples,i);
		if (rcv_samples == 0) {
			moddebug("%d samples to process. Returning.\n", rcv_samples);
			continue;
		}

		if ((rcv_samples) % nof_packets) {
			moderror_msg("Received samples (%d) should multiple of "
			"nof_packets (%d)\n", rcv_samples, nof_packets);
			return -1;
		}

		in_pkt_len = rcv_samples / nof_packets;
		if (direction) {
			out_pkt_len = in_pkt_len - pre_padding - post_padding;
		} else {
			out_pkt_len = in_pkt_len + pre_padding + post_padding;
		}

		if (in_pkt_len) {
			if (direction) {
				for (j=0;j<nof_packets;j++) {
					memcpy(outaddr(0),inaddr(pre_padding),input_sample_sz*out_pkt_len);
				}
			} else {
				for (j=0;j<nof_packets;j++) {
					memset(outaddr(0),0,input_sample_sz*pre_padding);
					memcpy(outaddr(pre_padding),inaddr(0),input_sample_sz*in_pkt_len);
					memset(outaddr(pre_padding+in_pkt_len),0,input_sample_sz*post_padding);
				}
			}
			moddebug("%d samples sent to output interface %d.\n",out_pkt_len*nof_packets, i);
			set_output_samples(i,out_pkt_len*nof_packets);
		}

	}
	return 0;
}
Exemplo n.º 4
0
/**@ingroup gen_dft
 * \param direction Direction of the dft: 0 computes a dft and 1 computes an idft (default is 0)
 * \param mirror 0 computes a normal dft, 1 swaps the two halfes of the input signal before computing
 * the dft (used in LTE) (default is 0)
 * \param psd Set to 1 to compute the power spectral density (untested) (default is 0)
 * \param out_db Set to 1 to produce the output results in dB (untested) (default is 0)
 * \param dft_size Number of DFT points. This parameter is mandatory.
 */
int initialize() {
	int tmp;
	int i;

	memset(plans,0,sizeof(dft_plan_t)*NOF_PRECOMPUTED_DFT);
	memset(extra_plans,0,sizeof(dft_plan_t)*MAX_EXTRA_PLANS);

	if (param_get_int(param_id("direction"),&direction) != 1) {
		modinfo("Parameter direction not defined. Setting to FORWARD\n");
		direction = 0;
	}

	options = 0;
	if (param_get_int(param_id("mirror"),&tmp) != 1) {
		modinfo("Parameter mirror not defined. Disabling. \n");
	} else {
		if (tmp) options |= DFT_MIRROR;
	}
	if (param_get_int(param_id("psd"),&tmp) != 1) {
		modinfo("Parameter psd not defined. Disabling. \n");
	} else {
		if (tmp) options |= DFT_PSD;
	}
	if (param_get_int(param_id("out_db"),&tmp) != 1) {
		modinfo("Parameter out_db not defined. Disabling. \n");
	} else {
		if (tmp) options |= DFT_OUT_DB;
	}
	if (param_get_int(param_id("normalize"),&tmp) != 1) {
		modinfo("Parameter normalize not defined. Disabling. \n");
	} else {
		if (tmp) options |= DFT_NORMALIZE;
	}

	dft_size_id = param_id("dft_size");
	if (!dft_size_id) {
		moderror("Parameter dft_size not defined\n");
		return -1;
	}

	if (dft_plan_multi_c2c(precomputed_dft_len, (!direction)?FORWARD:BACKWARD, NOF_PRECOMPUTED_DFT,
			plans)) {
		moderror("Precomputing plans\n");
		return -1;
	}
	for (i=0;i<NOF_PRECOMPUTED_DFT;i++) {
		plans[i].options = options;
	}

	return 0;
}
Exemplo n.º 5
0
/**@ingroup gen_crc
 * Adds a CRC to every received packet from each interface
 */
int work(void **inp, void **out) {
	int i;
	unsigned int n;
	input_t *input;

	if (poly_id) param_get_int(poly_id,&poly);
	if (long_crc_id) param_get_int(long_crc_id, &long_crc);

	for (i=0;i<NOF_INPUT_ITF;i++) {
		if (get_input_samples(i)) {
			moddebug("rcv_len=%d\n",get_input_samples(i));
			memcpy(out[i],inp[i],sizeof(input_t)*get_input_samples(i));
			input = out[i];
			n = icrc(0, input, get_input_samples(i), long_crc, poly, mode == MODE_ADD);

			if (mode==MODE_CHECK) {
				if (n) {
					total_errors++;
				}
				total_pkts++;
				set_output_samples(i,get_input_samples(i)-long_crc);

				if (!print_nof_pkts) {
					tscnt++;
					if (tscnt==interval_ts) {
						tscnt=0;
						#ifdef PRINT_BLER
						printf("Total blocks: %d\tTotal errors: %d\tBLER=%g\n",
								total_pkts,total_errors,(float)total_errors/total_pkts);
						#endif
					}
				} else {
					print_nof_pkts_cnt++;
					if (print_nof_pkts_cnt == print_nof_pkts) {
						print_nof_pkts_cnt=0;
						printf("Total blocks: %d\tTotal errors: %d\tBLER=%g\n",
								total_pkts,total_errors,(float)total_errors/total_pkts);
						total_pkts=0;
						total_errors=0;
					}
				}

			} else {
				set_output_samples(i,get_input_samples(i)+long_crc);
			}
		}
	}
	return 0;
}
Exemplo n.º 6
0
/** Stores in the address of the second parameter the scalar integer value of the
 * parameter name.
 * Tries to parse the parameter as an integer. Read param_addr() for supported formats.
 * \returns 0 on success or -1 on error.
 */
int param_get_int_name(char *name, int *value) {
	pmid_t id = param_id(name);
	if (id == NULL) {
		return -1;
	}
	return (param_get_int(id,value)==-1)?-1:0;
}
Exemplo n.º 7
0
/**
 * @ingroup udp_sink
 *
 *  Writes the received samples to the dac output buffer
 *
 */
int work(void **inp, void **out) {
	int rcv_samples;
	int n;
	char tmp[16];
	int nof_pkts,pkt_len,i;
	input_t *input = inp[0];

	rcv_samples = get_input_samples(0);
	if (!rcv_samples) {
		return 0;
	}

	nof_pkts=1;
	param_get_int(blen_id,&nof_pkts);

	if (rcv_samples % nof_pkts) {
		modinfo_msg("Warning received packet len %d not multiple of %d packets\n",
				rcv_samples,nof_pkts);
	}
	pkt_len = rcv_samples/nof_pkts;

	modinfo_msg("Sending %d packets of %d bytes\n",nof_pkts,pkt_len);

	for (i=0;i<nof_pkts;i++) {
		n = sendto(fd,&input[i*pkt_len],pkt_len,0,(struct sockaddr *) &servaddr, sizeof (servaddr));
		if (n == -1) {
			perror("sendto");
			return -1;
		}
	}

	return 0;
}
Exemplo n.º 8
0
Arquivo: source.c Projeto: alring/aloe
/**@ingroup source
 *
 * The available generators are defined in generators.h
 * \param block_length Number of items (bits or samples) to generate
 * \param generator Integer indicating the generator (see generators.h)
 *
 */
int initialize() {
	int size;
	int block_length;

	blen_id = param_id("block_length");
	if (!blen_id) {
		moderror("Parameter block_length not found\n");
		return -1;
	}

	if (param_get_int(blen_id,&block_length) != 1) {
		moderror("Getting integer parameter block_length\n");
		return -1;
	}

	period=1;
	param_get_int_name("period",&period);
	period_cnt=period;

	generator_init_random();

	moddebug("Parameter block_length is %d\n",block_length);

	gen_id = param_id("generator");
	if (!gen_id) {
		moderror("Parameter type not found\n");
		return -1;
	}

	last_type = -1;

	return 0;
}
Exemplo n.º 9
0
/**
 * Generates input signal. VERY IMPORTANT to fill length vector with the number of
 * samples that have been generated.
 * @param inp Input interface buffers. Data from other interfaces is stacked in the buffer.
 * Use in(ptr,idx) to access the address.
 *
 * @param lengths Save on n-th position the number of samples generated for the n-th interface
 */
int generate_input_signal(void *in, int *lengths)
{
	int i;
	input_t *input = in;
	int block_length;
	pmid_t blen_id;

	blen_id = param_id("block_length");
	if (!blen_id) {
		moderror("Parameter block_length not found\n");
		return -1;
	}
	if (!param_get_int(blen_id,&block_length)) {
		moderror("Getting integer parameter block_length\n");
		return -1;
	}

	modinfo_msg("Parameter block_length is %d\n",block_length);


	/** HERE INDICATE THE LENGTH OF THE SIGNAL */
	lengths[0] = block_length;

	for (i=0;i<block_length;i++) {
		input[i] = 0.7 + 0.7*_Complex_I;
	}
	return 0;
}
Exemplo n.º 10
0
/**
 *  Generates input signal. VERY IMPORTANT to fill length vector with the number of
 * samples that have been generated.
 * @param inp Input interface buffers. Data from other interfaces is stacked in the buffer.
 * Use in(ptr,idx) to access the address.
 *
 * @param lengths Save on n-th position the number of samples generated for the n-th interface
 */
int generate_input_signal(void *in, int *lengths)
{
  int i;
  input_t *input = in;
  int block_length;
  pmid_t blen_id;

  blen_id = param_id("block_length");
  if (!blen_id) {
    moderror("Parameter block_length not found\n");
    return -1;
  }
  if (!param_get_int(blen_id,&block_length)) {
    moderror("Getting integer parameter block_length\n");
    return -1;
  }

  modinfo_msg("Parameter block_length is %d\n",block_length);


  /** HERE INDICATE THE LENGTH OF THE SIGNAL */
  lengths[0] = block_length;

  for (i=0;i<block_length;i++) {
#ifdef GENESRSLTE_TCOD_RATE_COMPLEX
    __real__ input[i] = (float) ((i+offset)%(block_length));
    __imag__ input[i] = (float) ((block_length-i-1+offset)%(block_length));
#else
    input[i] = (i+offset)%(block_length);
#endif
  }
  offset++;
  return 0;
}
Exemplo n.º 11
0
/**
 * @ingroup lte_resource_mapper
 *
 *  Main DSP function
 *
 * This function allocates the data symbols of one slot (0.5 ms) in the corresponding place
 * of the LTE frame grid. During initialization phase CRS, PSS and SSS signals has been
 * incorporated and will no be modified during run phase.
 * PBCH (Physical Broadcast Channel), PCFICH (Physical Control Format Indicator Channel) &
 * PDCCH (Physical Downlink Control Channel) will be incorporated.
 *
 */
int work(void **inp, void **out) {

	if (subframe_idx_id) {
		param_get_int(subframe_idx_id, &subframe_idx);
	}
#ifdef CHECK_RCV_SAMPLES
	int n;
	n=check_received_samples_mapper();
	if (n < 1) {
		return n;
	}
#endif

#ifdef _COMPILE_ALOE
	moddebug("subframe_idx=%d tstamp=%d rcv=%d\n",subframe_idx,oesr_tstamp(ctx),get_input_samples(0));
#endif

	if (allocate_all_channels(inp,out[0])) {
		moderror("Error allocating channels\n");
		return 0;
	}

	subframe_idx++;
	if (subframe_idx==NOF_SUBFRAMES_X_FRAME) {
		subframe_idx=0;
	}

	return 0;
}
Exemplo n.º 12
0
/*=============================================================================

FUNCTION sh_boot_get_bootmode_to_user

DESCRIPTION

DEPENDENCIES
  None

RETURN VALUE

SIDE EFFECTS
  None

NOTE
  None

=============================================================================*/
static int sh_boot_get_bootmode_to_user(char *buffer, const struct kernel_param *kp)
{
	int ret = 0;

	boot_mode = sh_boot_get_bootmode();
	ret = param_get_int(buffer, kp);

	return ret;
}
Exemplo n.º 13
0
/*=============================================================================

FUNCTION sh_boot_get_handset_to_user

DESCRIPTION

DEPENDENCIES
  None

RETURN VALUE

SIDE EFFECTS
  None

NOTE
  None

=============================================================================*/
static int sh_boot_get_handset_to_user(char *buffer, const struct kernel_param *kp)
{
	int ret = 0;

	handset = sh_boot_get_handset();
	ret = param_get_int(buffer, kp);

	return ret;
}
Exemplo n.º 14
0
int initialize() {
	int tslen;

	if (param_get_int_name("direction",&mode)) {
		mode = MODE_ADD;
	}

	if (param_get_int_name("print_nof_pkts",&print_nof_pkts)) {
		print_nof_pkts = 0;
	} else {
		print_nof_pkts_cnt = 0;
	}

	long_crc_id = param_id("long_crc");
	if (param_get_int(long_crc_id,&long_crc) != 1) {
		modinfo_msg("Parameter long_crc not configured. Set to %d\n",
				DEFAULT_LONG_CRC);
		long_crc = DEFAULT_LONG_CRC;
		long_crc_id = NULL;
	}

	poly_id = param_id("poly");
	if (param_get_int(poly_id,&poly) != 1) {
		poly = DEFAULT_POLY;
		poly_id = NULL;
	}


#ifdef _COMPILE_ALOE
	tslen = oesr_tslot_length(ctx);
	if (tslen > EXEC_MIN_INTERVAL_MS*1000) {
		interval_ts = 1;
	} else {
		interval_ts = (EXEC_MIN_INTERVAL_MS*1000)/tslen;
		modinfo_msg("Timeslot is %d usec, refresh interval set to %d tslots\n",tslen,interval_ts);
	}
#endif
	total_errors=0;
	total_pkts=0;
	tscnt=0;
	return 0;
}
Exemplo n.º 15
0
/**
 * @ingroup Zero padding/unpadding
 * This module has two operational modes.
 * Zero-padding mode (direction = 0): Pads pre_padding and post_padding zeros
 * to each of the nof_packets data packets
 * Sample-unpadding mode (direction != 0): Eliminates pre_padding and
 * post_padding samples from each of the nof_packets data packets
 *
 * \param data_type Specify data type: 0 for _Complex float, 1 for real, 2 for
 * char (default: 0)
 * \param direction Padding if 0 and unpadding otherwise (default: 0)
 * \param pre_padding Number of samples to be added to/ eliminated from the
 * beginning of the packet
 * \param post_padding Number of samples to be added to/ eliminated from the
 * end of the packet
 * \param nof_packets Number of data packets that the input stream contains
 *
 * \returns This function returns 0 on success or -1 on error
 */
int initialize() {
	int data_type;

	if (param_get_int(param_id("data_type"),&data_type) != 1) {
		modinfo("Parameter data_type undefined. Using complex data type\n");
		data_type = DATA_TYPE_COMPLEX;
	}

	input_sample_sz = get_input_sample_sz(data_type);
	output_sample_sz = input_sample_sz;
	moddebug("Chosen data type %d sample_sz=%d\n",data_type, input_sample_sz);

	if (param_get_int(param_id("direction"),&direction) != 1) {
		modinfo("Parameter direction undefined. Assuming padding mode.\n");
		direction = 0;
	}

	pre_padding_id = param_id("pre_padding");
	if (!pre_padding_id) {
		modinfo("Parameter pre_padding undefined. Adding 0 bits.\n");
		pre_padding = 0;
	}

	post_padding_id = param_id("post_padding");
	if (!post_padding_id) {
		modinfo("Parameter post_padding undefined. Adding 0 bits.\n");
		post_padding = 0;
	}

	nof_packets_id = param_id("nof_packets");
	if (!nof_packets_id) {
		modinfo("Parameter nof_packets undefined. Assuming 1 packet.\n");
		nof_packets = 1;
	}

	return 0;
}
Exemplo n.º 16
0
/**
 * @ingroup gen_hard_demod
 *
 * Main DSP function
 *
 * Calls the appropriate function for demodulating all recevied symbols.
 *
 * \param inp Input interface buffers. The value inp[i] points to the buffer received
 * from the i-th interface. The function get_input_samples(i) returns the number of received
 * samples (the sample size is by default sizeof(input_t))
 *
 * \param out Output interface buffers. The value out[i] points to the buffer where the samples
 * to be sent through the i-th interfaces must be stored.
 *
 * @return On success, returns a non-negative number indicating the output
 * samples that should be transmitted through all output interface. To specify a different length
 * for certain interface, use the function set_output_samples(int idx, int len)
 * On error returns -1.
 *
 *
 */
int work(void **inp, void **out) {

	int rcv_samples, snd_samples;
	int modulation;

	int bits_per_symbol;
	input_t *input;
	output_t *output;
	float *inreal;

	if (!get_input_samples(0)) {
		return 0;
	}

	/* Dynamically obtain modulation type */
	if (param_get_int(modulation_id, &modulation) != 1) {
		moderror("Error getting 'modulation' parameter. Assuming BPSK.\n");
		modulation = BPSK;
	}

	/* Verify parameters */
	if ((modulation != BPSK) && (modulation != QPSK) && (modulation != QAM16) && (modulation != QAM64)) {
		moderror_msg("Invalid modulation %d. Specify 1 for BPSK, 2 for QPSK,"
				"4 for 16QAM, or 6 for 64QAM\n", modulation);
		return -1;
	}

	input = inp[0];
	output = out[0];
	rcv_samples = get_input_samples(0); /* number of input samples */
	bits_per_symbol = get_bits_per_symbol(modulation);
	if (in_real) {
		inreal = inp[0];
		hard_demod_real(inreal, output, rcv_samples, modulation);
	} else {
		hard_demod(input, output, rcv_samples, modulation);
	}
	snd_samples = rcv_samples*bits_per_symbol;

	return snd_samples;
}
Exemplo n.º 17
0
int work(void **inp, void **out) {
	int i,n;
#if NOF_INPUTS>1
	for (i=0;i<NOF_INPUT_ITF;i++) {
		binsource.input[i] = inp[i];
		binsource.in_len[i] = get_input_samples(i)
	}
#elif NOF_INPUTS == 1
	binsource.input = inp[0];
	binsource.in_len = get_input_samples(0);
#endif

#if NOF_OUTPUTS>1
	for (i=0;i<NOF_OUTPUT_ITF;i++) {
		binsource.output[i] = out[i];
		binsource.out_len = &out_len[i];
	}
#elif NOF_OUTPUTS == 1
	binsourceoutput = out[0];
	binsource.out_len = &out_len[0];
#endif

	/* Get input parameters */
	if (param_get_int(nbits_id, &binsource.ctrl_in.nbits) != 1) {
		moderror("Error getting parameter nbits\n");
		return -1;
	}

	/* call work */
	n = binsource_work(&binsource);

	/* Set output nof_samples */
	for (i=0;i<NOF_OUTPUT_ITF;i++) {
		set_output_samples(i,out_len[i]);
		binsource.out_len = &out_len[i];
	}

	/* Set output parameters */

	return n;
}
Exemplo n.º 18
0
int work(void **inp, void **out) {
	int i, out_len;
	input_t *input;
	output_t *output;

	param_get_int(modulation_id,&modulation);

	for (i=0;i<NOF_INPUT_ITF;i++) {
		input = inp[i];
		output = out[i];

		if (get_input_samples(i)) {
			out_len = modulate(input,output,get_input_samples(i));
			if (out_len == -1) {
				return -1;
			}
			set_output_samples(i,out_len);
		}
	}
	return 0;
}
Exemplo n.º 19
0
int work(void **inp, void **out) {
	int i, j, nof_fft;
	int dft_size;
	input_t *input;
	output_t *output;
	dft_plan_t *plan;

	if (param_get_int(dft_size_id,&dft_size) != 1) {
		moderror("Getting parameter dft_size\n");
		return -1;
	}

	plan = find_plan(dft_size);
	if (!plan) {
		if ((plan = generate_new_plan(dft_size)) == NULL) {
			moderror("Generating plan.\n");
			return -1;
		}
	}

	for (i=0;i<NOF_INPUT_ITF;i++) {
		input = inp[i];
		output = out[i];

		if (get_input_samples(i) % dft_size) {
			moderror_msg("Number of input samples (%d) must be multiple of dft_size (%d), in "
					"interface %d\n",get_input_samples(i),dft_size,i);
			return -1;
		}

		nof_fft = get_input_samples(i)/dft_size;

		for (j=0;j<nof_fft;j++) {
			dft_run_c2c(plan, &input[j*dft_size], &output[j*dft_size]);
		}

		set_output_samples(i,dft_size*nof_fft);
	}
	return 0;
}
Exemplo n.º 20
0
/**
 * @ingroup lte_resource_mapper
 *
 *  Main DSP function
 *
 * This function allocates the data symbols of one slot (0.5 ms) in the corresponding place
 * of the LTE frame grid. During initialization phase CRS, PSS and SSS signals has been
 * incorporated and will no be modified during run phase.
 * PBCH (Physical Broadcast Channel), PCFICH (Physical Control Format Indicator Channel) &
 * PDCCH (Physical Downlink Control Channel) will be incorporated.
 *
 */
int work(void **inp, void **out) {
	int n;

	subframe_idx=-1;
	if (subframe_idx_id) {
		param_get_int(subframe_idx_id, &subframe_idx);
	}

#ifdef _COMPILE_ALOE
	moddebug("subframe_idx=%d tstamp=%d rcv_len=%d cfi=%d\n",subframe_idx,oesr_tstamp(ctx),
		get_input_samples(0),grid.cfi);
#endif

	if (subframe_idx==-1) {
		return 0;
	}

	n=check_received_samples_demapper();
	if (n < 1) {
		return n;
	}

	if (channels_init_grid(channel_ids, nof_channels)) {
		moderror("Initiating resource grid\n");
		return 0;
	}

	if (deallocate_all_channels(channel_ids, nof_channels, inp[0],out)) {
		return -1;
	}
	if (extract_refsig(inp[0],out)) {
		return -1;
	}

	if (copy_signal(inp[0],out)) {
		return -1;
	}

	return 0;
}
Exemplo n.º 21
0
/**
 * @ingroup gen_hard_demod
 *
 * Main DSP function
 *
 * Calls the appropriate function for demodulating all recevied symbols.
 *
 * \param inp Input interface buffers. The value inp[i] points to the buffer received
 * from the i-th interface. The function get_input_samples(i) returns the number of received
 * samples (the sample size is by default sizeof(input_t))
 *
 * \param out Output interface buffers. The value out[i] points to the buffer where the samples
 * to be sent through the i-th interfaces must be stored.
 *
 * @return On success, returns a non-negative number indicating the output
 * samples that should be transmitted through all output interface. To specify a different length
 * for certain interface, use the function set_output_samples(int idx, int len)
 * On error returns -1.
 *
 *
 */
int work(void **inp, void **out) {
	int i;
	int rcv_samples, snd_samples;
	int modulation;
	float sigma2;
	int bits_per_symbol;
	input_t *input;
	output_t *output;

	/* Dynamically obtain modulation type */
	if (param_get_int(modulation_id, &modulation) != 1) {
		moderror("Error getting 'modulation' parameter. Assuming QPSK.\n");
		modulation = QPSK;
	}

	/* Verify parameters */
	if (modulation > 3 || modulation < 0) {
		moderror_msg("Invalid modulation %d. Specify 0 for BPSK, 1 for QPSK,"
				"2 for 16QAM, or 3 for 64QAM\n", modulation);
		return -1;
	} else {
		modinfo_msg("Modulation type is %d (0:BPSK; 1:QPSK; 2:16QAM;"
				"3:64QAM)\n",modulation);
	}

	input = inp[0];
	output = out[0];
	rcv_samples = get_input_samples(0); /* number of input samples */
	bits_per_symbol = get_bits_per_symbol(modulation);
	hard_demod(input, output, rcv_samples, modulation);
	snd_samples = rcv_samples*bits_per_symbol;

/*	printf("\n\n");
	for (i=0; i<snd_samples; i++) {
		printf("%d",output[i]);
	}
*/
	return snd_samples;
}
Exemplo n.º 22
0
int process_params() {
	float _rate,_gain,_freq;
	if (param_get_float(rate_id,&_rate) != 1) {
		modinfo("Getting parameter rate\n");
		return -1;
	}
	if (_rate != rate) {
		rate = _rate;
		_rate = rtdal_dac_set_rx_srate(dac,rate);
		modinfo_msg("Set TX sampling rate %g MHz\n", _rate/1000000);
	}

	if (param_get_float(freq_id,&_freq) != 1) {
		modinfo("Getting parameter freq\n");
		return -1;
	}
	if (_freq != freq) {
		freq = _freq;
		_freq = rtdal_dac_set_rx_freq(dac,freq);
		modinfo_msg("Set TX freq %g MHz\n",_freq/1000000);
	}

	if (gain_id) {
		if (param_get_float(gain_id,&_gain) != 1) {
			modinfo("Getting parameter gain\n");
			return -1;
		}
	} else {
		_gain = 0.0;
	}
	if (_gain != gain) {
		gain = _gain;
		_gain = rtdal_dac_set_rx_gain(dac,gain);
		modinfo_msg("Set TX gain %g dB (%g)\n",_gain,gain);
	}
	param_get_int(nsamples_id, &nsamples);
	return 0;
}
Exemplo n.º 23
0
static int emscripten_setup(struct sim_state *s, const struct run_ops *ops,
        void **run_data, void *ops_data)
{
    struct emscripten_wrap data = {
        .s = s,
        .ops = ops,
        .run_data = run_data,
        .ops_data = ops_data,
        .insns_per_frame = 1,
    };

    param_get_int(s->conf.params, "emscripten.insns_per_anim_frame", &data.insns_per_frame);
    emscripten_cancel_main_loop(); // In case we get called more than once
    emscripten_set_main_loop_arg(emscripten_wrap_step, &data, 0, 1);

    return data.rc;
}

int recipe_emscript(struct sim_state *s)
{
    s->run_sim = emscripten_setup;
    return 0;
}
Exemplo n.º 24
0
/**
 * Generates input signal. VERY IMPORTANT to fill length vector with the number of
 * samples that have been generated.
 * @param inp Input interface buffers. Data from other interfaces is stacked in the buffer.
 * Use in(ptr,idx) to access the address.
 *
 * @param lengths Save on n-th position the number of samples generated for the n-th interface
 */
int generate_input_signal(void *in, int *lengths)
{
	int i;
	input_t *input = in;
	int block_length;
	pmid_t blen_id;
	int size;

	blen_id = param_id("block_length");
	if (!blen_id) {
		moderror("Parameter block_length not found\n");
		return -1;
	}
	if (!param_get_int(blen_id,&block_length)) {
		moderror("Getting integer parameter block_length\n");
		return -1;
	}

	modinfo_msg("Parameter block_length is %d\n",block_length);


	/** HERE INDICATE THE LENGTH OF THE SIGNAL */
	lengths[0] = block_length;

	for (i=0;i<block_length;i++) {
		input[i] = 0x1;
	}
	/* UL: test*/
	input[10] = 'x';
	input[11] = 'x';
	input[12] = 'x';
	input[13] = 'x';
	input[14] = 'y';

	return 0;
}
static int hp_state_get(char *buffer, const struct kernel_param *kp)
{
    return param_get_int(buffer, kp);
}
Exemplo n.º 26
0
static int min_online_cpus_fn_get(char *buffer, const struct kernel_param *kp)
{
    return param_get_int(buffer, kp);
}
Exemplo n.º 27
0
static int wakeup_delay_time_get(char *buffer, const struct kernel_param *kp)
{
	int ret = param_get_int(buffer, kp);
	return param_get_int(buffer, kp);
}
Exemplo n.º 28
0
int work(void **inp, void **out) {
	int i, j, k;
	int rcv_samples, nof_ffts;
	int df, fs;
	int e;
	int dft_size;
	input_t *input;
	output_t *output;
	dft_plan_t *plan;
	
 
	if (param_get_int(dft_size_id,&dft_size) != 1) {
		dft_size = get_input_samples(0);
		moddebug("Parameter dft_size not defined. Assuming %d"
		" (number of input samples on interface 0).\n", dft_size);
		/*moderror("Getting parameter dft_size\n");
		return -1;*/
	}

	if (dft_size == 0) {
		modinfo("dft_size = 0. Returning.\n");
		return 0;
	} else {
		moddebug("dft_size = %d.\n", dft_size);
	}
	
/*	if (param_get_int(param_id("dft_size"),&dft_size) != 1) {
		
		moddebug("Parameter dft_size not defined. Assuming %d"
			" (number of input samples on interface 0).\n", dft_size);
	}
*/
	plan = find_plan(dft_size);
	if (!plan) {
		if ((plan = generate_new_plan(dft_size)) == NULL) {
			moderror("Generating plan.\n");
			return -1;
		}
	}
	
	if (param_get_int(df_id, &df) != 1) {
		df = 0;
	}
	if (df != 0) {
		if (param_get_int(fs_id, &fs) != 1) {
			moderror("Parameter fs not defined.\n");
			return -1;
		}
		if (fs <= 0) {
			moderror("Sampling rate fs must be larger than 0.\n");
			return -1;
		}
		if ((df != previous_df) || (fs != previous_fs) || (dft_size != previous_dft_size)) {
			e = process_shift_params(df, fs, dft_size);
			if (e < 0) {
				return -1;
			}
			previous_df = df;
			previous_fs = fs;
			previous_dft_size = dft_size;
		}
	}

	for (i=0;i<NOF_INPUT_ITF;i++) {
		input = inp[i];
		output = out[i];
		rcv_samples = get_input_samples(i);
		moddebug("%d samples received on interface %d.\n",rcv_samples, i);
		if (rcv_samples == 0) {
			moddebug("%d samples to process. Returning.\n", rcv_samples);
			continue;
		}
		moddebug("Processing %d samples...\n",rcv_samples);

		if (rcv_samples % dft_size) {
			moderror_msg("Number of input samples (%d) not integer multiple"
			" of dft_size (%d) on interface %d\n",rcv_samples,dft_size,i);
			return -1;
		}
		if (get_input_samples(0)>0) {
			modinfo_msg("received %d samples\n",get_input_samples(0));
		}

		nof_ffts = rcv_samples/dft_size;

		for (j=0;j<nof_ffts;j++) {
			if ((df != 0) && (direction == FORWARD)) { /* Rx: shift before FFT */
				for (k=0;k<dft_size;k++) {
					input[j*dft_size+k] *= shift[k*shift_increment];
				}
			}

			dft_run_c2c(plan, &input[j*dft_size], &output[j*dft_size]);

			if ((df !=0) && (direction == BACKWARD)) { /* Tx: shift after IFFT */
				for (k=0;k<dft_size;k++) {
					output[j*dft_size+k] *= shift[k*shift_increment];
				}
			}
		}

		set_output_samples(i,dft_size*nof_ffts);
		moddebug("%d samples sent to output interface %d.\n",dft_size*nof_ffts,i);
	}

	return 0;
}
Exemplo n.º 29
0
/**@ingroup gen_dft
 * \param direction Direction of the dft: 0 computes a dft and 1 computes an idft (default is 0)
 * \param mirror 0 computes a normal dft, 1 swaps the two halfes of the input signal before computing
 * the dft (used in LTE) (default is 0)
 * \param dc_offset Set a null to the 0 subcarrier
 * \param psd Set to 1 to compute the power spectral density (untested) (default is 0)
 * \param out_db Set to 1 to produce the output results in dB (untested) (default is 0)
 * \param dft_size Number of DFT points. This parameter is mandatory.
 * \param df Frequency shift (choose a positive value for upconversion and a negative value for 
 * downconversion) (default is 0--no frequency shift)
 * \param fs Sampling rate. This parameter is mandatory if df!=0.
 */
int initialize() {
	int tmp;
	int i;

	memset(plans,0,sizeof(dft_plan_t)*NOF_PRECOMPUTED_DFT);
	memset(extra_plans,0,sizeof(dft_plan_t)*MAX_EXTRA_PLANS);

	if (param_get_int(param_id("direction"),&direction) != 1) {
		modinfo("Parameter direction not defined. Setting to FORWARD\n");
		direction = 0;
	}

	options = 0;
	if (param_get_int(param_id("mirror"),&tmp) != 1) {
		modinfo("Parameter mirror not defined. Disabling. \n");
	} else {
		if (tmp == 1) {
			options |= DFT_MIRROR_PRE;
		} else if (tmp == 2) {
			options |= DFT_MIRROR_POS;
		}
	}
	if (param_get_int(param_id("psd"),&tmp) != 1) {
		modinfo("Parameter psd not defined. Disabling. \n");
	} else {
		if (tmp) options |= DFT_PSD;
	}
	if (param_get_int(param_id("out_db"),&tmp) != 1) {
		modinfo("Parameter out_db not defined. Disabling. \n");
	} else {
		if (tmp) options |= DFT_OUT_DB;
	}
	if (param_get_int(param_id("dc_offset"),&tmp) != 1) {
		modinfo("Parameter dc_offset not defined. Disabling. \n");
	} else {
		if (tmp) options |= DFT_DC_OFFSET;
	}
	if (param_get_int(param_id("normalize"),&tmp) != 1) {
		modinfo("Parameter normalize not defined. Disabling. \n");
	} else {
		if (tmp) options |= DFT_NORMALIZE;
	}

	dft_size_id = param_id("dft_size");
	if (!dft_size_id) {
/*		moderror("Parameter dft_size not defined\n");
		return -1;*/
		modinfo("Parameter dft_size not defined. Assuming "
			"dft_size = number of input samples on interface 0.\n");
	}
		

	if (dft_plan_multi_c2c(precomputed_dft_len, (!direction)?FORWARD:BACKWARD, NOF_PRECOMPUTED_DFT,
			plans)) {
		moderror("Precomputing plans\n");
		return -1;
	}
	for (i=0;i<NOF_PRECOMPUTED_DFT;i++) {
		plans[i].options = options;
	}

	df_id = param_id("df");
	fs_id = param_id("fs");
	precalculate_shift_vectors(precomputed_shift_1536, precomputed_shift_reg);

	/* assume 1.4 MHz LTE UL Tx (fs = 1.92 MHz, 128 IFFT, df = 7.5 kHz) */
	shift = precomputed_shift_reg;
	previous_df = df_lte;
	previous_fs = 1920000;
	previous_dft_size = 128;
	shift_increment = 16;

	return 0;
}
static int mp_policy_get(char *buffer, const struct kernel_param *kp)
{
	return param_get_int(buffer, kp);
}