Author: jaguarondi
Date: 2008-07-25 16:54:20 +0200 (Fri, 25 Jul 2008)
New Revision: 1354
Modified:
firmware/tuxaudio/branches/new_rf/communication.c
firmware/tuxaudio/branches/new_rf/flash.c
firmware/tuxaudio/branches/new_rf/hardware.h
firmware/tuxaudio/branches/new_rf/main.c
firmware/tuxaudio/branches/new_rf/varis.c
firmware/tuxaudio/branches/new_rf/varis.h
Log:
* Re-enabled the audio flash (play and program).
Modified: firmware/tuxaudio/branches/new_rf/communication.c
===================================================================
--- firmware/tuxaudio/branches/new_rf/communication.c 2008-07-25 14:45:47 UTC
(rev 1353)
+++ firmware/tuxaudio/branches/new_rf/communication.c 2008-07-25 14:54:20 UTC
(rev 1354)
@@ -245,16 +245,24 @@
static uint8_t frame_in_idx, frame_out_idx;
static uint8_t spi_in[52], spi_out[52], spi_idx;
+static bool rf_spi_request;
/* INT1 (PD3) Interrupt on TXE signal. */
ISR(SIG_INTERRUPT1)
{
+ rf_spi_request = true;
+ rf_txe = true;
+}
+
+void start_rf_spi(void)
+{
//PORTB |= 0x80; // XXX DEBUG
//if (spi_idx) // XXX debug
//PORTB |= 0x80; // XXX DEBUG
spi_idx = 0;
- /* Chip select */
- PORTB &= ~_BV(PB2);
+
+ flash_onhold();
+ rf_select();
SPDR = spi_out[spi_idx];
EIMSK |= _BV(INT0);
EIFR |= _BV(INT0);
@@ -279,8 +287,9 @@
{
/* Unselect by waiting here otherwise we would have to use the SPI
* interrupt to do it. */
- PORTB |= _BV(PB2);
+ rf_unselect();
EIMSK &= ~_BV(INT0);
+ flash_enable();
}
else
{
@@ -330,8 +339,14 @@
* when the RF is off. */
/* XXX this doesn't work anymore with the current RF, to check later. */
/*if (!(RF_ONLINE_PIN & RF_ONLINE_MK))*/
- /*FifoClear(rf_cmdout_buf);*/
+ //FifoClear(rf_cmdout_buf);
+ if (rf_spi_request)
+ {
+ rf_spi_request = false;
+ start_rf_spi();
+ }
+
/* Fill and process RF data. */
if (spi_idx >= SPI_SIZE)
{
@@ -360,7 +375,7 @@
}
//else
//PORTB |= 0x80; // XXX DEBUG
- if (config_in & CFG_AUDIO_MK)
+ if (config_in & CFG_AUDIO_MK && !flashPlay)
{
adapt_audio_rate();
@@ -370,7 +385,10 @@
}
}
else
- PORTB ^= 0x80; // XXX DEBUG
+ {
+ if (frame_without_sound)
+ frame_without_sound --;
+ }
/* DEBUG VERSION
* The first part checks a saw wave, the second part can check for
@@ -424,6 +442,7 @@
config_out &= ~CFG_AUDIO_MK;
}
spi_out[SPI_CONFIG_OFFSET] = config_out;
+ rf_txe = false;
}
/* If busy, pass. */
Modified: firmware/tuxaudio/branches/new_rf/flash.c
===================================================================
--- firmware/tuxaudio/branches/new_rf/flash.c 2008-07-25 14:45:47 UTC (rev
1353)
+++ firmware/tuxaudio/branches/new_rf/flash.c 2008-07-25 14:54:20 UTC (rev
1354)
@@ -116,8 +116,9 @@
uint8_t static programming_state = DETECT_INDEXES;
if (programming_state == DETECT_INDEXES)
{
+ /* Disable audio PWM interrupt */
TIMSK0 = 0x00;
- //numSound = readFlashNumber();
+
if (numSound == 0)
{
/* The flash memory is empty. The first address is 0x000400 */
@@ -156,7 +157,6 @@
programming_state ++;
frame_without_sound = 5000;
- frame_without_sound_timeout = 5000;
queue_rf_cmd_p(STATUS_FLASH_PROG_CMD, IN_PROGRESS, ad[0], ad[1]);
}
@@ -190,28 +190,27 @@
}
else if (programming_state == WAITING_STATE)
{
- if (write_toc == 1)
- {
+ /*if (write_toc == 1)*/
+ /*{*/
programming_state = PROG_TOC;
- }
- else if (write_toc == 2)
- {
- queue_rf_cmd_p(STATUS_FLASH_PROG_CMD, ERASING_LAST_SOUND, 0, 0);
- if (first_block == 0)
- {
- eraseFlag = 1;
- frame_without_sound_timeout = TTS_TIMEOUT;
- programming_state = 0;
- programmingFlash = 0;
- }
- else
- {
- last_block = (ad[0] << 4) + (ad[1] >> 4);
- blockErase(first_block, last_block);
- programming_state = PROG_END;
- }
- }
- write_toc = 0;
+ /*}*/
+ /*else if (write_toc == 2)*/
+ /*{*/
+ /*queue_rf_cmd_p(STATUS_FLASH_PROG_CMD, ERASING_LAST_SOUND, 0,
0);*/
+ /*if (first_block == 0)*/
+ /*{*/
+ /*eraseFlag = 1;*/
+ /*programming_state = 0;*/
+ /*programmingFlash = 0;*/
+ /*}*/
+ /*else*/
+ /*{*/
+ /*last_block = (ad[0] << 4) + (ad[1] >> 4);*/
+ /*blockErase(first_block, last_block);*/
+ /*programming_state = PROG_END;*/
+ /*}*/
+ /*}*/
+ /*write_toc = 0;*/
}
else if (programming_state == PROG_TOC)
{
@@ -229,7 +228,6 @@
else if (programming_state == PROG_END)
{
numSound = readFlashNumber();
- frame_without_sound_timeout = TTS_TIMEOUT;
programming_state = 0;
programmingFlash = 0;
TIMSK0 = 0x01;
@@ -288,14 +286,18 @@
//queue_rf_cmd_p(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0);
enter = 1;
eraseFlag = 0;
+
+ /* Wite the first index. */
program_flash(0x00, 0x00, 0x00, 0xFE);
program_flash(0x00, 0x00, 0x01, 0x00);
program_flash(0x00, 0x00, 0x02, 0x04);
program_flash(0x00, 0x00, 0x03, 0x00);
numSound = 0;
last_block = 0;
+
queue_rf_cmd_p(STATUS_FLASH_PROG_CMD, STANDBY, 0, 0);
queue_rf_cmd_p(SOUND_VAR_CMD, numSound, last_block, 0);
+ /* Re-enable audio PWM interrupt */
TIMSK0 = 0x01;
}
}
@@ -459,11 +461,13 @@
static void playingSound(void)
{
uint8_t sound;
- while (!rf_txe && !FifoFull(PWMFifo))
+ while (!rf_txe && FifoLength(PWMFifo) < (PWMFifo->size-1))
{
sound = spiSend(0x00); // Wait response
sound = sound >> audioLevel;
+ /* Save it twice to have 16kHz */
FifoPut(PWMFifo, sound);
+ FifoPut(PWMFifo, sound);
ad[2]++; // Increment address for next play
if (ad[2] == 0)
@@ -562,12 +566,13 @@
uint8_t data;
sound_stored = 1;
frame_without_sound = STOP_FRAME_NUMBER;
- frame_without_sound_timeout = STOP_FRAME_NUMBER;
flash_select();
spiSend(SEQU_PROGRAM);
FifoGet(PWMFifo, &data);
spiSend(data);
+ /* Drop one byte out of 2 to store in 8kHz */
+ FifoGet(PWMFifo, &data);
flash_unselect();
ad[2] ++;
@@ -577,20 +582,23 @@
if (ad[1] == 0x00)
ad[0]++;
}
+ if (ad[0] == 0x07 && ad[1] == 0xFF && ad[2] == 0xFF)
+ {
+ flash_state = 0;
+ break;
+ }
while (read_status() & BUSY) ;
}
-
- /* Check for the last sound byte */
- if (!(frame_without_sound))
+ else
{
- flash_state = 0;
break;
}
- if (ad[0] == 0x07 && ad[1] == 0xFF && ad[2] == 0xFF)
- {
- flash_state = 0;
- break;
- }
+
}
+ /* Check for the last sound byte */
+ if (!(frame_without_sound))
+ {
+ flash_state = 0;
+ }
}
Modified: firmware/tuxaudio/branches/new_rf/hardware.h
===================================================================
--- firmware/tuxaudio/branches/new_rf/hardware.h 2008-07-25 14:45:47 UTC
(rev 1353)
+++ firmware/tuxaudio/branches/new_rf/hardware.h 2008-07-25 14:54:20 UTC
(rev 1354)
@@ -41,7 +41,6 @@
#define RF_RESET_PT PORTB
/** RF reset DDR. */
#define RF_RESET_DDR DDRB
-
/** RF online mask. */
#define RF_ONLINE_MK _BV(PB6)
/** RF online PIN. */
@@ -50,7 +49,18 @@
#define RF_ONLINE_PT PORTB
/** RF online DDR. */
#define RF_ONLINE_DDR DDRB
+/** RF chip select mask. */
+#define RF_CS_MK _BV(PB2)
+/** RF chip select PIN. */
+#define RF_CS_PIN PINB
+/** RF chip select PORT. */
+#define RF_CS_PT PORTB
+/** RF chip select DDR. */
+#define RF_CS_DDR DDRB
+#define rf_select() (PORTB &= ~_BV(PB2))
+#define rf_unselect() (PORTB |= _BV(PB2))
+
/* Flash memory port */
#define FLASH_PORT PORTB
#define FLASH_CS_PIN _BV(PB1)
Modified: firmware/tuxaudio/branches/new_rf/main.c
===================================================================
--- firmware/tuxaudio/branches/new_rf/main.c 2008-07-25 14:45:47 UTC (rev
1353)
+++ firmware/tuxaudio/branches/new_rf/main.c 2008-07-25 14:54:20 UTC (rev
1354)
@@ -159,10 +159,9 @@
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;
sei(); /* Init global interrupt */
@@ -201,14 +200,19 @@
//queue_core_cmd(spi_commandRX);
//}
- /*if (programmingFlash) // Restora all the context for flash
programming*/
- /*programming();*/
+ if (!rf_txe)
+ {
+ 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();
Modified: firmware/tuxaudio/branches/new_rf/varis.c
===================================================================
--- firmware/tuxaudio/branches/new_rf/varis.c 2008-07-25 14:45:47 UTC (rev
1353)
+++ firmware/tuxaudio/branches/new_rf/varis.c 2008-07-25 14:54:20 UTC (rev
1354)
@@ -38,7 +38,7 @@
volatile unsigned char spi_count;
volatile unsigned char spi_lenght_data;
volatile unsigned char spi_ready = 0;
-volatile unsigned char rf_txe = 0;
+volatile uint8_t rf_txe = 0;
volatile uint8_t spi_commandTX[5];
unsigned char spi_commandRX[5];
unsigned char commandRX = 0;
@@ -72,7 +72,6 @@
volatile unsigned char Fifoinert = 0;
uint16_t frame_without_sound = 0;
-uint16_t frame_without_sound_timeout= 0;
uint8_t sound_played = 0;
uint8_t last_block = 0;
Modified: firmware/tuxaudio/branches/new_rf/varis.h
===================================================================
--- firmware/tuxaudio/branches/new_rf/varis.h 2008-07-25 14:45:47 UTC (rev
1353)
+++ firmware/tuxaudio/branches/new_rf/varis.h 2008-07-25 14:54:20 UTC (rev
1354)
@@ -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 rf_txe;
+extern volatile uint8_t rf_txe;
extern uint8_t spi_commandTX[5];
extern unsigned char spi_commandRX[5];
extern unsigned char commandRX;
@@ -82,7 +82,6 @@
extern volatile unsigned char Fifoinert;
extern uint16_t frame_without_sound;
-extern uint16_t frame_without_sound_timeout;
extern uint8_t sound_played;
extern uint8_t last_block;
-------------------------------------------------------------------------
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