Author: ks156
Date: 2008-12-03 14:20:41 +0100 (Wed, 03 Dec 2008)
New Revision: 2994

Added:
   firmware/tuxaudio/trunk/audio_fifo.c
   firmware/tuxaudio/trunk/audio_fifo.h
   firmware/tuxaudio/trunk/micro_fifo.c
   firmware/tuxaudio/trunk/micro_fifo.h
Modified:
   firmware/tuxaudio/trunk/Makefile
   firmware/tuxaudio/trunk/communication.c
   firmware/tuxaudio/trunk/flash.c
   firmware/tuxaudio/trunk/main.c
   firmware/tuxaudio/trunk/varis.c
   firmware/tuxaudio/trunk/varis.h
Log:
* Merged rev 2696:2993 timing_opt->trunk

Modified: firmware/tuxaudio/trunk/Makefile
===================================================================
--- firmware/tuxaudio/trunk/Makefile    2008-12-03 12:38:44 UTC (rev 2993)
+++ firmware/tuxaudio/trunk/Makefile    2008-12-03 13:20:41 UTC (rev 2994)
@@ -65,7 +65,7 @@
 
 
 ## Objects that must be built in order to link
-OBJECTS = init.o main.o varis.o fifo.o spi.o AT26F004.o flash.o 
communication.o parser.o misc.o i2c.o config.o
+OBJECTS = init.o main.o varis.o fifo.o spi.o AT26F004.o flash.o 
communication.o parser.o misc.o i2c.o config.o audio_fifo.o micro_fifo.o
 
 ## Objects explicitly added by the user
 LINKONLYOBJECTS =
@@ -114,9 +114,12 @@
 bootloader.o: bootloader.c
        $(CC) $(INCLUDES) $(CFLAGS) -c  $<
 
+audio_fifo.o: audio_fifo.c
+       $(CC) $(INCLUDES) $(CFLAGS) -c  $<
 
+micro_fifo.o: micro_fifo.c
+       $(CC) $(INCLUDES) $(CFLAGS) -c  $<
 
-
 ##Link
 $(TARGET): $(OBJECTS)
         $(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o 
$(TARGET)

Copied: firmware/tuxaudio/trunk/audio_fifo.c (from rev 2993, 
firmware/tuxaudio/branches/timing_opt/audio_fifo.c)
===================================================================
--- firmware/tuxaudio/trunk/audio_fifo.c                                (rev 0)
+++ firmware/tuxaudio/trunk/audio_fifo.c        2008-12-03 13:20:41 UTC (rev 
2994)
@@ -0,0 +1,62 @@
+/*
+ * TUXAUDIO - Firmware for the 'audio' CPU of tuxdroid
+ * Copyright (C) 2007 C2ME S.A. <[EMAIL PROTECTED]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/* $Id$ */
+
+#include <inttypes.h>
+#include "audio_fifo.h"
+
+uint8_t AudioInIdx = 0;
+uint8_t AudioOutIdx = 0;
+uint8_t AudioFifoSize = 128;
+uint8_t AudioBuffer[128];
+
+/* Empty the buffer by clearing the indexes. */
+void AudioFifoClear(void)
+{
+    AudioInIdx = 0;
+    AudioOutIdx = 0;
+}
+
+/*  Add one data byte to the fifo buffer.
+ *  param data : Data byte to add to the queue.
+ *  return : Return A_FIFO_OK if the data has been added, A_FIFO_FULL if the 
buffer
+ *  was full and the data couldn't be added.
+ */
+int8_t AudioFifoPut(uint8_t const data)
+{
+    if (AudioFifoLength() == AudioFifoSize)
+        return A_FIFO_FULL;
+    AudioBuffer[AudioInIdx++ & (AudioFifoSize-1)] = data;
+    return A_FIFO_OK;
+}
+
+/*  Pop the oldest byte from the buffer.
+ *  param data : pointer for storing the data read from the queue
+ *  return : A_FIFO_OK if a value has been popped out at the pointer address. 
If
+ *  the fifo is empty, A_FIFO_EMPTY is returned and the pointed data is left
+ *  unchanged.
+ */
+int8_t AudioFifoGet(uint8_t *data)
+{
+    if (AudioOutIdx == AudioInIdx)
+        return A_FIFO_EMPTY;
+    *data = AudioBuffer[AudioOutIdx++ & (AudioFifoSize - 1)];
+    return A_FIFO_OK;
+}

Copied: firmware/tuxaudio/trunk/audio_fifo.h (from rev 2993, 
firmware/tuxaudio/branches/timing_opt/audio_fifo.h)
===================================================================
--- firmware/tuxaudio/trunk/audio_fifo.h                                (rev 0)
+++ firmware/tuxaudio/trunk/audio_fifo.h        2008-12-03 13:20:41 UTC (rev 
2994)
@@ -0,0 +1,53 @@
+/*
+ * TUXAUDIO - Firmware for the 'audio' CPU of tuxdroid
+ * Copyright (C) 2007 C2ME S.A. <[EMAIL PROTECTED]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/* $Id$ */
+
+#ifndef _AUDIO_FIFO_H_
+#define _AUDIO_FIFO_H_
+
+#define AudioFifoLength() (uint8_t)(AudioInIdx - AudioOutIdx)
+
+enum AUDIO_FIFO_STATUS {A_FIFO_OK = 0, A_FIFO_FULL, A_FIFO_EMPTY};
+
+extern void AudioFifoClear(void);
+int8_t AudioFifoPut(uint8_t const data);
+int8_t AudioFifoGet(uint8_t *data);
+
+extern uint8_t AudioInIdx;
+extern uint8_t AudioOutIdx;
+extern uint8_t AudioFifoSize;
+extern uint8_t AudioBuffer[];
+
+
+static inline void AudioFifoPut_inl(uint8_t const data)
+{
+    if (AudioFifoLength() == AudioFifoSize)
+       return;
+    AudioBuffer[AudioInIdx++ & (AudioFifoSize - 1)] = data;
+}
+
+static inline void AudioFifoGet_inl(uint8_t *data)
+{
+    if (AudioOutIdx == AudioInIdx)
+       return;
+    *data = AudioBuffer[AudioOutIdx++ & (AudioFifoSize -1)];
+}
+
+#endif /* _AUDIO_FIFO_H_ */

Modified: firmware/tuxaudio/trunk/communication.c
===================================================================
--- firmware/tuxaudio/trunk/communication.c     2008-12-03 12:38:44 UTC (rev 
2993)
+++ firmware/tuxaudio/trunk/communication.c     2008-12-03 13:20:41 UTC (rev 
2994)
@@ -28,8 +28,9 @@
 #include "i2c.h"
 #include "parser.h"
 #include "hardware.h"
-/* For ADCFifo... */
 #include "varis.h"
+#include "audio_fifo.h"
+#include "micro_fifo.h"
 
 /* I2C write message (out) */
 static uint8_t out_buf[CMD_SIZE];
@@ -315,18 +316,19 @@
 {
     static uint8_t prescaler = 0;
     uint8_t static prev_stack_length = 0;
-    uint8_t stack_length = FifoLength(PWMFifo);
+    uint8_t stack_length = AudioFifoLength();
     bool slope = 0;
 
     if (++prescaler == 0)
     {
+        prescaler = 127;
         if (stack_length >= prev_stack_length)
             slope = 1;
         prev_stack_length = stack_length;
 
-        if (slope && stack_length > 40)
+        if (slope && stack_length > 50)
             OCR0A--;
-        if (!slope && stack_length < 80)
+        if (!slope && stack_length < 70)
             OCR0A++;
 
         /* Limits to avoid oscillations when a lot of frames are
@@ -390,7 +392,7 @@
 
             for (i=0; i<AUDIO_SPK_SIZE; i++)
             {
-                FifoPut(PWMFifo, spi_in[i+SPI_AUDIO_OFFSET]);
+                AudioFifoPut_inl(spi_in[i+SPI_AUDIO_OFFSET]);
             }
         }
         else
@@ -439,12 +441,12 @@
                 FifoGet(rf_cmdout_buf, &spi_out[i+SPI_DATA_OFFSET]);
             }
         }
-        if (FifoLength(ADCFifo) >= AUDIO_MIC_SIZE)
+        if (MicroFifoLength() >= AUDIO_MIC_SIZE)
         {
             config_out |= CFG_AUDIO_MK;
             for (i=0; i<AUDIO_MIC_SIZE; i++)
             {
-                FifoGet(ADCFifo, &spi_out[i+SPI_AUDIO_OFFSET]);
+                MicroFifoGet_inl(&spi_out[i+SPI_AUDIO_OFFSET]);
             }
         }
         else

Modified: firmware/tuxaudio/trunk/flash.c
===================================================================
--- firmware/tuxaudio/trunk/flash.c     2008-12-03 12:38:44 UTC (rev 2993)
+++ firmware/tuxaudio/trunk/flash.c     2008-12-03 13:20:41 UTC (rev 2994)
@@ -29,6 +29,7 @@
 #include "AT26F004.h"
 #include "common/commands.h"
 #include "common/api.h"
+#include "audio_fifo.h"
 
 /* Declarations */
 static void init_programming(uint8_t adi0, uint8_t adi1, uint8_t adi2);
@@ -146,7 +147,7 @@
             ad[2] = 0;
             first_block = (ad[0] << 4) + (ad[1] >> 4);
         }
-        FifoClear(PWMFifo);
+        AudioFifoClear();
 
         if (ad[0] > 0x07)
         {
@@ -436,7 +437,7 @@
             }
         }
     }
-    FifoClear(PWMFifo);
+    AudioFifoClear();
     flash_select();             // Chip Select
 
     spiSend(0x03);              // Send Read Page Command
@@ -461,13 +462,13 @@
 static void playingSound(void)
 {
     uint8_t sound;
-    while (!rf_txe && FifoLength(PWMFifo) < (PWMFifo->size-1))
+    while (!rf_txe && AudioFifoLength() < (AudioFifoSize-1))
     {
         sound = spiSend(0x00);  // Wait response
         sound = sound >> audioLevel;
         /* Save it twice to have 16kHz */
-        FifoPut(PWMFifo, sound);
-        FifoPut(PWMFifo, sound);
+        AudioFifoPut_inl(sound);
+        AudioFifoPut_inl(sound);
 
         ad[2]++;        // Increment address for next play
         if (ad[2] == 0)
@@ -527,7 +528,7 @@
     spiSend(adi0);
     spiSend(adi1);
     spiSend(adi2);
-    if (FifoGet(PWMFifo, &data) == FIFO_OK)
+    if (AudioFifoGet(&data) == A_FIFO_OK)
         spiSend(data);
     else
         spiSend(0x80);
@@ -561,7 +562,7 @@
 {
     while (!rf_txe)
     {
-        if (FifoLength(PWMFifo))
+        if (AudioFifoLength())
         {
             uint8_t data;
             sound_stored = 1;
@@ -569,10 +570,10 @@
 
             flash_select();
             spiSend(SEQU_PROGRAM);
-            FifoGet(PWMFifo, &data);
+            AudioFifoGet_inl(&data);
             spiSend(data);
             /* Drop one byte out of 2 to store in 8kHz */
-            FifoGet(PWMFifo, &data);
+            AudioFifoGet_inl(&data);
             flash_unselect();
 
             ad[2] ++;

Modified: firmware/tuxaudio/trunk/main.c
===================================================================
--- firmware/tuxaudio/trunk/main.c      2008-12-03 12:38:44 UTC (rev 2993)
+++ firmware/tuxaudio/trunk/main.c      2008-12-03 13:20:41 UTC (rev 2994)
@@ -36,6 +36,8 @@
 #include "parser.h"
 #include "flash.h"
 #include "config.h"
+#include "audio_fifo.h"
+#include "micro_fifo.h"
 
 /*
  * Debug and test flags
@@ -233,8 +235,8 @@
     PORTB |= 0x80;
 
     /* Other initializations */
-    FifoClear(PWMFifo);
-    FifoClear(ADCFifo);
+    AudioFifoClear();
+    MicroFifoClear();
     /* Load configuration defaults from EEPROM */
     config_init();
     numSound = readFlashNumber();
@@ -378,12 +380,12 @@
     //FifoPut(ADCFifo, ADCH);
 
     /* Speaker at 16kHz */
-    FifoGet_inl(PWMFifo, (uint8_t *)&OCR0B);
+    AudioFifoGet_inl((uint8_t *)&OCR0B);
 
     if (sampling_pwm & 0x02)
     {
         /* Microphone at 8kHz */
-        FifoPut_inl(ADCFifo, ADCH);
+        MicroFifoPut_inl(ADCH);
         ADCSRA |= 0x40;
     }
 

Copied: firmware/tuxaudio/trunk/micro_fifo.c (from rev 2993, 
firmware/tuxaudio/branches/timing_opt/micro_fifo.c)
===================================================================
--- firmware/tuxaudio/trunk/micro_fifo.c                                (rev 0)
+++ firmware/tuxaudio/trunk/micro_fifo.c        2008-12-03 13:20:41 UTC (rev 
2994)
@@ -0,0 +1,62 @@
+/*
+ * TUXAUDIO - Firmware for the 'audio' CPU of tuxdroid
+ * Copyright (C) 2007 C2ME S.A. <[EMAIL PROTECTED]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/* $Id$ */
+
+#include <inttypes.h>
+#include "micro_fifo.h"
+
+uint8_t MicroInIdx = 0;
+uint8_t MicroOutIdx = 0;
+uint8_t MicroFifoSize = 64;
+uint8_t MicroBuffer[64];
+
+/* Empty the buffer by clearing the indexes. */
+void MicroFifoClear(void)
+{
+    MicroInIdx = 0;
+    MicroOutIdx = 0;
+}
+
+/*  Add one data byte to the fifo buffer.
+ *  param data : Data byte to add to the queue.
+ *  return : Return M_FIFO_OK if the data has been added, M_FIFO_FULL if the 
buffer
+ *  was full and the data couldn't be added.
+ */
+int8_t MicroFifoPut(uint8_t const data)
+{
+    if (MicroFifoLength() == MicroFifoSize)
+        return M_FIFO_FULL;
+    MicroBuffer[MicroInIdx++ & (MicroFifoSize-1)] = data;
+    return M_FIFO_OK;
+}
+
+/*  Pop the oldest byte from the buffer.
+ *  param data : pointer for storing the data read from the queue
+ *  return : M_FIFO_OK if a value has been popped out at the pointer address. 
If
+ *  the fifo is empty, M_FIFO_EMPTY is returned and the pointed data is left
+ *  unchanged.
+ */
+int8_t MicroFifoGet(uint8_t *data)
+{
+    if (MicroOutIdx == MicroInIdx)
+        return M_FIFO_EMPTY;
+    *data = MicroBuffer[MicroOutIdx++ & (MicroFifoSize - 1)];
+    return M_FIFO_OK;
+}

Copied: firmware/tuxaudio/trunk/micro_fifo.h (from rev 2993, 
firmware/tuxaudio/branches/timing_opt/micro_fifo.h)
===================================================================
--- firmware/tuxaudio/trunk/micro_fifo.h                                (rev 0)
+++ firmware/tuxaudio/trunk/micro_fifo.h        2008-12-03 13:20:41 UTC (rev 
2994)
@@ -0,0 +1,53 @@
+/*
+ * TUXAUDIO - Firmware for the 'audio' CPU of tuxdroid
+ * Copyright (C) 2007 C2ME S.A. <[EMAIL PROTECTED]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+/* $Id$ */
+
+#ifndef _MICRO_FIFO_H_
+#define _MICRO_FIFO_H_
+
+#define MicroFifoLength() (uint8_t)(MicroInIdx - MicroOutIdx)
+
+enum MICRO_FIFO_STATUS {M_FIFO_OK = 0, M_FIFO_FULL, M_FIFO_EMPTY};
+
+extern void MicroFifoClear(void);
+int8_t MicroFifoPut(uint8_t const data);
+int8_t MicroFifoGet(uint8_t *data);
+
+extern uint8_t MicroInIdx;
+extern uint8_t MicroOutIdx;
+extern uint8_t MicroFifoSize;
+extern uint8_t MicroBuffer[];
+
+
+static inline void MicroFifoPut_inl(uint8_t const data)
+{
+    if (MicroFifoLength() == MicroFifoSize)
+       return;
+    MicroBuffer[MicroInIdx++ & (MicroFifoSize - 1)] = data;
+}
+
+static inline void MicroFifoGet_inl(uint8_t *data)
+{
+    if (MicroOutIdx == MicroInIdx)
+       return;
+    *data = MicroBuffer[MicroOutIdx++ & (MicroFifoSize -1)];
+}
+
+#endif /* _MICRO_FIFO_H_ */

Modified: firmware/tuxaudio/trunk/varis.c
===================================================================
--- firmware/tuxaudio/trunk/varis.c     2008-12-03 12:38:44 UTC (rev 2993)
+++ firmware/tuxaudio/trunk/varis.c     2008-12-03 13:20:41 UTC (rev 2994)
@@ -47,11 +47,6 @@
 unsigned char commandRX = 0;
 uint8_t rf_data_sent_ack;
 
-// FIFO Variable
-FIFO_INSTANCE(PWM_buf_s, 128);
-fifo_t *PWMFifo = FifoPointer(PWM_buf_s);
-FIFO_INSTANCE(ADC_buf_s, 64);
-fifo_t *ADCFifo = FifoPointer(ADC_buf_s);
 
 // Flash programming
 uint8_t eraseFlag = 0;

Modified: firmware/tuxaudio/trunk/varis.h
===================================================================
--- firmware/tuxaudio/trunk/varis.h     2008-12-03 12:38:44 UTC (rev 2993)
+++ firmware/tuxaudio/trunk/varis.h     2008-12-03 13:20:41 UTC (rev 2994)
@@ -54,11 +54,6 @@
 #define RF_DATA_SENT_NACKED     0x03
 #define RF_DATA_SENT_DROPPED    0x80
 
-// Fifo Vairables
-extern volatile unsigned char PWMbuffer[128];
-extern fifo_t *PWMFifo;
-extern volatile unsigned char ADCbuffer[64];
-extern fifo_t *ADCFifo;
 
 // Flash programming
 


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

Reply via email to