CVS: jtag/msp430 MSP430mspgcc.c,1.10,1.11 funclets.c,1.9,1.10 funclets.h,1.6,1.7

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

Modified Files:
	MSP430mspgcc.c funclets.c funclets.h 
Log Message:
- prepare for DCO adjusting before writing or erasing the flash (measurement only yet, see getDCOFreq)
- add new function to header
- doc updates and some small fixes

Index: MSP430mspgcc.c
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/MSP430mspgcc.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -w -d -r1.10 -r1.11
--- MSP430mspgcc.c	27 Dec 2005 01:12:11 -0000	1.10
+++ MSP430mspgcc.c	27 Dec 2005 03:32:34 -0000	1.11
@@ -15,10 +15,11 @@
 
 // #defines. ------------------------------------------------------------------
 
-#define DLL_VERSION         03      // DLL version * 10.
+#define DLL_VERSION         04      // DLL version * 10.
 
 // (File) Global variables. ---------------------------------------------------
 static BOOL jtagReleased = FALSE;
+static BOOL frequencySet = FALSE;      // remenber if the DCO setup was done
 unsigned int debug_level = 0;
 
 static const char* errorStrings[] = {
@@ -45,6 +46,25 @@
 BOOL executeVerify = FALSE;     // Verify the stub code downloaded by executeCode().
 
 // Functions. -----------------------------------------------------------------
+/*
+This internal helper function is used to set up the DCO clock. If it is done once
+the state is remembered in a global variable frequencySet.
+*/
+static void MSP430_AdjustDCO() {
+    if (!frequencySet) {
+        ULONG freq;
+        if (STATUS_OK == getDCOFreq(&freq)) {
+            MSP430_Log(0, "MSP430mspgcc: DCO frequency = %lu\n", freq);
+            // XXX TODO: adjust DCO if the frequency is out of range
+            if (700000 < freq && freq < 900000) {
+                frequencySet = TRUE;
+            } else {
+                MSP430_Log(0, "MSP430mspgcc: DCO frequency out of range. Flash programming may be unreliable!\n");
+            }
+        }
+    }
+}
+
 
 /* ----------------------------------------------------------------------------
 Initialize the interface.
@@ -227,8 +247,8 @@
         RET_ERR(PARAMETER_ERR);
     }
 
-    //~ // Force a frequency set after reset.
-    //~ eraseFrequencySet = programFrequencySet = FALSE;
+    // Force a frequency set after reset.
+    frequencySet = FALSE;
 
     if (method & PUC_RESET) {                           //1st try: a PUC over JTAG
         ReleaseDevice(V_RESET);
@@ -346,6 +366,10 @@
         RET_ERR(PARAMETER_ERR);
     }
 
+    if (!frequencySet) {
+        MSP430_AdjustDCO();
+    }
+
     switch (type) {
         case ERASE_SEGMENT:
         {
@@ -492,6 +516,10 @@
                 BOOL mallocedBuffer = FALSE;
                 STATUS_T result;
                 
+                if (!frequencySet) {
+                    MSP430_AdjustDCO();
+                }
+                
                 // The flash only supports writing words on word boundaries. Force alignment
                 // if odd address and/or odd count.
                 // Even address and odd length: pad last, count + 1.

Index: funclets.c
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/funclets.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -w -d -r1.9 -r1.10
--- funclets.c	27 Dec 2005 01:12:11 -0000	1.9
+++ funclets.c	27 Dec 2005 03:32:34 -0000	1.10
@@ -114,6 +114,31 @@
 }
 
 // ----------------------------------------------------------------------------
+#include "counter.ci"                                   //include the counter program
+
+/**
+ * Meaqsure the DCO clock frequency
+ * @param frequency     [out] The measured frequency
+ * @return              STATUS_OK if the measurement succeeded
+ */
+STATUS_T getDCOFreq(ULONG *frequency) {
+    MSP430_Log(2, "funclets: getDCOFreq\n");
+    if (frequency == NULL) return STATUS_ERROR;
+    ULONG runtime;
+    if (STATUS_OK == executeCode(funclet_counter, sizeof(funclet_counter)/sizeof(WORD), 1, 100, &runtime)) {
+        WORD count_low;
+        WORD count_high;
+        if (STATUS_OK == GetReg(14, &count_low) && STATUS_OK == GetReg(15, &count_high)) {
+            ULONG count = count_low | (count_high << 16);
+            *frequency = 1000*count*4/runtime; //4 cyles/loop see funclets/counter.S
+            MSP430_Log(3, "funclets: getDCOFreq 0x%08lx in %lums -> %luHz\n", count, runtime, *frequency);
+            return STATUS_OK;
+        }
+    }
+    return STATUS_ERROR;
+}
+
+// ----------------------------------------------------------------------------
 
 //The following functions were originaly developed by TI. I added debug
 //outputs and simpified some parts
@@ -322,7 +347,7 @@
 
     if (wait) {
         ULONG runtime_internal;
-        MSP430_Log(1, "funclets: executeCodeSafe: wait for up to %ums\n", wait); //DEBUG
+        MSP430_Log(3, "funclets: executeCodeSafe: wait for up to %ums\n", wait); //DEBUG
         HIL_StartTimer();
         // Limit the number of cycles for the code to execute.
         while ((runtime_internal = HIL_ReadTimer()) < wait) {
@@ -337,13 +362,14 @@
             }
         }
         HIL_StopTimer();
-        MSP430_Log(1, "funclets: executeCodeSafe: wait failed (%ums)\n", runtime_internal); //DEBUG
         // if runtime out parameter is given, exit iwth success, the caller can
         // test the runtime to see if its OK for him. Otherways fail.
         if (runtime != NULL) {
             *runtime = runtime_internal;
+            MSP430_Log(3, "funclets: executeCodeSafe: timeout (%ums)\n", runtime_internal); //DEBUG
             return STATUS_OK;
         } else {
+            MSP430_Log(1, "funclets: executeCodeSafe: wait failed (%ums)\n", runtime_internal); //DEBUG
             return STATUS_ERROR;
         }
     }
@@ -447,7 +473,7 @@
 
     if (wait) {
         ULONG runtime_internal;
-        MSP430_Log(1, "funclets: executeCode: wait for up to %ums\n", wait); //DEBUG
+        MSP430_Log(3, "funclets: executeCode: wait for up to %ums\n", wait); //DEBUG
         HIL_StartTimer();
         // Limit the number of cycles for the code to execute.
         while ((runtime_internal = HIL_ReadTimer()) < wait) {
@@ -462,13 +488,14 @@
             }
         }
         HIL_StopTimer();
-        MSP430_Log(1, "funclets: executeCode: wait failed (%ums)\n", runtime_internal); //DEBUG
         // if runtime out parameter is given, exit iwth success, the caller can
         // test the runtime to see if its OK for him. Otherways fail.
         if (runtime != NULL) {
             *runtime = runtime_internal;
+            MSP430_Log(3, "funclets: executeCode: timeout (%ums)\n", runtime_internal); //DEBUG
             return STATUS_OK;
         } else {
+            MSP430_Log(1, "funclets: executeCode: wait failed (%ums)\n", runtime_internal); //DEBUG
             return STATUS_ERROR;
         }
     }

Index: funclets.h
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/funclets.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -w -d -r1.6 -r1.7
--- funclets.h	27 Dec 2005 01:12:11 -0000	1.6
+++ funclets.h	27 Dec 2005 03:32:34 -0000	1.7
@@ -7,6 +7,7 @@
 
 STATUS_T programFlash(WORD address, const CHAR* buffer, WORD count);
 STATUS_T eraseFlash(WORD type, WORD address);
+STATUS_T getDCOFreq(ULONG *frequency);
 STATUS_T syncCPU(void);
 STATUS_T executeCode(const WORD* code, WORD sizeCode, BOOL verify, ULONG wait, ULONG *runtime);
 int isHalted(void);



-------------------------------------------------------
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.