From a03f202e7c0cd88bdd0560976820fb8d21529ee7 Mon Sep 17 00:00:00 2001 From: Stefan `Sec` Zehl Date: Tue, 5 Jul 2011 02:33:36 +0200 Subject: [PATCH] First attempt at nrf support code --- firmware/basic/basic.h | 5 ++ firmware/funk/Makefile | 36 +++++++++++++ firmware/funk/nrf24l01p.c | 103 ++++++++++++++++++++++++++++++++++++++ firmware/funk/nrf24l01p.h | 96 +++++++++++++++++++++++++++++++++++ 4 files changed, 240 insertions(+) create mode 100644 firmware/funk/Makefile create mode 100644 firmware/funk/nrf24l01p.c create mode 100644 firmware/funk/nrf24l01p.h diff --git a/firmware/basic/basic.h b/firmware/basic/basic.h index d343862..4bd93ea 100644 --- a/firmware/basic/basic.h +++ b/firmware/basic/basic.h @@ -105,6 +105,11 @@ #define RB_HB5 1,2 #define RB_HB5_IO IOCON_PIO1_2 +// Funk +#define RB_NRF_CE 1,5 +#define RB_NRF_CE_IO IOCON_PIO1_5 +#define RB_SPI_NRF_CS 1,10 +#define RB_SPI_NRF_CS_IO IOCON_PIO1_10 // Misc #define RB_BUSINT 3,0 diff --git a/firmware/funk/Makefile b/firmware/funk/Makefile new file mode 100644 index 0000000..4fdde2b --- /dev/null +++ b/firmware/funk/Makefile @@ -0,0 +1,36 @@ +########################################################################## +# User configuration and firmware specific object files +########################################################################## + +OBJS = + +OBJS += nrf24l01p.o + +LIBNAME=funk + +########################################################################## +# GNU GCC compiler flags +########################################################################## +ROOT_PATH?= .. +INCLUDE_PATHS = -I$(ROOT_PATH) -I../core -I. + +include $(ROOT_PATH)/Makefile.inc + +LIBFILE=lib$(LIBNAME).a +########################################################################## +# Compiler settings, parameters and flags +########################################################################## + +all: $(LIBFILE) + +$(LIBFILE): $(OBJS) + $(AR) rcs $@ $(OBJS) + +%.o : %.c + $(CC) $(CFLAGS) -o $@ $< + +clean: + rm -f $(OBJS) $(LIBFILE) + +nrf24l01p.o: nrf24l01p.h + diff --git a/firmware/funk/nrf24l01p.c b/firmware/funk/nrf24l01p.c new file mode 100644 index 0000000..45c37e1 --- /dev/null +++ b/firmware/funk/nrf24l01p.c @@ -0,0 +1,103 @@ +#include +#include +#include "core/ssp/ssp.h" + +#define CHANNEL_BEACON 81 +#define DEFAULT_SPEED R_RF_SETUP_DR_2M +#define MAC_BEACON "BEACO" + +/*-----------------------------------------------------------------------*/ +/* Transmit a byte via SPI (Platform dependent) */ +/*-----------------------------------------------------------------------*/ +void xmit_spi(uint8_t dat) { + sspSend(0, (uint8_t*) &dat, 1); +} + +/*-----------------------------------------------------------------------*/ +/* Receive a byte from MMC via SPI (Platform dependent) */ +/*-----------------------------------------------------------------------*/ +uint8_t rcvr_spi (void) { + uint8_t data = 0; + + sspReceive(0, &data, 1); + + return data; +} + +#define rcvr_spi_m(dst) \ + do { \ + sspReceive(0, (uint8_t*)(dst), 1); \ + } while(0) + +#define CS_LOW() gpioSetValue(RB_SPI_NRF_CS, 0) +#define CS_HIGH() gpioSetValue(RB_SPI_NRF_CS, 1) + +void nrf_cmd(uint8_t cmd){ + xmit_spi(cmd); +}; + +uint8_t nrf_cmd_status(uint8_t cmd){ + xmit_spi(cmd); + return rcvr_spi(); +}; + +void nrf_write_reg(uint8_t reg, uint8_t val){ + xmit_spi(C_W_REGISTER | reg); + xmit_spi(val); +}; + +uint8_t nrf_read_reg(uint8_t reg, uint8_t val){ + xmit_spi(C_R_REGISTER | reg); + // do i need to read the status byte here? + xmit_spi(val); + return rcvr_spi(); +}; + +void nrf_write_reg_long(uint8_t reg, int len, char* data){ + xmit_spi(C_W_REGISTER | reg); + for(int i=0;i