From 496a0185c0bc88e6ccb768b7ff73055edc3cf4c3 Mon Sep 17 00:00:00 2001 From: travisutk Date: Wed, 7 Jul 2010 20:19:59 +0000 Subject: [PATCH 1/1] EM260 SPI support. Really needs to be cleaned up. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@661 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- firmware/apps/spi/spi.c | 55 ++++++++++++++++++++++++++++++++---- firmware/goodfet.c | 7 ++++- firmware/include/command.h | 1 + firmware/include/spi.h | 6 ++++ firmware/platforms/goodfet.h | 1 + 5 files changed, 64 insertions(+), 6 deletions(-) diff --git a/firmware/apps/spi/spi.c b/firmware/apps/spi/spi.c index 98ff8f7..c533a74 100644 --- a/firmware/apps/spi/spi.c +++ b/firmware/apps/spi/spi.c @@ -54,7 +54,6 @@ unsigned char spitrans8(unsigned char byte){ byte |= READMISO; CLRCLK; } - return byte; } @@ -220,6 +219,21 @@ void spiflash_erasesector(unsigned long adr){ } +//! Wake an EM260 Radio +void em260_wake(){ + //debugstr("Waking EM260."); + #define RST BIT6 + P2DIR|=RST; + SETRST; + delay(1024); + + CLRRST;//Wake chip. + while(P4IN&1); + SETRST;//Woken. + //debugstr("EM260 is now awake."); + delay(1024); //DO NOT REMOVE, fails without. +} + //! Handles a monitor command. void spihandle(unsigned char app, unsigned char verb, @@ -240,8 +254,40 @@ void spihandle(unsigned char app, SETSS; //Raise !SS to end transaction. txdata(app,verb,len); break; - - + + case SPI_RW_EM260: //SPI exchange with an EM260 + P4DIR=0; //TODO ASAP remove P4 references. + P4OUT=0; + + //See GoodFETEM260.py for details. + //The EM260 requires that the host wait for the client. + + em260_wake(); + + SETMOSI; //Autodetected SPI mode. + CLRSS; //Drop !SS to begin transaction. + //Host to slave. Ignore data. + for(i=0;i