2 * This file is part of the libsigrok project.
4 * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 SR_PRIV size_t get_memory_size(int type)
26 if (type == MEMORY_SIZE_8K)
28 if (type <= MEMORY_SIZE_8M)
29 return (32 * 1024) << type;
33 static int clz(unsigned int x)
38 if (!(x & 0xFFFF0000)) {
42 if (!(x & 0xFF000000)) {
46 if (!(x & 0xF0000000)) {
50 if (!(x & 0xC0000000)) {
54 if (!(x & 0x80000000))
59 SR_PRIV int set_limit_samples(struct dev_context *devc, uint64_t samples)
63 if (samples > devc->max_sample_depth)
64 samples = devc->max_sample_depth;
66 devc->limit_samples = samples;
68 if (samples <= (2 * 1024))
69 devc->memory_size = MEMORY_SIZE_8K;
70 else if (samples <= (16 * 1024))
71 devc->memory_size = MEMORY_SIZE_64K;
73 devc->memory_size = 19 - clz(samples - 1);
75 mem_kb = get_memory_size(devc->memory_size) / 1024;
76 sr_info("Setting memory size to %zuK.", mem_kb);
78 analyzer_set_memory_size(devc->memory_size);
83 SR_PRIV int set_voltage_threshold(struct dev_context *devc, double thresh)
90 devc->cur_threshold = thresh;
92 analyzer_set_voltage_threshold((int) round(-9.1*thresh + 62.6));
94 sr_info("Setting voltage threshold to %fV.", devc->cur_threshold);
99 SR_PRIV void set_triggerbar(struct dev_context *devc)
101 unsigned int trigger_depth, triggerbar, ramsize_trigger;
103 trigger_depth = get_memory_size(devc->memory_size) / 4;
104 if (devc->limit_samples < trigger_depth)
105 trigger_depth = devc->limit_samples;
108 triggerbar = (trigger_depth * devc->capture_ratio) / 100;
112 ramsize_trigger = trigger_depth - triggerbar;
113 /* Matches USB packet captures from official app/driver */
117 ramsize_trigger -= 1;
121 analyzer_set_triggerbar_address(triggerbar);
122 analyzer_set_ramsize_trigger_address(ramsize_trigger);
124 sr_dbg("triggerbar_address = %d(0x%x)", triggerbar, triggerbar);
125 sr_dbg("ramsize_triggerbar_address = %d(0x%x)",
126 ramsize_trigger, ramsize_trigger);