Author: jaguarondi
Date: 2008-07-10 14:25:01 +0200 (Thu, 10 Jul 2008)
New Revision: 1321
Modified:
firmware/rf/trunk/defines.h
firmware/rf/trunk/init.c
firmware/rf/trunk/interface.c
firmware/rf/trunk/misc.c
firmware/rf/trunk/prot.c
firmware/rf/trunk/rf_ctrl.c
Log:
* Fixed the size of the RF frame with a define which is used throughout the
code.
Modified: firmware/rf/trunk/defines.h
===================================================================
--- firmware/rf/trunk/defines.h 2008-07-10 11:10:13 UTC (rev 1320)
+++ firmware/rf/trunk/defines.h 2008-07-10 12:25:01 UTC (rev 1321)
@@ -109,7 +109,12 @@
#define PREAMBLE 8 /* Preamble in bytes */
#define SYNC 2 /* Sync data in bytes */
#define SOF 4 /* Start Of Frame in bytes */
-#define PAYLOAD 75 /* Payload in bytes */
+#define HEADER (PREAMBLE + SYNC + SOF)
+/* Part of the HEADER which is stored in the buffer. 2 bytes of the PREAMBLE
+ * aren't stored but sent directly. */
+#define STORED_HEADER (HEADER - 2)
+#define PAYLOAD 52 /* Payload in bytes */
+#define RF_BUFFER_SIZE (PAYLOAD + STORED_HEADER)
/* USART bit to tick ratio: sys_clk / (8 * 1152e3) */
#define TICKS_PER_BIT (F_CPU/(8.*1152000))
Modified: firmware/rf/trunk/init.c
===================================================================
--- firmware/rf/trunk/init.c 2008-07-10 11:10:13 UTC (rev 1320)
+++ firmware/rf/trunk/init.c 2008-07-10 12:25:01 UTC (rev 1321)
@@ -127,8 +127,7 @@
rf_buffer_tx[10]=sof_ary[2];
rf_buffer_tx[11]=sof_ary[3];
- /* TODO increase the frame size to add the previosu audio data */
- rf_buffer_tx[12]=52; /* Number of bytes from here */
+ rf_buffer_tx[12]=52;
rf_buffer_tx[13]=0x55;
rf_buffer_tx[14]=0x55;
rf_buffer_tx[15]=0x55;
Modified: firmware/rf/trunk/interface.c
===================================================================
--- firmware/rf/trunk/interface.c 2008-07-10 11:10:13 UTC (rev 1320)
+++ firmware/rf/trunk/interface.c 2008-07-10 12:25:01 UTC (rev 1321)
@@ -36,7 +36,7 @@
clr_spiack();
}
-static uint8_t * const spi_in = (uint8_t *)rf_buffer_tx+13;
+static uint8_t * const spi_in = (uint8_t *)rf_buffer_tx+12;
static uint8_t * spi_out;
static uint8_t spi_idx;
@@ -55,7 +55,7 @@
/* XXX should we disable/enable SPIE? */
spi_idx = 0;
/* XXX size is at [0] -> +1 for the start of the frame */
- spi_out = (uint8_t *)rf_buffer_rx_full+1;
+ spi_out = (uint8_t *)rf_buffer_rx_full;
SPDR = spi_out[spi_idx];
set_txe();
}
Modified: firmware/rf/trunk/misc.c
===================================================================
--- firmware/rf/trunk/misc.c 2008-07-10 11:10:13 UTC (rev 1320)
+++ firmware/rf/trunk/misc.c 2008-07-10 12:25:01 UTC (rev 1321)
@@ -129,9 +129,10 @@
uint8_t *ptr;
ptr = (uint8_t *)&rf_buffer_tx[12];
tmp = 0x00;
- for(i=rf_buffer_tx[12]; i>0x01; i--)
+ for(i=PAYLOAD; i>0x01; i--)
{
tmp += *ptr++;
}
+ /* Store the checksum at the last byte */
*ptr = (tmp ^ 0xFF) + 1;
}
Modified: firmware/rf/trunk/prot.c
===================================================================
--- firmware/rf/trunk/prot.c 2008-07-10 11:10:13 UTC (rev 1320)
+++ firmware/rf/trunk/prot.c 2008-07-10 12:25:01 UTC (rev 1321)
@@ -117,7 +117,6 @@
do{
if(rf_rx_state==0xFF){//something received
if(checksum==0x00){//correct received
- if(rf_buffer_rx[0]==52){//packet received
//pwr_dwn_atr2406();
rf_rx_state = 0x00;
@@ -132,9 +131,10 @@
start_rf_timer();
return;
- }
}
}
+ /* XXX use the overflow interrupt and the same timer
+ * settings as in normal mode. */
} while (TCNT1 < 43201); /* 200ms */
}
}
Modified: firmware/rf/trunk/rf_ctrl.c
===================================================================
--- firmware/rf/trunk/rf_ctrl.c 2008-07-10 11:10:13 UTC (rev 1320)
+++ firmware/rf/trunk/rf_ctrl.c 2008-07-10 12:25:01 UTC (rev 1321)
@@ -432,19 +432,18 @@
//*****************************************************************************
ISR (SIG_USART_DATA)
{
- uint8_t tmp = rf_tx_counter;
+ uint8_t cnt = rf_tx_counter;
/* Set nOLE to low when preamble is sent. */
- if(tmp == 0x07)
+ if(cnt == 0x07)
{
clr_nole();
}
- /* XXX frame size would better be fixed, no? */
/* Last data buffered. */
- if(tmp == rf_buffer_tx[12] + 11)
+ if(cnt == RF_BUFFER_SIZE - 1)
{
/* TODO this can be moved out of the if/else */
- UDR0 = rf_buffer_tx[tmp] ^ SCRAMBLE_BYTE;
+ UDR0 = rf_buffer_tx[cnt] ^ SCRAMBLE_BYTE;
//UDR0 = (0-checksum_tx) ^ SCRAMBLE_BYTE;
/* Enable USART Transmit complete interrupt (SIG_USART_TRANS) and
* disable DRE (SIG_USART_DATA) */
@@ -452,18 +451,11 @@
}
else
{
- UDR0 = rf_buffer_tx[tmp] ^ SCRAMBLE_BYTE;
- //checksum_tx += rf_buffer_tx[tmp];
+ UDR0 = rf_buffer_tx[cnt] ^ SCRAMBLE_BYTE;
+ //checksum_tx += rf_buffer_tx[cnt];
}
- rf_tx_counter = ++tmp;
+ rf_tx_counter = ++cnt;
}
-//worsest case duration 46 cycles
-//@13.824MHz ==> 38% (1N8)
-//@ 6.912MHz ==> 77% (1N8)
-//@13.824MHz ==> 35% (2N8)(1N8 + Parity)
-//@ 6.912MHz ==> 70% (2N8)(1N8 + Parity)
-//@13.824MHz ==> 32% (2N9)
-//@ 6.912MHz ==> 64% (2N9)
//*****************************************************************************
//* Project: RF-Firmware for ISM *
@@ -516,14 +508,12 @@
/* Frame detected, receive data */
{
rf_buffer_rx[rf_rx_counter++] = data;
- /* Wrap around buffer */
- rf_rx_counter &= 0x3F;
/* checksum is computed from buf[4] to buf[-1] and should be 0 at the
* end as buf[-1] contains the checksum of buf[4..-2] */
checksum += data;
- if(rf_rx_counter==rf_buffer_rx[0]) /* XXX better have a define here
unless we want dynamic length of frames */
+ if(rf_rx_counter == PAYLOAD)
{
state = 0xFF;
UCSR0A = 0x00;
@@ -542,7 +532,7 @@
{
#ifdef _SLAVE
ts = TCNT1;
- OCR1A = ts + T_SYNC - T_LATENCY - T_PWR_DWN;
+ OCR1A = ts + T_SYNC - T_LATENCY;
#endif
}
}
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn