Started to write another test case to blurt out OOK energenie messages.
This is only a test case.
But it has highlighted a whole load of discrepancies in the original C
code to do with payload length calculation, and the 'magic' zero byte
at the start of the buffer for stuffing the SPI register address in.
1 parent e05eddd commit eb0e15017ae8574873643a7bf2ab645db091bee0
@David Whale David Whale authored on 12 Apr 2016
Showing 4 changed files
View
103
src/energenie/drv/hrfm69.c
#include "system.h"
#include "hrfm69.h"
#include "spi.h"
#include "trace.h"
 
 
/***** LOW LEVEL REGISTER INTERFACE ******************************************/
 
// Write an 8 bit value to a register
void HRF_writereg(uint8_t addr, uint8_t data)
{
spi_deselect();
}
 
 
//TODO: where is the buffer memory defined?
//perhaps pass in buffer memory and maxlen
//how do we know the actual length of buffer written to?
//pass in ptr to len variable
uint8_t* HRF_readfifo_burst(void)
void HRF_readfifo_burst(uint8_t* buf, uint8_t len)
{
//def HRF_readfifo_burst():
// """Read bytes from the payload FIFO using burst read"""
// #first byte read is the length in remaining bytes
// count -= 1
// buf.append(data)
// spi.deselect()
// return buf
return (void*)0; // TODO
}
 
 
// Check to see if a register matches a specific value or not
}
}
 
 
// Wait for HRF to be ready after last command
void HRF_wait_ready(void)
// Clear any data in the HRF payload FIFO, by reading until empty
void HRF_clear_fifo(void)
{
HRF_pollreg(HRF_ADDR_IRQFLAGS1, HRF_MASK_MODEREADY, HRF_MASK_MODEREADY);
while ((HRF_readreg(HRF_ADDR_IRQFLAGS2) & HRF_MASK_FIFONOTEMPTY) == HRF_MASK_FIFONOTEMPTY)
{
HRF_readreg(HRF_ADDR_FIFO);
}
}
 
 
// Wait for the HRF to be ready, and ready for tx, after last command
void HRF_wait_txready(void)
{
HRF_pollreg(HRF_ADDR_IRQFLAGS1, HRF_MASK_MODEREADY|HRF_MASK_TXREADY, HRF_MASK_MODEREADY|HRF_MASK_TXREADY);
}
 
/***** HIGH LEVEL PAYLOAD INTERFACE ******************************************/
 
// Change the operating mode of the HRF radi
void HRF_change_mode(uint8_t mode)
{
HRF_writereg(HRF_ADDR_OPMODE, mode);
}
 
 
// Clear any data in the HRF payload FIFO, by reading until empty
void HRF_clear_fifo(void)
// Wait for HRF to be ready after last command
void HRF_wait_ready(void)
{
while ((HRF_readreg(HRF_ADDR_IRQFLAGS2) & HRF_MASK_FIFONOTEMPTY) == HRF_MASK_FIFONOTEMPTY)
HRF_pollreg(HRF_ADDR_IRQFLAGS1, HRF_MASK_MODEREADY, HRF_MASK_MODEREADY);
}
 
 
// Load a table of configuration values into HRF registers
void HRF_config(HRF_CONFIG_REC* config, uint8_t count)
{
while (count-- != 0)
{
HRF_readreg(HRF_ADDR_FIFO);
HRF_writereg(config->addr, config->value);
config++;
}
}
 
 
// Wait for the HRF to be ready, and ready for tx, after last command
void HRF_wait_txready(void)
{
HRF_pollreg(HRF_ADDR_IRQFLAGS1, HRF_MASK_MODEREADY|HRF_MASK_TXREADY, HRF_MASK_MODEREADY|HRF_MASK_TXREADY);
}
 
 
// Check if there is a payload in the FIFO waiting to be processed
return (irqflags2 & HRF_MASK_PAYLOADRDY) == HRF_MASK_PAYLOADRDY;
}
 
 
//TODO: unnecessary level of runtime indirection?
//TODO: where is the buffer memory defined?
//perhaps pass in buffer memory and maxlen
//how do we know the actual length of buffer written to?
//pass in ptr to len variable
uint8_t* HRF_receive_payload(void)
void HRF_receive_payload(uint8_t* buf, uint8_t len)
{
return HRF_readfifo_burst();
return HRF_readfifo_burst(buf, len);
}
 
 
// Send a preformatted payload of data
// warning("Failed to send payload to HRF")
}
 
 
// Load a table of configuration values into HRF registers
void HRF_config(HRF_CONFIG_REC* config, uint8_t count)
{
while (count-- != 0)
{
HRF_writereg(config->addr, config->value);
config++;
}
}
/***** END OF FILE *****/
 
//# END
View
42
src/energenie/drv/hrfm69.h
#define HRF_VAL_FIFOTHRESH1 0x81 // Condition to start packet transmission: at least one byte in FIFO
#define HRF_VAL_FIFOTHRESH30 0x1E // Condition to start packet transmission: wait for 30 bytes in FIFO
 
 
/* Low level register interface */
 
extern void HRF_writereg(uint8_t addr, uint8_t data);
 
extern uint8_t HRF_readreg(uint8_t addr);
 
extern void HRF_writefifo_burst(uint8_t* buf, uint8_t len);
 
//TODO unnecessary level of runtime indirection?
//TODO where is the buffer memory defined?
//perhaps pass in buffer memory and maxlen
//how do we know the actual length of buffer written to?
//pass in ptr to len variable
extern uint8_t* HRF_readfifo_burst(void);
extern void HRF_readfifo_burst(uint8_t* buf, uint8_t len);
 
extern HRF_RESULT HRF_checkreg(uint8_t addr, uint8_t mask, uint8_t value);
 
extern void HRF_pollreg(uint8_t addr, uint8_t mask, uint8_t value);
 
extern void HRF_clear_fifo(void);
 
 
/* High level payload interface */
 
extern void HRF_change_mode(uint8_t mode);
 
extern void HRF_wait_ready(void);
 
extern void HRF_wait_txready(void);
 
extern void HRF_change_mode(uint8_t mode);
 
extern void HRF_clear_fifo(void);
extern void HRF_config(HRF_CONFIG_REC* config, uint8_t len);
 
extern HRF_RESULT HRF_check_payload(void);
 
 
//TODO unnecessary level of runtime indirection?
//TODO where is the buffer memory defined?
//perhaps pass in buffer memory and maxlen
//how do we know the actual length of buffer written to?
//pass in ptr to len variable
extern uint8_t* HRF_receive_payload(void);
extern void HRF_receive_payload(uint8_t* buf, uint8_t len);
 
extern void HRF_send_payload(uint8_t* payload, uint8_t len);
 
extern void HRF_config(HRF_CONFIG_REC* config, uint8_t len);
 
#endif
 
/***** END OF FILE *****/
View
src/energenie/drv/hrfm69_test.c
View
src/energenie/radio.py