public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] E7T loosing data on serial port reception?
@ 2002-06-05  9:49 Carsten Andersen
  0 siblings, 0 replies; only message in thread
From: Carsten Andersen @ 2002-06-05  9:49 UTC (permalink / raw)
  To: 'ecos-discuss@sources.redhat.com'

I'm loosing chunks of data when trying to receive on the serial port on the
E7T.

I'm running the reception and transmission in two different threads and the
main program in the main thread. Basically I open the port:

	fd = open("/dev/termios0", O_RDWR | O_NOCTTY);
	fcntl(fd, F_SETFL, 0);

Then I configure the port:

	struct termios options;

	tcgetattr(fd, &options);

	cfsetispeed(&options, B9600);
	cfsetospeed(&options, B9600);

	/* 8E2 */
	options.c_cflag |= PARENB;
	options.c_cflag &= ~PARODD;
	options.c_cflag |= CSTOPB;
	options.c_cflag &= ~CSIZE;
	options.c_cflag |= CS8;

	options.c_cflag &= ~CRTSCTS;
/* disable HW flow control */

	options.c_cflag |= (CLOCAL | CREAD);
/* local line - do not change owner of port, enable receiver */

	options.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ISIG);
/* raw input, disable echo, no echo erase, disable signals */

	options.c_oflag &= ~(OPOST | ONLCR);
/* raw output */

	options.c_iflag |= (IGNPAR | ISTRIP);
/* ignore parity errors (we want the data even when it contains errors!),
strip parity bits */
	options.c_iflag &= ~(PARMRK | BRKINT | ICRNL);

	/* wait for at least 1 character, blocking */
	options.c_cc[VMIN] = 1;
	options.c_cc[VTIME] = 0;

	tcsetattr(fd, TCSANOW, &options);

And then I start the threads:

	pthread_create(&reader_thread, NULL, readerThread, NULL);
	pthread_create(&writer_thread, NULL, writerThread, NULL);

I have some receive and transmit buffers protected by the mutexes and I wait
for a transmitQueueNotEmptyCondition when there's nothing to transmit.

The reception thread looks like this:

static void * readerThread(void * threadParameter)
{
	int	numberOfBytesRead;
	uint32_t	currentNumberOfBytes;

	pthread_mutex_lock(&receiveMutex);
	while (1)
	{
		currentNumberOfBytes = UART0_RX_buffer_count;
		pthread_mutex_unlock(&receiveMutex);

		if (currentNumberOfBytes > 0)
		{
			signal_main_to_read_from_buffer();
		}

		if (currentNumberOfBytes + MAX_BYTES_TO_READ > QUEUE_SIZE)
		{
			currentNumberOfBytes = QUEUE_SIZE -
MAX_BYTES_TO_READ;
		}
		else
		{
			currentNumberOfBytes = MAX_BYTES_TO_READ;
		}
		if (currentNumberOfBytes + UART0_RX_in_PTR > QUEUE_SIZE)
		{
			currentNumberOfBytes = QUEUE_SIZE - UART0_RX_in_PTR;
		}

		numberOfBytesRead = read(fd,
&UART0_RX_QUEUE[UART0_RX_in_PTR], currentNumberOfBytes);
		if (numberOfBytesRead > 0)
		{
			UART0_RX_in_PTR += numberOfBytesRead;
			if (UART0_RX_in_PTR >= QUEUE_SIZE)
			{
				UART0_RX_in_PTR = 0;
			}
		}
		else
		{
			numberOfBytesRead = 0;
		}

		pthread_mutex_lock(&receiveMutex);
		UART0_RX_buffer_count += numberOfBytesRead;
	}
	pthread_mutex_unlock(&receiveMutex);
	return NULL;
}

The interrupt buffer is set to 128. I experience drop-outs even at 9600
baud!?!?

Any ideas?

	Carsten.



**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential 
and/or privileged material. 
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by 
persons or entities other than the intended recipient is 
prohibited.  
If you received this in error, please contact the sender and 
delete the material from any computer.
**********************************************************************

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-06-05 16:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-05  9:49 [ECOS] E7T loosing data on serial port reception? Carsten Andersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).