4 from UserDict
import UserDict
6 from collections
import UserDict
9 class InterfacesBase(UserDict
):
10 """ contains a list of interface definitions
13 def __init__(self
, ifacekls
, pth
=None, ifaceklsdict
=None):
17 if ifaceklsdict
is None:
19 UserDict
.__init
__(self
, {})
22 ift
= 'interfaces.txt'
24 ift
= os
.path
.join(pth
, ift
)
25 with
open(ift
, 'r') as ifile
:
26 for ln
in ifile
.readlines():
29 name
= ln
[0] # will have uart
30 count
= int(ln
[1]) # will have count of uart
31 self
.fastbus
+= ln
[2:]
32 # spec looks like this:
34 [{'name': 'sda', 'outen': True},
35 {'name': 'scl', 'outen': True},
39 for k
, v
in ifaceklsdict
.items():
40 if name
.startswith(k
):
43 spec
, ganged
= self
.read_spec(pth
, name
)
44 # XXX HORRIBLE hack!!!
45 if name
== 'pwm' and count
== 1 and len(spec
) != 1:
46 #print "read", name, count, spec, ganged
47 #print "multi pwm", spec[:1], len(spec)
48 spec
[0]['name'] = 'out'
49 iface
= ikls(name
, spec
[:1], ganged
, False)
50 self
.ifaceadd(name
, len(spec
), iface
)
52 iface
= ikls(name
, spec
, ganged
, count
== 1)
53 self
.ifaceadd(name
, count
, iface
)
55 def getifacetype(self
, fname
):
56 # finds the interface type, e.g sd_d0 returns "inout"
57 for iface
in self
.values():
58 typ
= iface
.getifacetype(fname
)
59 # if fname.startswith('pwm'):
60 # print fname, iface.ifacename, typ
65 def ifaceadd(self
, name
, count
, iface
, at
=None):
67 at
= len(self
.ifacecount
) # ifacecount is a list
68 self
.ifacecount
.insert(at
, (name
, count
)) # appends the list
69 # with (name,count) *at* times
73 will check specific files of kind peripheral.txt like spi.txt,
74 uart.txt in test directory
77 def read_spec(self
, pth
, name
):
80 fname
= '%s.txt' % name
82 ift
= os
.path
.join(pth
, fname
)
83 with
open(ift
, 'r') as sfile
:
84 for ln
in sfile
.readlines():
88 d
= {'name': name
, # here we start to make the dictionary
91 d
['action'] = True # adding element to the dict
92 elif ln
[1] == 'inout':
98 ganged
[bus
].append(name
)