⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blockcollect.c

📁 这是一个c++编写的WCDMA链路采用RAKE接收的方针源代码
💻 C
字号:
/* | | Copyright disclaimer: |   This software was developed at the National Institute of Standards |   and Technology by employees of the Federal Government in the course |   of their official duties. Pursuant to title 17 Section 105 of the |   United States Code this software is not subject to copyright |   protection and is in the public domain. | |   We would appreciate acknowledgement if the software is used. |*//* | Project:	WCDMA simulation environment | Module:      Collects received symbols from rake and outputs |              data when desired amount of symbols is available. | Author:      Tommi Makelainen, Nokia/NIST | Date:        April 20, 1999 | | History: |              April 20, 1999 Tommi Makelainen |                      Initial version. | */#include <stdio.h>#include <stdlib.h>#include <math.h>#include "config_wcdma.h"#include "spreading.h"#include "blockcollect.h"#ifndef TRUE#define TRUE 1#define FALSE 0#endif /* TRUE *//* -------------------------------------------------------------------- */static symbol_buffer_count = 0;static enum instance_state symbuf_alloc_list[MAX_SYMBOL_BUFFERS];static int general_init_flag = 0;static symbol_buffer_t symbolbuffers[MAX_SYMBOL_BUFFERS];/* -------------------------------------------------------------------- *//* * Function:	wcdma_symbolbuffer_init * Desc.:	Inits symbol collect buffer. * * Returns:	=> 0 allocated instance number, -1 if no free buffers. * * Note:	 */int wcdma_symbolbuffer_init(        int block_size)		/* IN: block size to collect */{    int instance, i;    /*     * Check for free symbol buffers.     */    if (symbol_buffer_count < MAX_SYMBOL_BUFFERS) {        /*         * If first call, initialize static data.         */        if (general_init_flag == FALSE) {            for (i=0; i < MAX_SYMBOL_BUFFERS; i++) {                symbuf_alloc_list[i] = FREE_INSTANCE;            } /* for */            general_init_flag = TRUE;        } /* if general_init_flag */        /*         * Find first free instance number.         */        instance = -1;        for (i=0; i < MAX_SYMBOL_BUFFERS; i++) {            if (symbuf_alloc_list[i] == FREE_INSTANCE) {                instance = i;                break;            }        } /* for */        if (instance == -1) return(-1); /* no free instances */        /*         * Init new buffer.         */        symbolbuffers[instance].size = block_size;        symbolbuffers[instance].fill_index = 0;        symbolbuffers[instance].read_index = 0;        symbolbuffers[instance].buffer =                      (double *)calloc(2*block_size, sizeof(double) );        /*         * Update symbol buffer allocation list.         */        symbuf_alloc_list[instance] = INSTANCE_IN_USE;        symbol_buffer_count++;        return(instance);    } else {        return(-1);    } /* else symbol_buffer_count */}/* -------------------------------------------------------------------- *//* * Function:	wcdma_symbolbuffer_free * Desc.:	Frees one frame buffer. * * Note:	 */void wcdma_symbolbuffer_free(int instance){    symbolbuffers[instance].size = 0;    symbolbuffers[instance].fill_index = 0;    symbolbuffers[instance].read_index = 0;    free( symbolbuffers[instance].buffer );    symbuf_alloc_list[instance] = FREE_INSTANCE;    symbol_buffer_count--;    return;}/* -------------------------------------------------------------------- *//* * Function:	wcdma_symbolbuffer * Desc.:	Collects input symbols until symbols enough for *              one frame is available. Then outputs one frame. * * Note:	 */int wcdma_symbolbuffer(           int instance,	/* IN: instance number */	   double data[],	/* IN: input data symbol vector */           int data_len,	/* IN: length of input data vector */           int *output_ready,   /* OUT: 1=output available, 0=no output */           double out[])	/* OUT: output symbols for one block */{     int i;    int blocksize;    double *symbolbuf;    int symbols_in_buffer;    int fill_index;    int first_part;    /*     * Get settings for this buffer.     */    blocksize = symbolbuffers[instance].size;    fill_index = symbolbuffers[instance].fill_index;    symbolbuf = symbolbuffers[instance].buffer;    /*     * Copy data to buffer.     */    if ( (fill_index + data_len) < (2*blocksize) ) {       memcpy(symbolbuf+fill_index, data, data_len * sizeof(double) );    } else {       first_part = 2*blocksize - fill_index;       memcpy(symbolbuf+fill_index, data, first_part * sizeof(double) );       memcpy(symbolbuf, data+first_part,                         (data_len - first_part) * sizeof(double) );    }    symbolbuffers[instance].fill_index = (fill_index+data_len) % (2*blocksize);    /*     * If enough data, copy one blocksize of data to output vector.     */    if (symbolbuffers[instance].fill_index >                          symbolbuffers[instance].read_index) {        symbols_in_buffer = symbolbuffers[instance].fill_index -                            symbolbuffers[instance].read_index;    } else {        symbols_in_buffer = 2*blocksize -                            symbolbuffers[instance].read_index +                            symbolbuffers[instance].fill_index;    }    if (symbols_in_buffer >= blocksize) {        if (symbolbuffers[instance].fill_index >                          symbolbuffers[instance].read_index) {            memcpy(out, symbolbuf+symbolbuffers[instance].read_index,                   blocksize * sizeof(double) );        } else {            first_part = 2*blocksize - symbolbuffers[instance].read_index;            memcpy(out, symbolbuf+symbolbuffers[instance].read_index,                   first_part * sizeof(double) );            if (first_part < blocksize) {                memcpy(out+first_part, symbolbuf,                       (blocksize-first_part) * sizeof(double) );             }        }        symbolbuffers[instance].read_index =             (symbolbuffers[instance].read_index + blocksize) %             (2*blocksize);        *output_ready = 1;    }    return(0);} /* wcmda_symbolbuffer *//* -------------------------------------------------------------------- */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -