[tuxdroid-svn] r574 - firmware/fuxusb/trunk/modules/usb
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2007-10-02 16:52:58
|
Author: jaguarondi Date: 2007-10-02 18:50:42 +0200 (Tue, 02 Oct 2007) New Revision: 574 Modified: firmware/fuxusb/trunk/modules/usb/usb_task.c Log: * Added and improved debug messages. Modified: firmware/fuxusb/trunk/modules/usb/usb_task.c =================================================================== --- firmware/fuxusb/trunk/modules/usb/usb_task.c 2007-10-02 16:42:39 UTC (rev 573) +++ firmware/fuxusb/trunk/modules/usb/usb_task.c 2007-10-02 16:50:42 UTC (rev 574) @@ -3,7 +3,6 @@ #include "lib_mcu\spi\spi_lib.h" #include "lib_mcu\usb\usb_drv.h" -#include "lib_mcu\usb\uart_usb_lib.h" #include "lib_mcu\uart\uart_lib.h" #include "lib_mcu\fa-usb\flash_api.h" #include "modules\usb\usb_task.h" @@ -431,6 +430,10 @@ } else { +#ifdef USB_CMD_DEBUG + if(Usb_rx_complete()) + printf("LOOP: interrupt flags: %Bx\n", Usb_rx_complete()); +#endif //-------------------------------------------------------------------------- // // USB Suspend and Reset @@ -487,8 +490,8 @@ if (tx_data_ready == 1) { -#ifdef USB_TASK_DEBUG - printf ("HIDCommand Sent \n"); +#ifdef USB_CMD_DEBUG + printf ("USB: Status ready to be sent.\n"); #endif tx_data_ready = 2; Usb_select_ep(EP_CMD_IN); @@ -622,6 +625,9 @@ Usb_select_ep(EP_CMD_IN); if(Usb_tx_complete()) { +#ifdef USB_CMD_DEBUG + printf ("USB: Status sent.\n"); +#endif Usb_clear_tx_complete(); tx_data_ready = 0; //Led_1_off(); @@ -731,14 +737,21 @@ if(USB_ParserProcess_Permit_Flag) /* XXX should be removed from here */ if(Usb_test_it_ep(EP_CMD_OUT)) { + Usb_select_ep(EP_CMD_OUT); #ifdef USB_CMD_DEBUG - printf("Event on EP_CMD_OUT, data received:\n"); + printf("Event on EP_CMD_OUT, data received:\n"); + printf("EP_CMD_OUT interrupt flags: %Bx\n", Usb_rx_complete()); #endif - Usb_select_ep(EP_CMD_OUT); if(Usb_rx_complete()) { USBCommand_Ctr = usb_get_nb_byte(); // Capture the number of Byte in USB FIFO + /* Check that there's some data. */ + if (USBCommand_Ctr) + { USBCommand_Header = Usb_read_byte(); // Read the Header +#ifdef USB_CMD_DEBUG + printf("EP_CMD_OUT processing %Bd data.\n", USBCommand_Ctr); +#endif //-------------------------------------------------------------------------- // @@ -808,7 +821,7 @@ if (Command_FromUSB_bootload_cmd == BOOT_INIT) /* initialize a new page programming */ { #ifdef BOOTLOAD_DEBUG - printf ("\n Command_FromUSB_bootload_cmd == BOOT_INIT \n"); + printf ("\nBOOT_INIT\n"); #endif rf_reset_signal = 0; /* disables the RF module */ SPI_CSn = 0; /* clear CS to enter bootloader mode */ @@ -820,7 +833,7 @@ page_size = Usb_read_byte(); packets_per_page = Usb_read_byte(); #ifdef BOOTLOAD_DEBUG - printf (" blHeader.slave_address = %BX , page_size = %BX, packets_per_page = %BX \n",blHeader.slave_address,page_size,packets_per_page); + printf ("Slave address: %BX, Page size: %BX, Packets per page: %BX.\n",blHeader.slave_address,page_size,packets_per_page); #endif address_idx = 0; packet_idx = 0; @@ -830,7 +843,7 @@ { char tmp; #ifdef BOOTLOAD_DEBUG - printf (" Command_FromUSB_bootload_cmd == BOOT_EXIT \n"); + printf ("BOOT_EXIT\n"); #endif i2c_bootloading_Flag = 0; tmp = Usb_read_byte(); @@ -840,7 +853,7 @@ else if (Command_FromUSB_bootload_cmd == BOOT_FILLPAGE) /* read all packet data and add it to the page_data */ { #ifdef BOOTLOAD_DEBUG - printf (" Command_FromUSB_bootload_cmd == BOOT_FILLPAGE \n"); + printf ("BOOT_FILLPAGE\n"); #endif if (packet_idx == 0) /* get the address on the first packet */ { @@ -848,29 +861,45 @@ blHeader.page_address = blHeader.page_address << 8; blHeader.page_address += Usb_read_byte(); #ifdef BOOTLOAD_DEBUG - printf (" blHeader.page_address %x \n",blHeader.page_address); + printf ("Page address: %x, ",blHeader.page_address); + printf ("Address index: %Bx - %Bx\n", address_idx, address_idx + USBCommand_Ctr - 5); #endif for(i=0; i<(USBCommand_Ctr - 4); i++) blHeader.blData[address_idx++] = Usb_read_byte(); } else /* the other packets hold only data */ + { +#ifdef BOOTLOAD_DEBUG + printf ("Packet %Bd received, ", packet_idx); + printf ("Address index: %Bx - %Bx\n", address_idx, address_idx + USBCommand_Ctr - 3); +#endif for(i=0; i<(USBCommand_Ctr - 2); i++) blHeader.blData[address_idx++] = Usb_read_byte(); + } packet_idx++; } - if ((packet_idx == packets_per_page) && (address_idx == page_size)) /* last packet received and page completely filled */ + if (packet_idx == packets_per_page) /* last packet received and page completely filled */ { + if (address_idx == page_size) + { #ifdef BOOTLOAD_DEBUG - printf ("last packet received and page completely filled \n"); + printf ("Last packet received (%Bd), page filled. Now programming.\n", packet_idx); #endif address_idx = 0; packet_idx = 0; i2c_task_on_Flag = 1; + } + else + { +#ifdef BOOTLOAD_DEBUG + printf ("ERROR: expecting %Bd samples and received %Bd.\n", page_size, address_idx); +#endif + } } else if (packet_idx >= packets_per_page) { #ifdef BOOTLOAD_DEBUG - printf ("Error :: packet_idx >= packets_per_page \n"); + printf ("ERROR: packet_idx >= packets_per_page \n"); #endif /* TODO add an error return function on the USB */ } @@ -887,8 +916,13 @@ Usb_clear_rx_bank1(); } CMD_OUT_usb_Bank ^=1; - } + } +#ifdef USB_CMD_DEBUG + else + printf("ERROR: got EP OUT event but Usb_rx_complete returns false.\n"); + printf("END of EP_CMD_OUT, interrupt flags: %Bx\n", Usb_rx_complete()); +#endif } /* if(Usb_test_it_ep(EP_CMD_OUT)) */ } /* if(Usb_endpoint_interrupt()) */ } /* if (!usb_connected_Flag) */ |