mirror of
https://github.com/ebrandi/FDD-book.git
synced 2026-12-06 00:23:30 +00:00
Organize companion code and materials by book part: part-01/ Foundations part-02/ Kernel & driver fundamentals part-03/ Character & block devices part-04/ Networking & storage part-05/ Buses & advanced topics part-06/ Debugging & performance part-07/ Real-world drivers appendices/ Supplementary material README.md Overview and build instructions
33 lines
771 B
Bash
Executable file
33 lines
771 B
Bash
Executable file
#!/bin/sh
|
|
# sim_sensor_oscillates.sh -- Chapter 17 Lab: sensor breathes.
|
|
#
|
|
# Confirms that the SENSOR register value changes autonomously over
|
|
# time. Samples the register several times with sleeps between samples
|
|
# and fails if all samples are identical.
|
|
|
|
set -e
|
|
|
|
DEV=dev.myfirst.0
|
|
|
|
if ! sysctl -q "${DEV}" >/dev/null 2>&1; then
|
|
echo "FAIL: ${DEV} not present. Load myfirst.ko first." >&2
|
|
exit 2
|
|
fi
|
|
|
|
sensor_value() {
|
|
sysctl -n "${DEV}.reg_sensor"
|
|
}
|
|
|
|
first=$(sensor_value)
|
|
sleep 0.5
|
|
second=$(sensor_value)
|
|
sleep 0.5
|
|
third=$(sensor_value)
|
|
|
|
if [ "${first}" = "${second}" ] && [ "${second}" = "${third}" ]; then
|
|
echo "FAIL: sensor value did not change: ${first}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "PASS: sensor oscillates. Samples: ${first} ${second} ${third}"
|
|
exit 0
|