Beispiel #1
0
/*****************************************************************************
 * submit a channel rpc call to the UART
 * If buffer slot is available, return immediately.
 * Otherwise wait until slot is available, then return
 * (while data is transferred in the background)
 *
 * Note: submitter must check buf_is_empty() for true or buf_wait_free() 
 * before reuse or freeing the memory!
 *
 * callback is called from delay() context when the response has been
 * received
 */
void serial_submit_call(void *epdata, int8_t channelno, packet_t *txbuf, packet_t *rxbuf, 
		uint8_t (*callback)(int8_t channelno, int8_t errnum, packet_t *packet)) {

	if (channelno < 0) {
		debug_printf("!!!! submit with channelno=%d\n", channelno);
	}
	if (txbuf->chan < 0) {
		debug_printf("!!!! submit with packet->chan=%d\n", txbuf->chan);
	}

	// check rx slot
	// wait / loop until receive buffer is being freed by interrupt routine
	int8_t channelpos = -1;
	while (channelpos < 0) {
		for (uint8_t i = 0; i < NUMBER_OF_SLOTS; i++) {
			// note: take either a free one or overwrite an existing one
			// the latter case is only used for rtconfig_pullconfig()
			// sending a new request
			if (rx_channels[i].channelno < 0
				|| rx_channels[i].channelno == channelno) {
				channelpos = i;
				break;
			}
		}
		serial_delay();
	}

	rx_channels[channelpos].channelno = channelno;
	rx_channels[channelpos].rxpacket = rxbuf;
	rx_channels[channelpos].callback = callback;

	// send request
	serial_submit(epdata, txbuf);
}
Beispiel #2
0
static int serial_read (void)
{
	FILE *fh;
	char buffer[1024];

	/* there are a variety of names for the serial device */
	if ((fh = fopen ("/proc/tty/driver/serial", "r")) == NULL &&
		(fh = fopen ("/proc/tty/driver/ttyS", "r")) == NULL)
	{
		char errbuf[1024];
		WARNING ("serial: fopen: %s",
				sstrerror (errno, errbuf, sizeof (errbuf)));
		return (-1);
	}

	while (fgets (buffer, sizeof (buffer), fh) != NULL)
	{
		derive_t rx = 0;
		derive_t tx = 0;
		_Bool have_rx = 0, have_tx = 0;
		size_t len;

		char *fields[16];
		int numfields;
		int i;

		numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
		if (numfields < 6)
			continue;

		/*
		 * 0: uart:16550A port:000003F8 irq:4 tx:0 rx:0
		 * 1: uart:16550A port:000002F8 irq:3 tx:0 rx:0
		 */
		len = strlen (fields[0]);
		if (len < 2)
			continue;
		if (fields[0][len - 1] != ':')
			continue;
		fields[0][len - 1] = 0;

		for (i = 1; i < numfields; i++)
		{
			len = strlen (fields[i]);
			if (len < 4)
				continue;

			if (strncmp (fields[i], "tx:", 3) == 0)
			{
				if (strtoderive (fields[i] + 3, &tx) == 0)
					have_tx = 1;
			}
			else if (strncmp (fields[i], "rx:", 3) == 0)
			{
				if (strtoderive (fields[i] + 3, &rx) == 0)
					have_rx = 1;
			}
		}

		if (have_rx && have_tx)
			serial_submit (fields[0], rx, tx);
	}

	fclose (fh);
	return (0);
} /* int serial_read */