Author: jaguarondi
Date: 2008-08-27 17:50:46 +0200 (Wed, 27 Aug 2008)
New Revision: 1618
Removed:
firmware/rf/trunk/spi.c
firmware/rf/trunk/spi.h
Modified:
firmware/rf/trunk/Makefile
firmware/rf/trunk/interface.c
firmware/rf/trunk/main.c
firmware/rf/trunk/prot.c
firmware/rf/trunk/rf_ctrl.c
Log:
* Tuned the AFH a bit and added a debug mode.
* Removed the spi.[ch] files that weren't used anymore.
Modified: firmware/rf/trunk/Makefile
===================================================================
--- firmware/rf/trunk/Makefile 2008-08-27 15:48:55 UTC (rev 1617)
+++ firmware/rf/trunk/Makefile 2008-08-27 15:50:46 UTC (rev 1618)
@@ -122,7 +122,7 @@
make TYPE=master
make TYPE=slave clean
make TYPE=slave
- tuxup fuxrf.hex tuxrf.hex
+ tuxup -k fuxrf.hex tuxrf.hex
dwen:
$(AVRDUDE) -p $(MCU) -c jtag2isp -P usb -B 10 -U hfuse:w:0x95:m
Modified: firmware/rf/trunk/interface.c
===================================================================
--- firmware/rf/trunk/interface.c 2008-08-27 15:48:55 UTC (rev 1617)
+++ firmware/rf/trunk/interface.c 2008-08-27 15:50:46 UTC (rev 1618)
@@ -18,6 +18,7 @@
*/
/* $Id$ */
+#define AFH_DEBUG
#include <avr/io.h>
#include <avr/interrupt.h>
@@ -49,6 +50,7 @@
set_spiack();
spi_in_idx++;
spi_out_idx++;
+#if !defined(AFH_DEBUG)
if (spi_in_idx == SPI_AUDIO_OFFSET)
{
/* Select the second part of the buffer if the spi frame index is even
*/
@@ -59,6 +61,7 @@
if (!second_buffer)
spi_out_idx += AUDIO_SPK_SIZE;
}
+#endif
SPDR = spi_out[spi_out_idx];
clr_spiack();
}
@@ -103,6 +106,25 @@
else
second_buffer = !second_buffer;
+#if defined(_MASTER) && defined(AFH_DEBUG)
+ /* Save frequencies and collisions in the audio buffer */
+ uint8_t i;
+ uint8_t static toggle = 0;
+ toggle = !toggle;
+ spi_out[SPI_AUDIO_OFFSET+2*AFH_RANGE] = toggle;
+ if (toggle)
+ {
+ for (i=0; i<AFH_RANGE; i++)
+ {
+ spi_out[SPI_AUDIO_OFFSET+i] = AFH_freq[i];
+ spi_out[SPI_AUDIO_OFFSET+AFH_RANGE+i] = AFH_collision[i];
+ }
+ }
+ else
+ if (!good_frame_received)
+ /* Mark as bad frame */
+ spi_out[SPI_AUDIO_OFFSET+2*AFH_RANGE] = 2;
+#endif
SPDR = spi_out[spi_out_idx];
set_txe();
}
@@ -117,4 +139,13 @@
if (second_buffer_included)
spi_in[SPI_CONFIG_OFFSET] |= CFG_SECBUF_MK;
second_buffer_included = spi_in[SPI_CONFIG_OFFSET] & CFG_AUDIO_MK;
+#if defined(_SLAVE) && defined(AFH_DEBUG)
+ /* Save frequencies and collisions in the audio buffer */
+ uint8_t i;
+ for (i=0; i<AFH_RANGE; i++)
+ {
+ spi_in[SPI_AUDIO_OFFSET+i] = AFH_freq[i];
+ spi_in[SPI_AUDIO_OFFSET+AFH_RANGE+i] = AFH_collision[i];
+ }
+#endif
}
Modified: firmware/rf/trunk/main.c
===================================================================
--- firmware/rf/trunk/main.c 2008-08-27 15:48:55 UTC (rev 1617)
+++ firmware/rf/trunk/main.c 2008-08-27 15:50:46 UTC (rev 1618)
@@ -107,12 +107,13 @@
/* Main loop */
for(;;)
{
- uint8_t i;
if (disconnected_flag)
{
disconnected_flag = false;
system_start_up();
}
+#if defined(AFH)
+ uint8_t i;
for (i=0; i<AFH_RANGE; i++)
{
if (AFH_collision[i] > AFH_COLL_TRSH)
@@ -124,8 +125,20 @@
AFH_freq[i] -= NUMBER_OF_CHANNELS;
}
}
- if (AFH_prescaler == 0 && AFH_collision[i] > 0)
- AFH_collision[i]--;
+ if (AFH_prescaler == 0)
+ {
+ if (AFH_collision[i] > 0)
+ {
+ AFH_collision[i]--;
+ }
+ else if (AFH_collision[i] < 0)
+ {
+ AFH_collision[i]++;
+ }
+ }
}
+ if (AFH_prescaler == 0)
+ AFH_prescaler++;
+#endif
}
}
Modified: firmware/rf/trunk/prot.c
===================================================================
--- firmware/rf/trunk/prot.c 2008-08-27 15:48:55 UTC (rev 1617)
+++ firmware/rf/trunk/prot.c 2008-08-27 15:50:46 UTC (rev 1618)
@@ -145,6 +145,7 @@
j = j << 3;
OCR1A = T_SYNC - j;
start_rf_timer();
+ connected = CONNECTED_TIMEOUT;
return;
}
}
Modified: firmware/rf/trunk/rf_ctrl.c
===================================================================
--- firmware/rf/trunk/rf_ctrl.c 2008-08-27 15:48:55 UTC (rev 1617)
+++ firmware/rf/trunk/rf_ctrl.c 2008-08-27 15:50:46 UTC (rev 1618)
@@ -85,7 +85,6 @@
{
/* Didn't receive or wrong checksum */
good_frame_received = false;
- AFH_collision[AFH_index]++;
if (connected)
{
if (!--connected)
@@ -94,6 +93,9 @@
disconnected_flag = true;
stop_rf_timer();
}
+#if defined(AFH)
+ AFH_collision[AFH_index]++;
+#endif
}
}
/* Configure in TX. */
Deleted: firmware/rf/trunk/spi.c
===================================================================
--- firmware/rf/trunk/spi.c 2008-08-27 15:48:55 UTC (rev 1617)
+++ firmware/rf/trunk/spi.c 2008-08-27 15:50:46 UTC (rev 1618)
@@ -1,210 +0,0 @@
-#include <avr/wdt.h>
-#include <stdlib.h>
-#include "defines.h"
-#include "varis.h"
-
-//*****************************************************************************
-//* Project: RF-Firmware for ISM *
-//* Function: spiTransaction *
-//* Parameters: NONE *
-//* Returns: NONE *
-//* Action: Manage the SPI transaction *
-//* Duration: tbd *
-//* Size: tbd *
-//* Date: 26.06.07 *
-//* Description: Send and receive sound / command via the SPI *
-//*****************************************************************************
-void spiTransaction(void)
-{
- unsigned char headerb; // Header spi byte
- unsigned char spi_count; // Counter for SPI transaction
- unsigned char spi_config_tx; // Configuration byte of the SPI
transaction in tx mode
- unsigned char spi_config_rx; // Configuration byte of the SPI
transaction in rx mode
- unsigned char *pspibuffer_rx;
- unsigned char *pspibuffer_tx;
-
- pspibuffer_rx = pspi_buffer_rx;
- pspibuffer_tx = pspi_buffer_tx;
- spi_count = 0; // Reset spi counter
- spi_config_tx = 0; // Reset config byte
- spi_config_rx = 0; // Reset config byte
- headerb = 0; // Reset header byte
- spi_lenght = 17; // SPI lenght low
- spi_slave = PUT_SOUND_SPI; // Init state machine
- while (!(PINB & 0x04)) ; // Verify that the previous transaction is
finish
- PORTC |= 0x04; // Generate a start SPI signal
- while (PINB & 0x04) ; // Wait CS
- PORTC &= ~0x04; // Reset start SPI signal
-
- if (rx_buffer_ready) // Correct receive
- {
- rx_buffer_ready = 0; // Reset receive flag
-
- if (errorFrame) // Error in precedent transmission
- {
- errorFrame = 0; // Reset error frame flag
- if (*(pspibuffer_rx + 1) & 0x02) // Zone 0 with audio
- {
- if (*(pspibuffer_rx + 1) & 0x04) // Double frame
- {
- spi_config_tx = 0x04; // Double frame Zone 1 + Zone 0
- headerb = 0x82; // Audio in SPI transaction + Double
SPI frame
- spi_lenght = 34; // SPI lenght high
- }
- else // Simple frame Zone 0
- {
- spi_config_tx = 0x01; // Zone 0
- headerb = 0x02; // Audio in SPI transaction + Double
SPI frame
- }
- }
- else // Zone 0 without audio
- {
- if (*(pspibuffer_rx + 1) & 0x04) // Simple frame Zone 1
- {
- spi_config_tx = 0x02; // Zone 1
- headerb = 0x02; // Audio in SPI transaction + Double
SPI frame
- }
- }
- }
- else // No previous error
- {
- if (*(pspibuffer_rx + 1) & 0x02) // Zonz 0 with audio
- {
- headerb = 0x02; // Audio in SPI transaction
- spi_config_tx |= 0x01; // Zone 0 first
- }
- }
-
- if (*(pspibuffer_rx + 1) & 0x08) // Command RX
- {
- if (!ACKmode) // Wait command
- {
- ACKmode = 1; // Wait ACK
- headerb |= 0x08; // Command in SPI frame
- spi_config_tx |= 0x08;
- }
- }
- else if (ACKmode)
- ACKmode = 0; // Command RX OK
-
- if (*(pspibuffer_rx + 1) & 0x80) // Wait ACK
- commandStatus = 0x02; // Command TX OK
- }
-
- if (commandStatus != 0x00) // No need of protection from interrupt,
timing protected
- {
- headerb |= 0x08; // Status in SPI frame
- spi_config_tx |= 0x10;
- }
-
- SPDR = headerb; // Header byte
- PORTC &= ~0x01; // Generate a ready SPI signal
- while ((SPSR & 0x80) == 0) ; // Wait SPI ready
-
- while (1) // SPI loop
- {
- if (!(PINB & 0x04)) // Chip select
- {
- PORTC |= 0x01; // Reset the ready SPI signal
- if (spi_count == 0) // Save data RX from SPI
- {
- spi_config_rx = SPDR; // Save the header of spi frame
- //spi_config_rx |= 0x08; // DEBUG
- }
- else if (spi_count <= 17) // Save audio
- {
- if (spi_config_rx & 0x02) // Audio in frame spi
- *(pspibuffer_tx + spi_count + 26) = SPDR; // Load audio
in frame radio
- if (spi_config_rx & 0x40) ; // Save Id from the PC
- {
- if (spi_count <= 7)
- spiConfigFrame[spi_count - 1] = SPDR;
- }
- }
- else if ((spi_count > 17) && (spi_count <= 21)) // Save command
- {
- if ((spi_config_rx & 0x08) && ((commandStatus == 0x00)))
// Command in frame spi + Commnand transmit ready
- {
- commandBuffer[spi_count - 18] = SPDR;
- if (spi_count == 21)
- {
- commandStatus = 0x01; // Command in progress
- commandCmpt = 0;
- }
- }
-
- }
-
- spi_count++; // Increment SPI byte counter
- if (spi_slave == PUT_SOUND_SPI) // Put sound into the SPI frame
- {
- if (spi_config_tx & 0x01) // Simple frame Zone 0
- {
- SPDR = *(pspibuffer_rx + spi_count + 10); // Sound
- }
- else if (spi_config_tx & 0x02) // Simple frame Zone 1
- {
- SPDR = *(pspibuffer_rx + spi_count + 28); // Sound
- }
- else if (spi_config_tx & 0x04) // Double frame Zone 1 + Zone 0
- {
- if (spi_count < 18)
- SPDR = *(pspibuffer_rx + spi_count + 28); //
Sound
- else
- SPDR = *(pspibuffer_rx + spi_count - 7); //
Sound
- }
- else
- {
- SPDR = 0x00; // No sound
- }
- if (spi_count == spi_lenght)
- spi_slave = PUT_COMMAND_SPI; // Go to the next
state of the machine
- PORTC &= ~0x01; // Generate request to master
- }
- else if (spi_slave == PUT_COMMAND_SPI) // Put command into
the SPI frame
- {
- if (spi_config_tx & 0x08)
- {
- if (spi_config_tx & 0x04) // Double frame
- SPDR = *(pspibuffer_rx + spi_count - 28); //
Command
- else // Simple frame
- SPDR = *(pspibuffer_rx + spi_count - 11); //
Command
- }
- else
- SPDR = 0x00; // No command
- if (spi_count == spi_lenght + 4)
- spi_slave = PUT_STATUS_SPI; // Go to the next state of the
machine
- PORTC &= ~0x01; // Generate request to master
- }
- else if (spi_slave == PUT_STATUS_SPI) // Put status command
into the SPI frame
- {
- if (spi_config_tx & 0x10) // Status command present
- {
- SPDR = commandStatus; // Status command, no need of
protection from interrupt, timing protected
- if (commandStatus != 0x01)
- commandStatus = 0x00; // Reset status command
- }
- else
- SPDR = 0x00; // No status command
- if (spi_count == spi_lenght + 5)
- spi_slave = END_SPI; // Go to the next state of the
machine
- PORTC &= ~0x01; // Generate request to master
- }
- }
- while ((SPSR & 0x80) == 0) ; // Wait SPI ready
-
- if (spi_slave == END_SPI) // Finish SPI transaction
- {
- PORTC |= 0x01; // Reset the ready SPI signal
- if (spi_config_rx & 0x02) // Audio in frame spi
- *(pspibuffer_tx + 17) |= 0x02;
- else
- *(pspibuffer_tx + 17) &= ~0x02;
- if (ACKmode)
- *(pspibuffer_tx + 17) |= 0x80; // Send ACK
- else
- *(pspibuffer_tx + 17) &= ~0x80; // Remove ACK
- break;
- }
- }
-}
Deleted: firmware/rf/trunk/spi.h
===================================================================
--- firmware/rf/trunk/spi.h 2008-08-27 15:48:55 UTC (rev 1617)
+++ firmware/rf/trunk/spi.h 2008-08-27 15:50:46 UTC (rev 1618)
@@ -1,2 +0,0 @@
-
-extern void spiTransaction(void);
-------------------------------------------------------------------------
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