Arduino port is working, but only at 9600 baud.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 17 Apr 2011 23:36:55 +0000 (23:36 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 17 Apr 2011 23:36:55 +0000 (23:36 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@1000 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/GoodFET.py
firmware/Makefile
firmware/apps/monitor/monitor.c
firmware/configs/README.txt [new file with mode: 0644]
firmware/configs/arduino.sh [new file with mode: 0644]
firmware/goodfet.c
firmware/lib/arduino.c
firmware/lib/atmega168.c
firmware/lib/command.c

index a602b1e..edcaf73 100755 (executable)
@@ -106,10 +106,13 @@ class GoodFET:
                     #Do nothing.
                     a=1;
         
                     #Do nothing.
                     a=1;
         
+        baud=115200;
+        if(os.environ.get("platform")=='arduino'):
+            baud=19200; #Slower, for now.
         self.serialport = serial.Serial(
             port,
             #9600,
         self.serialport = serial.Serial(
             port,
             #9600,
-            115200,
+            baud,
             parity = serial.PARITY_NONE,
             timeout=timeout
             )
             parity = serial.PARITY_NONE,
             timeout=timeout
             )
@@ -118,6 +121,7 @@ class GoodFET:
         attempts=0;
         connected=0;
         while connected==0:
         attempts=0;
         connected=0;
         while connected==0:
+            #print "Got %s" % self.data;
             while self.verb!=0x7F or self.data!="http://goodfet.sf.net/":
                 if attemptlimit is not None and attempts >= attemptlimit:
                     return
             while self.verb!=0x7F or self.data!="http://goodfet.sf.net/":
                 if attemptlimit is not None and attempts >= attemptlimit:
                     return
@@ -135,6 +139,8 @@ class GoodFET:
                 if(os.environ.get("platform")=='telosb'):
                     #print "TelosB Reset";
                     self.telosBReset();
                 if(os.environ.get("platform")=='telosb'):
                     #print "TelosB Reset";
                     self.telosBReset();
+                
+                    
                 #self.serialport.write(chr(0x80));
                 #self.serialport.write(chr(0x80));
                 #self.serialport.write(chr(0x80));
                 #self.serialport.write(chr(0x80));
                 #self.serialport.write(chr(0x80));
                 #self.serialport.write(chr(0x80));
@@ -147,15 +153,18 @@ class GoodFET:
                 attempts=attempts+1;
                 self.readcmd(); #Read the first command.
             #Here we have a connection, but maybe not a good one.
                 attempts=attempts+1;
                 self.readcmd(); #Read the first command.
             #Here we have a connection, but maybe not a good one.
+            #print "We have a connection."
             connected=1;
             olds=self.infostring();
             clocking=self.monitorclocking();
             connected=1;
             olds=self.infostring();
             clocking=self.monitorclocking();
+            #if(os.environ.get("platform")!='arduino'):
             for foo in range(1,30):
                 if not self.monitorecho():
             for foo in range(1,30):
                 if not self.monitorecho():
-                    if self.verbose: print "Comm error on %i try, resyncing out of %s." % (foo,
-                                                  clocking);
-                    connected=0;
-                    break;
+                    if self.verbose:
+                        print "Comm error on %i try, resyncing out of %s." % (foo,
+                                                                              clocking);
+                        connected=0;
+                        break;
         if self.verbose: print "Connected after %02i attempts." % attempts;
         self.mon_connected();
         self.serialport.setTimeout(12);
         if self.verbose: print "Connected after %02i attempts." % attempts;
         self.mon_connected();
         self.serialport.setTimeout(12);
@@ -493,7 +502,7 @@ class GoodFET:
         data="The quick brown fox jumped over the lazy dog.";
         self.writecmd(self.MONITORAPP,0x81,len(data),data);
         if self.data!=data:
         data="The quick brown fox jumped over the lazy dog.";
         self.writecmd(self.MONITORAPP,0x81,len(data),data);
         if self.data!=data:
-            if self.verbose: print "Comm error recognized by monitorecho().";
+            print "Comm error recognized by monitorecho(), got:\n%s" % self.data;
             return 0;
         return 1;
 
             return 0;
         return 1;
 
@@ -529,14 +538,20 @@ class GoodFET:
         self.MONpoke16(0x56, clock);
     def monitorgetclock(self):
         """Get the clocking value."""
         self.MONpoke16(0x56, clock);
     def monitorgetclock(self):
         """Get the clocking value."""
+        if(os.environ.get("platform")=='arduino'):
+            return 0xDEAD;
+        #Check for MSP430 before peeking this.
         return self.MONpeek16(0x56);
     # The following functions ought to be implemented in
     # every client.
     
     def infostring(self):
         return self.MONpeek16(0x56);
     # The following functions ought to be implemented in
     # every client.
     
     def infostring(self):
-        a=self.MONpeek8(0xff0);
-        b=self.MONpeek8(0xff1);
-        return "%02x%02x" % (a,b);
+        if(os.environ.get("platform")=='arduino'):
+            return "Arduino";
+        else:
+            a=self.MONpeek8(0xff0);
+            b=self.MONpeek8(0xff1);
+            return "%02x%02x" % (a,b);
     def lock(self):
         print "Locking Unsupported.";
     def erase(self):
     def lock(self):
         print "Locking Unsupported.";
     def erase(self):
index 1cf9b6c..e3c4ae2 100644 (file)
@@ -25,10 +25,10 @@ mcu?=RUNCONFIG
 platform?=goodfet
 
 #N.B., gcc WILL NOT BITCH if this file doesn't exist.
 platform?=goodfet
 
 #N.B., gcc WILL NOT BITCH if this file doesn't exist.
-GCCINC?=-T ldscripts/$(mcu).x
+GCCINC?=
 
 #GCC?=avr-gcc
 
 #GCC?=avr-gcc
-GCC?=msp430-gcc
+GCC?=msp430-gcc -T ldscripts/$(mcu).x
 
 CCEXTRA?=  -D$(mcu) -D$(platform) -Dplatform=$(platform) -DGCC $(GCCINC) -I include -I platforms
 CC=$(GCC) -Wall -Os -fno-strict-aliasing -g -mmcu=$(mcu)  $(CCEXTRA)
 
 CCEXTRA?=  -D$(mcu) -D$(platform) -Dplatform=$(platform) -DGCC $(GCCINC) -I include -I platforms
 CC=$(GCC) -Wall -Os -fno-strict-aliasing -g -mmcu=$(mcu)  $(CCEXTRA)
index 701de9e..39833d4 100644 (file)
@@ -78,14 +78,22 @@ void monitor_handle_fn(uint8_t const app,
                break;
 
        case PEEK:
                break;
 
        case PEEK:
+         #ifdef MSP430
                cmddata[0]=memorybyte[cmddataword[0]];
                cmddata[0]=memorybyte[cmddataword[0]];
+          #else
+               debugstr("Monitor peeks are unsupported on this platform.");
+         #endif
                txdata(app,verb,1);
                break;
 
        case POKE:
                txdata(app,verb,1);
                break;
 
        case POKE:
+         #ifdef MSP430
                //Todo, make word or byte.
                memorybyte[cmddataword[0]] = cmddata[2];
                cmddata[0] = memorybyte[cmddataword[0]];
                //Todo, make word or byte.
                memorybyte[cmddataword[0]] = cmddata[2];
                cmddata[0] = memorybyte[cmddataword[0]];
+          #else
+               debugstr("Monitor pokes are unsupported on this platform.");
+         #endif
                txdata(app,verb,1);
                break;
 
                txdata(app,verb,1);
                break;
 
diff --git a/firmware/configs/README.txt b/firmware/configs/README.txt
new file mode 100644 (file)
index 0000000..394c166
--- /dev/null
@@ -0,0 +1,3 @@
+These are configuration scripts which may be sourced to preconfigure
+the environment for a particular hardware platform.
+
diff --git a/firmware/configs/arduino.sh b/firmware/configs/arduino.sh
new file mode 100644 (file)
index 0000000..0088dd3
--- /dev/null
@@ -0,0 +1,7 @@
+export mcu=atmega168
+export GCC=avr-gcc
+export config=monitor
+export platform=arduino
+echo "Call this as 'source configs/arduino.sh'"
+echo "Assumes an 8MHz Atmega328P by default."
+echo "This port is utterly untested."
index 714fbe6..5f30c77 100644 (file)
@@ -40,32 +40,29 @@ INITCHIP
 
 //! Handle a command.
 void handle(uint8_t const app,
 
 //! Handle a command.
 void handle(uint8_t const app,
-                       uint8_t const verb,
-                       uint32_t const len)
-{
-       int i;
-
-       //debugstr("GoodFET");
-       PLEDOUT&=~PLEDPIN;
-
-       // find the app and call the handle fn
-       for(i = 0; i < num_apps; i++)
-       {
-               if(apps[i]->app == app)
-               {
-                       // call the app's handle fn
-                       (*(apps[i]->handle))(app, verb, len);
-
-                       // exit early
-                       return;
-               }
-       }
-
-       // if we get here, then the desired app is not copiled in 
-       // this firmware
-       debugstr("App missing.");
-       debughex(app);
-       txdata(app, NOK, 0);
+           uint8_t const verb,
+           uint32_t const len){
+  int i;
+  
+  //debugstr("GoodFET");
+  PLEDOUT&=~PLEDPIN;
+  
+  // find the app and call the handle fn
+  for(i = 0; i < num_apps; i++){
+    if(apps[i]->app == app){
+      // call the app's handle fn
+      (*(apps[i]->handle))(app, verb, len);
+
+      // exit early
+      return;
+    }
+  }
+
+  // if we get here, then the desired app is not copiled in 
+  // this firmware
+  debugstr("App missing.");
+  debughex(app);
+  txdata(app, NOK, 0);
 }
 
 
 }
 
 
@@ -80,9 +77,12 @@ int main(void)
        void (*reboot_function)(void) = (void *) 0xFFFE;
 
        init();
        void (*reboot_function)(void) = (void *) 0xFFFE;
 
        init();
-  
+       
        txstring(MONITOR,OK,"http://goodfet.sf.net/");
        txstring(MONITOR,OK,"http://goodfet.sf.net/");
-  
+       #ifdef ECHOTEST
+       while(1) serial0_tx(serial0_rx());
+       #endif
+       
        //Command loop.  There's no end!
        while(1)
        {
        //Command loop.  There's no end!
        while(1)
        {
@@ -101,7 +101,11 @@ int main(void)
                                // or
                                // WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00;
                                // but instead we'll jump to our reboot function pointer
                                // or
                                // WDTCTL = WDTPW + WDTCNTCL + WDTSSEL + 0x00;
                                // but instead we'll jump to our reboot function pointer
+                         #ifdef MSP430
                                (*reboot_function)();
                                (*reboot_function)();
+                         #else
+                               debugstr("Rebooting not supported on this platform.");
+                         #endif
                        }
 
                        continue;
                        }
 
                        continue;
@@ -112,7 +116,6 @@ int main(void)
                }
 
                verb = serial_rx();
                }
 
                verb = serial_rx();
-               //len=serial_rx();
                len = rxword();
 
                //Read data, looking for buffer overflow.y
                len = rxword();
 
                //Read data, looking for buffer overflow.y
index 698aa9e..581fcd5 100644 (file)
@@ -6,13 +6,17 @@
 #include "platform.h"
 #ifdef ARDUINO
 
 #include "platform.h"
 #ifdef ARDUINO
 
+#include <avr/interrupt.h>
 #include <util/delay.h>
 
 //! Arduino setup code.
 void arduino_init(){
 #include <util/delay.h>
 
 //! Arduino setup code.
 void arduino_init(){
-  /* set PORTB for output*/
+  //LED port as output.
   DDRB = 0xFF;
   
   DDRB = 0xFF;
   
+  //Disabled interrupts.
+  cli();
+  
   avr_init_uart0();
 }
 
   avr_init_uart0();
 }
 
index a5e8cb7..d8705ba 100644 (file)
@@ -52,7 +52,8 @@ void setbaud0(unsigned char rate){
   }
   
 #define F_CPU 8000000L
   }
   
 #define F_CPU 8000000L
-#define BAUD 115200L
+  //#define BAUD 115200L
+#define BAUD 9600L
 #include <util/setbaud.h>
   UBRR0H = UBRRH_VALUE;
   UBRR0L = UBRRL_VALUE;
 #include <util/setbaud.h>
   UBRR0H = UBRRH_VALUE;
   UBRR0L = UBRRL_VALUE;
@@ -88,7 +89,9 @@ void setbaud1(unsigned char rate){
 
 
 void avr_init_uart0(){
 
 
 void avr_init_uart0(){
+  PORTD = _BV(PD2);
   setbaud0(0);
   setbaud0(0);
+  _delay_ms(500); //takes a bit to stabilize
 }
 
 
 }
 
 
index ec74ebb..92c0b4c 100644 (file)
@@ -165,7 +165,7 @@ void delay_ms( unsigned int ms )
   }
   TBCTL = 0x0204; // Reset Timer B, till next time
   #else
   }
   TBCTL = 0x0204; // Reset Timer B, till next time
   #else
-  #warning "Function unimplemented for this platform."
+  debugstr("delay_ms unimplemented");
   #endif
 }
 
   #endif
 }
 
@@ -182,7 +182,7 @@ void delay_us( unsigned int us )
   }
   TBCTL = 0x0204; // Reset Timer B, till next time
   #else
   }
   TBCTL = 0x0204; // Reset Timer B, till next time
   #else
-  #warning "Function unimplemented for this platform."
+  debugstr("delay_us unimplemented");
   #endif
 }
 
   #endif
 }
 
@@ -195,6 +195,6 @@ void delay_ticks( unsigned int num_ticks )
     asm( "nop" );
   TBCTL = 0x0204; // Reset Timer B, till next time
   #else
     asm( "nop" );
   TBCTL = 0x0204; // Reset Timer B, till next time
   #else
-  #warning "Function unimplemented for this platform."
+  debugstr("delay_ticks unimplemented");
   #endif
 }
   #endif
 }