Skip to content

Commit

Permalink
[utils] - added some test scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Neill committed Mar 3, 2011
1 parent aef7906 commit aa659ff
Show file tree
Hide file tree
Showing 5 changed files with 213 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pbctl/pb_driver-load.sh
@@ -0,0 +1,35 @@
#!/bin/bash
#Copyright Richard Neill, 2011. Free software, licensed under GNU GPL version 3 or later.

#For backward compatibility only.

#This script explicitly loads the pulseblaster module, and grants the permissions.
#"make install" should already have set this up, such that:
# - the pulseblaster module is automatically loaded at boot
# - the permissions for the device in /sys are granted to the user at login
# (see /etc/security/console.perms.d/90-pulseblaster.perms and pam_console_apply)

module=pulseblaster
device=/sys/class/pulseblaster/pulseblaster0

if [ "$1" == "-h" -o "$1" == "--help" ];then
echo -e "This script loads the pulseblaster module ($module) and grants the permissions on ($device/*) to the logged in user."
echo -e "It shouldn't normally be necessary: the module should auto-load at boot, and get permissions at login."
echo -e "See also /etc/security/console.perms.d/90-pulseblaster.perms and pam_console_apply."
echo -e "USAGE:\t `basename $0`\n"
exit 1
fi


# Root or die
if [ "$(id -u)" != "0" ]; then
echo "You must be root to load or unload kernel modules"
exit 1
fi

#Do it
modprobe $module
pam_console_apply

#Say so
echo pulseblaster driver loaded.
25 changes: 25 additions & 0 deletions pbctl/pb_driver-unload.sh
@@ -0,0 +1,25 @@
#!/bin/bash
#Copyright Richard Neill, 2011. Free software, licensed under GNU GPL version 3 or later.

#For backward compatibility only.
#This script explicitly unloads the pulseblaster module

module=pulseblaster

if [ "$1" == "-h" -o "$1" == "--help" ];then
echo -e "This script unloads the pulseblaster module ($module)."
echo -e "USAGE:\t `basename $0`\n"
exit 1
fi

# Root or die
if [ "$(id -u)" != "0" ]; then
echo "You must be root to load or unload kernel modules"
exit 1
fi

#Do it
modprobe -r $module

#Say so
echo pulseblaster driver removed.
39 changes: 39 additions & 0 deletions pbctl/pb_test-flash-2Hz.sh
@@ -0,0 +1,39 @@
#!/bin/bash
#Copyright Richard Neill, 2011. Free software, licensed under GNU GPL version 3 or later.

#Quick test script to make the pulseblaster flash all outputs at 2Hz.
#This tests just the pulseblaster driver (not pb_utils, pb_parse etc).
#So it directly interfaces with the /sys interface.
#See doc/pulseblaster/raw.txt for the format of the binary file.

#A very simple pulseblaster program: so trivial we can store it as a string!
#Note that the first 3 bytes are the outputs that we set.
BIN_IMAGE="ffff ff00 0000 017d 783d 0000 0000 0006 017d 783d"

#Program and start interface.
PROGRAM=/sys/class/pulseblaster/pulseblaster0/program
START=/sys/class/pulseblaster/pulseblaster0/start
STOP=/sys/class/pulseblaster/pulseblaster0/stop

if [ $# -ge 1 ] ;then
echo "Simple test of the pulseblaster hardware and driver (without using pb_utils or pb_parse)."
echo "Flash all the outputs at 2Hz"
echo "This writes directly to the program interface: $PROGRAM"
echo "The program itself (via xxd -p -r) is: $BIN_IMAGE"
echo "Usage: `basename $0`"
exit 1
fi

#Load pb module and apply permissions (normally automatic, but useful if we installed it and haven't rebooted yet)
lsmod | grep -q pulseblaster || pb_driver-load

#Program it
echo -n "$BIN_IMAGE" | xxd -p -r > $PROGRAM

#Start it.
echo 1 > $START

#Say something
echo "Pulseblaster is now flashing all outputs at 2Hz."
echo "To stop it: 'echo 1 > $STOP'"

40 changes: 40 additions & 0 deletions pbctl/pb_test-flash-fastest-5.55MHz.sh
@@ -0,0 +1,40 @@
#!/bin/bash
#Copyright Richard Neill, 2011. Free software, licensed under GNU GPL version 3 or later.

#Quick test script to make the pulseblaster flash all outputs as fast as possible (5.55 MHz).
#This tests just the pulseblaster driver (not pb_utils, pb_parse etc).
#So it directly interfaces with the /sys interface.
#See doc/pulseblaster/raw.txt for the format of the binary file.

#A very simple pulseblaster program: so trivial we can store it as a string!
#Note that the first 3 bytes are the outputs that we set.
#The value 00000006 is the interval. (not to be confused with the 9th byte, also value 6, meaning "goto")
BIN_IMAGE="ffff ff00 0000 0000 0006 0000 0000 0006 0000 0006"

#Program and start interface.
PROGRAM=/sys/class/pulseblaster/pulseblaster0/program
START=/sys/class/pulseblaster/pulseblaster0/start
STOP=/sys/class/pulseblaster/pulseblaster0/stop

if [ $# -ge 1 ] ;then
echo "Simple test of the pulseblaster hardware and driver (without using pb_utils or pb_parse)."
echo "Flash all the outputs at 5.55 MHz"
echo "This writes directly to the program interface: $PROGRAM"
echo "The program itself (via xxd -p -r) is: $BIN_IMAGE"
echo "Usage: `basename $0`"
exit 1
fi

#Load pb module and apply permissions (normally automatic, but useful if we installed it and haven't rebooted yet)
lsmod | grep -q pulseblaster || pb_driver-load

#Program it
echo -n "$BIN_IMAGE" | xxd -p -r > $PROGRAM

#Start it.
echo 1 > $START

#Say something
echo "Pulseblaster is now flashing all outputs at 2Hz."
echo "To stop it: 'echo 1 > $STOP'"

74 changes: 74 additions & 0 deletions pbctl/pb_test-identify-output.sh
@@ -0,0 +1,74 @@
#!/bin/bash
#Copyright Richard Neill, 2011. Free software, licensed under GNU GPL version 3 or later.

#Quick test script to make the pulseblaster flash a specific outputs at 2Hz.
#Useful to identify which wire connects to what.
#This tests just the pulseblaster driver (not pb_utils, pb_parse etc).
#So it directly interfaces with the /sys interface.
#See doc/pulseblaster/raw.txt for the format of the binary file.

#A very simple pulseblaster program: so trivial we can store it as a string!
#Note that the first 3 bytes must be prepended as the outputs that we set.
BIN_IMAGE_END="00 0000 017d 783d 0000 0000 0006 017d 783d"

#Program and start interface.
PROGRAM=/sys/class/pulseblaster/pulseblaster0/program
START=/sys/class/pulseblaster/pulseblaster0/start
STOP=/sys/class/pulseblaster/pulseblaster0/stop

if [ "$1" == "-h" -o "$1" == "--help" ] ;then
echo "Identify pulseblaster outputs. Flash one line at 2Hz."
echo "Usage: `basename $0` BIT_N"
echo " where BIT_N is 0 .. 23"
exit 1
elif [ $# -ne 1 ];then
echo "Invoke with -h for usage"
exit 1
fi

#Which bit? Then work out the output.
BIT=$1
case $BIT in
0) OUT="00 00 01";;
1) OUT="00 00 02";;
2) OUT="00 00 04";;
3) OUT="00 00 08";;
4) OUT="00 00 10";;
5) OUT="00 00 20";;
6) OUT="00 00 40";;
7) OUT="00 00 80";;
8) OUT="00 01 00";;
9) OUT="00 02 00";;
10) OUT="00 04 00";;
11) OUT="00 08 00";;
12) OUT="00 10 00";;
13) OUT="00 20 00";;
14) OUT="00 40 00";;
15) OUT="00 80 00";;
16) OUT="01 00 00";;
17) OUT="02 00 00";;
18) OUT="04 00 00";;
19) OUT="08 00 00";;
20) OUT="10 00 00";;
21) OUT="20 00 00";;
22) OUT="40 00 00";;
23) OUT="80 00 00";;
*) echo "Error, bit must be 0 .. 23"; exit 1;;
esac

#Build the program:
BIN_IMAGE=$OUT$BIN_IMAGE_END

#Load pb module and apply permissions (normally automatic, but useful if we installed it and haven't rebooted yet)
lsmod | grep -q pulseblaster || pb_driver-load

#Program it
echo -n "$BIN_IMAGE" | xxd -p -r > $PROGRAM

#Start it.
echo 1 > $START

#Say something
echo "Pulseblaster is now flashing output bit $BIT ($OUT) at 2Hz."
echo "To stop it: 'echo 1 > $STOP'"

0 comments on commit aa659ff

Please sign in to comment.