Author: jaguarondi
Date: 2008-07-08 12:57:20 +0200 (Tue, 08 Jul 2008)
New Revision: 1313

Modified:
   firmware/fuxusb/branches/new_rf/src/spi_task.c
   firmware/tuxaudio/branches/new_rf/communication.c
Log:
* Added an ACK on commands bewteen tuxaudio and tuxcore. This slows down the
  data rate but we don't need much for data anyway. I'd leave like this until
  there's a real need to do otherwise.


Modified: firmware/fuxusb/branches/new_rf/src/spi_task.c
===================================================================
--- firmware/fuxusb/branches/new_rf/src/spi_task.c      2008-07-08 08:30:39 UTC 
(rev 1312)
+++ firmware/fuxusb/branches/new_rf/src/spi_task.c      2008-07-08 10:57:20 UTC 
(rev 1313)
@@ -31,6 +31,7 @@
 #include "fifo_spk.h"
 #include "fifo_mic.h"
 #include "fifo_stt.h"
+#include "common/defines.h"
 
 /**
  * \brief spi_slave enum define the steps of the SPI frame.
@@ -72,30 +73,8 @@
 static bit spi_ready = 0;
 static bit spi_Start_Flag = 0; 
 
-/** \name SPI frame constants 
- * @{ */
-/** Size of the audio data in the SPI frame */
-// XXX Double frame
-#define AUDIO_SPK_SIZE 34
-#define AUDIO_MIC_SIZE 17
-
-/* Bits of the config byte */
-#define _BV(x) (1<<x)
-#define CFG_CRCOK_MK _BV(0)
-#define CFG_DATA_MK _BV(1)
-#define CFG_AUDIO_MK _BV(2)
-#define CFG_PREVAUDIO_MK _BV(3)
-
-/* SPI frame organization */
-#define SPI_SIZE 50
-#define SPI_IDX_OFFSET 0
-#define SPI_CONFIG_OFFSET 1
-#define SPI_DATA_OFFSET 3
-#define SPI_AUDIO_OFFSET (SPI_DATA_OFFSET + CMD_SIZE)
-/*! @} */
-
 static uint8_t spi_in[SPI_SIZE], spi_out[SPI_SIZE], spi_idx;
-static uint8_t idx_in, idx_out;
+static uint8_t frame_in_idx, frame_out_idx;
 
 /**
  * \brief Reset the SPI task to the defaults states.
@@ -196,7 +175,6 @@
  */
 void spi_task(void)
 {
-    uint8_t config;
     uint8_t i;
     static bit prev_spi_start = False;
 
@@ -228,13 +206,38 @@
     }
     else if (spi_idx >= SPI_SIZE)
     {
+        uint8_t config_in = 0;
+        static uint8_t config_out = 0;
+
         spi_idx = 0;
-        /* Prepare next SPI frame to be sent to the RF */
-        config = 0;
-        if (new_command_received)
+        config_in = spi_in[SPI_CONFIG_OFFSET];
+
+        /* Incoming data */
+        if (frame_in_idx != spi_in[SPI_IDX_OFFSET])
         {
+            frame_in_idx = spi_in[SPI_IDX_OFFSET];
+            if ((!(config_in & CFG_DATA_MK)) != (!(config_out & CFG_ACK_MK)))
+            {
+                for (i=0; i<CMD_SIZE; i++)
+                {
+                    FIFO_STT_put(spi_in[i+SPI_DATA_OFFSET]);
+                }
+                /* Ack the data */
+                config_out ^= CFG_ACK_MK;
+            }
+            if (config_in & CFG_AUDIO_MK)
+            {
+                FIFO_MIC_put_n(&spi_in[SPI_AUDIO_OFFSET], AUDIO_MIC_SIZE);
+            }
+        }
+
+        /* Outgoing data, add commands and/or audio. */
+        spi_out[SPI_IDX_OFFSET] = frame_out_idx++;
+        if ((!(config_out & CFG_DATA_MK)) == (!(config_in & CFG_ACK_MK)) &&
+            new_command_received)
+        {
             new_command_received = False;          
-            config |= CFG_DATA_MK;
+            config_out ^= CFG_DATA_MK;
             for (i=0; i<CMD_SIZE; i++)
             {
                 spi_out[i+SPI_DATA_OFFSET] = command_received[i];
@@ -242,44 +245,14 @@
         }
         if (FIFO_SPK_length() >= AUDIO_SPK_SIZE)
         {
-            config |= CFG_AUDIO_MK;
+            config_out |= CFG_AUDIO_MK;
             FIFO_SPK_get_n(&spi_out[SPI_AUDIO_OFFSET], AUDIO_SPK_SIZE);
         }
-
-
-        /* Store the frame index and the config byte. */
-        spi_out[SPI_IDX_OFFSET] = idx_out++;
-        spi_out[SPI_CONFIG_OFFSET] = config;
-
-        /* XXX debug */
-        /*for (i=0; i<SPI_SIZE; i++)*/
-            /*spi_out[i] = 0x00;//1<<(i&7);*/
-        /*for (i=23; i<45; i++)*/
-            /*spi_out[i] = 0x00;//1<<(i&7);*/
-        /*for (i=45; i<SPI_SIZE; i+=1)*/
-            /*spi_out[i] = 0x01;*/
-        /*for (i=40; i<50; i++)*/
-            /*spi_out[i] = 0x55;*/
-
-        /* Store and increment the index of the frame. */
-
-        /* Process last SPI frame received from the RF */
-        if (idx_in != spi_in[SPI_IDX_OFFSET])
+        else
         {
-            idx_in = spi_in[SPI_IDX_OFFSET];
-            config = spi_in[SPI_CONFIG_OFFSET];
-            if (config & CFG_DATA_MK)
-            {
-                for (i=0; i<CMD_SIZE; i++)
-                {
-                    FIFO_STT_put(spi_in[i+SPI_DATA_OFFSET]);
-                }
-            }
-            if (config & CFG_AUDIO_MK)
-            {
-                FIFO_MIC_put_n(&spi_in[SPI_AUDIO_OFFSET], AUDIO_MIC_SIZE);
-            }
+            config_out &= ~CFG_AUDIO_MK;
         }
+        spi_out[SPI_CONFIG_OFFSET] = config_out;
     }
     P3_6 = 0; /* XXX debug */
 }

Modified: firmware/tuxaudio/branches/new_rf/communication.c
===================================================================
--- firmware/tuxaudio/branches/new_rf/communication.c   2008-07-08 08:30:39 UTC 
(rev 1312)
+++ firmware/tuxaudio/branches/new_rf/communication.c   2008-07-08 10:57:20 UTC 
(rev 1313)
@@ -242,26 +242,6 @@
  * SPI communication
  */
 
-/** \name SPI frame constants
- * @{ */
-/** Size of the audio data in the SPI frame */
-#define AUDIO_SPK_SIZE 34
-#define AUDIO_MIC_SIZE 17
-
-/* Bits of the config byte */
-#define CFG_CRCOK_MK _BV(0)
-#define CFG_DATA_MK _BV(1)
-#define CFG_AUDIO_MK _BV(2)
-#define CFG_PREVAUDIO_MK _BV(3)
-
-/* SPI frame organization */
-#define SPI_SIZE 51
-#define SPI_IDX_OFFSET 0
-#define SPI_CONFIG_OFFSET 1
-#define SPI_DATA_OFFSET 3
-#define SPI_AUDIO_OFFSET (SPI_DATA_OFFSET + CMD_SIZE)
-/*! @} */
-
 static uint8_t frame_in_idx, frame_out_idx;
 static uint8_t spi_in[52], spi_out[52], spi_idx;
 
@@ -280,8 +260,6 @@
     //PORTB &= ~0x80; // XXX DEBUG
 }
 
-
-/* XXX add an spi_config byte as register that could be checked by bits */
 /* INT0 (PD0) Interrupt on SPIACK signal. */
 ISR(SIG_INTERRUPT0)
 {
@@ -341,8 +319,8 @@
 }
 
 /**
- * \brief Service routine that handles the regular communication tasks like 
sending
- * and fetching commands.
+ * \brief Service routine that handles the regular communication tasks like
+ * sending and fetching commands.
  */
 void communication_task(void)
 {
@@ -356,47 +334,29 @@
     /* Fill and process RF data. */
     if (spi_idx >= SPI_SIZE)
     {
-        uint8_t config;
+        uint8_t config_in;
+        static uint8_t config_out;
         uint8_t i;
 
         spi_idx = 0;
+        config_in = spi_in[SPI_CONFIG_OFFSET];
 
-        /* Add data and/or audio if necessary. */
-        config = 0;
-        if (FifoLength(rf_cmdout_buf) >= CMD_SIZE)
-        {
-            config |= CFG_DATA_MK;
-            for (i=0; i<CMD_SIZE; i++)
-            {
-                FifoGet(rf_cmdout_buf, &spi_out[i+SPI_DATA_OFFSET]);
-            }
-        }
-        if (FifoLength(ADCFifo) >= AUDIO_MIC_SIZE)
-        {
-            config |= CFG_AUDIO_MK;
-            for (i=0; i<AUDIO_MIC_SIZE; i++)
-            {
-                FifoGet(ADCFifo, &spi_out[i+SPI_AUDIO_OFFSET]);
-            }
-        }
-        spi_out[SPI_IDX_OFFSET] = frame_out_idx++;
-        spi_out[SPI_CONFIG_OFFSET] = config;
-
         /* Incoming data */
         if (frame_in_idx != spi_in[SPI_IDX_OFFSET])
         {
             //PORTB |= 0x80; // XXX DEBUG
             frame_in_idx = spi_in[SPI_IDX_OFFSET];
-            config = spi_in[SPI_CONFIG_OFFSET];
-            if (config & CFG_DATA_MK)
+            if ((!(config_in & CFG_DATA_MK)) != (!(config_out & CFG_ACK_MK)))
             {
                 /* Parse the command and forward to tuxcore if it isn't
                  * dropped. */
                 uint8_t *cmd = &spi_in[SPI_DATA_OFFSET];
                 if (!parse_cmd(cmd))
                     queue_core_cmd(cmd);
+                /* Ack the data by toggling the bit */
+                config_out ^= CFG_ACK_MK;
             }
-            if (config & CFG_AUDIO_MK)
+            if (config_in & CFG_AUDIO_MK)
             {
                 adapt_audio_rate();
 
@@ -414,6 +374,31 @@
         }
         //else
             //PORTB |= 0x80; // XXX DEBUG
+
+        /* Outgoing data, add commands and/or audio. */
+        spi_out[SPI_IDX_OFFSET] = frame_out_idx++;
+        if ((!(config_out & CFG_DATA_MK)) == (!(config_in & CFG_ACK_MK)) &&
+            FifoLength(rf_cmdout_buf) >= CMD_SIZE)
+        {
+            config_out ^= CFG_DATA_MK;
+            for (i=0; i<CMD_SIZE; i++)
+            {
+                FifoGet(rf_cmdout_buf, &spi_out[i+SPI_DATA_OFFSET]);
+            }
+        }
+        if (FifoLength(ADCFifo) >= AUDIO_MIC_SIZE)
+        {
+            config_out |= CFG_AUDIO_MK;
+            for (i=0; i<AUDIO_MIC_SIZE; i++)
+            {
+                FifoGet(ADCFifo, &spi_out[i+SPI_AUDIO_OFFSET]);
+            }
+        }
+        else
+        {
+            config_out &= ~CFG_AUDIO_MK;
+        }
+        spi_out[SPI_CONFIG_OFFSET] = config_out;
     }
 
     /* If busy, pass. */


-------------------------------------------------------------------------
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

Reply via email to