Author: jaguarondi
Date: 2008-06-24 12:34:57 +0200 (Tue, 24 Jun 2008)
New Revision: 1256

Removed:
   firmware/tuxaudio/branches/new_rf/interrupt.c
Modified:
   firmware/tuxaudio/branches/new_rf/Makefile
   firmware/tuxaudio/branches/new_rf/PC_communication.c
   firmware/tuxaudio/branches/new_rf/communication.c
   firmware/tuxaudio/branches/new_rf/flash.c
   firmware/tuxaudio/branches/new_rf/main.c
   firmware/tuxaudio/branches/new_rf/parser.c
   firmware/tuxaudio/branches/new_rf/parser.h
   firmware/tuxaudio/branches/new_rf/varis.c
   firmware/tuxaudio/branches/new_rf/varis.h
Log:
* First functional version. A couple of things have been commented in order to
  test the RF communication first: flash and I2C. Next step is to move to 16kHz
  audio.


Modified: firmware/tuxaudio/branches/new_rf/Makefile
===================================================================
--- firmware/tuxaudio/branches/new_rf/Makefile  2008-06-24 10:24:05 UTC (rev 
1255)
+++ firmware/tuxaudio/branches/new_rf/Makefile  2008-06-24 10:34:57 UTC (rev 
1256)
@@ -1,7 +1,7 @@
 # Makefile for the 'audio' CPU of Tux Droid
 
 ## Configuration Flags
-MIC_GAIN = 6 # values can be 0, 6 or 12 (which is the gain in dB)
+MIC_GAIN = 0 # values can be 0, 6 or 12 (which is the gain in dB)
 
 ## General Flags
 PROJECT = tuxaudio
@@ -38,11 +38,7 @@
 CINCS =
 
 # Compile options common for all C compilation units.
-ifdef windir
-CDEBUG = -gdwarf-2
-else
 CDEBUG = -g
-endif
 CWARN = -Wall -Wstrict-prototypes
 CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
 CFLAGS = $(COMMON) $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) 
$(CEXTRA)
@@ -142,29 +138,17 @@
 
 size: ${TARGET}
        @echo
-ifdef windir
-       @avr-size -C --mcu=${MCU} ${TARGET}
-else
        @avr-size ${TARGET}
-endif
 
 bl_size: ${BOOTLOADER}
        @echo
-ifdef windir
-       @avr-size -C --mcu=${MCU} ${BOOTLOADER}
-else
        @avr-size ${BOOTLOADER}
-endif
 
 ## Generate SVN info
 #  We need to change the status each time a file changes, thus so many
 #  dependencies
 svnrev.h: $(CSOURCE) $(HEADERS)
-ifdef windir
-       SubWCRev . svnrev.tmpl.h svnrev.h
-else
        svnwcrev . svnrev.tmpl.h svnrev.h
-endif
 
 ## Clean target
 .PHONY: clean
@@ -178,11 +162,7 @@
 ## Generate doxygen documentation
 .PHONY: doc
 doc: svnrev.h
-ifdef windir
-       # XXX add windows version
-else
        @./doc/builddoc.sh
-endif
 
 
 # Programming
@@ -192,6 +172,15 @@
 progisp: $(PROJECT).hex $(PROJECT).eep
        $(AVRDUDE) -p $(MCU) -c jtag2isp -P usb -B 10 -e -U 
flash:w:$(PROJECT).hex -U eeprom:w:$(PROJECT).eep
 
+dwen:
+       $(AVRDUDE) -p $(MCU) -c jtag2isp -P usb -B 10 -U hfuse:w:0x9D:m
+
+nodwen:
+       $(AVRDUDE) -p $(MCU) -c jtag2isp -P usb -B 10 -U hfuse:w:0xDD:m
+
+debug:
+       avarice -P $(MCU) -2 -w -j usb -p -f $(PROJECT).elf :4242
+
 progisp_bl: $(PROJECT).hex $(PROJECT).eep $(PROJECT)_bl.hex
        $(AVRDUDE) -p $(MCU) -c jtag2isp -P usb -B 10 -e -U 
flash:w:$(PROJECT)_bl.hex -U eeprom:w:$(PROJECT).eep -D -U 
flash:w:$(PROJECT).hex
 

Modified: firmware/tuxaudio/branches/new_rf/PC_communication.c
===================================================================
--- firmware/tuxaudio/branches/new_rf/PC_communication.c        2008-06-24 
10:24:05 UTC (rev 1255)
+++ firmware/tuxaudio/branches/new_rf/PC_communication.c        2008-06-24 
10:34:57 UTC (rev 1256)
@@ -31,113 +31,128 @@
 
 void spiTransaction(void)
 {
-    if (spi_start)    // Wait start
-    {
-        spi_start = 0;          // Reset the spi start flag
-        spi_count = 0;          // Reset spi counter
-        spi_slave = HEADERS;    // Set state machine
-        spi_master = HEADERM;
-        // Reset SPI to fix strange bug on the spi
-        SPCR = 0x50;
-        SPSR = 0x00;
-        asm volatile            /* Clear the SPI interrupt flag */
-          ("in __tmp_reg__, %0" "\n\t" "in __tmp_reg__, %1" "\n\t"::
-           "I" (_SFR_IO_ADDR(SPSR)), "I"(_SFR_IO_ADDR(SPDR)));
+    /*if (rf_txe) // Wait TX EMPTY*/
+    /*{*/
+        /*uint8_t i;*/
+        /*PORTB &= ~_BV(PB2); // Chip select*/
+        /*rf_txe = 0;*/
+        /*spi_ready = 0;*/
+        /*SPDR = 1;*/
+        /*while ((SPSR & 0x80) == 0);*/
+        /*for (i=0; i<50; i++)*/
+        /*{*/
+            /*while (!spi_ready);*/
+            /*spi_ready = 0;*/
+            /*SPDR = i;//0x55;*/
+            /*while ((SPSR & 0x80) == 0);*/
+        /*}*/
+        /*PORTB |= _BV(PB2); // Chip select*/
+
+
+        /*spi_count = 0;          // Reset spi counter*/
+        /*spi_slave = HEADERS;    // Set state machine*/
+        /*spi_master = HEADERM;*/
+        /*// Reset SPI to fix strange bug on the spi*/
+        /*SPCR = 0x50;*/
+        /*SPSR = 0x00;*/
+        /*asm volatile            [> Clear the SPI interrupt flag <]*/
+          /*("in __tmp_reg__, %0" "\n\t" "in __tmp_reg__, %1" "\n\t"::*/
+           /*"I" (_SFR_IO_ADDR(SPSR)), "I"(_SFR_IO_ADDR(SPDR)));*/
         flash_onhold();
-        PORTB &= ~0x04;         // Chip select
-        while (1)
-        {
-            if (spi_ready)
-            {
-                spi_ready = 0;
-                if (spi_slave == HEADERS)
-                {
-                    /* Sound */
-                    if (FifoLength(ADCFifo) >= 17)
-                        spi_headerb = 0x02;     /* frame will contain sound */
-                    else
-                        spi_headerb = 0x00;     /* no sound in frame */
+        /*PORTB &= ~0x04;         // Chip select*/
+        /*while (1)*/
+        /*{*/
+            /*if (spi_ready)*/
+            /*{*/
+                /*spi_ready = 0;*/
+                /*if (spi_slave == HEADERS)*/
+                /*{*/
+                    /*[> Sound <]*/
+                    /*if (FifoLength(ADCFifo) >= 17)*/
+                        /*spi_headerb = 0x02;     [> frame will contain sound 
<]*/
+                    /*else*/
+                        /*spi_headerb = 0x00;     [> no sound in frame <]*/
 
-                    /* Status */
-                    if ((rf_data_sent_ack == RF_DATA_SENT_NACKED)
-                        || (rf_data_sent_ack == RF_DATA_SENT_DROPPED))
-                    {
-                        spi_headerb |= 0x08;    /* resend the previous status 
if nacked */
-                    }
-                    else if (rf_data_sent_ack != RF_DATA_SENT_BUSY)     /* 
wait the end of transmission */
-                        if (!popStatus(spi_commandTX))  /* fetch the next 
status */
-                            spi_headerb |= 0x08;        /* indicate that the 
frame contains status */
+                    /*[> Status <]*/
+                    /*if ((rf_data_sent_ack == RF_DATA_SENT_NACKED)*/
+                        /*|| (rf_data_sent_ack == RF_DATA_SENT_DROPPED))*/
+                    /*{*/
+                        /*spi_headerb |= 0x08;    [> resend the previous 
status if nacked <]*/
+                    /*}*/
+                    /*else if (rf_data_sent_ack != RF_DATA_SENT_BUSY)     [> 
wait the end of transmission <]*/
+                        /*if (!popStatus(spi_commandTX))  [> fetch the next 
status <]*/
+                            /*spi_headerb |= 0x08;        [> indicate that the 
frame contains status <]*/
 
-                    SPDR = spi_headerb; // Header byte
-                    spi_slave = GET_SOUND_FIFO; // Next state
-                }
-                else if (spi_slave == GET_SOUND_FIFO)
-                {
-                    if (spi_count == 17)
-                        spi_slave = PUT_COMMAND;        // Next state
-                    if (spi_headerb & 0x02)
-                    {
-                        uint8_t data;
-                        cli();
-                        FifoGet(ADCFifo, &data);
-                        SPDR = data;      // Get data from FIFO
-                        sei();
-                    }
-                    else
-                        SPDR = 0x00;    // No data to transmit
-                }
-                else if (spi_slave == PUT_COMMAND)
-                {
-                    if (spi_count == 21)
-                        spi_slave = DUMMY;      // Next state
-                    if (spi_headerb & 0x08)
-                    {
-                        SPDR = spi_commandTX[spi_count - 18];   // Get command 
from buffer
-                    }
-                    else
-                        SPDR = 0x00;    // No command to transmit
-                }
-                else if (spi_slave == DUMMY)
-                {
-                    SPDR = 0x00;        // Dummy byte in case of big frame
-                }
+                    /*SPDR = spi_headerb; // Header byte*/
+                    /*spi_slave = GET_SOUND_FIFO; // Next state*/
+                /*}*/
+                /*else if (spi_slave == GET_SOUND_FIFO)*/
+                /*{*/
+                    /*if (spi_count == 17)*/
+                        /*spi_slave = PUT_COMMAND;        // Next state*/
+                    /*if (spi_headerb & 0x02)*/
+                    /*{*/
+                        /*uint8_t data;*/
+                        /*cli();*/
+                        /*FifoGet(ADCFifo, &data);*/
+                        /*SPDR = data;      // Get data from FIFO*/
+                        /*sei();*/
+                    /*}*/
+                    /*else*/
+                        /*SPDR = 0x00;    // No data to transmit*/
+                /*}*/
+                /*else if (spi_slave == PUT_COMMAND)*/
+                /*{*/
+                    /*if (spi_count == 21)*/
+                        /*spi_slave = DUMMY;      // Next state*/
+                    /*if (spi_headerb & 0x08)*/
+                    /*{*/
+                        /*SPDR = spi_commandTX[spi_count - 18];   // Get 
command from buffer*/
+                    /*}*/
+                    /*else*/
+                        /*SPDR = 0x00;    // No command to transmit*/
+                /*}*/
+                /*else if (spi_slave == DUMMY)*/
+                /*{*/
+                    /*SPDR = 0x00;        // Dummy byte in case of big frame*/
+                /*}*/
 
-                while ((SPSR & 0x80) == 0) ;    // Wait SPI response
+                /*while ((SPSR & 0x80) == 0) ;    // Wait SPI response*/
 
-                spi_count++;
-                if (spi_master == HEADERM)
-                {
-                    spi_master_config = SPDR;   // Save header config byte
-                    if (spi_master_config & 0x08)       // Command
-                        commandRX = 1;  // Flag to send command on I2C
-                    if (spi_master_config & 0x80)       // Double frame
-                        spi_lenght_data = 34;
-                    else
-                        spi_lenght_data = 17;
-                    if (spi_master_config == 0x08 || spi_master_config == 0x00)
-                    {
-                        if (frame_without_sound)
-                            frame_without_sound --;
+                /*spi_count++;*/
+                /*if (spi_master == HEADERM)*/
+                /*{*/
+                    /*spi_master_config = SPDR;   // Save header config byte*/
+                    /*if (spi_master_config & 0x08)       // Command*/
+                        /*commandRX = 1;  // Flag to send command on I2C*/
+                    /*if (spi_master_config & 0x80)       // Double frame*/
+                        /*spi_lenght_data = 34;*/
+                    /*else*/
+                        /*spi_lenght_data = 17;*/
+                    /*if (spi_master_config == 0x08 || spi_master_config == 
0x00)*/
+                    /*{*/
+                        /*if (frame_without_sound)*/
+                            /*frame_without_sound --;*/
 
-                        else
-                            sound_played = 0;
-                    }
-                    else
-                    {
-                        sound_played = 1;
-                        frame_without_sound = frame_without_sound_timeout;
-                    }
+                        /*else*/
+                            /*sound_played = 0;*/
+                    /*}*/
+                    /*else*/
+                    /*{*/
+                        /*sound_played = 1;*/
+                        /*frame_without_sound = frame_without_sound_timeout;*/
+                    /*}*/
 
-                    spi_master = PUT_SOUND_FIFO;        // Go to the next state
+                    /*spi_master = PUT_SOUND_FIFO;        // Go to the next 
state*/
 
-                    if (!programmingFlash && !flashPlay)      // XXX code must 
be review it's very strange .....
-                    {
-                        if (!(spi_master_config & 0x02))
-                        {
-                            if (!lockAdaptFifo)
-                            {
-                                //adaptFifo(PWMFifo);    // Adaptative FIFO
-#if 0
+                    /*if (!programmingFlash && !flashPlay)      // XXX code 
must be review it's very strange .....*/
+                    /*{*/
+                        /*if (!(spi_master_config & 0x02))*/
+                        /*{*/
+                            /*if (!lockAdaptFifo)*/
+                            /*{*/
+                                /*//adaptFifo(PWMFifo);    // Adaptative FIFO*/
+/*#if 0*/
 /** \brief 3 levels adaptative function.
  * \param p fifo pointer
  *
@@ -145,117 +160,117 @@
  * each level, a custom code or a function call can be provided to do the
  * adaptation.
  */
-void adaptFifo(fifo_t * p)
-{
-    unsigned char fifoLevel;
+/*void adaptFifo(fifo_t * p)*/
+/*{*/
+    /*unsigned char fifoLevel;*/
 
-    fifoLevel = fifoLength(p);
-    if (!p->adpt_cycle)
-    {
-        if (p->matched == 8)
-        {
-            if (OCR0A < 254)
-                p->pwm_max = OCR0A + 2;
-            else
-                p->pwm_max = 255;
-            if (OCR0A > 231)
-                p->pwm_min = OCR0A - 2;
-            else
-                p->pwm_min = 230;
-            p->matched = 9;
-        }
+    /*fifoLevel = fifoLength(p);*/
+    /*if (!p->adpt_cycle)*/
+    /*{*/
+        /*if (p->matched == 8)*/
+        /*{*/
+            /*if (OCR0A < 254)*/
+                /*p->pwm_max = OCR0A + 2;*/
+            /*else*/
+                /*p->pwm_max = 255;*/
+            /*if (OCR0A > 231)*/
+                /*p->pwm_min = OCR0A - 2;*/
+            /*else*/
+                /*p->pwm_min = 230;*/
+            /*p->matched = 9;*/
+        /*}*/
 
-        if (fifoLevel >= FIFO_ADAPT_HIGH)
-        {
-            if (OCR0A > p->pwm_min)
-            {
-                OCR0A--;
-                p->pwm_adpt_sens = 1;
-            }
-        }
-        else if (fifoLevel < FIFO_ADAPT_LOW)
-        {
-            if (OCR0A < p->pwm_max)
-            {
-                OCR0A++;
-                p->pwm_adpt_sens = 2;
-            }
-        }
-        else
-        {
-            if (p->pwm_adpt_sens)
-            {
-                if ((p->pwm_adpt_sens) == 1)
-                {
-                    if (OCR0A < p->pwm_max)
-                        OCR0A++;
-                }
-                else
-                {
-                    if (OCR0A > p->pwm_min)
-                        OCR0A--;
-                }
-                p->pwm_adpt_sens = 0;
-                p->matched = 0;
-            }
-            else
-            {
-                if (p->matched != 9)
-                    p->matched++;
-            }
-        }
-    }
-    p->adpt_cycle++;
-    p->adpt_cycle &= (FIFO_ADAPT_RATE << 1) - 1;
-}
-#endif
-                                lockAdaptFifo = 1;
-                            }
-                            else
-                                FifoClear(PWMFifo);
-                        }
-                        else
-                        {
-                            lockAdaptFifo = 0;
-                        }
-                    }
+        /*if (fifoLevel >= FIFO_ADAPT_HIGH)*/
+        /*{*/
+            /*if (OCR0A > p->pwm_min)*/
+            /*{*/
+                /*OCR0A--;*/
+                /*p->pwm_adpt_sens = 1;*/
+            /*}*/
+        /*}*/
+        /*else if (fifoLevel < FIFO_ADAPT_LOW)*/
+        /*{*/
+            /*if (OCR0A < p->pwm_max)*/
+            /*{*/
+                /*OCR0A++;*/
+                /*p->pwm_adpt_sens = 2;*/
+            /*}*/
+        /*}*/
+        /*else*/
+        /*{*/
+            /*if (p->pwm_adpt_sens)*/
+            /*{*/
+                /*if ((p->pwm_adpt_sens) == 1)*/
+                /*{*/
+                    /*if (OCR0A < p->pwm_max)*/
+                        /*OCR0A++;*/
+                /*}*/
+                /*else*/
+                /*{*/
+                    /*if (OCR0A > p->pwm_min)*/
+                        /*OCR0A--;*/
+                /*}*/
+                /*p->pwm_adpt_sens = 0;*/
+                /*p->matched = 0;*/
+            /*}*/
+            /*else*/
+            /*{*/
+                /*if (p->matched != 9)*/
+                    /*p->matched++;*/
+            /*}*/
+        /*}*/
+    /*}*/
+    /*p->adpt_cycle++;*/
+    /*p->adpt_cycle &= (FIFO_ADAPT_RATE << 1) - 1;*/
+/*}*/
+/*#endif*/
+                                /*lockAdaptFifo = 1;*/
+                            /*}*/
+                            /*else*/
+                                /*FifoClear(PWMFifo);*/
+                        /*}*/
+                        /*else*/
+                        /*{*/
+                            /*lockAdaptFifo = 0;*/
+                        /*}*/
+                    /*}*/
 
-                }
-                else if (spi_master == PUT_SOUND_FIFO)
-                {
-                    if (spi_master_config & 0x02)
-                    {
-                        if (!flashPlay)
-                            FifoPut(PWMFifo, SPDR);       // Put into the FIFO
-                    }
-                    if (spi_count == (spi_lenght_data + 1))
-                        spi_master = READ_COMMAND;      // Go to the next state
+                /*}*/
+                /*else if (spi_master == PUT_SOUND_FIFO)*/
+                /*{*/
+                    /*if (spi_master_config & 0x02)*/
+                    /*{*/
+                        /*if (!flashPlay)*/
+                            /*FifoPut(PWMFifo, SPDR);       // Put into the 
FIFO*/
+                    /*}*/
+                    /*if (spi_count == (spi_lenght_data + 1))*/
+                        /*spi_master = READ_COMMAND;      // Go to the next 
state*/
 
-                }
-                else if (spi_master == READ_COMMAND)
-                {
-                    if (spi_master_config & 0x08)
-                    {
-                        if (spi_master_config & 0x80)
-                            spi_commandRX[spi_count - 36] = SPDR;       // Put 
command into the buffer
-                        else
-                            spi_commandRX[spi_count - 19] = SPDR;       // Put 
command into the buffer
-                    }
-                    if (spi_count == spi_lenght_data + 6)
-                    {
-                        /* Check the acknowledge from the rf */
-                        if (spi_headerb & 0x08) /* if data was sent in the 
current SPI transaction, mark buffer as full and drop the received status */
-                            rf_data_sent_ack = RF_DATA_SENT_BUSY;       /* 
status buffer of the rf filled */
-                        else
-                            rf_data_sent_ack = spi_commandRX[4];        /* get 
the acknowledge of the previous sent data */
+                /*}*/
+                /*else if (spi_master == READ_COMMAND)*/
+                /*{*/
+                    /*if (spi_master_config & 0x08)*/
+                    /*{*/
+                        /*if (spi_master_config & 0x80)*/
+                            /*spi_commandRX[spi_count - 36] = SPDR;       // 
Put command into the buffer*/
+                        /*else*/
+                            /*spi_commandRX[spi_count - 19] = SPDR;       // 
Put command into the buffer*/
+                    /*}*/
+                    /*if (spi_count == spi_lenght_data + 6)*/
+                    /*{*/
+                        /*[> Check the acknowledge from the rf <]*/
+                        /*if (spi_headerb & 0x08) [> if data was sent in the 
current SPI transaction, mark buffer as full and drop the received status <]*/
+                            /*rf_data_sent_ack = RF_DATA_SENT_BUSY;       [> 
status buffer of the rf filled <]*/
+                        /*else*/
+                            /*rf_data_sent_ack = spi_commandRX[4];        [> 
get the acknowledge of the previous sent data <]*/
 
-                        PORTB |= 0x04;  // Chip deselect
-                        break;
-                    }
-                }
-            }
-        }
-        flash_enable();
-    }
+                        /*PORTB |= 0x04;  // Chip deselect*/
+                        /*break;*/
+                    /*}*/
+                /*}*/
+            /*}*/
+        /*}*/
+        /*flash_enable();*/
+    /*}*/
 }
 

Modified: firmware/tuxaudio/branches/new_rf/communication.c
===================================================================
--- firmware/tuxaudio/branches/new_rf/communication.c   2008-06-24 10:24:05 UTC 
(rev 1255)
+++ firmware/tuxaudio/branches/new_rf/communication.c   2008-06-24 10:34:57 UTC 
(rev 1256)
@@ -27,6 +27,8 @@
 #include "i2c.h"
 #include "parser.h"
 #include "hardware.h"
+/* For ADCFifo... */
+#include "varis.h"
 
 /* I2C write message (out) */
 static uint8_t out_buf[CMD_SIZE];
@@ -38,17 +40,21 @@
 /** Size of the stack buffer to tuxcore */
 #define CORE_OUT_BUF_SIZE    16
 /** Size of the stack buffer to tuxrf */
-#define RF_OUT_BUF_SIZE   32
+#define RF_BUF_SIZE   32
 
 FIFO_INSTANCE(core_cmdout_buf, CORE_OUT_BUF_SIZE);
 /** Stack for commands to be sent to tuxcore */
 fifo_t *core_cmdout = FifoPointer(core_cmdout_buf);
 
-FIFO_INSTANCE(rf_cmdout_buf_s, RF_OUT_BUF_SIZE);
+FIFO_INSTANCE(rf_cmdout_buf_s, RF_BUF_SIZE);
 /** Stack for commands to be sent to rf */
 fifo_t *rf_cmdout_buf = FifoPointer(rf_cmdout_buf_s);
 
+FIFO_INSTANCE(rf_cmdin_buf_s, RF_BUF_SIZE);
+/** Stack for commands received from the rf */
+fifo_t *rf_cmdin_buf = FifoPointer(rf_cmdin_buf_s);
 
+
 /*
  * Initialize (clear) the communication buffers
  * XXX can't we delete this?
@@ -94,7 +100,7 @@
 static void get_core_cmd(void)
 {
     /* First check if the stack is not full */
-    if (FifoLength(rf_cmdout_buf) > RF_OUT_BUF_SIZE - CMD_SIZE)
+    if (FifoLength(rf_cmdout_buf) > RF_BUF_SIZE - CMD_SIZE)
         return;
 
     if (i2c_get_status() != I2C_BUSY)
@@ -146,7 +152,7 @@
 {
     uint8_t i;
 
-    if (FifoLength(rf_cmdout_buf) > RF_OUT_BUF_SIZE - CMD_SIZE)
+    if (FifoLength(rf_cmdout_buf) > RF_BUF_SIZE - CMD_SIZE)
         return 0;
 
     uint8_t sreg;
@@ -189,16 +195,12 @@
     if (msg->addr == TUXCORE_ADDR)
         /* From tuxcore */
     {
-        /* New pointer necessary as parse_cmd modifies the pointer. */
-        uint8_t *cmd = msg->buf;
-        /* Parse the command */
-        parse_cmd(cmd);
-        /* and forward if it isn't dropped. */
-        if (cmd)
-            queue_rf_cmd(cmd);
+        /* Parse the command and forward if it isn't dropped. */
+        if (!parse_cmd(msg->buf))
+            queue_rf_cmd(msg->buf);
         /* As we got something, there's maybe more so if the stack is not full,
          * continue */
-        if (FifoLength(rf_cmdout_buf) <= RF_OUT_BUF_SIZE - CMD_SIZE)
+        if (FifoLength(rf_cmdout_buf) <= RF_BUF_SIZE - CMD_SIZE)
             return 1;
     }
     return 0;
@@ -229,6 +231,121 @@
 }
 
 /**
+ * \brief Initialize the I2C communication and the in and out buffers.
+ */
+void communication_init(void)
+{
+    i2c_init();
+    msg_out.addr = TUXCORE_ADDR;
+    msg_out.len = CMD_SIZE;
+    msg_in.addr = TUXCORE_ADDR;
+    msg_in.len = CMD_SIZE;
+    i2c_master_receive_handler(i2c_master_receive_service);
+}
+
+/*
+ * SPI communication
+ */
+
+/** \name SPI frame constants
+ * @{ */
+/** Size of the audio data in the SPI frame */
+#define AUDIO_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)
+#define SPI_PREVAUDIO_OFFSET (SPI_AUDIO_OFFSET + AUDIO_SIZE)
+/*! @} */
+
+static uint8_t frame_in_idx, frame_out_idx;
+static uint8_t spi_in[52], spi_out[52], spi_idx;
+
+/* INT1 (PD3) Interrupt on TXE signal. */
+ISR(SIG_INTERRUPT1)
+{
+    //PORTB |= 0x80; // XXX DEBUG
+    //if (spi_idx) // XXX debug
+        //PORTB |= 0x80; // XXX DEBUG
+    spi_idx = 0;
+    /* Chip select */
+    PORTB &= ~_BV(PB2);
+    SPDR = spi_out[spi_idx];
+    EIMSK |= _BV(INT0);
+    EIFR |= _BV(INT0);
+    //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)
+{
+    //PORTB |= 0x80; // XXX DEBUG
+    /* Check if we got the start of SPI frame (TXE). */
+    /* XXX try to remove this */
+    if (PORTB & _BV(PB2))
+        return;
+    /* Check that the previous SPI transmission is done. */
+    if ((SPSR & 0x80) == 0)
+        return;
+
+    spi_in[spi_idx++] = SPDR;
+
+    if (spi_idx == SPI_SIZE)
+    {
+        /* Unselect by waiting here otherwise we would have to use the SPI
+         * interrupt to do it. */
+        PORTB |= _BV(PB2);
+        EIMSK &= ~_BV(INT0);
+    }
+    else
+    {
+        SPDR = spi_out[spi_idx];
+    }
+    //PORTB &= ~0x80; // XXX DEBUG
+}
+
+/**
+ * \brief Adapt the audio output rate to keep the stack at a mean level.
+ */
+void adapt_audio_rate(void)
+{
+    static uint8_t prescaler = 0;
+    uint8_t static prev_stack_length = 0;
+    uint8_t stack_length = FifoLength(PWMFifo);
+    bool slope = 0;
+
+    if (++prescaler == 0)
+    {
+        if (stack_length >= prev_stack_length)
+            slope = 1;
+        prev_stack_length = stack_length;
+
+        if (slope && stack_length > 50)
+            OCR0A--;
+        if (!slope && stack_length < 80)
+            OCR0A++;
+
+        /* Limits to avoid oscillations when a lot of frames are
+         * dropped and to prevent jumping over 255. */
+        if (OCR0A > 252)
+            OCR0A = 252;
+        if (OCR0A < 246)
+            OCR0A = 246;
+    }
+}
+
+/**
  * \brief Service routine that handles the regular communication tasks like 
sending
  * and fetching commands.
  */
@@ -237,9 +354,89 @@
     /* Clear stack when the RF is disconnected. This makes sense but is
      * necessary otherwise the standalone commands won't be fetched anymore
      * when the RF is off. */
-    if (!(RF_ONLINE_PIN & RF_ONLINE_MK))
-        FifoClear(rf_cmdout_buf);
+    /* XXX this doesn't work anymore with the current RF, to check later. */
+    /*if (!(RF_ONLINE_PIN & RF_ONLINE_MK))*/
+        /*FifoClear(rf_cmdout_buf);*/
 
+    /* Fill and process RF data. */
+    if (spi_idx >= SPI_SIZE)
+    {
+        uint8_t config;
+        uint8_t i;
+
+        spi_idx = 0;
+
+        /* 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_SIZE)
+        {
+            config |= CFG_AUDIO_MK;
+            for (i=0; i<AUDIO_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)
+            {
+                /* 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);
+            }
+            if (config & CFG_PREVAUDIO_MK)
+            {
+                for (i=0; i<AUDIO_SIZE; i++)
+                {
+                    FifoPut(PWMFifo, spi_in[i+SPI_PREVAUDIO_OFFSET]);
+                }
+            }
+            if (config & CFG_AUDIO_MK)
+            {
+                adapt_audio_rate();
+
+                //static uint8_t cnt = 0;
+                for (i=0; i<AUDIO_SIZE; i++)
+                {
+                    //if ((spi_in[i+SPI_AUDIO_OFFSET] == (cnt+1)) ||
+                        //(spi_in[i+SPI_AUDIO_OFFSET] == (cnt-1)))
+                    //{
+                        //PORTB |= 0x80; // XXX DEBUG
+                    //}
+                    //else
+                        //PORTB &= ~0x80; // XXX DEBUG
+                    //cnt = spi_in[i+SPI_AUDIO_OFFSET];
+
+                    //FifoPut(PWMFifo, spi_in[i+SPI_AUDIO_OFFSET]);
+                    if (FifoPut(PWMFifo, spi_in[i+SPI_AUDIO_OFFSET]) != 
FIFO_OK)
+                        PORTB |= 0x80; // XXX DEBUG
+                    else
+                        PORTB &= ~0x80; // XXX DEBUG
+                }
+            }
+            //PORTB &= ~0x80; // XXX DEBUG
+        }
+        //else
+            //PORTB |= 0x80; // XXX DEBUG
+    }
+
     /* If busy, pass. */
     if (i2c_get_status() == I2C_BUSY)
         return;
@@ -252,21 +449,8 @@
     }
 
     /* Send otherwise get commands. */
-    if (!send_core_cmds())
-    {
-        get_core_cmd();
-    }
+    //if (!send_core_cmds())
+    //{
+        //get_core_cmd();
+    //}
 }
-
-/**
- * \brief Initialize the I2C communication and the in and out buffers.
- */
-void communication_init(void)
-{
-    i2c_init();
-    msg_out.addr = TUXCORE_ADDR;
-    msg_out.len = CMD_SIZE;
-    msg_in.addr = TUXCORE_ADDR;
-    msg_in.len = CMD_SIZE;
-    i2c_master_receive_handler(i2c_master_receive_service);
-}

Modified: firmware/tuxaudio/branches/new_rf/flash.c
===================================================================
--- firmware/tuxaudio/branches/new_rf/flash.c   2008-06-24 10:24:05 UTC (rev 
1255)
+++ firmware/tuxaudio/branches/new_rf/flash.c   2008-06-24 10:34:57 UTC (rev 
1256)
@@ -341,11 +341,13 @@
     if (numSound == 0x00)  /* if unprogrammed we have 0xFF stored in flash */
     {
         flashPlay = 0;
+        soundToPlay = 0;
         return;
     }
     if (!nsound || (nsound > numSound))    /* check the limits */
     {
         flashPlay = 0;
+        soundToPlay = 0;
         return;
     }
 
@@ -387,26 +389,31 @@
     if (ad[0] > TOP_A2)
     {
         flashPlay = 0;
+        soundToPlay = 0;
         return;
     }                  /* don't read outside the flash */
     if (ad[3] > TOP_A2)
     {
         flashPlay = 0;
+        soundToPlay = 0;
         return;
     }                  /* don't read outside the flash */
     if ((ad[0] == 0) && (ad[1] < 0x04))
     {
         flashPlay = 0;
+        soundToPlay = 0;
         return;
     }                  /* minimum index not respected */
     if ((ad[4] == 0) && (ad[5] < 0x04))
     {
         flashPlay = 0;
+        soundToPlay = 0;
         return;
     }    /* minimum index not respected */
     if (ad[3] < ad[0])
     {
         flashPlay = 0;
+        soundToPlay = 0;
         return;
     }    /* check that the stop index is greater than the start index */
     else if (ad[3] == ad[0])
@@ -414,6 +421,7 @@
         if (ad[4] < ad[1])
         {
             flashPlay = 0;
+            soundToPlay = 0;
             return;
         }
         else if (ad[4] == ad[1])
@@ -421,6 +429,7 @@
             if (ad[5] <= ad[2])
             {
                 flashPlay = 0;
+                soundToPlay = 0;
                 return;
             }
         }
@@ -450,7 +459,7 @@
 static void playingSound(void)
 {
     uint8_t sound;
-    while (!spi_start && !FifoFull(PWMFifo))
+    while (!rf_txe && !FifoFull(PWMFifo))
     {
         sound = spiSend(0x00);  // Wait response
         sound = sound >> audioLevel;
@@ -546,7 +555,7 @@
 
 static void programming_sound(void)
 {
-    while (!spi_start)
+    while (!rf_txe)
     {
         if (FifoLength(PWMFifo))
         {

Deleted: firmware/tuxaudio/branches/new_rf/interrupt.c
===================================================================
--- firmware/tuxaudio/branches/new_rf/interrupt.c       2008-06-24 10:24:05 UTC 
(rev 1255)
+++ firmware/tuxaudio/branches/new_rf/interrupt.c       2008-06-24 10:34:57 UTC 
(rev 1256)
@@ -1,46 +0,0 @@
-/*
- * 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 <avr/io.h>
-#include <avr/interrupt.h>
-#include "varis.h"
-
-// Timer 0 overflow interrupt service routine (PWM)
-ISR(SIG_OVERFLOW0)
-{
-    if (--sampling_pwm == 0)    /* timer 0 is clocked at 32KHz so we divide it 
by 4 to get 8KHz */
-    {
-        ADCSRA |= 0x40;         // XXX a laisser la ??
-        //FIFOputMic (AudioRampCmpt);
-        //AudioRampCmpt++;
-
-        sampling_pwm = 0x04;    // Reinit
-
-        OCR0B = pullFifo(&PWMFifo);     /* set the sample value to timer pulse 
width */
-//        adaptSpkFifo();
-    }
-}
-
-// External Interrupt 0 service routine PD2
-void SIG_INTERRUPT0(void)
-{
-    spi_ready = 1;              // Set the flag SPI ready from RF
-}

Modified: firmware/tuxaudio/branches/new_rf/main.c
===================================================================
--- firmware/tuxaudio/branches/new_rf/main.c    2008-06-24 10:24:05 UTC (rev 
1255)
+++ firmware/tuxaudio/branches/new_rf/main.c    2008-06-24 10:34:57 UTC (rev 
1256)
@@ -41,7 +41,7 @@
 /*
  * Debug and test flags
  */
-#define DBG_STACK       0
+#define DBG_STACK 0
 
 /*
  * Stack Overflow detection
@@ -50,14 +50,33 @@
  * detect any stack overflow just by looking to the memory at any breakpoint
  */
 #if (DBG_STACK)
+extern uint16_t __heap_start;
 void init_ram(void) __attribute__ ((naked)) __attribute__ 
((section(".init1")));
 void init_ram(void)
 {
     uint8_t *ptr;
 
-    for (ptr = (uint8_t *) 0x0100; ptr < (uint8_t *) 0x0300; ptr++)
+    for (ptr = (uint8_t *) &__heap_start; ptr < (uint8_t *) 0x800500; ptr++)
         *ptr = 0x5F;
 }
+
+int8_t check_stack(void)
+{
+    uint8_t *ptr, cnt=0;
+
+    for (ptr = (uint8_t *) &__heap_start; ptr < (uint8_t *) 0x800500; ptr++)
+    {
+        if (*ptr == 0x5F)
+            cnt++;
+        else
+            cnt = 0;
+        if (cnt == 10)
+            return 1;
+    }
+    return 0;
+}
+#else
+#define check_stack() 1
 #endif
 
 /* Set when sleep should be entered */
@@ -140,8 +159,8 @@
     FifoClear(PWMFifo);        /* Initialise the PWM fifo */
     FifoClear(ADCFifo);        /* Initialise the ADC fifo */
     config_init();              /* load the configuration defaults from EEPROM 
*/
-    numSound = readFlashNumber();
-    last_block = readLastBlock(numSound);
+    /*numSound = readFlashNumber();*/
+    /*last_block = readLastBlock(numSound);*/
     communication_init();     /* I2C initialization */
     frame_without_sound_timeout = TTS_TIMEOUT;
 
@@ -153,7 +172,7 @@
      * This delay is critical as the INT0 is quite shaky and any glitches on
      * INT0 at the boot of the RF CPU immeditely crash this CPU or set it in
      * the while(1) loop of spi.c */
-    while (RF_ONLINE_PIN & RF_ONLINE_MK);
+    //while (RF_ONLINE_PIN & RF_ONLINE_MK);
     /* Activate the interrupts used by the RF module. */
     EIFR = (_BV(INT1) | _BV(INT0));
     EIMSK = (_BV(INT1) | _BV(INT0));
@@ -162,26 +181,33 @@
     {
         sei();                  // Reactivate global interrupt in case of 
flash programmation
 
+        if (!check_stack())
+            while(1)
+            {
+                PORTB |= 0x80;
+                PORTB &= ~0x80;
+            }
         spiTransaction();   // Spi transaction from radio
 
-        if (commandRX)          // commend RX from radio
-        {
-            commandRX = 0;      // Reset flag
-            parse_cmd(spi_commandRX);
+        //XXX to delete
+        //if (commandRX)          // commend RX from radio
+        //{
+            //commandRX = 0;      // Reset flag
+            //parse_cmd(spi_commandRX);
             /* XXX there are some empty commands getting through, removed from
              * here for now. */
-            if (spi_commandRX && spi_commandRX[0])
-                queue_core_cmd(spi_commandRX);
-        }
+            //if (spi_commandRX[0])
+                //queue_core_cmd(spi_commandRX);
+        //}
 
-        if (programmingFlash)   // Restora all the context for flash 
programming
-            programming();
+        /*if (programmingFlash)   // Restora all the context for flash 
programming*/
+            /*programming();*/
 
-        if (flashPlay)
-            playSound();
+        /*if (flashPlay)*/
+            /*playSound();*/
 
-        if (eraseFlag)
-            erase();
+        /*if (eraseFlag)*/
+            /*erase();*/
 
         /* Send commands to I2C, otherwise get new status from tuxcore */
         communication_task();
@@ -224,6 +250,7 @@
                 else
                     DDRD &= ~0x03;
             }
+            queue_rf_cmd_p(0xFE, FifoLength(PWMFifo), OCR0A, 0);
         }
 
         /* Sleep mode */
@@ -232,16 +259,98 @@
         }
 }
 
-// External Interrupt 0 service routine PD2
-ISR(SIG_INTERRUPT0)
+//static inline void audio_sampling(void) __attribute__ ( ( always_inline ) );
+//void audio_sampling(void) __attribute__ ( ( signal ) );
+//void audio_sampling(void)
+//ISR(audio_sampling)
+//{
+    //ADCSRA |= 0x40;             // ADC started at  XXX a laisser la ??
+
+//#ifndef MIC_GAIN
+//#define MIC_GAIN    0 [> default value if not declared in the makefile <]
+//#endif
+//#if (MIC_GAIN == 6)
+    //[> MEDIUM GAIN MODE <]
+    //uint8_t tmp;
+
+    //[> Audio in: microphone <]
+    //tmp = ADCL;
+    //tmp = tmp >> 1;
+    //if (!(ADCH & 0x01)) [> AND the 9th bit then add 0x80 is equivalent to 
AND the complement of the 9th bit <]
+        //tmp |= 0x80;
+    //FifoPut_inl(ADCFifo, tmp);
+    //[> HIGH GAIN MODE <]
+//#elif (MIC_GAIN == 12)
+    //uint8_t tmp;
+
+    //tmp = ADCL + 0x80;
+    //FifoPut_inl(ADCFifo, tmp);
+    //asm volatile ("lds __tmp_reg__, %0"::"M" (_SFR_MEM_ADDR(ADCH)));    [> 
ADCH needs to be read for the next acquisition <]
+//#else [> (MIC_GAIN == 0) or anything else <]
+    //[> LOW GAIN MODE <]
+    //[>if (ADCH == 0)      [> XXX RF looses connection if too much '0' are 
sent, but the noise should normally be enough to avoid that <]<]
+    //[>FifoPut(ADCFifo, 0x01);<]
+    //[>else<]
+    //FifoPut_inl(ADCFifo, ADCH);
+//#endif
+
+    //FifoGet_inl(PWMFifo, (uint8_t *)&OCR0B); [> set the sample value to 
timer pulse width <]
+    //[>if (!FifoGet(PWMFifo, (uint8_t *)&OCR0B))  [> set the sample value to 
timer pulse width <]<]
+    //[>{<]
+    //[>Fifoinert = 0;<]
+    //[>if (tuxaudio_config.automute)   [> XXX mute functions should not be 
called here each time a sample is placed, this is silly <]<]
+    //[>unmute_amp();<]
+    //[>}<]
+    //[>else<]
+    //[>{<]
+    //[>Fifoinert++;<]
+    //[>if (Fifoinert >= 30)<]
+    //[>{<]
+    //[>if (tuxaudio_config.automute)<]
+    //[>mute_amp();<]
+    //[>Fifoinert = 30;<]
+    //[>//OCR0A = 250; // Normal operation for ADC sampling if FIFO Adaptative 
is on<]
+    //[>}<]
+    //[>}<]
+    //[> XXX we should move this timer away from here <]
+    /* send status to the behavioural CPU, 8KHz divided by 256 lead to a
+     * status sent each 32ms */
+    //if (--sendSensorsCmpt == 0)
+        //sendSensorsFlag = 1;
+    ////asm volatile (
+        ////"pop r25 \n"
+        ////"pop r23 \n"
+        ////"pop r22 \n"
+        ////::);
+//}
+
+ISR(__vector_audio_sampling)
 {
-    spi_start = 1;
-}
+    //FifoPut(ADCFifo, ADCH);
+    FifoGet(PWMFifo, (uint8_t *)&OCR0B); /* set the sample value to timer 
pulse width */
+    /*if (FifoGet(PWMFifo, (uint8_t *)&OCR0B)) [> set the sample value to 
timer pulse width <]*/
+    /*{*/
+        /*PORTB &= ~0x80; // XXX DEBUG*/
+    /*}*/
+    /*else*/
+    /*{*/
+        /*PORTB |= 0x80; // XXX DEBUG*/
+    /*}*/
 
-// External Interrupt 1 service routine PD3
-ISR(SIG_INTERRUPT1)
-{
-    spi_ready = 1;
+    //static uint8_t cnt = 0;
+    //static uint8_t dir = 1;
+//#define STEP 8
+    //OCR0B = cnt;
+    //if (dir)
+        //cnt += STEP;
+    //else
+        //cnt -= STEP;
+    //if ((cnt >= (0xFF - STEP)) || (cnt == 0))
+        //dir = !dir;
+
+    ADCSRA |= 0x40;
+    if (--sendSensorsCmpt == 0)
+        sendSensorsFlag = 1;
 }
 
 /*
@@ -250,61 +359,34 @@
  */
 ISR(SIG_OVERFLOW0)
 {
+    uint8_t tmp = sampling_pwm;
 
-    ADCSRA |= 0x40;             // ADC started at  XXX a laisser la ??
-    if (--sampling_pwm == 0)    /* timer 0 is clocked at 32KHz so we divide it 
by 4 to get 8KHz */
+    /* timer 0 is clocked at 32KHz so we divide it by 4 to get 8KHz */
+    tmp--;
+    tmp &= 3;
+    if (tmp == 0)
     {
-        sampling_pwm = 0x04;    /* reinit counter */
-
-#ifndef MIC_GAIN
-#define MIC_GAIN    0 /* default value if not declared in the makefile */
-#endif
-#if (MIC_GAIN == 6)
-        /* MEDIUM GAIN MODE */
-        uint8_t tmp;
-
-        /* Audio in: microphone */
-        tmp = ADCL;
-        tmp = tmp >> 1;
-        if (!(ADCH & 0x01)) /* AND the 9th bit then add 0x80 is equivalent to 
AND the complement of the 9th bit */
-            tmp |= 0x80;
-        FifoPut(ADCFifo, tmp);
-        /* HIGH GAIN MODE */
-#elif (MIC_GAIN == 12)
-        uint8_t tmp;
-
-        tmp = ADCL + 0x80;
-        FifoPut(ADCFifo, tmp);
-        asm volatile ("lds __tmp_reg__, %0"::"M" (_SFR_MEM_ADDR(ADCH)));    /* 
ADCH needs to be read for the next acquisition */
-#else /* (MIC_GAIN == 0) or anything else */
-        /* LOW GAIN MODE */
-        if (ADCH == 0)      /* XXX RF looses connection if too much '0' are 
sent, but the noise should normally be enough to avoid that */
-            FifoPut(ADCFifo, 0x01);
-        else
-            FifoPut(ADCFifo, ADCH);
-#endif
-
-        if (!FifoGet(PWMFifo, (uint8_t *)&OCR0B))  /* set the sample value to 
timer pulse width */
-        {
-            Fifoinert = 0;
-            if (tuxaudio_config.automute)   /* XXX mute functions should not 
be called here each time a sample is placed, this is silly */
-                unmute_amp();
-        }
-        else
-        {
-            Fifoinert++;
-            if (Fifoinert >= 30)
-            {
-                if (tuxaudio_config.automute)
-                    mute_amp();
-                Fifoinert = 30;
-                //OCR0A = 250; // Normal operation for ADC sampling if FIFO 
Adaptative is on
-            }
-        }
-        /* XXX we should move this timer away from here */
-        /* send status to the behavioural CPU, 8KHz divided by 256 lead to a
-         * status sent each 32ms */
-        if (--sendSensorsCmpt == 0)
-            sendSensorsFlag = 1;
+        asm("rcall __vector_audio_sampling"::);
+        cli();
     }
+    sampling_pwm = tmp;
 }
+
+//ISR(SIG_OVERFLOW0) __attribute__((naked));
+//ISR(SIG_OVERFLOW0)
+//{
+    ////asm volatile (
+        ////"in __tmp_reg__,__SREG__" "\n\t"
+        ////"push r24" "\n\t"
+        ////"lds r24, sampling_pwm" "\n\t"
+        ////"subi r24, 0x01" "\n\t"
+        ////"andi r24, 0x03" "\n\t"
+        ////"sts sampling_pwm, r24" "\n\t"
+        ////"brne 1f" "\n\t"
+        ////"rcall audio_sampling" "\n\t"
+        ////"1: cli" "\n\t"
+        ////"1: pop r24" "\n\t"
+        ////"out  __SREG__, __tmp_reg__" "\n\t"
+        ////"reti" "\n\t"
+        ////::);
+//}

Modified: firmware/tuxaudio/branches/new_rf/parser.c
===================================================================
--- firmware/tuxaudio/branches/new_rf/parser.c  2008-06-24 10:24:05 UTC (rev 
1255)
+++ firmware/tuxaudio/branches/new_rf/parser.c  2008-06-24 10:34:57 UTC (rev 
1256)
@@ -32,94 +32,101 @@
 /**
  * Parse a cmd received by the computer or by tuxcore and drop it if it
  * shouldn't be forwarded.
+ * \return True if the command has been parsed and shouldn't be forwarded,
+ * false if it should be forwarded.
  */
-void parse_cmd(uint8_t *cmd)
+bool parse_cmd(uint8_t *cmd)
 {
+        /* XXX there are some empty commands getting through, removed from
+         * here for now. */
 
-    /*
-     * Commands that should be forwarded
-     */
-
-    /* Ping */
-    if (cmd[0] == PONG_CMD)
+        /*
+         * Commands that shouldn't be forwarded.
+         */
+        /* Version */
+    if (cmd[0] == NULL_CMD)
     {
-        /* Index of the pong that is supposed to be received from tuxcore */
-        static uint8_t pong_received;
-        /* Counter of the missed pongs */
-        static uint8_t pong_missed;
-        if (pong_received-- < cmd[1])       /* new ping, reset */
-        {
-            pong_received = cmd[1];
-            pong_missed = 0;
-        }
-        else /* pongs */
-        {
-            pong_missed += pong_received - cmd[1];
-            pong_received = cmd[1]; /* resync */
-        }
-        cmd[2] = pong_missed;
     }
-    else if (cmd[0] == SLEEP_CMD)
+    else if (cmd[0] == INFO_TUXAUDIO_CMD)
     {
-        /* XXX sleep commented for now */
-        /* Forwards the cmd to the rf CPU */
-        /*cmd[0] = SLEEP_ACK_CMD;*/
-        /*cmd[1] = 0;*/
-        /*cmd[2] = 0;*/
-        /*cmd[3] = 0;*/
-        /*pre_sleep_delay = 30; [> handle sleep in its own function <]*/
-        /*sleep_f = 1;*/
-        /*statusFlag = 1;*/
+        send_info();
     }
-    else
+    else if (cmd[0] == PLAY_SOUND_CMD)
+        /* param: cmd[1] : sound number */
+        /* cmd[2] : mic sound intensity  */
     {
-        /*
-         * Commands that shouldn't be forwarded.
-         */
-        /* Version */
-        if (cmd[0] == INFO_TUXAUDIO_CMD)
+        /* Drop the cmd if a sound is already playing */
+        if (!(flashPlay || programmingFlash))
         {
-            send_info();
-        }
-        else if (cmd[0] == PLAY_SOUND_CMD)
-            /* param: cmd[1] : sound number */
-            /* cmd[2] : mic sound intensity  */
-        {
-            /* postpone the cmd if a sound is already playing */
-            if (flashPlay || programmingFlash)
-                return;
             audioLevel = cmd[2];
-            //playingAudio(cmd[1]); /* start playing the sound */
             soundToPlay = cmd[1];
             flashPlay = 1;
             flash_state = 1;
         }
-        else if (cmd[0] == MUTE_CMD)
+    }
+    else if (cmd[0] == MUTE_CMD)
+    {
+        if (cmd[1])
+            mute_amp();
+        else
+            unmute_amp();
+    }
+    else if (cmd[0] == STORE_SOUND_CMD)
+    {
+        if (flashPlay)
+            flashPlay = 0;
+        flash_state = 1; /* Erasing flash flag */
+        programmingFlash = 1; /* Set the flag to enter programming sequence */
+    }
+    else if (cmd[0] == ERASE_FLASH_CMD)
+    {
+        eraseFlag = 1;
+    }
+    else if (cmd[0] == CONFIRM_STORAGE_CMD)
+    {
+        if (cmd[1])
+            write_toc = 1;
+        else
+            write_toc = 2;
+    }
+    else
+    {
+        /*
+         * Commands that should be forwarded
+         */
+
+        /* Ping */
+        if (cmd[0] == PONG_CMD)
         {
-            if (cmd[1])
-                mute_amp();
-            else
-                unmute_amp();
+            /* Index of the pong that is supposed to be received from tuxcore 
*/
+            static uint8_t pong_received;
+            /* Counter of the missed pongs */
+            static uint8_t pong_missed;
+            if (pong_received-- < cmd[1])       /* new ping, reset */
+            {
+                pong_received = cmd[1];
+                pong_missed = 0;
+            }
+            else /* pongs */
+            {
+                pong_missed += pong_received - cmd[1];
+                pong_received = cmd[1]; /* resync */
+            }
+            cmd[2] = pong_missed;
         }
-        else if (cmd[0] == STORE_SOUND_CMD)
+        else if (cmd[0] == SLEEP_CMD)
         {
-            if (flashPlay)
-                flashPlay = 0;
-            flash_state = 1; /* Erasing flash flag */
-            programmingFlash = 1; /* Set the flag to enter programming 
sequence */
+            /* XXX sleep commented for now */
+            /* Forwards the cmd to the rf CPU */
+            /*cmd[0] = SLEEP_ACK_CMD;*/
+            /*cmd[1] = 0;*/
+            /*cmd[2] = 0;*/
+            /*cmd[3] = 0;*/
+            /*pre_sleep_delay = 30; [> handle sleep in its own function <]*/
+            /*sleep_f = 1;*/
+            /*statusFlag = 1;*/
         }
-        else if (cmd[0] == ERASE_FLASH_CMD)
-        {
-            eraseFlag = 1;
-        }
-        else if (cmd[0] == CONFIRM_STORAGE_CMD)
-        {
-            if (cmd[1])
-                write_toc = 1;
-            else
-                write_toc = 2;
-        }
-        /* Drop the command */
-        cmd = NULL;
+        return false;
     }
+    return true;
 }

Modified: firmware/tuxaudio/branches/new_rf/parser.h
===================================================================
--- firmware/tuxaudio/branches/new_rf/parser.h  2008-06-24 10:24:05 UTC (rev 
1255)
+++ firmware/tuxaudio/branches/new_rf/parser.h  2008-06-24 10:34:57 UTC (rev 
1256)
@@ -24,6 +24,6 @@
 
 #include <stdbool.h>
 
-void parse_cmd(uint8_t *cmd);
+bool parse_cmd(uint8_t *cmd);
 
 #endif /* PARSER_H */

Modified: firmware/tuxaudio/branches/new_rf/varis.c
===================================================================
--- firmware/tuxaudio/branches/new_rf/varis.c   2008-06-24 10:24:05 UTC (rev 
1255)
+++ firmware/tuxaudio/branches/new_rf/varis.c   2008-06-24 10:34:57 UTC (rev 
1256)
@@ -38,7 +38,7 @@
 volatile unsigned char spi_count;
 volatile unsigned char spi_lenght_data;
 volatile unsigned char spi_ready = 0;
-volatile unsigned char spi_start = 0;
+volatile unsigned char rf_txe = 0;
 volatile uint8_t spi_commandTX[5];
 unsigned char spi_commandRX[5];
 unsigned char commandRX = 0;

Modified: firmware/tuxaudio/branches/new_rf/varis.h
===================================================================
--- firmware/tuxaudio/branches/new_rf/varis.h   2008-06-24 10:24:05 UTC (rev 
1255)
+++ firmware/tuxaudio/branches/new_rf/varis.h   2008-06-24 10:34:57 UTC (rev 
1256)
@@ -40,7 +40,7 @@
 extern volatile unsigned char spi_count;
 extern volatile unsigned char spi_lenght_data;
 extern volatile unsigned char spi_ready;
-extern volatile unsigned char spi_start;
+extern volatile unsigned char rf_txe;
 extern uint8_t spi_commandTX[5];
 extern unsigned char spi_commandRX[5];
 extern unsigned char commandRX;


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to