示例#1
0
static int swan_ts_poll_registers_main(int argc, char *argv[])
{
	int ret;
	u16 offset;
	u16 count;
	u32 timeout;
	int fd;
	char *buff;
	const char *devpath;

	assert(argc > 2);

	offset = text2value_unsigned(argv[1], NULL, 10);
	count = text2value_unsigned(argv[2], NULL, 10);
	timeout = argc > 3 ? text2value_unsigned(argv[3], NULL, 10) : 200;
	devpath = argc > 4 ? argv[4] : SWAN_TS_DEFAULT_DEVICE;

	println("offset = %d, count = %d, timeout = %d, devpath = %s", offset, count, timeout, devpath);

	buff = malloc(count);
	if (buff == NULL)
	{
		pr_red_info("malloc");
		return -ENOMEM;
	}

	fd = swan_ts_open_misc_device(devpath, 0);
	if (fd < 0)
	{
		pr_red_info("swan_ts_open_misc_device");
		ret = fd;
		goto out_free_buff;
	}

	while (1)
	{
		msleep(timeout);

		ret = swan_ts_read_registers_fd(fd, offset, buff, count);
		if (ret < 0)
		{
			continue;
		}

		print_mem((u8 *) buff, count);
	}

	close(fd);

out_free_buff:
	free(buff);

	return ret;
}
示例#2
0
文件: swan_ts.c 项目: FuangCao/cavan
int swan_ts_read_registers(const char *devpath, u16 addr, void *buff, size_t size)
{
	int fd;
	int ret;

	fd = swan_ts_open_misc_device(devpath, 0);
	if (fd < 0) {
		return fd;
	}

	ret = swan_ts_read_registers_fd(fd, addr, buff, size);

	close(fd);

	return ret;
}