blob: c23349fa183339bb0e8201e48c304858c2199e41 (
plain)
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
|
#!/bin/sh
#
# Copyright 2004-present Facebook. All rights reserved.
#
# This program file 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; version 2 of the License.
#
# 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 in a file named COPYING; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
usage() {
echo "Displays values onto the debug header LEDs."
echo "Hex and decimal accepted."
echo "Usage: $0 <value>"
}
. /usr/local/fbpackages/utils/ast-functions
# Function to set the less significant hex digit
display_lower() {
local bit0=$(expr $1 % 2)
local bit1=$(expr $1 / 2 % 2)
local bit2=$(expr $1 / 4 % 2)
local bit3=$(expr $1 / 8 % 2)
# Set the pins to the correct operating mode.
# The relevant pins are GPIOG[0...3].
# For GPIO bank G, SCU84[0..3] must be 0.
devmem_clear_bit $(scu_addr 84) 0
devmem_clear_bit $(scu_addr 84) 1
devmem_clear_bit $(scu_addr 84) 2
devmem_clear_bit $(scu_addr 84) 3
# Now set the GPIOs to the right binary values
gpio_set 48 $bit0
gpio_set 49 $bit1
gpio_set 50 $bit2
gpio_set 51 $bit3
}
# Function to set the more significant hex digit
display_upper() {
local bit0=$(expr $1 % 2)
local bit1=$(expr $1 / 2 % 2)
local bit2=$(expr $1 / 4 % 2)
local bit3=$(expr $1 / 8 % 2)
# Set the pins to the correct operating mode.
# The relevant pins are GPIOB[4...7].
# GPIOB4: SCU80[12] = 0 and Strap[14] = 0
# GPIOB5: SCU80[13] = 0
# GPIOB6: SCU80[14] = 0
# GPIOB7: SCU80[15] = 0
devmem_clear_bit $(scu_addr 70) 14
devmem_clear_bit $(scu_addr 80) 12
devmem_clear_bit $(scu_addr 80) 13
devmem_clear_bit $(scu_addr 80) 14
devmem_clear_bit $(scu_addr 80) 15
gpio_set 12 $bit0
gpio_set 13 $bit1
gpio_set 14 $bit2
gpio_set 15 $bit3
}
# Check number of parameters
if [ $# -ne 1 ]
then
usage
exit 1
fi
# Make sure input is actually numeric
DEC_VALUE=$(printf "%d" $1 2>/dev/null)
if [ $? -eq 1 ]
then
echo "Unable to parse input as numeric value."
exit 1
fi
# Make sure input is within proper range
if [ $DEC_VALUE -lt 0 ] || [ $DEC_VALUE -gt 255 ]
then
echo "Value $DEC_VALUE is outside of displayable range 0 - 0xff (255)."
exit 1
fi
# Get upper/lower decimal values
LOWER_DEC_VALUE=$(expr $DEC_VALUE % 16)
UPPER_DEC_VALUE=$(expr $DEC_VALUE / 16)
# Display the results
display_lower $LOWER_DEC_VALUE
display_upper $UPPER_DEC_VALUE
|