Forked SPI to NRF.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Tue, 18 May 2010 18:29:40 +0000 (18:29 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Tue, 18 May 2010 18:29:40 +0000 (18:29 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@520 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

firmware/Makefile
firmware/apps/radios/nrf.c [new file with mode: 0644]
firmware/goodfet.c
firmware/include/command.h
firmware/include/nrf.h [new file with mode: 0644]

index 5117f0c..c84afb2 100644 (file)
@@ -23,12 +23,12 @@ CCEXTRA?=
 CC=msp430-gcc -Wall -Os -g -mmcu=$(mcu) -D$(mcu) -DGCC $(GCCINC) -I include $(CCEXTRA)
 
 #Define extra modules here.
-moreapps?=apps/i2c/i2c.o apps/chipcon/chipcon.o apps/glitch/glitch.o apps/jtag/sbw.o apps/smartcard/smartcard.o apps/jtag/ejtag.o apps/jtag/jtagxscale.o
+moreapps?=apps/i2c/i2c.o  apps/glitch/glitch.o apps/jtag/sbw.o apps/smartcard/smartcard.o apps/jtag/ejtag.o apps/jtag/jtagxscale.o
 # should include apps/jtag/jtagarm7tdmi.o to build jtag for ARM7
 # should include apps/pic/dspic33f.o to build support for PIC24H/dsPIC33F
 
 # Used to include  $(moreapps)
-apps=  apps/monitor/monitor.o apps/spi/spi.o   apps/jtag/jtag.o apps/jtag/jtag430.o apps/jtag/jtag430x2.o apps/avr/avr.o 
+apps=  apps/chipcon/chipcon.o apps/radios/nrf.o apps/monitor/monitor.o apps/spi/spi.o   apps/jtag/jtag.o apps/jtag/jtag430.o apps/jtag/jtag430x2.o apps/avr/avr.o 
 
 #apps/chipcon/chipconasm.o removed
 libs= lib/$(mcu).o lib/command.o apps/jtag/jtag430asm.o  lib/dco_calib.o
diff --git a/firmware/apps/radios/nrf.c b/firmware/apps/radios/nrf.c
new file mode 100644 (file)
index 0000000..f81afba
--- /dev/null
@@ -0,0 +1,102 @@
+/*! \file nrf.c
+  \author Travis Goodspeed
+  \brief NordicRF Register Interface
+*/
+
+//Higher level left to client application.
+
+#include "platform.h"
+#include "command.h"
+
+#include <signal.h>
+#include <io.h>
+#include <iomacros.h>
+
+#include "nrf.h"
+#include "spi.h"
+
+//This could be more accurate.
+//Does it ever need to be?
+#define NRFSPEED 0
+#define NRFDELAY(x)
+//delay(x)
+
+
+//! Set up the pins for NRF mode.
+void nrfsetup(){
+  P5OUT|=SS;
+  P5DIR|=MOSI+SCK+SS;
+  P5DIR&=~MISO;
+  
+  //Begin a new transaction.
+  P5OUT&=~SS; 
+  P5OUT|=SS;
+}
+
+
+//! Read and write an NRF byte.
+unsigned char nrftrans8(unsigned char byte){
+  register unsigned int bit;
+  //This function came from the NRF Wikipedia article.
+  //Minor alterations.
+  
+  for (bit = 0; bit < 8; bit++) {
+    /* write MOSI on trailing edge of previous clock */
+    if (byte & 0x80)
+      SETMOSI;
+    else
+      CLRMOSI;
+    byte <<= 1;
+    SETCLK;
+  
+    /* read MISO on trailing edge */
+    byte |= READMISO;
+    CLRCLK;
+  }
+  
+  return byte;
+}
+
+
+
+
+//! Handles a Nordic RF command.
+void nrfhandle(unsigned char app,
+              unsigned char verb,
+              unsigned long len){
+  unsigned long i;
+  
+  //Raise !SS to end transaction, just in case we forgot.
+  P5OUT|=SS;
+  nrfsetup();
+  
+  switch(verb){
+    //PEEK and POKE might come later.
+  case READ:
+  case WRITE:
+    P5OUT&=~SS; //Drop !SS to begin transaction.
+    for(i=0;i<len;i++)
+      cmddata[i]=nrftrans8(cmddata[i]);
+    P5OUT|=SS;  //Raise !SS to end transaction.
+    txdata(app,verb,len);
+    break;
+
+
+
+  case PEEK://Grab NRF Register
+    txdata(app,verb,0);
+    break;
+    
+  case POKE://Poke NRF Register
+    
+    txdata(app,verb,0);
+    break;
+    
+  case SETUP:
+    nrfsetup();
+    txdata(app,verb,0);
+    break;
+  }
+  
+}
index 9fb9ec9..f12e278 100644 (file)
@@ -75,14 +75,16 @@ void handle(unsigned char app,
   case SPI:
     spihandle(app,verb,len);
     break;
+  case NRF:
+    nrfhandle(app,verb,len);
+    break;
   case AVR:
     avrhandle(app,verb,len);
     break;
-#ifdef INSTALL_PIC_APP
   case PIC:
     pichandle(app,verb,len);
     break;
-#endif
+
   case I2CAPP:
     i2chandle(app,verb,len);
     break;
index ab15feb..6e88874 100644 (file)
@@ -145,16 +145,19 @@ void delay_ticks( unsigned int num_ticks );
 
 
 void monitorhandle(unsigned char, unsigned char, unsigned long);
-void spihandle(unsigned char, unsigned char, unsigned long);
-void i2chandle(unsigned char, unsigned char, unsigned long) WEAKDEF;
-void cchandle(unsigned char, unsigned char, unsigned long) WEAKDEF;
-void jtaghandle(unsigned char, unsigned char, unsigned long);
-void jtag430handle(unsigned char, unsigned char, unsigned long);
+WEAKDEF void spihandle(unsigned char, unsigned char, unsigned long);
+WEAKDEF void i2chandle(unsigned char, unsigned char, unsigned long);
+WEAKDEF void cchandle(unsigned char, unsigned char, unsigned long);
+WEAKDEF void jtaghandle(unsigned char, unsigned char, unsigned long);
+WEAKDEF void jtag430handle(unsigned char, unsigned char, unsigned long);
 WEAKDEF void ejtaghandle(unsigned char, unsigned char, unsigned long);
 WEAKDEF void jtagarm7tdmihandle(unsigned char app, unsigned char verb, unsigned long len);
 
-void jtag430x2handle(unsigned char app, unsigned char verb, unsigned long len);
+WEAKDEF void jtag430x2handle(unsigned char app, unsigned char verb, unsigned long len);
 
+WEAKDEF void nrfhandle(unsigned char,
+                      unsigned char,
+                      unsigned long);
 WEAKDEF void avrhandle(unsigned char app,
                       unsigned char verb,
                       unsigned long len);  
diff --git a/firmware/include/nrf.h b/firmware/include/nrf.h
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+