コード例 #1
0
static bool fmcomms2adv_identify(void)
{
	/* Use the OSC's IIO context just to detect the devices */
	struct iio_context *osc_ctx = get_context_from_osc();
	struct iio_device *osc_dev = iio_context_find_device(
			osc_ctx, "ad9361-phy");
	if (!osc_dev || !iio_device_get_debug_attrs_count(osc_dev))
		return false;

	ctx = osc_create_context();
	dev = iio_context_find_device(ctx, "ad9361-phy");
	dev_slave = iio_context_find_device(ctx, "ad9361-phy-hpc");

	if (dev_slave) {
		cf_ad9361_lpc = iio_context_find_device(ctx, "cf-ad9361-lpc");
		cf_ad9361_hpc = iio_context_find_device(ctx, "cf-ad9361-hpc");

		dev_dds_master = iio_context_find_device(ctx, "cf-ad9361-dds-core-lpc");
		dev_dds_slave = iio_context_find_device(ctx, "cf-ad9361-dds-core-hpc");
		if (!(cf_ad9361_lpc && cf_ad9361_hpc && dev_dds_master && dev_dds_slave))
			dev = NULL;
		else
			if (get_dds_channels())
				dev = NULL;
	}

	if (dev && !iio_device_get_debug_attrs_count(dev))
		dev = NULL;
	if (!dev)
		iio_context_destroy(ctx);

	return !!dev;
}
コード例 #2
0
ファイル: device.c プロジェクト: PierreBizouard/libiio
static int write_each_attr(struct iio_device *dev, bool is_debug,
		ssize_t (*cb)(struct iio_device *dev,
			const char *attr, void *buf, size_t len, void *d),
		void *data)
{
	char *buf, *ptr;
	unsigned int i, count;
	size_t len = 0x100000;
	int ret;

	/* We need a big buffer here; 1 MiB should be enough */
	buf = malloc(len);
	if (!buf)
		return -ENOMEM;

	ptr = buf;

	if (is_debug)
		count = iio_device_get_debug_attrs_count(dev);
	else
		count = iio_device_get_attrs_count(dev);

	for (i = 0; i < count; i++) {
		const char *attr;

		if (is_debug)
			attr = iio_device_get_debug_attr(dev, i);
		else
			attr = iio_device_get_attr(dev, i);

		ret = (int) cb(dev, attr, ptr + 4, len - 4, data);
		if (ret < 0)
			goto err_free_buf;

		*(int32_t *) ptr = (int32_t) htonl((uint32_t) ret);
		ptr += 4;
		len -= 4;

		if (ret > 0) {
			if (ret & 0x3)
				ret = ((ret >> 2) + 1) << 2;
			ptr += ret;
			len -= ret;
		}
	}

	if (is_debug)
		ret = (int) iio_device_debug_attr_write_raw(dev,
				NULL, buf, ptr - buf);
	else
		ret = (int) iio_device_attr_write_raw(dev,
				NULL, buf, ptr - buf);

err_free_buf:
	free(buf);
	return ret < 0 ? ret : 0;
}
コード例 #3
0
ファイル: device.c プロジェクト: PierreBizouard/libiio
static int read_each_attr(struct iio_device *dev, bool is_debug,
		int (*cb)(struct iio_device *dev,
			const char *attr, const char *val, size_t len, void *d),
		void *data)
{
	int ret;
	char *buf, *ptr;
	unsigned int i, count;

	/* We need a big buffer here; 1 MiB should be enough */
	buf = malloc(0x100000);
	if (!buf)
		return -ENOMEM;

	if (is_debug) {
		count = iio_device_get_debug_attrs_count(dev);
		ret = (int) iio_device_debug_attr_read(dev,
				NULL, buf, 0x100000);
	} else {
		count = iio_device_get_attrs_count(dev);
		ret = (int) iio_device_attr_read(dev, NULL, buf, 0x100000);
	}

	if (ret < 0)
		goto err_free_buf;

	ptr = buf;

	for (i = 0; i < count; i++) {
		const char *attr;
		int32_t len = (int32_t) ntohl(*(uint32_t *) ptr);

		if (is_debug)
			attr = iio_device_get_debug_attr(dev, i);
		else
			attr = iio_device_get_attr(dev, i);

		ptr += 4;
		if (len > 0) {
			ret = cb(dev, attr, ptr, (size_t) len, data);
			if (ret < 0)
				goto err_free_buf;

			if (len & 0x3)
				len = ((len >> 2) + 1) << 2;
			ptr += len;
		}
	}
コード例 #4
0
static bool fmcomms2adv_identify(void)
{
	/* Use the OSC's IIO context just to detect the devices */
	struct iio_context *osc_ctx = get_context_from_osc();

	dev = iio_context_find_device(osc_ctx, PHY_DEVICE);
	dev_slave = iio_context_find_device(osc_ctx, PHY_SLAVE_DEVICE);
	if (dev_slave) {
		cf_ad9361_lpc = iio_context_find_device(osc_ctx, CAP_DEVICE_ALT);
		cf_ad9361_hpc = iio_context_find_device(osc_ctx, CAP_SLAVE_DEVICE);
		dev_dds_master = iio_context_find_device(osc_ctx, DDS_DEVICE);
		dev_dds_slave = iio_context_find_device(osc_ctx, DDS_SLAVE_DEVICE);
	}

	return !!dev && iio_device_get_debug_attrs_count(dev)
		&& (!dev_slave || (!!cf_ad9361_lpc && !!cf_ad9361_hpc &&
					!!dev_dds_master && !!dev_dds_slave));
}
コード例 #5
0
static bool pr_config_identify(void)
{
	/* Use the OSC's IIO context just to detect the devices */
	struct iio_context *osc_ctx = get_context_from_osc();

	if (!iio_context_find_device(osc_ctx, PHY_DEVICE) ||
		!iio_context_find_device(osc_ctx, DEVICE_NAME_ADC) ||
		!iio_context_find_device(osc_ctx, DEVICE_NAME_DAC))
		return false;

	ctx = osc_create_context();
	phy = iio_context_find_device(ctx, PHY_DEVICE);
	adc = iio_context_find_device(ctx, DEVICE_NAME_ADC);
	dac = iio_context_find_device(ctx, DEVICE_NAME_DAC);

	context_is_local = !strncmp(iio_context_get_name(ctx), "local", strlen("local"));

	int id;
	bool init = true;

	if (!phy || !adc || !dac) {
		init = false;
	} else {
		id = getPrId();
		if ((id != PR_LOGIC_DEFAULT_ID) &&
				(id != PR_LOGIC_BIST_ID) &&
				(id != PR_LOGIC_QPSK_ID))
			init = false;
	}
	if (phy && !iio_device_get_debug_attrs_count(phy))
		init = false;
	if (!init)
		iio_context_destroy(ctx);

	return init;
}