From dffb4095b5c57ed45748646d224b719015ebd92f Mon Sep 17 00:00:00 2001 From: travisutk Date: Tue, 18 May 2010 18:29:40 +0000 Subject: [PATCH] Forked SPI to NRF. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@520 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- firmware/Makefile | 4 +- firmware/apps/radios/nrf.c | 102 +++++++++++++++++++++++++++++++++++++ firmware/goodfet.c | 6 ++- firmware/include/command.h | 15 +++--- firmware/include/nrf.h | 1 + 5 files changed, 118 insertions(+), 10 deletions(-) create mode 100644 firmware/apps/radios/nrf.c create mode 100644 firmware/include/nrf.h diff --git a/firmware/Makefile b/firmware/Makefile index 5117f0c..c84afb2 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -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 index 0000000..f81afba --- /dev/null +++ b/firmware/apps/radios/nrf.c @@ -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 +#include +#include + +#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