Author: jaguarondi
Date: 2008-06-25 16:38:07 +0200 (Wed, 25 Jun 2008)
New Revision: 1267
Modified:
firmware/tuxaudio/branches/new_rf/communication.c
firmware/tuxaudio/branches/new_rf/fifo.h
firmware/tuxaudio/branches/new_rf/main.c
Log:
* Now in 16kHz with microphone and I2C running.
Modified: firmware/tuxaudio/branches/new_rf/communication.c
===================================================================
--- firmware/tuxaudio/branches/new_rf/communication.c 2008-06-25 11:11:17 UTC
(rev 1266)
+++ firmware/tuxaudio/branches/new_rf/communication.c 2008-06-25 14:38:07 UTC
(rev 1267)
@@ -245,7 +245,8 @@
/** \name SPI frame constants
* @{ */
/** Size of the audio data in the SPI frame */
-#define AUDIO_SIZE 17
+#define AUDIO_SPK_SIZE 34
+#define AUDIO_MIC_SIZE 17
/* Bits of the config byte */
#define CFG_CRCOK_MK _BV(0)
@@ -259,7 +260,6 @@
#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;
@@ -326,7 +326,7 @@
slope = 1;
prev_stack_length = stack_length;
- if (slope && stack_length > 50)
+ if (slope && stack_length > 40)
OCR0A--;
if (!slope && stack_length < 80)
OCR0A++;
@@ -371,10 +371,10 @@
FifoGet(rf_cmdout_buf, &spi_out[i+SPI_DATA_OFFSET]);
}
}
- if (FifoLength(ADCFifo) >= AUDIO_SIZE)
+ if (FifoLength(ADCFifo) >= AUDIO_MIC_SIZE)
{
config |= CFG_AUDIO_MK;
- for (i=0; i<AUDIO_SIZE; i++)
+ for (i=0; i<AUDIO_MIC_SIZE; i++)
{
FifoGet(ADCFifo, &spi_out[i+SPI_AUDIO_OFFSET]);
}
@@ -400,24 +400,14 @@
{
adapt_audio_rate();
- //static uint8_t cnt = 0;
- //for (i=0; i<AUDIO_SIZE; i++)
- for (i=0; i<34; i++)
+ for (i=0; i<AUDIO_SPK_SIZE; i++)
{
- //if ((spi_in[i+SPI_AUDIO_OFFSET] == (cnt+1)) ||
- //(spi_in[i+SPI_AUDIO_OFFSET] == (cnt-1)))
- //{
+ FifoPut(PWMFifo, spi_in[i+SPI_AUDIO_OFFSET]);
+ //XXX DEBUG: used to show when the stack overflows.
+ //if (FifoPut(PWMFifo, spi_in[i+SPI_AUDIO_OFFSET]) !=
FIFO_OK)
//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
Modified: firmware/tuxaudio/branches/new_rf/fifo.h
===================================================================
--- firmware/tuxaudio/branches/new_rf/fifo.h 2008-06-25 11:11:17 UTC (rev
1266)
+++ firmware/tuxaudio/branches/new_rf/fifo.h 2008-06-25 14:38:07 UTC (rev
1267)
@@ -157,6 +157,22 @@
int8_t FifoPut(fifo_t *p, uint8_t const data);
int8_t FifoGet(fifo_t *p, uint8_t *data);
+static inline void FifoPut_inl(fifo_t *p, uint8_t const data)
+{
+ if (FifoLength(p) == p->size)
+ return;
+
+ p->buffer[p->inIdx++ & (p->size-1)] = data; /* store data */
+}
+
+static inline void FifoGet_inl(fifo_t *p, uint8_t *data)
+{
+ if (p->outIdx == p->inIdx)
+ return;
+
+ *data = p->buffer[p->outIdx++ & (p->size-1)];
+}
+
/*! @} */
/*! @} */
#endif /* _FIFO_H_ */
Modified: firmware/tuxaudio/branches/new_rf/main.c
===================================================================
--- firmware/tuxaudio/branches/new_rf/main.c 2008-06-25 11:11:17 UTC (rev
1266)
+++ firmware/tuxaudio/branches/new_rf/main.c 2008-06-25 14:38:07 UTC (rev
1267)
@@ -181,13 +181,14 @@
{
sei(); // Reactivate global interrupt in case of
flash programmation
+ /* Check for stack overflow. */
if (!check_stack())
while(1)
{
PORTB |= 0x80;
PORTB &= ~0x80;
}
- spiTransaction(); // Spi transaction from radio
+ //spiTransaction(); // Spi transaction from radio
//XXX to delete
//if (commandRX) // commend RX from radio
@@ -328,16 +329,20 @@
ISR(__vector_audio_sampling)
{
//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*/
- /*}*/
+ /* Speaker at 16kHz */
+ FifoGet_inl(PWMFifo, (uint8_t *)&OCR0B);
+
+ if (sampling_pwm & 0x02)
+ {
+ /* Microphone at 8kHz */
+ FifoPut_inl(ADCFifo, ADCH);
+ ADCSRA |= 0x40;
+ if (--sendSensorsCmpt == 0)
+ sendSensorsFlag = 1;
+ }
+
+ // XXX DEBUG: used to generate a saw waveform
//static uint8_t cnt = 0;
//static uint8_t dir = 1;
//#define STEP 8
@@ -348,16 +353,13 @@
//cnt -= STEP;
//if ((cnt >= (0xFF - STEP)) || (cnt == 0))
//dir = !dir;
-
- ADCSRA |= 0x40;
- if (--sendSensorsCmpt == 0)
- sendSensorsFlag = 1;
}
/*
* Timer 0 overflow interrupt service routine (PWM)
* 32KHz timer so the ISR is called each 31.25us
*/
+#if 0
ISR(SIG_OVERFLOW0)
{
/* timer 0 is clocked at 32KHz so we divide it by 4 to get 8KHz */
@@ -367,7 +369,29 @@
cli();
}
}
+#endif
+#if 1
+ISR(SIG_OVERFLOW0) __attribute__((naked));
+ISR(SIG_OVERFLOW0)
+{
+ asm volatile (
+ "in r0, 0x3f" "\n\t"
+ "push r28" "\n\t"
+ "lds r28, 0x0100" "\n\t"
+ "subi r28, 0xFF" "\n\t"
+ "sts 0x0100, r28" "\n\t"
+ "sbrs r28, 0" "\n\t"
+ "rjmp v_out" "\n\t"
+ "rcall __vector_audio_sampling" "\n\t"
+ "cli" "\n\t"
+ "v_out:"
+ "pop r28" "\n\t"
+ "out 0x3f, r0" "\n\t"
+ ::);
+ asm ("reti" "\n\t"::);
+}
+#endif
//ISR(SIG_OVERFLOW0) __attribute__((naked));
//ISR(SIG_OVERFLOW0)
//{
-------------------------------------------------------------------------
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