CVS: jtag/msp430 clock.c,NONE,1.1 clock.h,NONE,1.1 MSP430mspgcc.c,1.11,1.12 funclets.c,1.10,1.11 funclets.h,1.7,1.8 makefile,1.8,1.9
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-serv25503/jtag/msp430
Modified Files:
MSP430mspgcc.c funclets.c funclets.h makefile
Added Files:
clock.c clock.h
Log Message:
- NEW: adjust the clock before writing or erasing the Flash
- add software FLL implementations for DCO and DCO+ (see clock.c)
- add funclets for clock measurements with DCO and DCO+ (see funclets.c)
--- NEW FILE: clock.c ---
#include "Basic_Types.h"
#include "clock.h"
#include "funclets.h"
#include "MSP430mspgcc.h"
// the flash funclets divide MCLK/5 for the flash clock, thus the clock adjusted here
//is 5 times faster
#define MCLK_MAX (428000UL * 5) // f(max_flash) - 10%
#define MCLK_MIN (282000UL * 5) // f(min_flash) + 10%
#define MCLK_ABS_MAX (476000UL * 5) // f(max_flash)
#define MCLK_ABS_MIN (257000UL * 5) // f(min_flash)
/* Set the DCO clock on F1xx and F2xx devices
*/
STATUS_T setDCO(void) { // Set DCO to gien frequency
MSP430_Log(1, "setDCO: adjusting %lu < MCLK < %lu\n", MCLK_MIN, MCLK_MAX);
CHAR DCO = 3; // As an initial speed, select CPU speed slightly > (476KHz - 10%) * 5.
CHAR BCS1 = 7;
ULONG frequency;
while (TRUE) {
if (STATUS_OK != getDCOFreq(DCO<<5, BCS1, &frequency)) {
return STATUS_ERROR;
}
if (frequency > MCLK_MAX) { // Check for upper limit.
MSP430_Log(3, "setDCO: %luHz is too high, decreasing\n", frequency);
if(--DCO <= 0) {
DCO = 7;
if (--BCS1 <= 0) {
return STATUS_ERROR; // Couldn't get DCO working with correct frequency.
}
}
} else if (frequency < MCLK_MIN) { // Check for lower limit + 10%.
MSP430_Log(3, "setDCO: %luHz is too low, increasing\n", frequency);
if(++DCO > 7) {
DCO = 0;
if (++BCS1 > 7) {
return STATUS_ERROR; // Couldn't get DCO working with correct frequency.
}
}
} else {
MSP430_Log(3, "setDCO: %luHz is OK\n", frequency);
break; // We have a working DCO!
}
}
return STATUS_OK;
}
/* Set DCO+ clock on F4xx devices.
*/
STATUS_T setDCOPlus(void) {
int first = 0, last = 27, mid, reload;
ULONG frequency;
MSP430_Log(1, "setDCOPlus: adjusting %lu < MCLK < %lu\n", MCLK_ABS_MIN, MCLK_ABS_MAX);
// Binary search through the available frequencies, selecting the highest
// frequency whithin the acceptable range
while (first + 1 < last) {
mid = (last + first) / 2;
// Select DCO range from 0.23MHz to 11.2MHz. Specify frequency via Ndco.
// Disable Modulation. Enable DCO+.
if (STATUS_OK != getDCOPlusFreq(0x00, (WORD) (mid << 3), 0x80, 0x80, 0, &frequency)) {
return STATUS_ERROR;
}
if (frequency > MCLK_MAX) {
MSP430_Log(3, "setDCOPlus: %luHz is too high, decreasing\n", frequency);
last = mid;
reload = TRUE;
} else {
MSP430_Log(3, "setDCOPlus: %luHz is too low, increasing\n", frequency);
first = mid;
reload = FALSE;
}
}
if (reload) {
if (STATUS_OK != getDCOPlusFreq(0x00, (WORD) (first << 3), 0x80, 0x80, 0, &frequency)) {
return STATUS_ERROR;
}
}
MSP430_Log(3, "setDCOPlus: MCLK set to %luHz\n", frequency);
// Ensure that frequency is within absolute min and max.
if (frequency < MCLK_ABS_MIN || frequency > MCLK_ABS_MAX) {
return STATUS_ERROR;
}
return STATUS_OK;
}
--- NEW FILE: clock.h ---
#ifndef CLOCK_H
#define CLOCK_H
#include "Basic_Types.h"
STATUS_T setDCO(void);
STATUS_T setDCOPlus(void);
#endif //CLOCK_H
Index: MSP430mspgcc.c
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/MSP430mspgcc.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -w -d -r1.11 -r1.12
--- MSP430mspgcc.c 27 Dec 2005 03:32:34 -0000 1.11
+++ MSP430mspgcc.c 27 Dec 2005 13:48:50 -0000 1.12
@@ -12,6 +12,7 @@
#include "MSP430mspgcc.h"
#include "JTAGfunc.h"
#include "funclets.h"
+#include "clock.h"
// #defines. ------------------------------------------------------------------
@@ -52,15 +53,14 @@
*/
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) {
+ if (((DEVICE & 0xff00) == 0xf100) || ((DEVICE & 0xff00) == 0xf200)) { // is it a F1xx or F2xx series device?
+ setDCO();
+ frequencySet = TRUE;
+ } else if ((DEVICE & 0xff00) == 0xf400) { //F4xx series
+ setDCOPlus();
frequencySet = TRUE;
} else {
- MSP430_Log(0, "MSP430mspgcc: DCO frequency out of range. Flash programming may be unreliable!\n");
- }
+ MSP430_Log(0, "MSP430mspgcc: unknown device, cannot set DCO frequency. Flash programming may be unreliable!\n");
}
}
}
Index: funclets.c
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/funclets.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -w -d -r1.10 -r1.11
--- funclets.c 27 Dec 2005 03:32:34 -0000 1.10
+++ funclets.c 27 Dec 2005 13:48:50 -0000 1.11
@@ -121,10 +121,13 @@
* @param frequency [out] The measured frequency
* @return STATUS_OK if the measurement succeeded
*/
-STATUS_T getDCOFreq(ULONG *frequency) {
- MSP430_Log(2, "funclets: getDCOFreq\n");
+STATUS_T getDCOFreq(CHAR DCOCTL, CHAR BCSCTL1, ULONG *frequency) {
+ MSP430_Log(2, "funclets: getDCOFreq(0x%02x, 0x%02x, ...)\n",
+ ((int)DCOCTL) & 0xff, ((int)BCSCTL1) & 0xff
+ );
if (frequency == NULL) return STATUS_ERROR;
ULONG runtime;
+ funclet_counter[3] = (BCSCTL1 << 8) | (DCOCTL & 0xff);
if (STATUS_OK == executeCode(funclet_counter, sizeof(funclet_counter)/sizeof(WORD), 1, 100, &runtime)) {
WORD count_low;
WORD count_high;
@@ -139,6 +142,38 @@
}
// ----------------------------------------------------------------------------
+#include "counterplus.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 getDCOPlusFreq(CHAR SCFI0, CHAR SCFI1, CHAR SCFQCTL, CHAR FLL_CTL0, CHAR FLL_CTL1, ULONG *frequency) {
+ MSP430_Log(2, "funclets: getDCOPlusFreq(0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, ...)\n",
+ ((int)SCFI0 & 0xff), ((int)SCFI1 & 0xff), ((int)SCFQCTL & 0xff),
+ ((int)FLL_CTL0 & 0xff), ((int)FLL_CTL1 & 0xff)
+ );
+ if (frequency == NULL) return STATUS_ERROR;
+ ULONG runtime;
+ funclet_counterplus[3] = (SCFI1 << 8) | SCFI0;
+ funclet_counterplus[4] = (FLL_CTL0 << 8) | SCFQCTL;
+ funclet_counterplus[5] = FLL_CTL1;
+
+ if (STATUS_OK == executeCode(funclet_counterplus, sizeof(funclet_counterplus)/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: getDCOPlusFreq 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
Index: funclets.h
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/funclets.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -d -r1.7 -r1.8
--- funclets.h 27 Dec 2005 03:32:34 -0000 1.7
+++ funclets.h 27 Dec 2005 13:48:50 -0000 1.8
@@ -7,7 +7,8 @@
STATUS_T programFlash(WORD address, const CHAR* buffer, WORD count);
STATUS_T eraseFlash(WORD type, WORD address);
-STATUS_T getDCOFreq(ULONG *frequency);
+STATUS_T getDCOFreq(CHAR DCOCTL, CHAR BCSCTL1, ULONG *frequency);
+STATUS_T getDCOPlusFreq(CHAR SCFI0, CHAR SCFI1, CHAR SCFQCTL, CHAR FLL_CTL0, CHAR FLL_CTL1, ULONG *frequency);
STATUS_T syncCPU(void);
STATUS_T executeCode(const WORD* code, WORD sizeCode, BOOL verify, ULONG wait, ULONG *runtime);
int isHalted(void);
Index: makefile
===================================================================
RCS file: /cvsroot/mspgcc/jtag/msp430/makefile,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -w -d -r1.8 -r1.9
--- makefile 13 Oct 2005 01:04:39 -0000 1.8
+++ makefile 27 Dec 2005 13:48:50 -0000 1.9
@@ -4,7 +4,7 @@
LIB_PREFIX := /usr/local/lib
-objects = MSP430mspgcc.o JTAGfunc.o funclets.o
+objects = MSP430mspgcc.o JTAGfunc.o funclets.o clock.o
CFLAGS = -O -Wall -I.. -I ../hardware_access -I ../funclets
# CFLAGS += -DDEBUG
-------------------------------------------------------
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