tps/test/spec: added setup of the oscillator si570

parent fcb0d321
......@@ -136,6 +136,10 @@ class CSI570 :
return self.i2c.read(True);
def setup_oscillator(self, hs_div, n1_div, rfreq) :
# Freeze the oscillator to setup it
self.wr_reg8(self.FREEZE_DCO, (1 << 4));
val = ((hs_div & 0x7) << 5) | (n1_div >> 2)
self.wr_reg8(self.HS_N1_DIV, val);
......@@ -154,6 +158,40 @@ class CSI570 :
val = rfreq & 0xFF;
self.wr_reg8(self.REF_FREQ_7_0, val);
# Unfreeze it
self.wr_reg8(self.FREEZE_DCO, 0);
self.wr_reg8(self.RST_MEM_CTRL, (1 << 6));
time.sleep(0.010)
self.wr_reg8(self.RST_MEM_CTRL, 0);
def setup_frequency(self, freq) :
finish = 0;
for N1 in range(0,65) :
if N1 == 0 :
n1 = 1;
else :
n1 = N1*2;
for HSDIV in [4, 5, 6, 7, 9, 11] :
x = HSDIV * n1;
if (x < 5670) and (x > 4850) :
finish = 1;
freq_dco = x;
break;
if finish :
break;
if (not finish):
raise TpsError('SI570: Not found a proper setup')
tmp = freq_dco / 114.285;
rfreq = int((tmp * 2**28));
rfreq = hex(rfreq);
self.setup_oscillator(HSDIV, n1, rfreq);
def reset(self) :
val = (1 << 7);
self.wr_reg8(self.RST_MEM_CTRL, val);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment