DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
timing
python
afc
mmc.py
Go to the documentation of this file.
1
from
__future__
import
print_function
2
3
import
struct
4
import
click
5
from
click
import
echo, style, secho
6
from
.click_texttable
import
Texttable
7
from
.
import
toolbox
8
from
.
import
ipmi
9
10
# ------------------------------------------------------------------------------
11
@click.group('mmc', invoke_without_command=False)
12
@click.pass_obj
13
def
mmc(obj):
14
# make ipmi connection
15
obj.ipmi_connection = ipmi.establishIPMIConnectionToAMC(obj.mch_ip_adr, obj.amc_slot)
16
# ------------------------------------------------------------------------------
17
18
# ------------------------------------------------------------------------------
19
@mmc.command('read-pin-port-status', short_help='Read back the configuration and states of the AMC MMC pins for a particular port')
20
@click.option('--port-number', 'port_number', required=True, type=toolbox.IntRange(0x0,0x4)
, help=
'MMC pin port, 0-4'
)
21
@click.pass_obj
22
def
read_pin_port_status
(obj, port_number):
23
echo(
readGPIOPortOverIPMI
(obj.ipmi_connection, port_number) )
24
obj.ipmi_connection.session.close()
25
# ------------------------------------------------------------------------------
26
27
# ------------------------------------------------------------------------------
28
def
readGPIOPortOverIPMI
(ipmi_connection, port):
29
raw_gpio_cmd = b
'\x01'
30
mode=b
'\x00'
31
cmd = raw_gpio_cmd+struct.pack(
"B"
, port)+mode
32
33
cmd_result = []
34
result = ipmi_connection.raw_command(0x00, 0x30, cmd)
35
36
for
char
in
result:
37
cmd_result.append(char)
38
39
# first 4 bytes contain the pin directions
40
port_directions_flag=0b0
41
for
i
in
range(4,0,-1):
42
port_directions_flag = (port_directions_flag << 8) | cmd_result[i]
43
44
# second 4 bytes contain the pin states
45
port_states_flag=0b0
46
for
i
in
range(8,4,-1):
47
port_states_flag = (port_states_flag << 8) | cmd_result[i]
48
49
portTable =
Texttable
(max_width=0)
50
portTable.set_deco(Texttable.VLINES | Texttable.BORDER | Texttable.HEADER)
51
portTable.set_cols_align([
"l"
,
"l"
,
"l"
])
52
portTable.set_chars([
'-'
,
'|'
,
'+'
,
'-'
])
53
portTable.header( [
'Pin'
,
'Direction'
,
'State'
] )
54
55
for
i
in
range(32):
56
pin_dir =
'In'
57
pin_dir_colour =
'yellow'
58
if
port_directions_flag & (0x1 << i):
59
pin_dir =
'Out'
60
pin_dir_colour =
'green'
61
62
pin_state =
'Low'
63
pin_state_colour =
'blue'
64
if
port_states_flag & (0x1 << i):
65
pin_state =
'High'
66
pin_state_colour =
'red'
67
68
portTable.add_row( [i, style(pin_dir, fg=pin_dir_colour), style(pin_state, fg=pin_state_colour)] )
69
70
print(
"Port {} pins"
.format(port))
71
return
portTable.draw()
72
# ------------------------------------------------------------------------------
73
74
# mode description: 0 - read port info, 1 - set port dir to in, 2 - set port dir to out with optional value
75
# ------------------------------------------------------------------------------
76
def
configureGPIOPortOverIPMI
(ipmi_connection, port, mode, pin, value=-1):
77
78
if
mode < 1
or
mode > 2:
79
raise
click.ClickException(
"Valid configuring modes are 1 or 2"
)
80
81
raw_gpio_cmd = b
'\x01'
82
cmd = raw_gpio_cmd + struct.pack(
"B"
, port) + struct.pack(
"B"
, mode) + struct.pack(
"B"
, pin)
83
84
if
mode==2
and
value >= 0:
85
cmd = cmd+struct.pack(
"B"
, value)
86
87
cmd_attempts=0
88
max_attempts=10
89
while
True
:
90
if
cmd_attempts > max_attempts:
91
raise
click.ClickException(
"Failed to configure port {} pin {} after {} attempts"
.format(hex(port), hex(pin), max_attempts))
92
cmd_result = []
93
result = ipmi_connection.raw_command(0x00, 0x30, cmd)
94
for
char
in
result:
95
cmd_result.append(char)
96
if
cmd_result[1] == 0
and
mode == 0x1:
97
return
98
elif
cmd_result[1] == 1
and
mode == 0x2:
99
if
value < 0:
100
return
101
else
:
102
if
cmd_result[2] == value:
103
return
104
else
:
105
echo (
"error configured pin state {}, does not match requested {}"
.format(cmd_result[2], value))
106
cmd_attempts += 1
107
else
:
108
cmd_attempts += 1
109
# ------------------------------------------------------------------------------
afc.click_texttable.Texttable
Definition
click_texttable.py:149
afc.mmc.configureGPIOPortOverIPMI
configureGPIOPortOverIPMI(ipmi_connection, port, mode, pin, value=-1)
Definition
mmc.py:76
afc.mmc.readGPIOPortOverIPMI
readGPIOPortOverIPMI(ipmi_connection, port)
Definition
mmc.py:28
afc.mmc.read_pin_port_status
read_pin_port_status(obj, port_number)
Definition
mmc.py:22
Generated on
for DUNE-DAQ by
1.17.0