[tuxdroid-svn] r1328 - firmware/rf/trunk
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2008-07-16 08:14:28
|
Author: jaguarondi Date: 2008-07-16 10:14:37 +0200 (Wed, 16 Jul 2008) New Revision: 1328 Modified: firmware/rf/trunk/interface.c firmware/rf/trunk/interface.h firmware/rf/trunk/rf_ctrl.c firmware/rf/trunk/varis.c firmware/rf/trunk/varis.h Log: * Added redundancy for the audio data, seems correct and will benefit from some cleanup later. The SPI and RF frames aren't in sync anymore as the redundancy is onle dealt with in the RF frame. Data and audio sent in the same SPI frame end up in different SPI frames at the other side as the audio frame is buffered. Modified: firmware/rf/trunk/interface.c =================================================================== --- firmware/rf/trunk/interface.c 2008-07-16 08:08:10 UTC (rev 1327) +++ firmware/rf/trunk/interface.c 2008-07-16 08:14:37 UTC (rev 1328) @@ -25,6 +25,7 @@ #include "interface.h" #include "varis.h" +uint8_t second_buffer; /** * Initialize the SPI interface. */ @@ -39,44 +40,81 @@ static uint8_t * const spi_in = (uint8_t *)rf_buffer_tx+12; static uint8_t * spi_out; -static uint8_t spi_idx; +static uint8_t spi_in_idx; +static uint8_t spi_out_idx; ISR(SIG_SPI) { /* Get byte n and prepare byte n+1 to send. */ - spi_in[spi_idx] = SPDR; + spi_in[spi_in_idx] = SPDR; set_spiack(); - spi_idx++; - SPDR = spi_out[spi_idx]; + spi_in_idx++; + spi_out_idx++; + if (spi_in_idx == SPI_AUDIO_OFFSET) + { + /* Select the second part of the buffer if the spi frame index is even */ + if (spi_in[SPI_IDX_OFFSET] & 0x01) + spi_in_idx += AUDIO_SPK_SIZE; + /* second_buffer is for upcoming data, so we invert for the data + * received. */ + if (!second_buffer) + spi_out_idx += AUDIO_SPK_SIZE; + } + SPDR = spi_out[spi_out_idx]; clr_spiack(); } void spi_request(void) { + uint8_t tmp; + static uint8_t prev_audio = 0; + static uint8_t frame_dropped = 0; /* XXX should we disable/enable SPIE? */ - spi_idx = 0; - /* XXX size is at [0] -> +1 for the start of the frame */ + spi_in_idx = 0; + spi_out_idx = 0; + /* Select the lastest received data */ spi_out = (uint8_t *)rf_buffer_rx_full; - SPDR = spi_out[spi_idx]; - set_txe(); -} -int8_t spi_complete(void) - /* XXX guess this isn't truly necessary */ -{ - clr_txe(); - if (spi_idx == 63) + /* As we send the previous audio frame, we have to reconfigure the audio + * bit in the config byte. */ + if (checksum1 == 0) { - return 1; + prev_audio = spi_out[SPI_CONFIG_OFFSET] & CFG_SECBUF_MK; + frame_dropped = 0; } - else if (spi_idx > 63) - /* Error */ + else { - return -1; + if (frame_dropped) + prev_audio = 0; + else + frame_dropped = 1; } + tmp = spi_out[SPI_CONFIG_OFFSET] & CFG_AUDIO_MK; + if (prev_audio) + spi_out[SPI_CONFIG_OFFSET] |= CFG_AUDIO_MK; else - /* Not finished */ - /* XXX what to do here? */ - { - return 0; - } + spi_out[SPI_CONFIG_OFFSET] &= ~CFG_AUDIO_MK; + /* We store the information here in case the next frame is dropped. */ + prev_audio = tmp; + + /* The frame idx indicates in which buffer the audio is, but if we don't + * get a frame, just use the alternate buffer of the previous frame. */ + if (checksum1 == 0) + second_buffer = spi_out[SPI_IDX_OFFSET] & 0x01; + else + second_buffer = !second_buffer; + + SPDR = spi_out[spi_out_idx]; + set_txe(); } + +void spi_complete(void) + /* XXX guess this isn't truly necessary */ +{ + static uint8_t second_buffer_included = 0; + clr_txe(); + /* Store whether the current frame will contain the previous audio in the + * second buffer */ + if (second_buffer_included) + spi_in[SPI_CONFIG_OFFSET] |= CFG_SECBUF_MK; + second_buffer_included = spi_in[SPI_CONFIG_OFFSET] & CFG_AUDIO_MK; +} Modified: firmware/rf/trunk/interface.h =================================================================== --- firmware/rf/trunk/interface.h 2008-07-16 08:08:10 UTC (rev 1327) +++ firmware/rf/trunk/interface.h 2008-07-16 08:14:37 UTC (rev 1328) @@ -22,6 +22,8 @@ #ifndef INTERFACE_H #define INTERFACE_H +#include "common/defines.h" + #define LINK_PORT PORTD #define LINK_DDR DDRD #define LINK_OUT PD7 @@ -40,7 +42,7 @@ #define clr_spiack() (SPIACK_PORT &= ~_BV(SPIACK_OUT)) void interface_init(void); -int8_t spi_complete(void); +void spi_complete(void); void spi_request(void); #endif /* INTERFACE_H */ Modified: firmware/rf/trunk/rf_ctrl.c =================================================================== --- firmware/rf/trunk/rf_ctrl.c 2008-07-16 08:08:10 UTC (rev 1327) +++ firmware/rf/trunk/rf_ctrl.c 2008-07-16 08:14:37 UTC (rev 1328) @@ -27,7 +27,6 @@ #include "prot.h" #include "interface.h" -volatile int8_t spi_tmp; /* XXX debug */ uint8_t checksum_tx; static void reset_atr2406(void); @@ -50,7 +49,7 @@ ISR (SIG_OUTPUT_COMPARE1A) { - PORTD ^= 0x08; // XXX DEBUG + //PORTD ^= 0x08; // XXX DEBUG switch(rf_state) { /* @@ -81,8 +80,12 @@ uint8_t volatile *p = rf_buffer_rx; rf_buffer_rx = rf_buffer_rx_full; rf_buffer_rx_full = p; + PORTD ^= 0x08; // XXX DEBUG } + checksum1 = checksum; } + else + checksum1 = 10; /* Configure in TX. */ #ifdef NOHOPP channel = TRX_CHANNEL; @@ -107,9 +110,12 @@ OCR1A = OCR1A + T_LOOP; //calculate new RF-Packet! SOF depending wether connected or not!! rf_buffer_tx[8] = channel; + /* What should we do if it's not complete? + * 2 ways, either continue the SPI until all data is gotten, but then + * that doesn't work if there's a problem, or drop the data, in which + * case it's possible to extend slightly the com period. */ + spi_complete(); - //PACKET CALCULATIONS - break; case 0x02: /* Start transmission. */ @@ -137,12 +143,6 @@ //} //} - /* What should we do if it's not complete? - * 2 ways, either continue the SPI until all data is gotten, but then - * that doesn't work if there's a problem, or drop the data, in which - * case it's possible to extend slightly the com period. */ - spi_tmp = spi_complete(); - rf_state = 3; // XXX skip PU break; @@ -155,11 +155,7 @@ /* Request a SPI communication. */ /* XXX Should check here whether we're connected or not */ - if (rf_status) - /* XXX I think we don't need this 'if' anymore */ - { - spi_request(); - } + spi_request(); //pwr_up_atr2406(); break; @@ -249,7 +245,7 @@ break; } rf_state = (rf_state + 1) & 7; - PORTD ^= 0x08; // XXX DEBUG + //PORTD ^= 0x08; // XXX DEBUG } volatile uint16_t testt = T_HEADER; Modified: firmware/rf/trunk/varis.c =================================================================== --- firmware/rf/trunk/varis.c 2008-07-16 08:08:10 UTC (rev 1327) +++ firmware/rf/trunk/varis.c 2008-07-16 08:14:37 UTC (rev 1328) @@ -99,6 +99,7 @@ volatile uint8_t rf_rx_state; //State of the RX interrupt volatile uint8_t checksum; +volatile uint8_t checksum1; //Checksum => 0x00 => okay Modified: firmware/rf/trunk/varis.h =================================================================== --- firmware/rf/trunk/varis.h 2008-07-16 08:08:10 UTC (rev 1327) +++ firmware/rf/trunk/varis.h 2008-07-16 08:14:37 UTC (rev 1328) @@ -61,6 +61,7 @@ extern volatile uint8_t rf_rx_counter; extern volatile uint8_t rf_rx_state; extern volatile uint8_t checksum; +extern volatile uint8_t checksum1; extern volatile uint8_t trial_cnt; extern volatile uint16_t ts; |