summaryrefslogtreecommitdiff
path: root/software
diff options
context:
space:
mode:
authorBernhard Tittelbach <xro@realraum.at>2012-05-19 03:47:23 +0000
committerBernhard Tittelbach <xro@realraum.at>2012-05-19 03:47:23 +0000
commit56f60406799444317d08259beaa874eed0404494 (patch)
tree5a6865919bf168597b6e36f9d203477382a736f2 /software
parentTX test (diff)
tx should work, but fifo isn't transmitted
git-svn-id: https://svn.spreadspace.org/mur.sat@431 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'software')
-rw-r--r--software/hhd70dongle/c1101lib.c79
-rw-r--r--software/hhd70dongle/hhd70dongle.c1
2 files changed, 50 insertions, 30 deletions
diff --git a/software/hhd70dongle/c1101lib.c b/software/hhd70dongle/c1101lib.c
index 60a3b4d..7958309 100644
--- a/software/hhd70dongle/c1101lib.c
+++ b/software/hhd70dongle/c1101lib.c
@@ -62,6 +62,8 @@ int16_t spi_c1101_write_byte_ok_get_status(char data)
return sb;
}
+#define spi_c1101_strobe_command spi_c1101_write_byte_ok_get_status
+
// note addresses range from 0x00 to 0x2F for normal registers and 0xF0 to 0xFD for special status registers
int16_t spi_c1101_read_register(char address)
{
@@ -94,14 +96,6 @@ int16_t spi_c1101_write_register(char address, char byte)
return 1;
}
-// note addresses range from 0x30 to 0x3D for command strobes
-int16_t spi_c1101_strobe_command(char address)
-{
- if (spi_c1101_write_byte_ok_get_status(address) < 0)
- return -1;
- return 1;
-}
-
void spi_c1101_dump_registers_to_usb(void)
{
int c = 0;
@@ -130,7 +124,7 @@ int spi_c1101_read_rxfifo(int leave_num_bytes, char *buffer, int maxlen)
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((char)sb);
+ 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)
@@ -143,26 +137,22 @@ int spi_c1101_read_rxfifo(int leave_num_bytes, char *buffer, int maxlen)
}
//note: always check if num_written returned == len given
-//note: currently this function writes at most 15 bytes
int spi_c1101_write_txfifo(char *buffer, int len)
{
char sb;
int num_written = 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_WRITE_BURST);
if (sb < 0)
return -1;
- num_fifo_available = SPIC1101_SB_FIFO_BYTES_AVAILABLE((char)sb);
- //note if num_fifo_available == 15 then 15 or more bytes are available
- //FIXTHIS
- if (num_fifo_available < len)
- len = num_fifo_available;
- while (len--)
+ uint8_t debug_sb[6];
+ while (len-- > 0 && SPIC1101_SB_FIFO_BYTES_AVAILABLE(sb) > 2)
{
- //hope this works !!
- spi_write_byte(buffer[num_written++]);
+ usb_rawhid_send((uint8_t*)"TXFifo bytes available",255);
+ debug_sprint_int16hex(debug_sb, SPIC1101_SB_FIFO_BYTES_AVAILABLE(sb));
+ usb_rawhid_send(debug_sb,255);
+ sb = spi_c1101_write_byte_ok_get_status(buffer[num_written++]);
}
spi_cs_disable();
return num_written;
@@ -184,10 +174,13 @@ void c1101_init(void)
spi_c1101_dump_registers_to_usb();
//enable analog temperature sensor on GDO0
spi_c1101_write_register(SPIC1101_ADDR_IOCFG0, 0x80);
+ //enable RX FIFO interrupt (i.e. GPO1 pulls high if >= FIFOTHR bytes are in RX FIFO)
+ spi_c1101_write_register(SPIC1101_ADDR_IOCFG1, 0);
// FIFOTHR RX FIFO and TX FIFO Thresholds
- spi_c1101_write_register(SPIC1101_ADDR_FIFOTHR, 0x47);
+ // pull GPO high (interrupt) if more than 12 bytes in rx buffer (or less than 53 in tx)
+ spi_c1101_write_register(SPIC1101_ADDR_FIFOTHR, 2);
// PKTCTRL0 Packet Automation Control
- spi_c1101_write_register(SPIC1101_ADDR_PKTCTRL0, 0x05);
+ spi_c1101_write_register(SPIC1101_ADDR_PKTCTRL0, 0b0000000010);
// FSCTRL1 Frequency Synthesizer Control
spi_c1101_write_register(SPIC1101_ADDR_FSCTRL1, 0x06);
// FREQn Frequency Control Words
@@ -298,6 +291,10 @@ char c1101_getStatus(void)
return sb;
}
+uint8_t c1101_getNumBytesInTXFifo(void)
+{
+ return spi_c1101_read_register(SPIC1101_ADDR_TXBYTES);
+}
void c1101_transmitData(char *buffer, unsigned int len)
{
@@ -308,23 +305,45 @@ void c1101_transmitData(char *buffer, unsigned int len)
//configure state machine to automatically go to IDLE, once packet was transmitted
mcsm1 = (mcsm1 & 0b11111100) | 0b00;
spi_c1101_write_register(SPIC1101_ADDR_MCSM1, 0x18);
+
+ uint8_t debug_sb[6];
+
//fill buffer
- do
- {
- num_written = spi_c1101_write_txfifo(buffer, len);
- buffer += num_written;
- len -= num_written;
- } while (num_written > 0);
+ num_written = spi_c1101_write_txfifo(buffer, len);
+ buffer += num_written;
+ len -= num_written;
+
+ usb_rawhid_send((uint8_t*)"TX num written",255);
+ debug_sprint_int16hex(debug_sb, num_written);
+ usb_rawhid_send(debug_sb,255);
+ usb_rawhid_send((uint8_t*)"TX len",255);
+ debug_sprint_int16hex(debug_sb, len);
+ usb_rawhid_send(debug_sb,255);
+
+ c1101_getStatus();
+ usb_rawhid_send((uint8_t*)"TX bytes",255);
+ debug_sprint_int16hex(debug_sb, c1101_getNumBytesInTXFifo());
+ usb_rawhid_send(debug_sb,255);
+
//start transmitting
spi_c1101_strobe_command(SPIC1101_ADDR_STX);
//keep buffer filled
do
{
- num_written = spi_c1101_write_txfifo(buffer, len);
+ num_written = spi_c1101_write_txfifo(buffer, len );
buffer += num_written;
len -= num_written;
- if (num_written == 0 && len > 0)
- _delay_ms(1);
+
+ usb_rawhid_send((uint8_t*)"TX2 num written",255);
+ debug_sprint_int16hex(debug_sb, num_written);
+ usb_rawhid_send(debug_sb,255);
+ usb_rawhid_send((uint8_t*)"TX2 len",255);
+ debug_sprint_int16hex(debug_sb, len);
+ usb_rawhid_send(debug_sb,255);
+ c1101_getStatus();
+ usb_rawhid_send((uint8_t*)"TX2 bytes",255);
+ debug_sprint_int16hex(debug_sb, c1101_getNumBytesInTXFifo());
+ usb_rawhid_send(debug_sb,255);
} while (len > 0);
}
diff --git a/software/hhd70dongle/hhd70dongle.c b/software/hhd70dongle/hhd70dongle.c
index acb3d2f..97b82a5 100644
--- a/software/hhd70dongle/hhd70dongle.c
+++ b/software/hhd70dongle/hhd70dongle.c
@@ -52,6 +52,7 @@ uint8_t write_buffer[64]; // buffer for writing usb signals
// * use adc noise canceler (i.e. automatic sampling during cpu sleep)
// * read atmega temp
// * safely save state in eeprom (2 memory regions, only use the one with the "written successfully bit" which is written last)
+// * what if c1101 resets spuriously and clears it's settings ? -> check peridically ?
int main(void)
{