diff --git a/src/energenie/drv/build_mac b/src/energenie/drv/build_mac index 95781bd..8e7a16e 100755 --- a/src/energenie/drv/build_mac +++ b/src/energenie/drv/build_mac @@ -13,6 +13,12 @@ mv a.out spis_test chmod u+x spis_test +# build hrf69_test +gcc hrf69_test.c hrf69.c spis.c gpio_sim.c delay_posix.c +mv a.out hrf69_test +chmod u+x hrf69_test + + # build spih_test (hard SPI tester) ##gcc spi_test.c spih_rpi.c gpio_rpi.c diff --git a/src/energenie/drv/delay.h b/src/energenie/drv/delay.h index 63bfe1e..a071e18 100644 --- a/src/energenie/drv/delay.h +++ b/src/energenie/drv/delay.h @@ -15,6 +15,8 @@ void delaysec(uint8_t secs); +void delayms(unsigned int ms); + void delayus(unsigned int us); #endif diff --git a/src/energenie/drv/delay_posix.c b/src/energenie/drv/delay_posix.c index a5f27a8..3604557 100644 --- a/src/energenie/drv/delay_posix.c +++ b/src/energenie/drv/delay_posix.c @@ -7,14 +7,10 @@ #include #include "system.h" +#include "delay.h" -static struct timespec delay_1sec = {1, 0}; - - -void delay(struct timespec time) -{ - nanosleep(&time, NULL); -} +static struct timespec delay_1sec = {1, 0}; // 1sec, 0us +static struct timespec delay_1ms = {0, 1000}; // 0sec, 1000us void delaysec(uint8_t secs) @@ -26,6 +22,21 @@ } +void delayms(unsigned int ms) +{ + while (ms-- > 0) + { + delay(delay_1ms); + } +} + + +void delay(struct timespec time) +{ + nanosleep(&time, NULL); +} + + /* Based on code suggested by Gordon Henderson: * https://github.com/WiringPi/WiringPi/blob/master/wiringPi/wiringPi.c * diff --git a/src/energenie/drv/hrf69.c b/src/energenie/drv/hrf69.c index b2c297b..3c032bd 100644 --- a/src/energenie/drv/hrf69.c +++ b/src/energenie/drv/hrf69.c @@ -3,6 +3,9 @@ * Hope RF RFM69 radio controller code. */ +#include "system.h" +#include "hrf69.h" + //import spi //def warning(msg): @@ -41,10 +44,11 @@ // res = spi.frame(buf) // spi.deselect() // return res[1] # all registers are 8 bit + return 0; // TODO } -void HRF_writefifo_burst(uint8_t* buf uint8_t len) +void HRF_writefifo_burst(uint8_t* buf, uint8_t len) { //def HRF_writefifo_burst(buf): // """Write all bytes in buf to the payload FIFO, in a single burst""" @@ -81,6 +85,7 @@ // buf.append(data) // spi.deselect() // return buf + return (void*)0; // TODO } @@ -91,6 +96,7 @@ // regval = HRF_readreg(addr) // #print("addr %d mask %d wanted %d actual %d" % (addr,mask,value,regval)) // return (regval & mask) == value + return 0; // TODO } @@ -142,6 +148,7 @@ // irqflags1 = HRF_readreg(ADDR_IRQFLAGS1) // irqflags2 = HRF_readreg(ADDR_IRQFLAGS2) // return (irqflags2 & MASK_PAYLOADRDY) == MASK_PAYLOADRDY + return 0; // TODO } @@ -152,9 +159,7 @@ //pass in ptr to len variable uint8_t* HRF_receive_payload(void) { -//def HRF_receive_payload(): -// """Receive the whole payload""" -// return HRF_readfifo_burst() + return HRF_readfifo_burst(); } diff --git a/src/energenie/drv/hrf69.h b/src/energenie/drv/hrf69.h index 9b17c32..a5b6aa3 100644 --- a/src/energenie/drv/hrf69.h +++ b/src/energenie/drv/hrf69.h @@ -116,7 +116,7 @@ extern uint8_t HRF_readreg(uint8_t addr); -extern void HRF_writefifo_burst(uint8_t* buf uint8_t len); +extern void HRF_writefifo_burst(uint8_t* buf, uint8_t len); //TODO unnecessary level of runtime indirection? //TODO where is the buffer memory defined? diff --git a/src/energenie/drv/hrf69_test.c b/src/energenie/drv/hrf69_test.c index 2e62d03..508a093 100644 --- a/src/energenie/drv/hrf69_test.c +++ b/src/energenie/drv/hrf69_test.c @@ -6,19 +6,81 @@ /***** INCLUDES *****/ -//#include +#include //#include -//#include "gpio.h" -//#include "spi.h" +#include "system.h" +#include "delay.h" +#include "gpio.h" +#include "spi.h" +#include "hrf69.h" -/***** CONSTANTS *****/ +/***** CONFIGURATION *****/ +/* Only define this if you are running mac/pc/pi, + * arduino will have a different console wrapper to drive tests, probably + */ + +#define HRF69_TEST + +/* GPIO assignments for Arduino Pro Micro */ + +#define RESET 2 +#define CS 3 +#define MOSI 4 +#define MISO 5 +#define SCLK 6 + + +/***** FUNCTION PROTOTYPES *****/ + +static void reset(void); +void hrf_test_connect(void); + + + +#if defined(HRF69_TEST) int main(int argc, char **argv) { - //TODO + hrf_test_connect(); return 0; } +#endif + +// Reset is really a function of how the Energenie radio is wired up to the Pi or +// Arduino, so it will appear in the 'radio' module. It is here for testing convenience. + + +static void reset(void) +{ + SPI_CONFIG radioConfig = {CS, SCLK, MOSI, MISO, SPI_SPOL0, SPI_CPOL0, SPI_CPHA0}; + //TSETTLE, THOLD, TFREQ}; + spi_init(&radioConfig); + + gpio_setout(RESET); + gpio_low(RESET); + delayus(100); + + gpio_high(RESET); + delayms(150); + + gpio_low(RESET); + delayus(100); +} + + +void hrf_test_connect(void) +{ + uint8_t result; + + // can we reset the HRF, and read a register from it? + + reset(); + result = HRF_readreg(0x00); + printf("result:%02X", (unsigned int) result); + + spi_finished(); +} /***** END OF FILE *****/