Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
euro-adc-65m-14b-40cha-gw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
eurocard
euro-adc-65m-14b-40cha
euro-adc-65m-14b-40cha-gw
Commits
934276ff
Commit
934276ff
authored
Aug 31, 2017
by
Dave Newbold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding config check for si****
parent
cca11ec3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
113 deletions
+43
-113
si5344.py
components/solid/software/si5344.py
+43
-113
No files found.
components/solid/software/si5344.py
View file @
934276ff
...
...
@@ -5,127 +5,57 @@ import StringIO
import
csv
class
si5344
:
#Class to configure the Si5344 clock generator
def
__init__
(
self
,
i2c
,
slaveaddr
=
0x68
):
self
.
i2c
=
i2c
self
.
slaveaddr
=
slaveaddr
#self.configList=
#def writeReg(self, address, data):
def
readRegister
(
self
,
myaddr
,
nwords
):
### Read a specific register on the Si5344 chip. There is not check on the validity of the address but
### the code sets the correct page before reading.
#First make sure we are on the correct page
currentPg
=
self
.
getPage
()
requirePg
=
(
myaddr
&
0xFF00
)
>>
8
# print "REG", hex(myaddr), "CURR PG" , hex(currentPg[0]), "REQ PG", hex(requirePg)
if
currentPg
[
0
]
!=
requirePg
:
self
.
setPage
(
requirePg
)
#Now read from register.
addr
=
[]
addr
.
append
(
myaddr
)
mystop
=
False
self
.
i2c
.
write
(
self
.
slaveaddr
,
addr
,
mystop
)
# time.sleep(0.1)
res
=
self
.
i2c
.
read
(
self
.
slaveaddr
,
nwords
)
return
res
def
writeRegister
(
self
,
myaddr
,
data
,
verbose
=
False
):
### Write a specific register on the Si5344 chip. There is not check on the validity of the address but
### the code sets the correct page before reading.
### myaddr is an int
### data is a list of ints
#First make sure we are on the correct page
myaddr
=
myaddr
&
0xFFFF
currentPg
=
self
.
getPage
()
requirePg
=
(
myaddr
&
0xFF00
)
>>
8
# print "REG", hex(myaddr), "CURR PG" , currentPg, "REQ PG", hex(requirePg)
if
currentPg
[
0
]
!=
requirePg
:
self
.
setPage
(
requirePg
)
#Now write to register.
data
.
insert
(
0
,
myaddr
)
if
verbose
:
print
" Writing: "
result
=
"
\t
"
for
iaddr
in
data
:
result
+=
"
%#02
x "
%
(
iaddr
)
print
result
self
.
i2c
.
write
(
self
.
slaveaddr
,
data
)
#time.sleep(0.01)
def
setPage
(
self
,
page
,
verbose
=
False
):
#Configure the chip to perform operations on the specified address page.
mystop
=
True
myaddr
=
[
0x01
,
page
]
self
.
i2c
.
write
(
self
.
slaveaddr
,
myaddr
,
mystop
)
#time.sleep(0.01)
if
verbose
:
print
"Si5344 Set Reg Page:"
,
page
def
getPage
(
self
,
verbose
=
False
):
#Read the current address page
mystop
=
False
myaddr
=
[
0x01
]
self
.
i2c
.
write
(
self
.
slaveaddr
,
myaddr
,
mystop
)
rPage
=
self
.
i2c
.
read
(
self
.
slaveaddr
,
1
)
#time.sleep(0.1)
if
verbose
:
print
" Page read:"
,
rPage
return
rPage
def
getDeviceVersion
(
self
):
#Read registers containing chip information
mystop
=
False
nwords
=
2
myaddr
=
[
0x02
]
#0xfa
def
__init__
(
self
,
i2c
,
slaveaddr
=
0x68
):
self
.
i2c
=
i2c
self
.
slaveaddr
=
slaveaddr
def
readRegister
(
self
,
myaddr
,
nwords
):
currentPg
=
self
.
getPage
()
requirePg
=
(
myaddr
&
0xFF00
)
>>
8
if
currentPg
[
0
]
!=
requirePg
:
self
.
setPage
(
requirePg
)
self
.
i2c
.
write
(
self
.
slaveaddr
,
[
myaddr
],
False
)
return
self
.
i2c
.
read
(
self
.
slaveaddr
,
nwords
)
def
writeRegister
(
self
,
myaddr
,
data
):
myaddr
=
myaddr
&
0xFFFF
currentPg
=
self
.
getPage
()
requirePg
=
(
myaddr
&
0xFF00
)
>>
8
if
currentPg
[
0
]
!=
requirePg
:
self
.
setPage
(
requirePg
)
data
.
insert
(
0
,
myaddr
)
self
.
i2c
.
write
(
self
.
slaveaddr
,
[
myaddr
])
def
setPage
(
self
,
page
):
myaddr
=
[
0x01
,
page
]
self
.
i2c
.
write
(
self
.
slaveaddr
,
[
0x01
,
page
],
True
)
def
getPage
(
self
):
self
.
i2c
.
write
(
self
.
slaveaddr
,
[
0x01
],
False
)
return
self
.
i2c
.
read
(
self
.
slaveaddr
,
1
)
def
getDeviceVersion
(
self
):
self
.
setPage
(
0
)
self
.
i2c
.
write
(
self
.
slaveaddr
,
myaddr
,
mystop
)
#time.sleep(0.1)
res
=
self
.
i2c
.
read
(
self
.
slaveaddr
,
nwords
)
print
" CLOCK EPROM: "
result
=
"
\t
"
for
iaddr
in
res
:
result
+=
"
%#02
x "
%
(
iaddr
)
print
result
return
res
self
.
i2c
.
write
(
self
.
slaveaddr
,
[
0x02
],
False
)
return
self
.
i2c
.
read
(
self
.
slaveaddr
,
2
)
def
parse_clk
(
self
,
filename
):
#Parse the configuration file produced by Clockbuilder Pro (Silicon Labs)
def
parse_clk
(
self
,
filename
):
deletedcomments
=
""""""
print
"
\t
Parsing file"
,
filename
with
open
(
filename
,
'rb'
)
as
configfile
:
for
i
,
line
in
enumerate
(
configfile
):
if
not
line
.
startswith
(
'#'
)
:
if
not
line
.
startswith
(
'Address'
):
deletedcomments
+=
line
if
not
line
.
startswith
(
'#'
)
:
if
not
line
.
startswith
(
'Address'
):
deletedcomments
+=
line
csvfile
=
StringIO
.
StringIO
(
deletedcomments
)
cvr
=
csv
.
reader
(
csvfile
,
delimiter
=
','
,
quotechar
=
'|'
)
#print "\tN elements parser:", sum(1 for row in cvr)
#return [addr_list,data_list]
# for item in cvr:
# print "rere"
# regAddr= int(item[0], 16)
# regData[0]= int(item[1], 16)
# print "\t ", hex(regAddr), hex(regData[0])
#self.configList= cvr
regSettingList
=
list
(
cvr
)
print
"
\t
"
,
len
(
regSettingList
),
"elements"
return
regSettingList
regSettingList
=
list
(
cvr
)
return
regSettingList
def
writeConfiguration
(
self
,
regSettingList
):
print
"
\t
Write configuration:"
for
item
in
regSettingList
:
regAddr
=
int
(
item
[
0
],
16
)
regData
[
0
]
=
int
(
item
[
1
],
16
)
self
.
writeRegister
(
regAddr
,
regData
)
self
.
writeRegister
(
item
[
0
],
[
item
[
1
]])
for
item
in
regSettingList
:
d
=
self
.
readRegister
(
i
nt
(
item
[
0
],
16
)
)
if
i
nt
(
item
[
1
],
16
)
!=
int
(
d
):
d
=
self
.
readRegister
(
i
tem
[
0
]
)
if
i
tem
[
1
]
!=
int
(
d
):
print
"Config error"
,
hex
(
item
[
0
]),
hex
(
item
[
1
]),
hex
(
d
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment