Exemplo n.º 1
0
SR_PRIV int cv_set_samplerate(const struct sr_dev_inst *sdi, uint64_t samplerate)
{
	struct dev_context *devc;

	/* Note: Caller checked that sdi and sdi->priv != NULL. */

	devc = sdi->priv;

	sr_spew("Trying to set samplerate to %" PRIu64 "Hz.", samplerate);

	cv_fill_samplerates_if_needed(sdi);

	/* Check if this is a samplerate supported by the hardware. */
	if (!is_valid_samplerate(sdi, samplerate)) {
		sr_dbg("Failed to set invalid samplerate (%" PRIu64 "Hz).",
		       samplerate);
		return SR_ERR;
	}

	devc->cur_samplerate = samplerate;

	sr_dbg("Samplerate set to %" PRIu64 "Hz.", devc->cur_samplerate);

	return SR_OK;
}
Exemplo n.º 2
0
/**
 * Convert a samplerate (in Hz) to the 'divcount' value the LA8 wants.
 *
 * LA8 hardware: sample period = (divcount + 1) * 10ns.
 * Min. value for divcount: 0x00 (10ns sample period, 100MHz samplerate).
 * Max. value for divcount: 0xfe (2550ns sample period, 392.15kHz samplerate).
 *
 * @param samplerate The samplerate in Hz.
 * @return The divcount value as needed by the hardware, or 0xff upon errors.
 */
SR_PRIV uint8_t samplerate_to_divcount(uint64_t samplerate)
{
	if (samplerate == 0) {
		sr_err("%s: samplerate was 0.", __func__);
		return 0xff;
	}

	if (!is_valid_samplerate(samplerate)) {
		sr_err("%s: Can't get divcount, samplerate invalid.", __func__);
		return 0xff;
	}

	return (SR_MHZ(100) / samplerate) - 1;
}
Exemplo n.º 3
0
/**
 * Convert a samplerate (in Hz) to the 'divcount' value the device wants.
 *
 * The divcount value can be 0x00 - 0xfe (0xff is not valid).
 *
 * LA8:
 * sample period = (divcount + 1) * 10ns.
 * divcount = 0x00: 10ns period, 100MHz samplerate.
 * divcount = 0xfe: 2550ns period, 392.15kHz samplerate.
 *
 * LA16:
 * sample period = (divcount + 1) * 5ns.
 * divcount = 0x00: 5ns period, 200MHz samplerate.
 * divcount = 0xfe: 1275ns period, ~784.31kHz samplerate.
 *
 * @param sdi Device instance.
 * @param samplerate The samplerate in Hz.
 *
 * @return The divcount value as needed by the hardware, or 0xff upon errors.
 */
SR_PRIV uint8_t cv_samplerate_to_divcount(const struct sr_dev_inst *sdi,
					  uint64_t samplerate)
{
	struct dev_context *devc;

	devc = sdi->priv;

	if (samplerate == 0) {
		sr_err("Can't convert invalid samplerate of 0 Hz.");
		return 0xff;
	}

	if (!is_valid_samplerate(sdi, samplerate)) {
		sr_err("Can't get divcount, samplerate invalid.");
		return 0xff;
	}

	return (devc->prof->max_samplerate / samplerate) - 1;
}