Ejemplo n.º 1
0
Status SynchronousBuffer::MemoryGet(void* dest, size_t length)
{
	// TODO copy something from buffer to dest

	int rtn;
	if ((rtn = pthread_mutex_lock(&bufferLock)) != 0)
		fprintf(stderr, "pthread_mutex_lock %d", rtn), exit(1);

	while (IsBufferEmpty()) {
		if( finish == true){
			pthread_mutex_unlock(&bufferLock);
			return FINISH_READ;
		}
		if ((rtn = pthread_cond_wait(&bufferNotEmpty, &bufferLock)) != 0)
			fprintf(stderr, "pthread_cond_wait %d", rtn), exit(1);
	}

	memcpy((char*)dest, (const char*)(base + readPos), length);
	readPos = (readPos + length) % pageSize;

	if ((rtn = pthread_cond_broadcast(&bufferNotFull)) != 0)
		fprintf(stderr, "pthread_cond_signal %d", rtn), exit(1);

	pthread_mutex_unlock(&bufferLock);

	return OK;
}
Ejemplo n.º 2
0
McoStatus Techkon::GetPaperDensity(void)
{
long tick = TickCount();

while (TickCount() - tick < 240)
	{
	if ((!IsBufferEmpty()) && (IsDataPresent())) return getNextPatch(paperDensity);
	}
return MCO_FAILURE;
}
Ejemplo n.º 3
0
McoStatus Techkon::sendReadCommand(void)
{
int32 tc;

if (sp == 0L) return MCO_SERIAL_ERROR;

tc = TickCount();

sendCommand(Tech_Measure);
do {} while (IsBufferEmpty() && (TickCount() - tc < 120));
return MCO_SUCCESS;
}
Ejemplo n.º 4
0
static ssize_t cpcusb_read(struct file *file, char *buffer, size_t count,
			   loff_t *ppos)
{
	CPC_USB_T *card = (CPC_USB_T *) file->private_data;
	CPC_CHAN_T *chan;
	int retval = 0;

	if (count < sizeof(CPC_MSG_T))
		return CPC_ERR_UNKNOWN;

	/* check if can read from the given address */
	if (!access_ok(VERIFY_WRITE, buffer, count))
		return CPC_ERR_UNKNOWN;

	/* lock this object */
	down(&card->sem);

	/* verify that the device wasn't unplugged */
	if (!card->present) {
		up(&card->sem);
		return CPC_ERR_NO_INTERFACE_PRESENT;
	}

	if (IsBufferEmpty(card->chan)) {
		retval = 0;
	} else {
		chan = card->chan;

#if 0
		/* convert LPC2119 params back to SJA1000 params */
		if (card->deviceRevision >= 0x0200
		    && chan->buf[chan->oidx].type == CPC_MSG_T_CAN_PRMS) {
			LPC2119_TO_SJA1000_Params(&chan->buf[chan->oidx]);
		}
#endif

		if (copy_to_user(buffer, &chan->buf[chan->oidx], count) != 0) {
			retval = CPC_ERR_IO_TRANSFER;
		} else {
			chan->oidx = (chan->oidx + 1) % CPC_MSG_BUF_CNT;
			chan->WnR = 1;
			retval = sizeof(CPC_MSG_T);
		}
	}
/*	spin_unlock_irqrestore(&card->slock, flags); */

	/* unlock the device */
	up(&card->sem);

	return retval;
}
Ejemplo n.º 5
0
	// установить длинну буфера точно
	// 0 - очищает буфер
	BOOL SetLength( int lenNew )
	{
		if ( lenNew > 0 )
		{
			T* sNew = (T*)malloc( lenNew * sizeof(T) );
//			T* sNew = (T*)::VirtualAlloc( NULL, lenNew * sizeof(T), MEM_COMMIT, PAGE_READWRITE );
			if ( sNew != NULL )
			{
				if ( !IsBufferEmpty() )
				{
					memcpy( sNew,
							m_pData,
							lenNew > m_iSize ? m_iSize * sizeof(T) : lenNew * sizeof(T) );
//					::VirtualFree( m_pData, 0, MEM_RELEASE );
					free( m_pData );
					m_pData = NULL;
				}
				m_pData = sNew;
				m_iSize = lenNew;
			}
			else
			{
				return FALSE;
			}
		}
		else
		{
			if ( !IsBufferEmpty() )
			{
//				::VirtualFree( m_pData, 0, MEM_RELEASE );
				free( m_pData );
				m_pData = NULL;
			}
			m_iSize = 0;
		}
		return TRUE;
	}
Ejemplo n.º 6
0
int main(int argc, char **argv)
{
	VGA_Parms VGAParms;
	mod_parms modParms;
	rt_buffer baseBandBuffer; 
	input_scale_struct inputStruct;
	pthread_t thread;
    int i;
	long long sampleCount=0;
	long long sampleWrittenCount=0;
	
	int fc =  35000000;
	int rate = 146200000;
	int fs =  1500000;
	int inputShift = 0; //input>>inputShift
	int carrierShift=0; //carrier>>inputShift
	char * inputName = "stdin";
	char * outputName = "stdout";
	FILE * inPipe;
	FILE * outPipe;
	int bInvert;
	struct timeval tv1, tv2;
    unsigned int offset_s=0;
	unsigned int offset_c=0;
	int outputBufferSize;
	int * outputBuffer;
	long long k_s; //2^16*fs/rate
	long long k_c; //2^16*fc/rate
	int ts_us,us; 
	
	VGAParms.width = 40;
	VGAParms.wtotal = 50;
	VGAParms.height = 40;
	VGAParms.htotal = 42;
	VGAParms.outputShiftRight = 0; //shift right after multiply
	VGAParms.outputMask=0xFFFFFFFF; //clamp ouput value with mask
	VGAParms.outputShiftLeft = 0; //left shift after clamping
	VGAParms.outputAddOffset = 0;
	VGAParms.vsyncOffset = 0;

	/* Signal parameters */

    // Get Input parameters 
    while ((i = getopt(argc, argv, "w:W:h:H:r:c:s:i:o:C:I:O:a:v:")) != -1) 
    {
		switch(i) 
		{
			case 'w':
				VGAParms.width = atoi(optarg);
				break;
			case 'W':
				VGAParms.wtotal = atoi(optarg);
				break;
			case 'h':
				VGAParms.height = atoi(optarg);
				break;
			case 'H':
				VGAParms.htotal = atoi(optarg);
				break;
			case 'r':
				rate = atoi(optarg);
				break;
			case 'c':
				fc = atoi(optarg);
				break;
			case 's':
				fs = atoi(optarg);
				break;
			case 'i':
				inputName = strdup(optarg);
				break;
			case 'o':
				outputName = strdup(optarg);
				break;
			case 'C':
				carrierShift = atoi(optarg);
				break;
			case 'I':
				inputShift = atoi(optarg);
				break;
			case 'O':
				VGAParms.outputShiftRight = atoi(optarg);
				break;
			case 'M':
				sscanf(optarg, "%x", &VGAParms.outputMask);
				break;			
			case 'L':
				VGAParms.outputShiftLeft = atoi(optarg);
				break;
			case 'a':
				VGAParms.outputAddOffset = atoi(optarg);
				break;
			case 'v':
				VGAParms.vsyncOffset = atoi(optarg);
				break;

		}
	}
	if(argc==1)
	{
		printf("Usage: testmod -w [width] -W [wtotal] -h [height] -H [htotal] \n");
		printf("               -r [rate] -c [CarrierFreq] -s [SampleFreq] -i [InputFile]\n");
		printf("               -o [outfile]  -C [CarrierSignalShift] -I [InputSignalShift]\n");
		printf("               -O [OutputShiftRight] -M [OutputMask] -L [OutputShiftLeft]\n");
		printf("               -f [OutputAddOffset] \n");
 	}

	if(strcmp(inputName,"stdin")!=0)
	{
		inPipe = fopen(inputName,"rb");
		if(!inPipe) 
		{
			fprintf(stderr, "Cannon open file %s",inputName);
			exit(-1);
		}
	}else
		inPipe= stdin;
		
	if(strcmp(outputName,"stdout")!=0)
	{
		outPipe = fopen(outputName,"wb");
		if(!outPipe) 
		{
			fprintf(stderr, "Cannon open file %s",outputName);
			exit(-1);
		}
	}else
		outPipe= stdout;
	VGAParms.wtotal = max(VGAParms.wtotal,VGAParms.width);
	VGAParms.htotal = max(VGAParms.htotal,VGAParms.height);
	
	if(fc<0)
	{
		fc=-fc;
		modParms.Qsign=-1;
	}else
		modParms.Qsign=1;
	modParms.k_s = ((long long)(1<<OFFSET_BITS))*fs/rate;
	modParms.k_c = ((long long) (1<<OFFSET_BITS))*fc*COS_BUFFER_SIZE/rate;
	modParms.offset_s=0;
	modParms.offset_c=0;

    outputBufferSize = VGAParms.width*VGAParms.height;
	outputBuffer = malloc(	outputBufferSize*sizeof(int));
	InitBuffer(&baseBandBuffer,outputBufferSize);
   	initCosineTable((float)1/(1<<carrierShift));
	ts_us = 1000000/fs;

	inputStruct.buf = &baseBandBuffer;
	inputStruct.inputFile = inPipe;
	inputStruct.scale=((float)1/(1<<inputShift));

	if (pthread_create(&thread, NULL, readInputScale, &inputStruct))
	{
		printf("ERROR; Could not create read thread\n");
        exit(-1);
    }
  

    fprintf(stderr, "buffering input...");
    while (IsBufferEmpty(&baseBandBuffer)) 
		usleep(100000);
    fprintf(stderr, "done %d\n",GetBufferFullness(&baseBandBuffer));

    fprintf(stderr, "\n");
    fprintf(stderr, "SampleRate:   %3.2f MHz\n", (double)rate/1000000);
    fprintf(stderr, "Carrier:      %3.2f MHz\n", (double)fc/1000000);
    fprintf(stderr, "SymbolRate:   %3.2f\n", (double)fs);
    fprintf(stderr, "\n");
	

	gettimeofday(&tv1, 0);
	while(!IsFlushComplete(&baseBandBuffer))
	{
		if(GetBufferFullness(&baseBandBuffer)>=outputBufferSize || IsFlushing(&baseBandBuffer))
		{
			sampleWrittenCount += ComplexModulate(&baseBandBuffer, outputBuffer, &modParms, &VGAParms);
			sampleCount += fwrite(outputBuffer, sizeof(int), outputBufferSize, outPipe);
			gettimeofday(&tv2, 0);
			us = time_delta(&tv1, &tv2);
			us = ts_us - us;
			if (us > 0)
				usleep(us);
			gettimeofday(&tv1, 0);
		}
	
	}
	fprintf(stderr,"Sample        : %llu\n",sampleCount);
	fprintf(stderr,"Sample Written: %llu\n",sampleWrittenCount);

	DeInitBuffer(&baseBandBuffer);
	if(inPipe!=stdin)
		fclose(inPipe);
	if(outPipe!=stdout)
		fclose(outPipe);
	pthread_exit(NULL);
 }