CVS: libraries/mspgcc flash_write_byte.c,1.1,1.2 flash_write_word.c,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/libraries/mspgcc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5570/libraries/mspgcc

Modified Files:
	flash_write_byte.c flash_write_word.c 
Log Message:
fix when running the code from RAM

Index: flash_write_byte.c
===================================================================
RCS file: /cvsroot/mspgcc/libraries/mspgcc/flash_write_byte.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- flash_write_byte.c	22 Aug 2005 11:23:20 -0000	1.1
+++ flash_write_byte.c	23 Aug 2005 18:03:22 -0000	1.2
@@ -5,6 +5,9 @@
 // FCTL2 must be initialized by the user
 // NMI, Oscillator Fault interrupts must be disabled by the user
 // byte copy (works with unaligned data)
+// waiting for the BUSY flasg is not needed when the code is run from flash as
+// the hardware halts programm execution, but it is required when running the
+// programm from RAM
 critical void flash_write(void *dst, const void *src, unsigned int size) {
     FCTL3 = FWKEY;                      // unlock
     FCTL1 = FWKEY|WRT;                  // select write
@@ -12,6 +15,7 @@
     while (size) {
         size--;   //decrement before using as array indexing starts at 0, not 1
         ((unsigned char *)dst)[size] = ((unsigned char *)src)[size];  // copy
+        while (FCTL3 & BUSY) {}         // wait until write is completed
     }
     FCTL1 = FWKEY;                      // disable flash writing
     FCTL3 = FWKEY|LOCK;                 // lock

Index: flash_write_word.c
===================================================================
RCS file: /cvsroot/mspgcc/libraries/mspgcc/flash_write_word.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -d -r1.1 -r1.2
--- flash_write_word.c	22 Aug 2005 11:23:20 -0000	1.1
+++ flash_write_word.c	23 Aug 2005 18:03:22 -0000	1.2
@@ -6,6 +6,9 @@
 // NMI, Oscillator Fault interrupts must be disabled by the user
 // word copy
 // data must be word aligned
+// waiting for the BUSY flasg is not needed when the code is run from flash as
+// the hardware halts programm execution, but it is required when running the
+// programm from RAM
 critical void flash_write_word(void *dst, const void *src, unsigned int size) {
     FCTL3 = FWKEY;                      // unlock
     FCTL1 = FWKEY|WRT;                  // select write
@@ -15,6 +18,7 @@
     while (size) {
         size--;   //decrement before using as array indexing starts at 0, not 1
         ((unsigned short *)dst)[size] = ((unsigned short *)src)[size];  // copy
+        while (FCTL3 & BUSY) {}         // wait until write is completed
     }
     FCTL1 = FWKEY;                      // disable flash writing
     FCTL3 = FWKEY|LOCK;                 // lock



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
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.