Esempio n. 1
0
/**
 * UART RX Interrupt
 */
static void uart_recv_next_char(uint8_t num)
{
#ifdef CONFIG_MODULE_UART_9BITS
	if (uart_getconf_nbits() == 9) {
		int elt = 0;

		elt = uart_get_udr_9bits(num);
		if (CIRBUF_GET_FREELEN(&g_rx_fifo[num]) >= 2) {
			cirbuf_add_buf_head(&g_rx_fifo[num], (char *)&elt, 2);
		}

		if (rx_event[num])
			((event_9bits *)rx_event[num])(elt);
	}
	else 
#endif /* CONFIG_MODULE_UART_9BITS */
	{
		char elt = 0;

		elt = uart_get_udr(num);
		if (!CIRBUF_IS_FULL(&g_rx_fifo[num])) {
			cirbuf_add_head(&g_rx_fifo[num], elt);
		}

		if (rx_event[num])
			rx_event[num](elt);
	}
}
Esempio n. 2
0
cirbuf_int
cirbuf_add_buf_tail(struct cirbuf * cbuf, const char * c, cirbuf_uint n)
{
	cirbuf_uint e;

	if (!n || n > CIRBUF_GET_FREELEN(cbuf))
		return -EINVAL;

	e = CIRBUF_IS_EMPTY(cbuf) ? 1 : 0;
	
	if (n < cbuf->maxlen - cbuf->end - 1 + e) {
		dprintf("s[%d] -> d[%d] (%d)\n", 0, cbuf->end + !e, n);
		memcpy(cbuf->buf + cbuf->end + !e, c, n);
	}
	else {
		dprintf("s[%d] -> d[%d] (%d)\n", cbuf->end + !e, 0, cbuf->maxlen - cbuf->end - 1 + e);
		dprintf("s[%d] -> d[%d] (%d)\n", cbuf->maxlen - cbuf->end - 1 + e, 0, n - cbuf->maxlen + cbuf->end + 1 - e);
		memcpy(cbuf->buf + cbuf->end + !e, c, cbuf->maxlen - cbuf->end - 1 + e);
		memcpy(cbuf->buf, c + cbuf->maxlen - cbuf->end - 1 + e, n - cbuf->maxlen + cbuf->end + 1 - e);
	}
	cbuf->len += n;
	cbuf->end += n - e;
	cbuf->end %= cbuf->maxlen;
	return n;
}