Quelle gpio-sloppy-logic-analyzer.sh
Sprache: Shell
#!/bin/sh -eu # SPDX-License-Identifier: GPL-2.0 # # Helper script for the Linux Kernel GPIO sloppy logic analyzer # # Copyright (C) Wolfram Sang <wsa@sang-engineering.com> # Copyright (C) Renesas Electronics Corporation
samplefreq=1000000
numsamples=250000
cpusetdefaultdir='/sys/fs/cgroup'
cpusetprefix='cpuset.'
debugdir='/sys/kernel/debug'
ladirname='gpio-sloppy-logic-analyzer'
outputdir="$PWD"
neededcmds='taskset zip'
max_chans=8
duration=
initcpu=
listinstances=0
lainstance=
lasysfsdir=
triggerdat=
trigger_bindat=
progname="${0##*/}"
print_help()
{ cat << EOF
$progname - helper script for the Linux Kernel Sloppy GPIO Logic Analyzer
Available options:
-c|--cpu <n>: which CPU to isolate for sampling. Only needed once. Default <1>.
Remember that a more powerful CPU gives you higher sampling speeds.
Also CPU0 is not recommended as it usually does extra bookkeeping.
-d|--duration-us <SI-n>: number of microseconds to sample. Overrides -n, no default value.
-h|--help: print this help
-i|--instance <str>: name of the logic analyzer in case you have multiple instances. Default
to first instance found
-k|--kernel-debug-dir <str>: path to the kernel debugfs mountpoint. Default: <$debugdir>
-l|--list-instances: list all available instances
-n|--num_samples <SI-n>: number of samples to acquire. Default <$numsamples>
-o|--output-dir <str>: directory to put the result files. Default: current dir
-s|--sample_freq <SI-n>: desired sampling frequency. Might be capped if too large.
Default: <1000000>
-t|--trigger <str>: pattern to use as trigger. <str> consists of two-char pairs. First
char is channel number starting at "1". Second char is trigger level: "L" - low; "H" - high; "R" - rising; "F" - falling
These pairs can be combined with "+", so "1H+2F" triggers when probe 1
is high while probe 2 has a falling edge. You can have multiple triggers
combined with ",". So, "1H+2F,1H+2R" is like the example before but it
waits for a rising edge on probe 2 while probe 1 is still high after the
first trigger has been met.
Trigger data will only be used for the next capture and then be erased.
<SI-n> is an integer value where SI units "T", "G", "M", "K" are recognized, e.g. '1M500K' is 1500000.
Examples:
Samples $numsamples values at 1MHz with an already prepared CPU or automatically prepares CPU1 if needed,
use the first logic analyzer instance found: '$progname'
Samples 50us at 2MHz waiting for a falling edge on channel 2. CPU and instance as above: '$progname -d 50 -s 2M -t "2F"'
Note that the process exits after checking all parameters but a sub-process still works in
the background. The result is only available once the sub-process finishes.
Result is a .sr file to be consumed with PulseView from the free Sigrok project. It is
a zip file which also contains the binary sample data which may be consumed by others.
The filename is the logic analyzer instance name plus a since-epoch timestamp.
EOF
}
fail()
{ echo"$1"
exit 1
}
parse_si()
{
conv_si="$(printf $1 | sed 's/[tT]+\?/*1000G+/g; s/[gG]+\?/*1000M+/g; s/[mM]+\?/*1000K+/g; s/[kK]+\?/*1000+/g; s/+$//')"
si_val="$((conv_si))"
}
set_newmask()
{ for f in $(find "$1" -iname "$2"); doecho"$newmask" > "$f" 2>/dev/null || true; done
}
# Move tasks away from isolated CPU for p in $(ps -o pid | tail -n +2); do
mask=$(taskset -p "$p") || continue # Ignore tasks with a custom mask, i.e. not equal $oldmask
[ "${mask##*: }" = "$oldmask" ] || continue
taskset -p "$newmask""$p" || continue done 2>/dev/null >/dev/null
# Big hammer! Working with 'rcu_momentary_eqs()' for a more fine-grained solution # still printed warnings. Same for re-enabling the stall detector after sampling. echo 1 > /sys/module/rcupdate/parameters/rcu_cpu_stall_suppress
if [ -n "$triggerdat" ]; then
parse_triggerdat "$triggerdat"
printf "$trigger_bindat" > "$lasysfsdir"/trigger 2>/dev/null || fail "Trigger data '$triggerdat' rejected" fi
workcpu=$(cat"${lacpusetfile}effective_cpus")
[ -n "$workcpu" ] || fail "No isolated CPU found"
cpumask=$(printf '%x' $((1 << workcpu)))
instance=${lasysfsdir##*/} echo"Setting up '$instance': $numsamples samples at ${samplefreq}Hz with ${triggerdat:-no} trigger using CPU$workcpu"
do_capture "$cpumask" &
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.