[tuxdroid-svn] r1109 - in firmware/fuxusb/branches/usb_cleanup: . bootloader usb
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2008-05-06 09:27:01
|
Author: Paul_R Date: 2008-05-06 11:27:01 +0200 (Tue, 06 May 2008) New Revision: 1109 Added: firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.c firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.h firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.c firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.h Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.c firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 firmware/fuxusb/branches/usb_cleanup/main.c firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h Log: * Added new modules (usb_misc and usb_endpoints). Many parts of usb_task have been moved into these new modules. * Reindent. i2c.c Modified: firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.c 2008-05-06 09:18:01 UTC (rev 1108) +++ firmware/fuxusb/branches/usb_cleanup/bootloader/i2c.c 2008-05-06 09:27:01 UTC (rev 1109) @@ -306,29 +306,29 @@ void i2c_task(void) { - if (i2c_wait_counter) - /* Wait */ - ; - else if (i2c_task_on_Flag) + if (i2c_wait_counter) + /* Wait */ + ; + else if (i2c_task_on_Flag) + { + /* Send data through I2C */ + bl_senddata(blHeader, 64); +#ifdef BOOTLOAD_DEBUG + printf ("I2C: Send data"); + while (i2cFlags.i2c_busy) { - /* Send data through I2C */ - bl_senddata(blHeader, 64); -#ifdef BOOTLOAD_DEBUG - printf ("I2C: Send data"); - while (i2cFlags.i2c_busy) - { - uint8_t i; - for (i=0; i<0xFF; i++); - printf ("."); - } - printf (" [OK]\n"); + uint8_t i; + for (i=0; i<0xFF; i++); + printf ("."); + } + printf (" [OK]\n"); #else - while (i2cFlags.i2c_busy); + while (i2cFlags.i2c_busy); #endif - /* Wait 20ms before next I2C */ - i2c_wait_counter = 20; - /* ACK or NACK and exit I2C task */ - usb_Bootloader_acknowledge(i2cFlags.s_val, 0, 0, 0); - i2c_task_on_Flag = 0; - } + /* Wait 20ms before next I2C */ + i2c_wait_counter = 20; + /* ACK or NACK and exit I2C task */ + usb_Bootloader_acknowledge(i2cFlags.s_val, 0, 0, 0); + i2c_task_on_Flag = 0; + } } Modified: firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 =================================================================== --- firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 2008-05-06 09:18:01 UTC (rev 1108) +++ firmware/fuxusb/branches/usb_cleanup/fuxusb.Uv2 2008-05-06 09:27:01 UTC (rev 1109) @@ -17,6 +17,8 @@ File 2,1,<.\usb\usb_task.c><usb_task.c> 0x0 File 2,1,<.\usb\usb_enum.c><usb_enum.c> 0x0 File 2,1,<.\usb\usb_drv.c><usb_drv.c> 0x0 +File 2,1,<.\usb\usb_misc.c><usb_misc.c> 0x0 +File 2,1,<.\usb\usb_endpoints.c><usb_endpoints.c> 0x0 File 3,1,<.\spi\spi_task.c><spi_task.c> 0x0 File 3,1,<.\spi\spi_lib.c><spi_lib.c> 0x0 File 4,1,<.\bootloader\bootloading.c><bootloading.c> 0x0 @@ -54,7 +56,7 @@ EnvLib () EnvReg () OrgReg () - TgStat=11 + TgStat=0 OutDir (.\obj\) OutName (fuxusb.aof) GenApp=1 Modified: firmware/fuxusb/branches/usb_cleanup/main.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/main.c 2008-05-06 09:18:01 UTC (rev 1108) +++ firmware/fuxusb/branches/usb_cleanup/main.c 2008-05-06 09:27:01 UTC (rev 1109) @@ -70,5 +70,14 @@ printf("\n\n= TUX started ==\n"); #endif while(1) + { usb_task(); + + /* XXX + if (BOOT_MODE) + bootloader_task(); + else + spi_task(); + */ + } } Added: firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.c (rev 0) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.c 2008-05-06 09:27:01 UTC (rev 1109) @@ -0,0 +1,364 @@ +#include "global.h" +#include "config.h" +#include "usb/usb_endpoints.h" +#include "usb/usb_drv.h" +#include "usb/usb_task.h" +#include "usb/usb_enum.h" +#include "spi/spi_task.h" +#include "bootloader/bootloading.h" +#include "modules/fifo/fifo.h" +#include "modules/fifo/fifo_spk.h" +#include "modules/fifo/fifo_mic.h" +#include "modules/fifo_stt/fifo_stt.h" +#include "lib_mcu\fa-usb\flash_api.h" + +static void ep_enum(void); +static void ep_cmd_in(void); +static void ep_cmd_out(void); +static void ep_spk(void); +static void ep_tts(void); +static void ep_mic(void); +static void tux_command_parser (unsigned char* commands, unsigned char data_length); +static void usb_command_parser(void); + +void endpoints_ctr(void) +{ + if (Usb_test_it_ep(EP_CMD_IN)) + { + ep_cmd_in(); + } + + if (Usb_test_it_ep(0)) + { + ep_enum(); + } + + if(Usb_test_it_ep(EP_AUDIO_OUT_TTS)) + { + ep_tts(); + } + + if(Usb_test_it_ep(EP_AUDIO_OUT)) + { + ep_spk(); + } + + if(Usb_test_it_ep(EP_AUDIO_IN)) + { + ep_mic(); + } + + if(USB_ParserProcess_Permit_Flag) + { + if(Usb_test_it_ep(EP_CMD_OUT)) + { + ep_cmd_out(); + } + } +} + + +static void ep_enum(void) +{ + Usb_select_ep(EP_CONTROL); + if (Usb_setup_received()) + { +#ifdef USB_TASK_DEBUG + printf("Go to Enum process\n"); +#endif + usb_enumeration_process(); + } +} + + +static void ep_cmd_in(void) +{ + Usb_select_ep(EP_CMD_IN); + if(Usb_tx_complete()) + { + Usb_clear_tx_complete(); + CMD_IN_Bank_Nb--; + if (CMD_IN_Bank_Nb<0) + CMD_IN_Bank_Nb = 0; + if (CMD_IN_Bank_Nb != 0) + Usb_set_tx_ready(); + } +} + +static void ep_tts(void) +{ + uint8_t i; + Usb_select_ep(EP_AUDIO_OUT_TTS); + + if(usb_get_nb_byte()) + if(Speaker_TTS_Select_Flag) + { + i=8; + do + { + // Use Only one Call to Get 8 Bytes + FIFO_SPK_put(Usb_read_byte()); + i--; + }while(i); + } + Usb_clear_rx(); +} + +static void ep_spk(void) +{ + uint8_t i; + //DEBUG_1 = 1; + Usb_select_ep(EP_AUDIO_OUT); + + if(usb_get_nb_byte()) + if(Speaker_TTS_Select_Flag==0) + { + i=8; + do + { + // Use Only one Call to Get 8 Bytes + FIFO_SPK_put(Usb_read_byte()); + i--; + }while(i); + } + Usb_clear_rx(); + //DEBUG_1 = 0; + +} + +static void ep_mic(void) +{ + Usb_select_ep(EP_AUDIO_IN); + if(Usb_tx_complete()) + { + Usb_clear_tx_complete(); + // -> Enable a new Loading of the FIFO + EP_AUDIOIN_Loaded = 0; + } +} + +static void ep_cmd_out(void) +{ + uint8_t i; +#ifdef FIFO_DEBUG + printf("CMD OUT\n"); +#endif + if(!USBCommand_NewRequest_Flag) + { + //DEBUG_2 = 1; + Usb_select_ep(EP_CMD_OUT); + //DEBUG_2 = 0; + if(Usb_rx_complete()) + { + // Capture the number of Byte in USB FIFO + USBCommand_Ctr = usb_get_nb_byte(); + // Read the Header + USBCommand_Header = Usb_read_byte(); + //-------------------------------------------------------------------------- + // + // TUX CMD HEADER received + // -> Store Data in USBCommand_ForRF[] + // -> USBCommand_NewRequest_Flag = 1 + // to inform SPI_task that a new command is arrived + // + //-------------------------------------------------------------------------- + if(USBCommand_Header == LIBUSB_TUX_CMD_HDR) + { + if (!RF_OFFLINE) + USBCommand_NewRequest_Flag = 1; + for(i=0;i<(USBCommand_Ctr-1);i++) + USBCommand_ForRF[i] = Usb_read_byte(); + tux_command_parser(USBCommand_ForRF, \ + USBCommand_Ctr); + } + + /* + * DONGLE CMD HEADER received + */ + else if(USBCommand_Header == LIBUSB_DONGLE_CMD_HDR) + { + for(i=0;i<(USBCommand_Ctr-1);i++) + USBCommand_ForDongle[i] = Usb_read_byte(); +#ifdef FIFO_DEBUG + printf("usb command parser\n"); +#endif + usb_command_parser(); + /* Request processed */ + USBCommand_NewRequest_Flag = 0; + } + + /* + * BOOTLOADER HEADER received + */ + else if(USBCommand_Header == + LIBUSB_BOOTLOADER_CMD_HDR) + { + bootloader_task(); + } + + + /* Clear the bank */ + Usb_select_ep(EP_CMD_OUT); + if (CMD_OUT_Bank_Nb == 0 && Usb_rx_bank0_complete()) + { +#ifdef USB_TASK_DEBUG + printf ("USB: clear bank 0\n"); +#endif + Usb_clear_rx_bank0(); + CMD_OUT_Bank_Nb = 1; + } + else if(CMD_OUT_Bank_Nb == 1 && \ + Usb_rx_bank1_complete()) + { +#ifdef USB_TASK_DEBUG + printf ("USB: clear bank 1\n"); +#endif + Usb_clear_rx_bank1(); + CMD_OUT_Bank_Nb = 0; + } +#ifdef USB_TASK_DEBUG + else + { + printf ("USB: ERROR bank synchronisation\n"); + if (Usb_rx_bank1_complete()) + Usb_clear_rx_bank1(); + else + Usb_clear_rx_bank0(); + } +#endif + } + } +} + +/** + * Parse generic tux commands and process those addressed to the dongle. + */ +static void tux_command_parser (unsigned char* commands, unsigned char data_length) +{ + unsigned char i = 0; + + while (data_length > i) + { + + if (commands[i] == INFO_FUXUSB_CMD) + { + // VERSION_CMD + //------------------------------------- + FIFO_STT_put(info_version.version_cmd); + FIFO_STT_put(info_version.cpu_ver_maj); + FIFO_STT_put(info_version.ver_minor); + FIFO_STT_put(info_version.ver_update); + + // REVISION_CMD + //------------------------------------- + FIFO_STT_put(info_revision.revision_cmd); + FIFO_STT_put((info_revision.revision&0xFF00)>>8); + FIFO_STT_put((info_revision.revision&0x00FF)); + FIFO_STT_put(info_revision.release_type); + + // AUTHOR_CMD + //------------------------------------- + FIFO_STT_put(info_author.author_cmd); + FIFO_STT_put((info_author.author_id&0xFF00)>>8); + FIFO_STT_put((info_author.author_id&0x00FF)); + FIFO_STT_put(info_author.variation); + } + i+=4; + + } +} + +/*F************************************************************************** + * NAME: usb_command_parser + *---------------------------------------------------------------------------- + * PARAMS: + * delay: none + * return: none + *---------------------------------------------------------------------------- + * PURPOSE: + * This function initializes the USB controller and the associated variables. + *---------------------------------------------------------------------------- + * EXAMPLE: + *---------------------------------------------------------------------------- + * NOTE: + *---------------------------------------------------------------------------- + * REQUIREMENTS: + *****************************************************************************/ +static void usb_command_parser(void) +{ + + long tc; // R modif + + //-------------------------------------------------------------------------- + // Read Status from RF + //-------------------------------------------------------------------------- + if (USBCommand_ForDongle[0] == 0x01) + { + if (USBCommand_ForDongle[1] == 0x00) + { + if(USBCommand_ForDongle[2] == 0x00) + { + + // Read Status from RF + //////////////////////////////////////// + if(USBCommand_ForDongle[3] == 0x00) + { + //DEBUG_2 = 1; + USB_Status_NewCmd_Flag = TRUE; + //DEBUG_2 = 0; + } + // Complete reset + //////////////////////////////////////// + if(USBCommand_ForDongle[3] == 0xfe) + { + IEN0 = 0; + IEN1 = 0; + SPCON = 0x14; + tc=10000; + Usb_detach(); + while(tc) tc --; //tempo(TIMER_5_MS); + Usb_attach(); + WDTRST = 0x1E; + WDTRST = 0xE1; + while(1); + } + // Jump in ISP Mode + //////////////////////////////////////// + if(USBCommand_ForDongle[3] == 0xff) + { + //--------------------------- + IEN0 = 0; + IEN1 = 0; + SPCON = 0x14; + __api_clr_BLJB(); + __api_wr_SBV (0xF4); + tc=10000; + + Usb_detach(); + while(tc) tc --; //tempo(TIMER_5_MS); + Usb_attach(); + __api_start_bootloader(); + WDTRST = 0x1E; + WDTRST = 0xE1; + while(1); + } + } + } + } + //------------------------------------------------------------------------- + // Text To Speech + // + // USBCommand_ForDongle[1] == 0x01 Text To Speech Selected + // USBCommand_ForDongle[1] == 0x00 Text To Speech UnSelected + //------------------------------------------------------------------------- + if (USBCommand_ForDongle[0] == 0x02) + { + if (USBCommand_ForDongle[1] == 0x01) + Speaker_TTS_Select_Flag = 1; + + else if (USBCommand_ForDongle[1] == 0x00) + Speaker_TTS_Select_Flag = 0; + } +} + + Property changes on: firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.h (rev 0) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.h 2008-05-06 09:27:01 UTC (rev 1109) @@ -0,0 +1 @@ +void endpoints_ctr(void); Property changes on: firmware/fuxusb/branches/usb_cleanup/usb/usb_endpoints.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.c (rev 0) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.c 2008-05-06 09:27:01 UTC (rev 1109) @@ -0,0 +1,99 @@ +#include "global.h" +#include "config.h" +#include "usb/usb_misc.h" +#include "usb/usb_drv.h" +#include "usb/usb_enum.h" +#include "spi/spi_task.h" +#include "modules/fifo/fifo.h" +#include "modules/fifo/fifo_spk.h" +#include "modules/fifo/fifo_mic.h" +#include "modules/fifo_stt/fifo_stt.h" + +/** + * This function is used to resume the usb communication. + */ +void resume(void) +{ +#ifdef USB_TASK_DEBUG + printf(" Usb_resume \n"); +#endif + Usb_clear_suspend_clock(); + usb_connected_Flag = TRUE; + Usb_clear_suspend(); + Usb_clear_resume(); + Usb_clear_sof(); +} + +/** + * Suspend the usb bus. + */ +void suspend(void) +{ +#ifdef USB_TASK_DEBUG + printf(" Usb_suspend \n"); +#endif + usb_connected_Flag = FALSE; + Led_0_off(); + rf_reset_signal = 0; + Usb_clear_suspend(); + Usb_set_suspend_clock(); +} + +/** + * Reset the communication + */ +void reset(void) +{ +#ifdef USB_TASK_DEBUG + printf(" Usb_reset \n"); +#endif + Usb_clear_reset(); + usb_var_init(); + usb_connected_Flag = TRUE; + spi_task_init(); + FIFO_SPK_init(); + FIFO_MIC_init(); + FIFO_STT_init(); + Led_0_off(); + rf_reset_signal = 0; +} + + +void led_behavior(void) +{ + if(RF_OFFLINE) + { + if(RF_OFFLine_Back == 0) + { + Configure_led(0,LED_PORT_2MA); + usb_sof_counter = 0; + RF_OFFLine_Back = 1; + } + if (usb_sof_counter == 0x00) + Led_0_off(); + if (usb_sof_counter == 0x2FF) + Led_0_on(); + if (usb_sof_counter == 0x3FF) //==> Time Base = 1sec + usb_sof_counter = 0xFFFE; + + + } + else // RF ON Line + { + if(RF_OFFLine_Back == 1) + { + Configure_led(0,LED_PORT_10MA); + usb_sof_counter = 0; + RF_OFFLine_Back = 0; + } + { + if (usb_sof_counter == 0x00) + Led_0_off(); + if (usb_sof_counter == 0x10) + Led_0_on(); + if (usb_sof_counter == 0x20) //Time Base = 1sec + usb_sof_counter = 0xFFFE; + } + } +} + Property changes on: firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.h (rev 0) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.h 2008-05-06 09:27:01 UTC (rev 1109) @@ -0,0 +1,4 @@ +void resume(void); +void reset(void); +void suspend(void); +void led_behavior(void); Property changes on: firmware/fuxusb/branches/usb_cleanup/usb/usb_misc.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c 2008-05-06 09:18:01 UTC (rev 1108) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_task.c 2008-05-06 09:27:01 UTC (rev 1109) @@ -15,7 +15,9 @@ #include "rf.h" #include "spi\spi_lib.h" #include "usb\usb_drv.h" -#include "lib_mcu\fa-usb\flash_api.h" +#include "usb/usb_misc.h" +#include "usb/usb_endpoints.h" + #include "usb\usb_task.h" #include "spi\spi_task.h" #include "usb\usb_enum.h" @@ -191,160 +193,12 @@ -/*F************************************************************************** - * NAME: usb_command_parser - *---------------------------------------------------------------------------- - * PARAMS: - * delay: none - * return: none - *---------------------------------------------------------------------------- - * PURPOSE: - * This function initializes the USB controller and the associated variables. - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ -void usb_command_parser(void) -{ - long tc; // R modif - //-------------------------------------------------------------------------- - // Read Status from RF - //-------------------------------------------------------------------------- - if (USBCommand_ForDongle[0] == 0x01) - { - if (USBCommand_ForDongle[1] == 0x00) - { - if(USBCommand_ForDongle[2] == 0x00) - { - - // Read Status from RF - //////////////////////////////////////// - if(USBCommand_ForDongle[3] == 0x00) - { - //DEBUG_2 = 1; - USB_Status_NewCmd_Flag = TRUE; - //DEBUG_2 = 0; - } - // Complete reset - //////////////////////////////////////// - if(USBCommand_ForDongle[3] == 0xfe) - { - IEN0 = 0; - IEN1 = 0; - SPCON = 0x14; - tc=10000; - Usb_detach(); - while(tc) tc --; //tempo(TIMER_5_MS); - Usb_attach(); - WDTRST = 0x1E; - WDTRST = 0xE1; - while(1); - } - // Jump in ISP Mode - //////////////////////////////////////// - if(USBCommand_ForDongle[3] == 0xff) - { - //--------------------------- - IEN0 = 0; - IEN1 = 0; - SPCON = 0x14; - __api_clr_BLJB(); - __api_wr_SBV (0xF4); - tc=10000; - - Usb_detach(); - while(tc) tc --; //tempo(TIMER_5_MS); - Usb_attach(); - __api_start_bootloader(); - WDTRST = 0x1E; - WDTRST = 0xE1; - while(1); - } - } - } - } - //------------------------------------------------------------------------- - // Text To Speech - // - // USBCommand_ForDongle[1] == 0x01 Text To Speech Selected - // USBCommand_ForDongle[1] == 0x00 Text To Speech UnSelected - //------------------------------------------------------------------------- - if (USBCommand_ForDongle[0] == 0x02) - { - if (USBCommand_ForDongle[1] == 0x01) - Speaker_TTS_Select_Flag = 1; - - else if (USBCommand_ForDongle[1] == 0x00) - Speaker_TTS_Select_Flag = 0; - } -} - -/** - * Parse generic tux commands and process those addressed to the dongle. - */ -void tux_command_parser (unsigned char* commands, unsigned char data_length) -{ - unsigned char i = 0; - - while (data_length > i) - { - - if (commands[i] == INFO_FUXUSB_CMD) - { - // VERSION_CMD - //------------------------------------- - FIFO_STT_put(info_version.version_cmd); - FIFO_STT_put(info_version.cpu_ver_maj); - FIFO_STT_put(info_version.ver_minor); - FIFO_STT_put(info_version.ver_update); - - // REVISION_CMD - //------------------------------------- - FIFO_STT_put(info_revision.revision_cmd); - FIFO_STT_put((info_revision.revision&0xFF00)>>8); - FIFO_STT_put((info_revision.revision&0x00FF)); - FIFO_STT_put(info_revision.release_type); - - // AUTHOR_CMD - //------------------------------------- - FIFO_STT_put(info_author.author_cmd); - FIFO_STT_put((info_author.author_id&0xFF00)>>8); - FIFO_STT_put((info_author.author_id&0x00FF)); - FIFO_STT_put(info_author.variation); - } - i+=4; - - } -} - /*F************************************************************************** * NAME: usb_task *---------------------------------------------------------------------------- - * PARAMS: - * delay: none - * return: none - *---------------------------------------------------------------------------- * PURPOSE: - * This function manages the USB communication - *---------------------------------------------------------------------------- - * EXAMPLE: - *---------------------------------------------------------------------------- - * NOTE: - *---------------------------------------------------------------------------- - * REQUIREMENTS: - *****************************************************************************/ - - - -/*F************************************************************************** - * NAME: usb_task - *---------------------------------------------------------------------------- - * PURPOSE: * This part manages the USB communication *---------------------------------------------------------------------------- * NOTE: @@ -355,70 +209,16 @@ if (!usb_connected_Flag) { if (Usb_resume()) - { -#ifdef USB_TASK_DEBUG - printf(" Usb_resume \n"); -#endif - Usb_clear_suspend_clock(); - usb_connected_Flag = TRUE; - Usb_clear_suspend(); - Usb_clear_resume(); - Usb_clear_sof(); - //FIFO_SPK_init(); - //FIFO_MIC_init(); - //spi_task_init(); - } + resume(); } else { -//-------------------------------------------------------------------------- -// -// USB Suspend and Reset -// -//-------------------------------------------------------------------------- - if(USB_suspend_resume_reset()) - { -//-------------------------------------------------------------------------- -// -// USB Suspend -// -//-------------------------------------------------------------------------- - if (Usb_suspend()) - { -#ifdef USB_TASK_DEBUG - printf(" Usb_suspend \n"); -#endif - usb_connected_Flag = FALSE; - Led_0_off(); - rf_reset_signal = 0; - Usb_clear_suspend(); - Usb_set_suspend_clock(); - } + if (Usb_suspend()) + suspend(); -//-------------------------------------------------------------------------- -// USB Reset -//-------------------------------------------------------------------------- - if (Usb_reset()) - { -#ifdef USB_TASK_DEBUG - printf(" Usb_reset \n"); -#endif - Usb_clear_reset(); - usb_var_init(); - usb_connected_Flag = TRUE; - spi_task_init(); - FIFO_SPK_init(); - FIFO_MIC_init(); - FIFO_STT_init(); - Led_0_off(); - rf_reset_signal = 0; - } -} -//-------------------------------------------------------------------------- -// -// SOF Start of Frame (each ms) -// -//-------------------------------------------------------------------------- + if (Usb_reset()) + reset(); + if (Usb_sof()) { Usb_clear_sof(); @@ -428,9 +228,9 @@ { spi_watchdog_ctr--; // Decrement Watchdog } -//--------------------------------------------------------- -// Reset SPI Transfer -//--------------------------------------------------------- + //--------------------------------------------------------- + // Reset SPI Transfer + //--------------------------------------------------------- else if (!i2c_bootloading_Flag) { //Led_1_on(); @@ -442,68 +242,33 @@ spi_ready = 0; } -//-------------------------------------------------------------------------- -// I2C pause timer -//-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + // I2C pause timer + //-------------------------------------------------------------------------- if (i2c_wait_counter) i2c_wait_counter--; -//-------------------------------------------------------------------------- -// Led Behavior -//-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + // Led Behavior + //-------------------------------------------------------------------------- if(usb_connected_Flag && usb_configuration_nb) - { - if(RF_OFFLINE) - { - if(RF_OFFLine_Back == 0) - { - Configure_led(0,LED_PORT_2MA); - usb_sof_counter = 0; - RF_OFFLine_Back = 1; - } - if (usb_sof_counter == 0x00) - Led_0_off(); - if (usb_sof_counter == 0x2FF) - Led_0_on(); - if (usb_sof_counter == 0x3FF) //==> Time Base = 1sec - usb_sof_counter = 0xFFFE; - - - } - else // RF ON Line - { - if(RF_OFFLine_Back == 1) - { - Configure_led(0,LED_PORT_10MA); - usb_sof_counter = 0; - RF_OFFLine_Back = 0; - } - { - if (usb_sof_counter == 0x00) - Led_0_off(); - if (usb_sof_counter == 0x10) - Led_0_on(); - if (usb_sof_counter == 0x20) //Time Base = 1sec - usb_sof_counter = 0xFFFE; - } - } - } + led_behavior(); } -//-------------------------------------------------------------------------- -// -// Process to load Status Data in the USB FIFO -// -//-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + // + // Process to load Status Data in the USB FIFO + // + //-------------------------------------------------------------------------- usb_Satus_command_process_task(); usb_Bootloader_command_process_task(); -//-------------------------------------------------------------------------- -// -// Load the USB AUDIO IN FIFO -// -// Data got from FIFO_MIC -// -//-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + // + // Load the USB AUDIO IN FIFO + // + // Data got from FIFO_MIC + // + //-------------------------------------------------------------------------- if(!EP_AUDIOIN_Loaded) if(usb_configuration_nb) if(Fifoready_MIC) @@ -521,223 +286,14 @@ EP_AUDIOIN_Loaded = 1; } -//-------------------------------------------------------------------------- -// -// USB Events -// -//-------------------------------------------------------------------------- + //-------------------------------------------------------------------------- + // + // USB Events + // + //-------------------------------------------------------------------------- if(Usb_endpoint_interrupt()) - { - if (Usb_test_it_ep(EP_CMD_IN)) - { - Usb_select_ep(EP_CMD_IN); - if(Usb_tx_complete()) - { - Usb_clear_tx_complete(); - CMD_IN_Bank_Nb--; - if (CMD_IN_Bank_Nb<0) - CMD_IN_Bank_Nb = 0; - if (CMD_IN_Bank_Nb != 0) - Usb_set_tx_ready(); - } - } - -//-------------------------------------------------------------------------- -// -// Event on Control EndPoint -// -// -> Enumeration Process -// -//-------------------------------------------------------------------------- - if (Usb_test_it_ep(0)) - { - - Usb_select_ep(EP_CONTROL); - if (Usb_setup_received()) - { -#ifdef USB_TASK_DEBUG - printf("Go to Enum process\n"); -#endif - usb_enumeration_process(); - } - } - - -//-------------------------------------------------------------------------- -// -// Event on EP_AUDIO_OUT TTS EndPoint -// -// Data got from PC , Put it in the Speaker FIFO -// -// -//-------------------------------------------------------------------------- - if(Usb_test_it_ep(EP_AUDIO_OUT_TTS)) - { - - Usb_select_ep(EP_AUDIO_OUT_TTS); - - if(usb_get_nb_byte()) - if(Speaker_TTS_Select_Flag) - { - i=8; - do - { - // Use Only one Call to Get 8 Bytes - FIFO_SPK_put(Usb_read_byte()); - i--; - }while(i); - } - Usb_clear_rx(); - } - -//-------------------------------------------------------------------------- -// -// Event on EP_AUDIO_OUT EndPoint -// -// Data got from PC , Put it in the Speaker FIFO -// -// -//-------------------------------------------------------------------------- - if(Usb_test_it_ep(EP_AUDIO_OUT)) - { - //DEBUG_1 = 1; - Usb_select_ep(EP_AUDIO_OUT); - - if(usb_get_nb_byte()) - if(Speaker_TTS_Select_Flag==0) - { - i=8; - do - { - // Use Only one Call to Get 8 Bytes - FIFO_SPK_put(Usb_read_byte()); - i--; - }while(i); - } - Usb_clear_rx(); - //DEBUG_1 = 0; - } - -//-------------------------------------------------------------------------- -// -// Event on EP_AUDIO_IN EndPoint -// -// -> EP_AUDIOIN_Loaded = 0; -// -> Enable a new Loading of the USB FIFO -// -//-------------------------------------------------------------------------- - if(Usb_test_it_ep(EP_AUDIO_IN)) - { - Usb_select_ep(EP_AUDIO_IN); - if(Usb_tx_complete()) - { - Usb_clear_tx_complete(); - // -> Enable a new Loading of the FIFO - EP_AUDIOIN_Loaded = 0; - } - } - - -//-------------------------------------------------------------------------- -// -// Event on EP_CMD_OUT EndPoint -// -// -//-------------------------------------------------------------------------- - if(USB_ParserProcess_Permit_Flag) - { - if(Usb_test_it_ep(EP_CMD_OUT)) - { -#ifdef FIFO_DEBUG - printf("CMD OUT\n"); -#endif - if(!USBCommand_NewRequest_Flag) - { - //DEBUG_2 = 1; - Usb_select_ep(EP_CMD_OUT); - //DEBUG_2 = 0; - if(Usb_rx_complete()) - { - // Capture the number of Byte in USB FIFO - USBCommand_Ctr = usb_get_nb_byte(); - // Read the Header - USBCommand_Header = Usb_read_byte(); -//-------------------------------------------------------------------------- -// -// TUX CMD HEADER received -// -> Store Data in USBCommand_ForRF[] -// -> USBCommand_NewRequest_Flag = 1 -// to inform SPI_task that a new command is arrived -// -//-------------------------------------------------------------------------- - if(USBCommand_Header == LIBUSB_TUX_CMD_HDR) - { - if (!RF_OFFLINE) - USBCommand_NewRequest_Flag = 1; - for(i=0;i<(USBCommand_Ctr-1);i++) - USBCommand_ForRF[i] = Usb_read_byte(); - tux_command_parser(USBCommand_ForRF, \ - USBCommand_Ctr); - } - - /* - * DONGLE CMD HEADER received - */ - else if(USBCommand_Header == LIBUSB_DONGLE_CMD_HDR) - { - for(i=0;i<(USBCommand_Ctr-1);i++) - USBCommand_ForDongle[i] = Usb_read_byte(); -#ifdef FIFO_DEBUG - printf("usb command parser\n"); -#endif - usb_command_parser(); - /* Request processed */ - USBCommand_NewRequest_Flag = 0; - } - - /* - * BOOTLOADER HEADER received - */ - else if(USBCommand_Header == - LIBUSB_BOOTLOADER_CMD_HDR) - { - bootloader_task(); - } - - - /* Clear the bank */ - Usb_select_ep(EP_CMD_OUT); - if (CMD_OUT_Bank_Nb == 0 && Usb_rx_bank0_complete()) - { -#ifdef USB_TASK_DEBUG - printf ("USB: clear bank 0\n"); -#endif - Usb_clear_rx_bank0(); - CMD_OUT_Bank_Nb = 1; - } - else if(CMD_OUT_Bank_Nb == 1 && \ - Usb_rx_bank1_complete()) - { -#ifdef USB_TASK_DEBUG - printf ("USB: clear bank 1\n"); -#endif - Usb_clear_rx_bank1(); - CMD_OUT_Bank_Nb = 0; - } -#ifdef USB_TASK_DEBUG - else - { - printf ("USB: ERROR bank synchronisation\n"); - if (Usb_rx_bank1_complete()) - Usb_clear_rx_bank1(); - else - Usb_clear_rx_bank0(); - } -#endif - } - } - } - } //if(Usb_endpoint_interrupt()) + { + endpoints_ctr(); } } @@ -745,32 +301,11 @@ if(!usb_connected_Flag) return; -/*F************************************************************************** -* NAME: I2C_task -*---------------------------------------------------------------------------- -* PURPOSE: -* This part manages the I2C communication -*---------------------------------------------------------------------------- -* NOTE: -*****************************************************************************/ if (i2c_bootloading_Flag) /* I2C bootloading */ { i2c_task(); } - - - - -/*F************************************************************************** -* NAME: SPI_task -*---------------------------------------------------------------------------- -* PURPOSE: -* This part manages the SPI communication with THE RF -*---------------------------------------------------------------------------- -* NOTE: -*****************************************************************************/ - else if(!RF_OFFLINE) { spi_task(); Modified: firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h =================================================================== --- firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h 2008-05-06 09:18:01 UTC (rev 1108) +++ firmware/fuxusb/branches/usb_cleanup/usb/usb_task.h 2008-05-06 09:27:01 UTC (rev 1109) @@ -26,6 +26,8 @@ extern bit Cpu_reset; extern bit i2c_bootloading_Flag; +extern bit Speaker_TTS_Select_Flag; +extern bit EP_AUDIOIN_Loaded; void data_to_send(void); void usb_task_init (void); |