Ejemplo n.º 1
0
BOOL ipcWriteMyPID( VOID )
{
	cyg_handle_t self;
	INT nStatus;
	INT nWriteLen;
	INT hFile;
	
	self = cyg_thread_self( );
	
	hFile = fsOpenFile((char*)MY_PID_LOG,NULL, O_WRONLY |O_CREAT | O_TRUNC);
	if(hFile < 0)
	{
		diag_printf("Open file error %x for writing PID\n", hFile);
		return FALSE;
	}
	
	nStatus = fsWriteFile(hFile, (VOID *)&self, sizeof(self), &nWriteLen);
	fsCloseFile(hFile);

	if((nStatus < 0)||(nWriteLen != sizeof(self)))
	{
		diag_printf("save configuration information error\n");
		return FALSE;
	}

	return TRUE;
}
Ejemplo n.º 2
0
void ftpServerReceiveData(FtpServerContext *context, FtpClientConnection *connection)
{
   error_t error;
   bool_t eof;
   size_t n;

   //File transfer in progress?
   if(connection->controlState == FTP_CONTROL_STATE_STOR ||
      connection->controlState == FTP_CONTROL_STATE_APPE)
   {
      //Read incoming data
      error = socketReceive(connection->dataSocket,
         connection->buffer + connection->bufferPos,
         FTP_SERVER_BUFFER_SIZE - connection->bufferLength, &n, 0);

      //Any error to report?
      if(error)
      {
         //Cannot read more data
         eof = TRUE;
      }
      else
      {
         //Successful read operation
         eof = FALSE;

         //Advance data pointer
         connection->bufferPos += n;
         connection->bufferLength += n;
      }

      //Read data until the buffer is full or the end of the file is reached
      if(eof || connection->bufferLength >= FTP_SERVER_BUFFER_SIZE)
      {
         //Any data to be written?
         if(connection->bufferLength > 0)
         {
            //Write data to the specified file
            error = fsWriteFile(connection->file,
               connection->buffer, connection->bufferLength);

            //Any error to report?
            if(error)
            {
               //Close the data connection
               ftpServerCloseDataConnection(connection);

               //Release previously allocated resources
               fsCloseFile(connection->file);
               connection->file = NULL;

               //Back to idle state
               connection->controlState = FTP_CONTROL_STATE_IDLE;

               //Transfer status
               strcpy(connection->response, "451 Transfer aborted\r\n");
               //Debug message
               TRACE_DEBUG("FTP server: %s", connection->response);

               //Number of bytes in the response buffer
               connection->responseLength = strlen(connection->response);
               connection->responsePos = 0;

               //Exit immediately
               return;
            }
         }

         //Flush reception buffer
         connection->bufferLength = 0;
         connection->bufferPos = 0;
      }

      //End of stream?
      if(eof)
      {
         //Close file
         fsCloseFile(connection->file);
         connection->file = NULL;

         //Graceful shutdown sequence
         connection->dataState = FTP_DATA_STATE_WAIT_ACK;
      }
   }
   //Invalid state?
   else
   {
      //The FTP server has encountered a critical error
      ftpServerCloseConnection(context, connection);
   }
}
Ejemplo n.º 3
0
void record_to_file(INT choose,INT ch)
{
	INT		hFile;
	INT		nWriteBytes, nTotalBytes = 0;
	INT		nTime0;
	INT8	bAsciiFileName[20] = "c:\\record.pcm";
	INT8	bUnicodeFileName[40];
	INT		ntick0;

	_uPcmQHead = _uPcmQTail = 0;
	fsAsciiToUnicode(bAsciiFileName, bUnicodeFileName, TRUE);
	hFile = fsOpenFile(bUnicodeFileName,NULL, O_CREATE);

	if (hFile < 0)
	{
		printf("Can't open playback file%d!\n",hFile);
		return;
	}
	printf("Start record...\n");

#if defined( TEST_I2S ) || defined (TEST_UDA1345TS)
	if (choose%11025==0){
		/* 16.934Mhz */
		outpw(REG_APLLCON, 0x642D);
		outpw(REG_CLKDIV0, (inpw(REG_CLKDIV0) & 0xFF0FFFFF) | 0x300000);
	}
	else{
		/* 12.288Mhz */
		outpw(REG_APLLCON, 0x6529);
		outpw(REG_CLKDIV0, (inpw(REG_CLKDIV0) & 0xFF0FFFFF) | 0x300000);
	}
#endif

#if defined (TEST_WM8978)
#if 0
	if (choose==32000)//8.192Mhz
	{
		outpw(REG_APLLCON, 0x6529);
		outpw(REG_CLKDIV0, (inpw(REG_CLKDIV0) & 0xFF0FFFFF) | 0x500000);
	}
	else if (choose%8000==0 || choose%12000==0){//12.288Mhz
		outpw(REG_APLLCON, 0x6529);
		outpw(REG_CLKDIV0, (inpw(REG_CLKDIV0) & 0xFF0FFFFF) | 0x300000);
	}
	else if (choose%11025==0){//11.289Mhz
		outpw(REG_APLLCON, 0x652f);
		outpw(REG_CLKDIV0, (inpw(REG_CLKDIV0) & 0xFF0FFFFF) | 0x400000);
	}
#else

	if (choose%8000==0 || choose%12000==0){//24.576Mhz
		outpw(REG_APLLCON, 0x6529);
		outpw(REG_CLKDIV0, (inpw(REG_CLKDIV0) & 0xFF0FFFFF) | 0x100000);
	}
	else if (choose%11025==0){//22.579Mhz
		outpw(REG_APLLCON, 0x642d);
		outpw(REG_CLKDIV0, (inpw(REG_CLKDIV0) & 0xFF0FFFFF) | 0x200000);
	}
#endif
#endif
	audioRecConfigMono(1);
	audioStartRecord(record_callback, choose, ch);
	
	//audioSetRecordVolume(31,31);
	nTime0 = ntick0 = sysGetTicks(TIMER1);
	
	while (1)
	{
		if (sysGetTicks(TIMER1) - nTime0 >= 100)
		{
			nTime0 = sysGetTicks(TIMER1);
			printf("H=%d, T=%d\n", _uPcmQHead/1024, _uPcmQTail/1024);

			
		}
		
		if ((_uPcmQHead > _uPcmQTail) ||
			((_uPcmQHead < _uPcmQTail) && (_uPcmQTail - _uPcmQHead > 64*1024)))
		{

			fsWriteFile(hFile, &_pucPcmQueue[_uPcmQHead], 64*1024, &nWriteBytes);
			
			if (nWriteBytes > 0)
				_uPcmQHead = (_uPcmQHead + nWriteBytes) % PCM_QUEUE_LEN;
			else
				break;
				
			

			if (sysGetTicks(TIMER1) - ntick0  >= 1000)
				break;
		}
	}
	fsCloseFile(hFile);
	audioStopRecord();
}