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):
16 if ifaceklsdict
is None:
18 UserDict
.__init
__(self
, {})
21 ift
= 'interfaces.txt'
23 ift
= os
.path
.join(pth
, ift
)
24 with
open(ift
, 'r') as ifile
:
25 for ln
in ifile
.readlines():
28 name
= ln
[0] # will have uart
29 count
= int(ln
[1]) # will have count of uart
30 # spec looks like this:
32 [{'name': 'sda', 'outen': True},
33 {'name': 'scl', 'outen': True},
37 for k
, v
in ifaceklsdict
.items():
38 if name
.startswith(k
):
41 spec
, ganged
= self
.read_spec(pth
, name
)
42 # XXX HORRIBLE hack!!!
43 if name
== 'pwm' and count
== 1 and len(spec
) != 1:
44 #print "read", name, count, spec, ganged
45 #print "multi pwm", spec[:1], len(spec)
46 spec
[0]['name'] = 'out'
47 iface
= ikls(name
, spec
[:1], ganged
, False)
48 self
.ifaceadd(name
, len(spec
), iface
)
50 iface
= ikls(name
, spec
, ganged
, count
== 1)
51 self
.ifaceadd(name
, count
, iface
)
53 def getifacetype(self
, fname
):
54 # finds the interface type, e.g sd_d0 returns "inout"
55 for iface
in self
.values():
56 typ
= iface
.getifacetype(fname
)
57 # if fname.startswith('pwm'):
58 # print fname, iface.ifacename, typ
63 def ifaceadd(self
, name
, count
, iface
, at
=None):
65 at
= len(self
.ifacecount
) # ifacecount is a list
66 self
.ifacecount
.insert(at
, (name
, count
)) # appends the list
67 # with (name,count) *at* times
71 will check specific files of kind peripheral.txt like spi.txt,
72 uart.txt in test directory
75 def read_spec(self
, pth
, name
):
78 fname
= '%s.txt' % name
80 ift
= os
.path
.join(pth
, fname
)
81 with
open(ift
, 'r') as sfile
:
82 for ln
in sfile
.readlines():
86 d
= {'name': name
, # here we start to make the dictionary
89 d
['action'] = True # adding element to the dict
90 elif ln
[1] == 'inout':
96 ganged
[bus
].append(name
)