diff options
Diffstat (limited to 'software/hhd70dongle')
-rw-r--r-- | software/hhd70dongle/c1101lib.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/software/hhd70dongle/c1101lib.c b/software/hhd70dongle/c1101lib.c index 0578099..a29974e 100644 --- a/software/hhd70dongle/c1101lib.c +++ b/software/hhd70dongle/c1101lib.c @@ -125,21 +125,37 @@ void spi_c1101_dump_registers_to_usb(void) spi_cs_disable(); } -//note: currently this function reads at most 15 bytes int spi_c1101_read_rxfifo(int leave_num_bytes, char *buffer, int maxlen) { + int num_read = 0; + uint8_t num_available = 0; + spi_cs_enable(); + spi_c1101_wait_chip_rdy(); + if (spi_c1101_write_byte_ok_get_status(SPIC1101_ADDR_RXBYTES) < 0) + return -1; + num_available = spi_read_byte(); + if (spi_c1101_write_byte_ok_get_status(SPIC1101_ADDR_FIFO_READ_BURST) < 0) + return -1; + while (maxlen-- > 0 && num_available - num_read > leave_num_bytes) + { + buffer[num_read++] = spi_read_byte(); + } + spi_cs_disable(); + return num_read; +} + +//note: currently this function reads at most 15 bytes +int spi_c1101_read_rxfifo_max15(int leave_num_bytes, char *buffer, int maxlen) +{ int16_t sb; int num_read = 0; - int num_fifo_available = 0; spi_cs_enable(); spi_c1101_wait_chip_rdy(); sb = spi_c1101_write_byte_ok_get_status(SPIC1101_ADDR_FIFO_READ_BURST); if (sb < 0) return -1; - num_fifo_available = SPIC1101_SB_FIFO_BYTES_AVAILABLE(sb); - //note if num_fifo_available == 15 then 15 or more bytes are available - //FIXTHIS - while (maxlen-- && num_fifo_available - num_read <= leave_num_bytes) + //note if SPIC1101_SB_FIFO_BYTES_AVAILABLE(sb) == 15 then 15 or more bytes are available + while (maxlen-- > 0 && SPIC1101_SB_FIFO_BYTES_AVAILABLE(sb) - num_read > leave_num_bytes) { //hope this works !! buffer[num_read++] = spi_read_byte(); |