Ejemplo n.º 1
0
size_t cavan_fifo_vprintf(struct cavan_fifo *fifo, const char *format, va_list ap)
{
	size_t size;
	char buff[2048];

	size = vsnprintf(buff, sizeof(buff), format, ap);

	return cavan_fifo_write(fifo, buff, size);
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	char c;
	int ret;
	struct cavan_fifo fifo;

	assert(argc > 1);

	ret = cavan_fifo_init(&fifo, 20, NULL);
	if (ret < 0) {
		pr_red_info("cavan_fifo_init");
		return ret;
	}

	fifo.read = test_fifo_read;
	fifo.write = test_fifo_write;

	if (strcmp(argv[1], "write") == 0) {
		for (c = 'A'; c <= 'Z'; c++) {
			cavan_fifo_write(&fifo, &c, 1);
		}

		cavan_fifo_fflush(&fifo);
	} else if (strcmp(argv[1], "read") == 0) {
		int  i;
		char buff[100];

		for (i = 0; i < (int) sizeof(buff) - 1 && cavan_fifo_read(&fifo, buff + i, 1) == 1; i++);

		buff[i] = 0;

		println("buff[%d] = %s", i, buff);
	} else {
		pr_red_info("inlivad action %s", argv[1]);
	}

	cavan_fifo_deinit(&fifo);

	return 0;
}