[tuxdroid-svn] r1102 - in firmware/fuxusb/branches/usb_cleanup: spi usb
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2008-05-05 12:20:45
|
Author: Paul_R Date: 2008-05-05 14:20:45 +0200 (Mon, 05 May 2008) New Revision: 1102 Modified: firmware/fuxusb/branches/usb_cleanup/spi/spi_task.c firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h Log: * Moved the spi_task from usb_task.c to spi_task.c Modified: firmware/fuxusb/branches/usb_cleanup/spi/spi_task.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/spi/spi_task.c 2008-05-05 10:48:26 UTC (rev 1101) +++ firmware/fuxusb/branches/usb_cleanup/spi/spi_task.c 2008-05-05 12:20:45 UTC (rev 1102) @@ -12,8 +12,13 @@ #include "global.h" #include "config.h" +#include "usb/usb_task.h" #include "spi\spi_lib.h" #include "spi\spi_task.h" +#include "modules\fifo\fifo_spk.h" +#include "modules\fifo\fifo_mic.h" +#include "modules\fifo\fifo.h" +#include "modules\fifo_stt\fifo_stt.h" #include "global.h" /*_____ M A C R O S ________________________________________________________*/ @@ -144,3 +149,232 @@ } +void spi_task(void) +{ + data unsigned char Spi_Overflow_Ctr; + uint8_t i; + data unsigned char received_status[4]; + data unsigned char received_data[34]; + Cpu_reset=1; + if(spi_task_on_Flag) + { + //-------------------------------------------------------------------------- + // + // Wait the START Event + // + //-------------------------------------------------------------------------- + if ((SPI_START) && (spi_enable)) // Wait start + { + spi_watchdog_ctr = SPI_WATCHDOG_MAX; + spi_ready = 0; + spi_count = 0; // Reset spi counter + spi_slave = HEADERS; // Set state machine + spi_master = HEADERM; + spi_enable = 0; // Communication in progress + + SPI_CSn = 0; // Chip select + spi_Start_Flag = 1; + USB_ParserProcess_Permit_Flag = FALSE; + USB_StatusProcess_Permit_Flag = FALSE; + } + + //-------------------------------------------------------------------------- + // + // SPI Streaming Analyze + // + //-------------------------------------------------------------------------- + if(spi_Start_Flag) + { + //-------------------------------------------------------------------------- + // + // Excecute When RF Module is Ready + // + // Falling Edge on spi_ready + // + //-------------------------------------------------------------------------- + if(spi_ready) + { + Spi_Overflow_Ctr = 0; + do + { + spi_ready = 0; + //-------------------------------------------------------------------------- + // Prepare the Byte to Send + //-------------------------------------------------------------------------- + if (spi_slave == HEADERS) + { + if (Fifoready_SPK) // FIFO ready to be empty + { + if (USBCommand_NewRequest_Flag) // + { + spi_slave_config = RF_AUDIO_HDR | + RF_CMD_HDR; // Config byte + SPDAT = spi_slave_config; // Header byte + } + else + { + // Config byte + spi_slave_config = RF_AUDIO_HDR; + // Header byte + SPDAT = spi_slave_config; + } + } + else + { + if (USBCommand_NewRequest_Flag) + { + // Config byte + spi_slave_config = RF_CMD_HDR; + // Header byte + SPDAT = spi_slave_config; +#ifdef FIFO_DEBUG + printf ("CMD For RF \n"); +#endif + } + else + { + spi_slave_config = 0x00; // Config byte + SPDAT = spi_slave_config; // 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_slave_config & RF_AUDIO_HDR) + { + SPDAT = FIFO_SPK_get(); // Get data from FIFO + } + else + SPDAT = 0x00; // No data to transmit + + } + else if (spi_slave == PUT_COMMAND) + { + if (spi_count == 21) + { + if(spi_slave_config & RF_CMD_HDR) + { + + USBCommand_NewRequest_Flag = 0; + } + spi_slave = DUMMY; // Next state + } + if (spi_slave_config & RF_CMD_HDR) + { + SPDAT =USBCommand_ForRF[spi_count-18]; + } + else + SPDAT = 0x00; // No command to transmit + } + else if (spi_slave == DUMMY) + { + SPDAT = 0x00; // Dummy byte in case of big frame + } + + spi_count++; + //-------------------------------------------------------------------------- + // Analyze the byte received + //-------------------------------------------------------------------------- + if (spi_master == HEADERM) + { + while (!(SPSTA == 0x80)) // Wait SPI response + if(RF_OFFLINE) + return; + + spi_master_config = SPDAT; + + + if (SPDAT & RF_2FRAMES_HDR) // Double frame + spi_lenght_data = 34; + else + spi_lenght_data = 17; + spi_master = PUT_SOUND_FIFO; // Go to the next state + } + else if (spi_master == PUT_SOUND_FIFO) + { + while (!(SPSTA == 0x80)) // Wait SPI response + if(RF_OFFLINE) + return; + + if (spi_master_config & RF_AUDIO_HDR) + { + P1_0 = 1; + received_data[spi_count-2] = SPDAT; + } + if (spi_count == (spi_lenght_data + 1)) + // Go to the next state + spi_master = READ_COMMAND; + } + else if (spi_master == READ_COMMAND) + { + while (!(SPSTA == 0x80)) // Wait SPI response + if(RF_OFFLINE) + return; + if (spi_master_config & RF_CMD_HDR) + { + if (spi_count <= spi_lenght_data + 5) + received_status[spi_count - \ + spi_lenght_data - 2] = SPDAT; + + if (spi_count == spi_lenght_data + 6) + { + RF_Status_Temp = SPDAT; + if(RF_Status < RF_Status_Temp) + RF_Status = RF_Status_Temp; + } + } + if (spi_count == spi_lenght_data + 6) + { + + USB_ParserProcess_Permit_Flag = TRUE; + USB_StatusProcess_Permit_Flag = TRUE; + spi_Start_Flag = 0; + SPI_CSn = 1; // Chip deselect + spi_enable = 1; + + // + // Store Sound Data in the FIFO MIC + // + // Double frame + if (spi_master_config & (RF_2FRAMES_HDR | \ + RF_AUDIO_HDR)) + { + //Led_0_off(); + i = 0; + do + { + FIFO_MIC_put(received_data[i]); + i++; + } while(i<spi_lenght_data); + //Led_0_on(); + } + // + // Store STATUS in the FIFO + // + if (spi_master_config & RF_CMD_HDR) + { + if(received_status[0]) + { + //Led_0_off(); + i = 0; + do{ + FIFO_STT_put(received_status[i]); + i++; + }while(i<4); + } + //Led_0_on(); + } + //if (spi_slave_config & RF_CMD_HDR) + //printf("\n"); + return; + } + } + Spi_Overflow_Ctr++; + }while(spi_ready&&(Spi_Overflow_Ctr<5)); + } + } + } +} Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c 2008-05-05 10:48:26 UTC (rev 1101) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c 2008-05-05 12:20:45 UTC (rev 1102) @@ -1026,229 +1026,7 @@ else if(!RF_OFFLINE) { - Cpu_reset=1; - if(spi_task_on_Flag) - { -//-------------------------------------------------------------------------- -// -// Wait the START Event -// -//-------------------------------------------------------------------------- - if ((SPI_START) && (spi_enable)) // Wait start - { - spi_watchdog_ctr = SPI_WATCHDOG_MAX; - spi_ready = 0; - spi_count = 0; // Reset spi counter - spi_slave = HEADERS; // Set state machine - spi_master = HEADERM; - spi_enable = 0; // Communication in progress - - SPI_CSn = 0; // Chip select - spi_Start_Flag = 1; - USB_ParserProcess_Permit_Flag = FALSE; - USB_StatusProcess_Permit_Flag = FALSE; - } - -//-------------------------------------------------------------------------- -// -// SPI Streaming Analyze -// -//-------------------------------------------------------------------------- - if(spi_Start_Flag) - { -//-------------------------------------------------------------------------- -// -// Excecute When RF Module is Ready -// -// Falling Edge on spi_ready -// -//-------------------------------------------------------------------------- - if(spi_ready) - { - Spi_Overflow_Ctr = 0; - do - { - spi_ready = 0; -//-------------------------------------------------------------------------- -// Prepare the Byte to Send -//-------------------------------------------------------------------------- - if (spi_slave == HEADERS) - { - if (Fifoready_SPK) // FIFO ready to be empty - { - if (USBCommand_NewRequest_Flag) // - { - spi_slave_config = RF_AUDIO_HDR | - RF_CMD_HDR; // Config byte - SPDAT = spi_slave_config; // Header byte - } - else - { - // Config byte - spi_slave_config = RF_AUDIO_HDR; - // Header byte - SPDAT = spi_slave_config; - } - } - else - { - if (USBCommand_NewRequest_Flag) - { - // Config byte - spi_slave_config = RF_CMD_HDR; - // Header byte - SPDAT = spi_slave_config; -#ifdef FIFO_DEBUG - printf ("CMD For RF \n"); -#endif - } - else - { - spi_slave_config = 0x00; // Config byte - SPDAT = spi_slave_config; // 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_slave_config & RF_AUDIO_HDR) - { - SPDAT = FIFO_SPK_get(); // Get data from FIFO - } - else - SPDAT = 0x00; // No data to transmit - - } - else if (spi_slave == PUT_COMMAND) - { - if (spi_count == 21) - { - if(spi_slave_config & RF_CMD_HDR) - { - - USBCommand_NewRequest_Flag = 0; - } - spi_slave = DUMMY; // Next state - } - if (spi_slave_config & RF_CMD_HDR) - { - SPDAT =USBCommand_ForRF[spi_count-18]; - } - else - SPDAT = 0x00; // No command to transmit - } - else if (spi_slave == DUMMY) - { - SPDAT = 0x00; // Dummy byte in case of big frame - } - - spi_count++; -//-------------------------------------------------------------------------- -// Analyze the byte received -//-------------------------------------------------------------------------- - if (spi_master == HEADERM) - { - while (!(SPSTA == 0x80)) // Wait SPI response - if(RF_OFFLINE) - return; - - spi_master_config = SPDAT; - - - if (SPDAT & RF_2FRAMES_HDR) // Double frame - spi_lenght_data = 34; - else - spi_lenght_data = 17; - spi_master = PUT_SOUND_FIFO; // Go to the next state - } - else if (spi_master == PUT_SOUND_FIFO) - { - while (!(SPSTA == 0x80)) // Wait SPI response - if(RF_OFFLINE) - return; - - if (spi_master_config & RF_AUDIO_HDR) - { - P1_0 = 1; - received_data[spi_count-2] = SPDAT; - } - if (spi_count == (spi_lenght_data + 1)) - // Go to the next state - spi_master = READ_COMMAND; - } - else if (spi_master == READ_COMMAND) - { - while (!(SPSTA == 0x80)) // Wait SPI response - if(RF_OFFLINE) - return; - if (spi_master_config & RF_CMD_HDR) - { - if (spi_count <= spi_lenght_data + 5) - received_status[spi_count - \ - spi_lenght_data - 2] = SPDAT; - - if (spi_count == spi_lenght_data + 6) - { - RF_Status_Temp = SPDAT; - if(RF_Status < RF_Status_Temp) - RF_Status = RF_Status_Temp; - } - } - if (spi_count == spi_lenght_data + 6) - { - - USB_ParserProcess_Permit_Flag = TRUE; - USB_StatusProcess_Permit_Flag = TRUE; - spi_Start_Flag = 0; - SPI_CSn = 1; // Chip deselect - spi_enable = 1; - - // - // Store Sound Data in the FIFO MIC - // - // Double frame - if (spi_master_config & (RF_2FRAMES_HDR | \ - RF_AUDIO_HDR)) - { - //Led_0_off(); - i = 0; - do - { - FIFO_MIC_put(received_data[i]); - i++; - } while(i<spi_lenght_data); - //Led_0_on(); - } - // - // Store STATUS in the FIFO - // - if (spi_master_config & RF_CMD_HDR) - { - if(received_status[0]) - { - //Led_0_off(); - i = 0; - do{ - FIFO_STT_put(received_status[i]); - i++; - }while(i<4); - } - //Led_0_on(); - } - //if (spi_slave_config & RF_CMD_HDR) - //printf("\n"); - return; - } - } - Spi_Overflow_Ctr++; - }while(spi_ready&&(Spi_Overflow_Ctr<5)); - } - } - } - + spi_task(); } else // if RF_OFFLINE { Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h 2008-05-05 10:48:26 UTC (rev 1101) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h 2008-05-05 12:20:45 UTC (rev 1102) @@ -24,8 +24,8 @@ /*_____ D E C L A R A T I O N ______________________________________________*/ +extern bit Cpu_reset; - void usb_task_init (void); void usb_task (void); void usb_Satus_command_process_task(void); |