From 5b89da5a9d7864784dbe4942d856f751c3758c1c Mon Sep 17 00:00:00 2001 From: travisutk Date: Sun, 17 Apr 2011 23:36:55 +0000 Subject: [PATCH] Arduino port is working, but only at 9600 baud. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@1000 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- client/GoodFET.py | 33 +++++++++++++----- firmware/Makefile | 4 +-- firmware/apps/monitor/monitor.c | 8 +++++ firmware/configs/README.txt | 3 ++ firmware/configs/arduino.sh | 7 ++++ firmware/goodfet.c | 61 +++++++++++++++++---------------- firmware/lib/arduino.c | 6 +++- firmware/lib/atmega168.c | 5 ++- firmware/lib/command.c | 6 ++-- 9 files changed, 88 insertions(+), 45 deletions(-) create mode 100644 firmware/configs/README.txt create mode 100644 firmware/configs/arduino.sh diff --git a/client/GoodFET.py b/client/GoodFET.py index a602b1e..edcaf73 100755 --- a/client/GoodFET.py +++ b/client/GoodFET.py @@ -106,10 +106,13 @@ class GoodFET: #Do nothing. a=1; + baud=115200; + if(os.environ.get("platform")=='arduino'): + baud=19200; #Slower, for now. self.serialport = serial.Serial( port, #9600, - 115200, + baud, parity = serial.PARITY_NONE, timeout=timeout ) @@ -118,6 +121,7 @@ class GoodFET: 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 @@ -135,6 +139,8 @@ class GoodFET: 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)); @@ -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. + #print "We have a connection." connected=1; olds=self.infostring(); clocking=self.monitorclocking(); + #if(os.environ.get("platform")!='arduino'): 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); @@ -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: - if self.verbose: print "Comm error recognized by monitorecho()."; + print "Comm error recognized by monitorecho(), got:\n%s" % self.data; return 0; return 1; @@ -529,14 +538,20 @@ class GoodFET: 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): - 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): diff --git a/firmware/Makefile b/firmware/Makefile index 1cf9b6c..e3c4ae2 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -25,10 +25,10 @@ mcu?=RUNCONFIG platform?=goodfet #N.B., gcc WILL NOT BITCH if this file doesn't exist. -GCCINC?=-T ldscripts/$(mcu).x +GCCINC?= #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) diff --git a/firmware/apps/monitor/monitor.c b/firmware/apps/monitor/monitor.c index 701de9e..39833d4 100644 --- a/firmware/apps/monitor/monitor.c +++ b/firmware/apps/monitor/monitor.c @@ -78,14 +78,22 @@ void monitor_handle_fn(uint8_t const app, break; case PEEK: + #ifdef MSP430 cmddata[0]=memorybyte[cmddataword[0]]; + #else + debugstr("Monitor peeks are unsupported on this platform."); + #endif txdata(app,verb,1); break; case POKE: + #ifdef MSP430 //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; diff --git a/firmware/configs/README.txt b/firmware/configs/README.txt new file mode 100644 index 0000000..394c166 --- /dev/null +++ b/firmware/configs/README.txt @@ -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 index 0000000..0088dd3 --- /dev/null +++ b/firmware/configs/arduino.sh @@ -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." diff --git a/firmware/goodfet.c b/firmware/goodfet.c index 714fbe6..5f30c77 100644 --- a/firmware/goodfet.c +++ b/firmware/goodfet.c @@ -40,32 +40,29 @@ INITCHIP //! 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(); - + txstring(MONITOR,OK,"http://goodfet.sf.net/"); - + #ifdef ECHOTEST + while(1) serial0_tx(serial0_rx()); + #endif + //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 + #ifdef MSP430 (*reboot_function)(); + #else + debugstr("Rebooting not supported on this platform."); + #endif } continue; @@ -112,7 +116,6 @@ int main(void) } verb = serial_rx(); - //len=serial_rx(); len = rxword(); //Read data, looking for buffer overflow.y diff --git a/firmware/lib/arduino.c b/firmware/lib/arduino.c index 698aa9e..581fcd5 100644 --- a/firmware/lib/arduino.c +++ b/firmware/lib/arduino.c @@ -6,13 +6,17 @@ #include "platform.h" #ifdef ARDUINO +#include #include //! Arduino setup code. void arduino_init(){ - /* set PORTB for output*/ + //LED port as output. DDRB = 0xFF; + //Disabled interrupts. + cli(); + avr_init_uart0(); } diff --git a/firmware/lib/atmega168.c b/firmware/lib/atmega168.c index a5e8cb7..d8705ba 100644 --- a/firmware/lib/atmega168.c +++ b/firmware/lib/atmega168.c @@ -52,7 +52,8 @@ void setbaud0(unsigned char rate){ } #define F_CPU 8000000L -#define BAUD 115200L + //#define BAUD 115200L +#define BAUD 9600L #include UBRR0H = UBRRH_VALUE; UBRR0L = UBRRL_VALUE; @@ -88,7 +89,9 @@ void setbaud1(unsigned char rate){ void avr_init_uart0(){ + PORTD = _BV(PD2); setbaud0(0); + _delay_ms(500); //takes a bit to stabilize } diff --git a/firmware/lib/command.c b/firmware/lib/command.c index ec74ebb..92c0b4c 100644 --- a/firmware/lib/command.c +++ b/firmware/lib/command.c @@ -165,7 +165,7 @@ void delay_ms( unsigned int ms ) } TBCTL = 0x0204; // Reset Timer B, till next time #else - #warning "Function unimplemented for this platform." + debugstr("delay_ms unimplemented"); #endif } @@ -182,7 +182,7 @@ void delay_us( unsigned int us ) } TBCTL = 0x0204; // Reset Timer B, till next time #else - #warning "Function unimplemented for this platform." + debugstr("delay_us unimplemented"); #endif } @@ -195,6 +195,6 @@ void delay_ticks( unsigned int num_ticks ) asm( "nop" ); TBCTL = 0x0204; // Reset Timer B, till next time #else - #warning "Function unimplemented for this platform." + debugstr("delay_ticks unimplemented"); #endif } -- 2.20.1