-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_cat
executable file
·124 lines (103 loc) · 3.15 KB
/
config_cat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
# A script to configure Lattice iCE40 FPGA by SPI from Raspberry Pi
#
# Copyright (C) 2015 Jan Marjanovic <jan@marjanovic.pro>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
echo ""
if [ $# -ne 1 ]; then
echo "Usage: $0 FPGA-bin-file "
exit 1
fi
if [ $EUID -ne 0 ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
if [ ! -d /sys/class/gpio/gpio25 ]; then
echo "GPIO 25 not exported, trying to export..."
echo 25 > /sys/class/gpio/export
if [ ! -d /sys/class/gpio/gpio25 ]; then
echo "ERROR: directory /sys/class/gpio/gpio25 does not exist"
exit 1
fi
else
echo "OK: GPIO 25 exported"
fi
if [ ! -d /sys/class/gpio/gpio17 ]; then
echo "GPIO 17 not exported, trying to export..."
echo 17 > /sys/class/gpio/export
if [ ! -d /sys/class/gpio/gpio17 ]; then
echo "ERROR: directory /sys/class/gpio/gpio17 does not exist"
exit 1
fi
else
echo "OK: GPIO 17 exported"
fi
if [ ! -d /sys/class/gpio/gpio22 ]; then
echo "GPIO 22 not exported, trying to export..."
echo 22 > /sys/class/gpio/export
if [ ! -d /sys/class/gpio/gpio22 ]; then
echo "ERROR: directory /sys/class/gpio/gpio22 does not exist"
exit 1
fi
else
echo "OK: GPIO 22 exported"
fi
echo ""
if [ -e /dev/spidev0.0 ]; then
echo "OK: SPI driver loaded"
else
echo "spidev does not exist"
lsmod | grep spi_bcm2708 >& /dev/null
if [ $? -ne 0 ]; then
echo "SPI driver not loaded, try to load it..."
modprobe spi_bcm2708
if [ $? -eq 0 ]; then
echo "OK: SPI driver loaded"
else
echo "Could not load SPI driver"
exit 1
fi
fi
fi
echo ""
echo "Setting GPIO directions"
echo out > /sys/class/gpio/gpio25/direction
cat /sys/class/gpio/gpio25/direction
echo out > /sys/class/gpio/gpio22/direction
cat /sys/class/gpio/gpio22/direction
echo in > /sys/class/gpio/gpio17/direction
cat /sys/class/gpio/gpio17/direction
echo "Setting output to low"
echo 0 > /sys/class/gpio/gpio25/value
cat /sys/class/gpio/gpio25/value
#echo ""
#echo "Please reset the iCE40 FPGA board"
#echo "Press any key..."
#read
echo "Reseting FPGA"
echo 0 > /sys/class/gpio/gpio22/value
cat /sys/class/gpio/gpio22/value
echo 1 > /sys/class/gpio/gpio22/value
cat /sys/class/gpio/gpio22/value
echo "Checking DONE pin"
cat /sys/class/gpio/gpio17/value
echo "Continuing with configuration procedure"
dd if=$1 of=/dev/spidev0.0
echo -e "\x0\x0\x0\x0\x0\x0\x0" > /dev/spidev0.0
echo "Setting output to high"
echo 1 > /sys/class/gpio/gpio25/value
cat /sys/class/gpio/gpio25/value
echo "Checking DONE pin"
cat /sys/class/gpio/gpio17/value