[tuxdroid-svn] r1258 - in firmware/fuxusb/branches/new_rf: . src
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2008-06-24 10:41:07
|
Author: jaguarondi Date: 2008-06-24 12:41:14 +0200 (Tue, 24 Jun 2008) New Revision: 1258 Modified: firmware/fuxusb/branches/new_rf/fuxusb.Opt firmware/fuxusb/branches/new_rf/src/fifo_mic.c firmware/fuxusb/branches/new_rf/src/fifo_mic.h firmware/fuxusb/branches/new_rf/src/fifo_spk.c firmware/fuxusb/branches/new_rf/src/fifo_spk.h firmware/fuxusb/branches/new_rf/src/main.c firmware/fuxusb/branches/new_rf/src/rf.c firmware/fuxusb/branches/new_rf/src/spi_task.c firmware/fuxusb/branches/new_rf/src/spi_task.h firmware/fuxusb/branches/new_rf/src/usb_commands.c firmware/fuxusb/branches/new_rf/src/usb_desc.h firmware/fuxusb/branches/new_rf/src/usb_ep.c firmware/fuxusb/branches/new_rf/src/version.h Log: * First functional version. Modified: firmware/fuxusb/branches/new_rf/fuxusb.Opt =================================================================== (Binary files differ) Modified: firmware/fuxusb/branches/new_rf/src/fifo_mic.c =================================================================== --- firmware/fuxusb/branches/new_rf/src/fifo_mic.c 2008-06-24 10:37:20 UTC (rev 1257) +++ firmware/fuxusb/branches/new_rf/src/fifo_mic.c 2008-06-24 10:41:14 UTC (rev 1258) @@ -76,9 +76,9 @@ * be previously selected. * \ingroup fifo_mic */ -void FIFO_MIC_put_n(uint8_t const n) +void FIFO_MIC_put_n(uint8_t *p, uint8_t const n) { - uint8_t data i; + uint8_t i; i = n; do @@ -87,7 +87,7 @@ return; Mic_buf[FifoIn_MIC_Idx++ & (MIC_BUF_SIZE-1)] = \ - received_rf_data[n-i]; + p[n-i]; } while (-- i); } Modified: firmware/fuxusb/branches/new_rf/src/fifo_mic.h =================================================================== --- firmware/fuxusb/branches/new_rf/src/fifo_mic.h 2008-06-24 10:37:20 UTC (rev 1257) +++ firmware/fuxusb/branches/new_rf/src/fifo_mic.h 2008-06-24 10:41:14 UTC (rev 1258) @@ -30,7 +30,7 @@ extern void FIFO_MIC_init (void); extern bit FIFO_MIC_ready(void); -extern void FIFO_MIC_put_n (uint8_t const n); +extern void FIFO_MIC_put_n(uint8_t *p, uint8_t const n); extern uint8_t FIFO_MIC_get (void); #endif /*_FIFO_MIC_H_*/ Modified: firmware/fuxusb/branches/new_rf/src/fifo_spk.c =================================================================== --- firmware/fuxusb/branches/new_rf/src/fifo_spk.c 2008-06-24 10:37:20 UTC (rev 1257) +++ firmware/fuxusb/branches/new_rf/src/fifo_spk.c 2008-06-24 10:41:14 UTC (rev 1258) @@ -33,8 +33,6 @@ * @{ */ /** Buffer size */ #define SPK_BUF_SIZE 64 -/** Ready threshold. This value allow to empty the fifo */ -#define FIFO_SPK_READY 32 /*! @} */ /** \name Variables @@ -63,10 +61,11 @@ /** * \brief Check if the fifo is ready to be empty. */ -bit FIFO_SPK_ready(void) +uint8_t FIFO_SPK_length(void) { - return ((FifoIn_SPK_Idx - FifoOut_SPK_Idx) > FIFO_SPK_READY); + return (FifoIn_SPK_Idx - FifoOut_SPK_Idx); } + /** * \brief Push N bytes in the Speaker FIFO. * \param n The number of byte to push. Modified: firmware/fuxusb/branches/new_rf/src/fifo_spk.h =================================================================== --- firmware/fuxusb/branches/new_rf/src/fifo_spk.h 2008-06-24 10:37:20 UTC (rev 1257) +++ firmware/fuxusb/branches/new_rf/src/fifo_spk.h 2008-06-24 10:41:14 UTC (rev 1258) @@ -29,9 +29,8 @@ #ifndef _FIFO_SPK_H_ #define _FIFO_SPK_H_ - extern void FIFO_SPK_init (void); -extern bit FIFO_SPK_ready(void); +extern uint8_t FIFO_SPK_length(void); extern void FIFO_SPK_put_n (uint8_t const n); extern uint8_t FIFO_SPK_get (void); Modified: firmware/fuxusb/branches/new_rf/src/main.c =================================================================== --- firmware/fuxusb/branches/new_rf/src/main.c 2008-06-24 10:37:20 UTC (rev 1257) +++ firmware/fuxusb/branches/new_rf/src/main.c 2008-06-24 10:41:14 UTC (rev 1258) @@ -60,7 +60,7 @@ i2c_task(); } /* Bootloader inactive : if RF is online, process spi_task. */ - else if (is_rf_online()) + else { spi_task(); } Modified: firmware/fuxusb/branches/new_rf/src/rf.c =================================================================== --- firmware/fuxusb/branches/new_rf/src/rf.c 2008-06-24 10:37:20 UTC (rev 1257) +++ firmware/fuxusb/branches/new_rf/src/rf.c 2008-06-24 10:41:14 UTC (rev 1258) @@ -83,7 +83,6 @@ { reset_rf(); } - new_cmd_enabled = True; rf_is_running = False; return False; } Modified: firmware/fuxusb/branches/new_rf/src/spi_task.c =================================================================== --- firmware/fuxusb/branches/new_rf/src/spi_task.c 2008-06-24 10:37:20 UTC (rev 1257) +++ firmware/fuxusb/branches/new_rf/src/spi_task.c 2008-06-24 10:41:14 UTC (rev 1258) @@ -57,11 +57,6 @@ /** Indicate the RF state. */ uint8_t RF_Status; -/** This flag is set when a new command can be received from the USB. - * When a command for tux is received, this flag = False. When the commands has - * been sent to the RF, this flag is set. - */ -bit new_cmd_enabled; /** This flag is set when a command for tux is received. It indicate the * RF that a command must be included in the frame. */ @@ -77,7 +72,30 @@ static bit spi_ready = 0; static bit spi_Start_Flag = 0; +/** \name SPI frame constants + * @{ */ +/** Size of the audio data in the SPI frame */ +#define AUDIO_SIZE 17 +/* Bits of the config byte */ +#define _BV(x) (1<<x) +#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 50 +#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 spi_in[SPI_SIZE], spi_out[SPI_SIZE], spi_idx; +static uint8_t idx_in, idx_out; + /** * \brief Reset the SPI task to the defaults states. * This function reset all SPI variables. @@ -91,7 +109,6 @@ SPI_CSn = 1; // Chip select spi_Start_Flag = 0; spi_ready = 0; - new_cmd_enabled = True; } /** @@ -132,8 +149,6 @@ spi_slave = 0; // Reset State Machine of spi_task() spi_master = 0; // Reset State Machine of spi_task() - - new_cmd_enabled = True; } /** @@ -144,7 +159,33 @@ */ void it_INT0(void) interrupt IRQ_INT0 { - spi_ready = 1; + P3_7 = 1; /* XXX debug */ + if (SPI_CSn) + { + /* No start yet. */ + P3_7 = 0; /* XXX debug */ + return; + } + /* Check that the previous SPI transmission is done. */ + /* XXX we can delete that later */ + if ((SPSTA & 0x80) == 0) + { + P3_7 = 0; /* XXX debug */ + return; + } + + spi_in[spi_idx++] = SPDAT; + + if (spi_idx == SPI_SIZE) + { + /* Last byte done, unselect. */ + SPI_CSn = 1; + } + else + { + SPDAT = spi_out[spi_idx]; + } + P3_7 = 0; /* XXX debug */ } /** @@ -154,6 +195,119 @@ */ void spi_task(void) { + uint8_t config; + uint8_t i; + static bit prev_spi_start = False; + + P3_6 = 1; /* XXX debug */ + /* Resset SPI state when the RF is done */ + if (!SPI_START) + { + prev_spi_start = False; + } + /* Check for rising edge on SPI_START */ + else if (!prev_spi_start) /* && SPI_START */ + { + prev_spi_start = True; + + /* Chip select */ + SPI_CSn = 0; + /* Send the first data */ + spi_idx = 0; + SPDAT = spi_out[spi_idx]; + P3_6 = 0; /* XXX debug */ + return; + } + + if (SPI_CSn == 0) + { + /* We're busy already */ + P3_6 = 0; /* XXX debug */ + return; + } + else if (spi_idx >= SPI_SIZE) + { + spi_idx = 0; + /* Prepare next SPI frame to be sent to the RF */ + config = 0; + if (new_command_received) + { + new_command_received = False; + config |= CFG_DATA_MK; + for (i=0; i<CMD_SIZE; i++) + { + spi_out[i+SPI_DATA_OFFSET] = command_received[i]; + } + } + if (FIFO_SPK_length() >= AUDIO_SIZE) + { + config |= CFG_AUDIO_MK; + for (i=0; i<AUDIO_SIZE; i++) + { + //static uint8_t cnt = 0; + //static bit dir = 1; + spi_out[i+SPI_AUDIO_OFFSET] = FIFO_SPK_get(); + //spi_out[i+SPI_AUDIO_OFFSET] = cnt; + //if (dir) + //cnt++; + //else + //cnt--; + //if ((cnt == 0xFF) || (cnt == 0)) + //dir = !dir; + } + } + + + /* Store the frame index and the config byte. */ + spi_out[SPI_IDX_OFFSET] = idx_out++; + spi_out[SPI_CONFIG_OFFSET] = config; + spi_out[2] = 0x81; //XXX debug + + /* XXX debug */ + /*for (i=0; i<SPI_SIZE; i++)*/ + /*spi_out[i] = 0x00;//1<<(i&7);*/ + /*for (i=23; i<45; i++)*/ + /*spi_out[i] = 0x00;//1<<(i&7);*/ + /*for (i=45; i<SPI_SIZE; i+=1)*/ + /*spi_out[i] = 0x01;*/ + /*for (i=40; i<50; i++)*/ + /*spi_out[i] = 0x55;*/ + + /* Store and increment the index of the frame. */ + + /* Process last SPI frame received from the RF */ + if (idx_in != spi_in[SPI_IDX_OFFSET]) + { + idx_in = spi_in[SPI_IDX_OFFSET]; + config = spi_in[SPI_CONFIG_OFFSET]; + if (config & CFG_DATA_MK) + { + for (i=0; i<CMD_SIZE; i++) + { + FIFO_STT_put(spi_in[i+SPI_DATA_OFFSET]); + } + } + if (config & CFG_PREVAUDIO_MK) + { + for (i=0; i<AUDIO_SIZE; i++) + { + FIFO_MIC_put_n(&spi_in[i+SPI_PREVAUDIO_OFFSET], AUDIO_SIZE); + } + } + if (config & CFG_AUDIO_MK) + { + for (i=0; i<AUDIO_SIZE; i++) + { + FIFO_MIC_put_n(&spi_in[i+SPI_AUDIO_OFFSET], AUDIO_SIZE); + } + } + } + } + P3_6 = 0; /* XXX debug */ +} + +void tmp(void) +{ uint8_t Spi_Overflow_Ctr; uint8_t i; uint8_t received_status[4]; @@ -200,7 +354,7 @@ //-------------------------------------------------------------------------- if (spi_slave == HEADERS) { - if (FIFO_SPK_ready()) + if (1)//FIFO_SPK_ready()) { if (new_command_received) // { @@ -321,8 +475,6 @@ } if (spi_count == spi_lenght_data + 6) { - new_cmd_enabled = True; - spi_Start_Flag = 0; SPI_CSn = 1; // Chip deselect spi_enable = 1; @@ -334,7 +486,7 @@ if (spi_master_config & (RF_2FRAMES_HDR | \ RF_AUDIO_HDR)) { - FIFO_MIC_put_n(spi_lenght_data); + //FIFO_MIC_put_n(spi_lenght_data); } // // Store STATUS in the FIFO Modified: firmware/fuxusb/branches/new_rf/src/spi_task.h =================================================================== --- firmware/fuxusb/branches/new_rf/src/spi_task.h 2008-06-24 10:37:20 UTC (rev 1257) +++ firmware/fuxusb/branches/new_rf/src/spi_task.h 2008-06-24 10:41:14 UTC (rev 1258) @@ -27,12 +27,11 @@ #ifndef _SPITASK_H_ #define _SPITASK_H_ -#define SPI_START P3_4 -#define SPI_DREADY P3_2 +#define SPI_START P3_4 +#define SPI_DREADY P3_2 /* Variables */ extern uint8_t RF_Status; -extern bit new_cmd_enabled; extern bit new_command_received; /* Functions */ Modified: firmware/fuxusb/branches/new_rf/src/usb_commands.c =================================================================== --- firmware/fuxusb/branches/new_rf/src/usb_commands.c 2008-06-24 10:37:20 UTC (rev 1257) +++ firmware/fuxusb/branches/new_rf/src/usb_commands.c 2008-06-24 10:41:14 UTC (rev 1258) @@ -74,11 +74,7 @@ /* Commands for Tux */ case TUX_CMD_HDR: - new_cmd_enabled = False; new_command_received = True; - /* Transfert commands from command_received buffer to rf_commands. */ - for(i=0;i < 4;i++) - rf_commands[i] = command_received[i]; break; /* Bootloader commands */ @@ -106,7 +102,7 @@ Usb_write_byte(0); Usb_write_byte(RF_OFFLINE ? 0 : 1); Usb_write_byte(RF_Status); - Usb_write_byte(FifoIn_STT_Idx ? (FifoIn_STT_Idx / 4) : 0); + Usb_write_byte(FifoIn_STT_Idx ? (FifoIn_STT_Idx / CMD_SIZE) : 0); /* Write statuses */ for(i=0;i<FifoIn_STT_Idx;i++) Modified: firmware/fuxusb/branches/new_rf/src/usb_desc.h =================================================================== --- firmware/fuxusb/branches/new_rf/src/usb_desc.h 2008-06-24 10:37:20 UTC (rev 1257) +++ firmware/fuxusb/branches/new_rf/src/usb_desc.h 2008-06-24 10:41:14 UTC (rev 1258) @@ -30,7 +30,7 @@ #include "version.h" /** Enable / Disable the HID interface */ -#define HID_DEVICE +//#define HID_DEVICE /** \name Descriptors type * @{ */ Modified: firmware/fuxusb/branches/new_rf/src/usb_ep.c =================================================================== --- firmware/fuxusb/branches/new_rf/src/usb_ep.c 2008-06-24 10:37:20 UTC (rev 1257) +++ firmware/fuxusb/branches/new_rf/src/usb_ep.c 2008-06-24 10:41:14 UTC (rev 1258) @@ -98,11 +98,8 @@ /* EP5 : Command out EP (PC -> dongle) */ if(Usb_test_it_ep(EP_CMD_OUT)) { - if (new_cmd_enabled) - { - commands_parser(); - clear_cmdout_ep(); - } + commands_parser(); + clear_cmdout_ep(); } } Modified: firmware/fuxusb/branches/new_rf/src/version.h =================================================================== --- firmware/fuxusb/branches/new_rf/src/version.h 2008-06-24 10:37:20 UTC (rev 1257) +++ firmware/fuxusb/branches/new_rf/src/version.h 2008-06-24 10:41:14 UTC (rev 1258) @@ -19,7 +19,7 @@ * KySoH iTux agent created on 2005/10/20 by David Bourgeois */ -/* $Id:$ */ +/* $Id$ */ #ifndef _VERSION_H_ #define _VERSION_H_ |