CVS: python/msp430 clock.py,1.1,1.2

Chris Liechti <[email protected]>
Newsgroups gmane.comp.hardware.texas-instruments.msp430.gcc.cvs
Message-ID <[email protected]>
Update of /cvsroot/mspgcc/python/msp430
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6538/python/msp430

Modified Files:
	clock.py 
Log Message:
- new --dcor option to use external RSEL
- improved F1xx/F2xx FLL for frequencies near possible min/max

Index: clock.py
===================================================================
RCS file: /cvsroot/mspgcc/python/msp430/clock.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- clock.py	29 Dec 2005 04:33:22 -0000	1.1
+++ clock.py	29 Dec 2005 14:01:48 -0000	1.2
@@ -15,26 +15,28 @@
 #see mspgcc cvs/jtag/funclets/counter.S
 COUNTER_FUNCLET = """\
 @0200
-00 02 08 02 22 02 60 07 32 c2 d2 40 fb ff 57 00
-d2 40 f4 ff 56 00 0e 43 0f 43 1e 53 0f 63 fd 3f
-03 43 ff 3f
+00 02 0a 02 2a 02 60 07 00 00 32 c2 d2 40 f9 ff
+57 00 d2 40 f4 ff 58 00 d2 40 ec ff 56 00 0e 43
+0f 43 1e 53 0f 63 fd 3f 03 43 ff 3f
 q
 """
 
 
-def getDCOFreq(dcoctl, bcsctl1):
+def getDCOFreq(dcoctl, bcsctl1, bcsctl2=0):
     """measure DCO frequency on a F1xx or F2xx device.
     
        return: frequency in Hz"""
     funclet = memory.Memory()
     funclet.loadTIText(cStringIO.StringIO(COUNTER_FUNCLET))
     #XXX dcor
-    funclet[0].data = funclet[0].data[:6] + chr(dcoctl) + chr(bcsctl1) + funclet[0].data[8:]
+    funclet[0].data = funclet[0].data[:6] \
+                    + chr(dcoctl) + chr(bcsctl1) + chr(bcsctl2) \
+                    + funclet[0].data[9:]
     runtime = jtag._parjtag.funclet(funclet[0].data, 100)
     count = jtag._parjtag.regread(14) | (jtag._parjtag.regread(15) << 16)
     return 1000*count*4/runtime
 
-def setDCO(fmin, fmax, maxrsel=7):
+def setDCO(fmin, fmax, maxrsel=7, dcor=False):
     """Software FLL for F1xx and F2xx devices.
     
        return: (frequency, DCOCTL, BCSCTL1)"""
@@ -48,12 +50,12 @@
     
     for tries in range(50):
         if upper and lower and resolution > 1:
-            if debug: sys.stderr.write("switching to higher resolution (%d)\n" % (resolution,))
             resolution /= 2
+            if resolution < 1: resolution = 1
+            if debug: sys.stderr.write("switching to higher resolution (-> %d)\n" % (resolution,))
             upper = False
             lower = False
-            if resolution < 1: resolution = 1
-        frequency = getDCOFreq(dco, bcs1)
+        frequency = getDCOFreq(dco, bcs1, dcor and 1 or 0)
         if frequency > fmax:
             if debug: sys.stderr.write("%luHz is too high, decreasing (was: BCSCTL1=0x%02x; DCOCTL=0x%02x\n" % (frequency, bcs1, dco))
             upper = True
@@ -61,8 +63,15 @@
             if dco <= 0:
                 dco = 255
                 bcs1 -= 1
-                if bcs1 <= 0:
-                    raise IOError("Couldn't get DCO working with correct frequency.")
+                if bcs1 < 0:
+                    if resolution > 1:
+                        #try again with minimum settings but increased resolution
+                        resolution /= 2
+                        if resolution < 1: resolution = 1
+                        bcs1 = 0
+                        dco = 0
+                    else:
+                        raise IOError("Couldn't get DCO working with correct frequency. Device is not slower than %dHz." % (frequency,))
         elif frequency < fmin:
             if debug: sys.stderr.write("%luHz is too low, increasing (was: BCSCTL1=0x%02x; DCOCTL=0x%02x\n" % (frequency, bcs1, dco))
             lower = True
@@ -70,12 +79,19 @@
             if dco > 255:
                 dco = 0
                 bcs1 += 1
-                if ++bcs1 > 7:
-                    raise IOError("Couldn't get DCO working with correct frequency.")
+                if bcs1 > maxrsel:
+                    if resolution > 1:
+                        #try again with maximum settings but increased resolution
+                        resolution /= 2
+                        if resolution < 1: resolution = 1
+                        bcs1 = maxrsel
+                        dco = 255
+                    else:
+                        raise IOError("Couldn't get DCO working with correct frequency. Device is not faster than %dHz." % (frequency,))
         else:
             if debug: sys.stderr.write("%luHz is OK (BCSCTL1=0x%02x; DCOCTL=0x%02x\n" % (frequency, bcs1, dco))
             return frequency, dco, bcs1
-    raise IOError("Couldn't get DCO working with correct frequency.")
+    raise IOError("Couldn't get DCO working with correct frequency. Tolerance too tight? Last frequency was %dHz" % (frequency,))
 
 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
@@ -95,10 +111,10 @@
        return: frequency in Hz"""
     funclet = memory.Memory()
     funclet.loadTIText(cStringIO.StringIO(COUNTERPLUS_FUNCLET))
-    funclet[0].data = funclet[0].data[:6] + \
-                      chr(scfi0) + chr(scfi1) + \
-                      chr(scfqctl) + chr(fll_ctl0) + \
-                      chr(fll_ctl1) + funclet[0].data[11:]
+    funclet[0].data = funclet[0].data[:6] \
+                    + chr(scfi0) + chr(scfi1) \
+                    + chr(scfqctl) + chr(fll_ctl0) \
+                    + chr(fll_ctl1) + funclet[0].data[11:]
     #~ funclet..[0x205] = scfi0, scfi1, scfqctl, fll_ctl0, fll_ctl1
     runtime = jtag._parjtag.funclet(funclet[0].data, 100)
     count = jtag._parjtag.regread(14) | (jtag._parjtag.regread(15) << 16)



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.