Author: jaguarondi
Date: 2008-08-21 18:05:14 +0200 (Thu, 21 Aug 2008)
New Revision: 1564
Modified:
firmware/rf/trunk/defines.h
firmware/rf/trunk/prot.c
firmware/rf/trunk/rf_ctrl.c
firmware/rf/trunk/varis.c
firmware/rf/trunk/varis.h
Log:
* Added frequency hopping from a table that will be used for adaptative.
Modified: firmware/rf/trunk/defines.h
===================================================================
--- firmware/rf/trunk/defines.h 2008-08-21 13:59:21 UTC (rev 1563)
+++ firmware/rf/trunk/defines.h 2008-08-21 16:05:14 UTC (rev 1564)
@@ -30,13 +30,19 @@
/*
* Define the used Hopping Scheme
*/
-#define HOPPING
//#define NOHOPP
+//#define HOPPING
+#define AFH
//#define CYCHOPP
/* Current transmit frequency channel */
#define TRX_CHANNEL 0
+/* Channel range */
+#define CHANNEL_MIN 0
+#define CHANNEL_MAX 88
+#define NUMBER_OF_CHANNELS (CHANNEL_MAX - CHANNEL_MIN + 1)
+
/* When adaptative frequency hopping, replace the noisy channel with one up of
* this number */
#define CHANNEL_JUMP 13
@@ -106,7 +112,7 @@
/* S[SC] of channel 0 in RX mode, p. 10 of datasheet */
#define CH00RX 28
-#define POLL_LOOPS 4
+#define POLL_LOOPS 2
/*
* T_SLOT == 1ms ==> every 1000us 48 Bytes of payload are exchanged
Modified: firmware/rf/trunk/prot.c
===================================================================
--- firmware/rf/trunk/prot.c 2008-08-21 13:59:21 UTC (rev 1563)
+++ firmware/rf/trunk/prot.c 2008-08-21 16:05:14 UTC (rev 1564)
@@ -76,11 +76,11 @@
pwr_dwn_atr2406();
wait_n_10us(250);//wait
-#ifdef _SLAVE
+ uint8_t i = 0;
+#ifdef _SLAVE /* SLAVE mode */
/* We loop until a master is found */
for(;;){
-#else
- uint8_t i;
+#else /* M/S mode */
/* If a master is not found, we skip and become master. */
for(i=0;i<3;i++){
#endif
@@ -95,13 +95,19 @@
//scan channel 0 for 89*2*slottime = 200ms
//scan channel 40 for 89*2*slottime = 200ms
//scan channel 80 for 89*2*slottime = 200ms
-//#ifdef NOHOPP /* XXX think we don't need this hopping here */
+#if defined(NOHOPP)
channel = TRX_CHANNEL;
- sof_ary[0] = TRX_CHANNEL;
-//#else
- //channel = 0x00 + i*40;
- //sof_ary[0] = TRX_CHANNEL;
-//#endif
+#elif defined(HOPPING)
+ /* Scan different channels in case some are clogged-up */
+ i = (i+1) % 3;
+ channel = 0x00 + i*40;
+#elif defined(AFH)
+ /* Scan different channels in case some are clogged-up */
+ AFH_index = (AFH_index+1) % AFH_RANGE;
+ channel = AFH_freq[AFH_index];
+#endif
+
+ sof_ary[0] = channel;
init_atr2406(channel,RXEN);//configure ATR2406 to desired channel
DDRD &= 0xEF;//XCK PIN set to input!!
wait_n_10us(37);//wait for 370us
Modified: firmware/rf/trunk/rf_ctrl.c
===================================================================
--- firmware/rf/trunk/rf_ctrl.c 2008-08-21 13:59:21 UTC (rev 1563)
+++ firmware/rf/trunk/rf_ctrl.c 2008-08-21 16:05:14 UTC (rev 1564)
@@ -29,6 +29,7 @@
uint8_t checksum_tx;
+static void update_channel(void);
static void reset_atr2406(void);
static void stop_rf_timer(void);
@@ -95,29 +96,14 @@
}
}
/* Configure in TX. */
-#ifdef NOHOPP
- channel = TRX_CHANNEL;
-#endif
-#ifdef HOPPING
- channel += CHANNEL_JUMP;
- if(channel > 88)
- {
- channel -= 89;
- }
-#endif
-#ifdef CYCHOPP
- channel ++;
- if(channel > channel_width)
- {
- channel = 0;
- }
-#endif
+ /* In frequency hopping, compute the next channel and save it in the RF
+ * frame. */
+ update_channel();
+ rf_buffer_tx[8] = channel;
init_atr2406(channel,TXEN);//configure ATR2406 to desired channel
UCSR0A = 0x40;
UCSR0B = 0x08;
OCR1A = OCR1A + T_LOOP;
- //calculate new RF-Packet! SOF depending wether connected or not!!
- rf_buffer_tx[8] = channel;
/* What should we do if it's not complete?
* 2 ways, either continue the SPI until all data is gotten, but then
* that doesn't work if there's a problem, or drop the data, in which
@@ -160,23 +146,10 @@
/* Configure in RX mode. */
reset_atr2406();
spi_request();
-#ifdef NOHOPP
- channel = TRX_CHANNEL;
-#endif
-#ifdef HOPPING
- channel += CHANNEL_JUMP;
- if(channel > 88)
- {
- channel -= 89;
- }
-#endif
-#ifdef CYCHOPP
- channel ++;
- if(channel > channel_width)
- {
- channel = 0;
- }
-#endif
+ /* In frequency hopping, compute the next channel and save it in the
+ * SOF to be recognized. */
+ update_channel();
+ sof_ary[0] = channel;
rf_rx_counter = 0x00;
rf_rx_state = 0x00;
checksum = 0x00;
@@ -184,8 +157,6 @@
OCR1A = OCR1A+T_LOOP_RX;
//PIN configuration for input or output
DDRD = DDRD&0xEF;//XCK PIN set to input!!
- //Setup SOFs!!
- sof_ary[0] = channel;
break;
case 0x03:
/* Start receiving. */
@@ -204,6 +175,29 @@
rf_state = rf_state % 5;
}
+static void update_channel(void)
+{
+#if defined(NOHOPP)
+ channel = TRX_CHANNEL;
+#elif defined(HOPPING)
+ channel += CHANNEL_JUMP;
+ if(channel > CHANNEL_MAX)
+ {
+ channel -= NUMBER_OF_CHANNELS;
+ }
+#elif defined(AFH)
+ AFH_index = (AFH_index+1) % AFH_RANGE;
+ channel = AFH_freq[AFH_index];
+#endif
+#ifdef CYCHOPP
+ channel ++;
+ if(channel > channel_width)
+ {
+ channel = 0;
+ }
+#endif
+}
+
/*
* Setup 16 bit timer1 which is used to generate all RF related timings.
* We're using a crystal @ sys_clk = 13.824 MHz
Modified: firmware/rf/trunk/varis.c
===================================================================
--- firmware/rf/trunk/varis.c 2008-08-21 13:59:21 UTC (rev 1563)
+++ firmware/rf/trunk/varis.c 2008-08-21 16:05:14 UTC (rev 1564)
@@ -76,6 +76,10 @@
uint8_t sof_ary[4] ;
//variable holding the 4 Byte start of frame
+/* Frequency hopping frequency table */
+uint8_t AFH_freq[AFH_RANGE] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 11, 12};
+uint8_t AFH_collision[AFH_RANGE];
+uint8_t AFH_index;
volatile uint8_t channel;
Modified: firmware/rf/trunk/varis.h
===================================================================
--- firmware/rf/trunk/varis.h 2008-08-21 13:59:21 UTC (rev 1563)
+++ firmware/rf/trunk/varis.h 2008-08-21 16:05:14 UTC (rev 1564)
@@ -53,6 +53,11 @@
extern uint8_t volatile connected;
extern bool volatile disconnected_flag;
+#define AFH_RANGE 13
+extern uint8_t AFH_freq[AFH_RANGE];
+extern uint8_t AFH_collision[AFH_RANGE];
+extern uint8_t AFH_index;
+
extern volatile uint8_t rf_buffer_tx[];
extern uint8_t volatile *rf_buffer_rx;
extern uint8_t volatile *rf_buffer_rx_full;
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn